| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, | 423 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, |
| 424 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) | 424 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) |
| 425 #undef C | 425 #undef C |
| 426 kIsolateAddressCount | 426 kIsolateAddressCount |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 // Returns the PerIsolateThreadData for the current thread (or NULL if one is | 429 // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 430 // not currently set). | 430 // not currently set). |
| 431 static PerIsolateThreadData* CurrentPerIsolateThreadData() { | 431 static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 432 return reinterpret_cast<PerIsolateThreadData*>( | 432 return reinterpret_cast<PerIsolateThreadData*>( |
| 433 Thread::GetThreadLocal(per_isolate_thread_data_key())); | 433 Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 // Returns the isolate inside which the current thread is running. | 436 // Returns the isolate inside which the current thread is running. |
| 437 INLINE(static Isolate* Current()) { | 437 INLINE(static Isolate* Current()) { |
| 438 const Thread::LocalStorageKey key = isolate_key(); | |
| 439 Isolate* isolate = reinterpret_cast<Isolate*>( | 438 Isolate* isolate = reinterpret_cast<Isolate*>( |
| 440 Thread::GetExistingThreadLocal(key)); | 439 Thread::GetExistingThreadLocal(isolate_key_)); |
| 441 if (!isolate) { | |
| 442 EnsureDefaultIsolate(); | |
| 443 isolate = reinterpret_cast<Isolate*>( | |
| 444 Thread::GetExistingThreadLocal(key)); | |
| 445 } | |
| 446 ASSERT(isolate != NULL); | 440 ASSERT(isolate != NULL); |
| 447 return isolate; | 441 return isolate; |
| 448 } | 442 } |
| 449 | 443 |
| 450 INLINE(static Isolate* UncheckedCurrent()) { | 444 INLINE(static Isolate* UncheckedCurrent()) { |
| 451 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key())); | 445 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_)); |
| 452 } | 446 } |
| 453 | 447 |
| 454 // Usually called by Init(), but can be called early e.g. to allow | 448 // Usually called by Init(), but can be called early e.g. to allow |
| 455 // testing components that require logging but not the whole | 449 // testing components that require logging but not the whole |
| 456 // isolate. | 450 // isolate. |
| 457 // | 451 // |
| 458 // Safe to call more than once. | 452 // Safe to call more than once. |
| 459 void InitializeLoggingAndCounters(); | 453 void InitializeLoggingAndCounters(); |
| 460 | 454 |
| 461 bool Init(Deserializer* des); | 455 bool Init(Deserializer* des); |
| 462 | 456 |
| 463 bool IsInitialized() { return state_ == INITIALIZED; } | 457 bool IsInitialized() { return state_ == INITIALIZED; } |
| 464 | 458 |
| 465 // True if at least one thread Enter'ed this isolate. | 459 // True if at least one thread Enter'ed this isolate. |
| 466 bool IsInUse() { return entry_stack_ != NULL; } | 460 bool IsInUse() { return entry_stack_ != NULL; } |
| 467 | 461 |
| 468 // Destroys the non-default isolates. | 462 // Destroys the non-default isolates. |
| 469 // Sets default isolate into "has_been_disposed" state rather then destroying, | 463 // Sets default isolate into "has_been_disposed" state rather then destroying, |
| 470 // for legacy API reasons. | 464 // for legacy API reasons. |
| 471 void TearDown(); | 465 void TearDown(); |
| 472 | 466 |
| 473 bool IsDefaultIsolate() const; | 467 bool IsDefaultIsolate() const { return this == default_isolate_; } |
| 474 | 468 |
| 475 // Ensures that process-wide resources and the default isolate have been | 469 // Ensures that process-wide resources and the default isolate have been |
| 476 // allocated. It is only necessary to call this method in rare cases, for | 470 // allocated. It is only necessary to call this method in rare cases, for |
| 477 // example if you are using V8 from within the body of a static initializer. | 471 // example if you are using V8 from within the body of a static initializer. |
| 478 // Safe to call multiple times. | 472 // Safe to call multiple times. |
| 479 static void EnsureDefaultIsolate(); | 473 static void EnsureDefaultIsolate(); |
| 480 | 474 |
| 481 // Find the PerThread for this particular (isolate, thread) combination | 475 // Find the PerThread for this particular (isolate, thread) combination |
| 482 // If one does not yet exist, return null. | 476 // If one does not yet exist, return null. |
| 483 PerIsolateThreadData* FindPerThreadDataForThisThread(); | 477 PerIsolateThreadData* FindPerThreadDataForThisThread(); |
| 484 | 478 |
| 485 #ifdef ENABLE_DEBUGGER_SUPPORT | 479 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 486 // Get the debugger from the default isolate. Preinitializes the | 480 // Get the debugger from the default isolate. Preinitializes the |
| 487 // default isolate if needed. | 481 // default isolate if needed. |
| 488 static Debugger* GetDefaultIsolateDebugger(); | 482 static Debugger* GetDefaultIsolateDebugger(); |
| 489 #endif | 483 #endif |
| 490 | 484 |
| 491 // Get the stack guard from the default isolate. Preinitializes the | 485 // Get the stack guard from the default isolate. Preinitializes the |
| 492 // default isolate if needed. | 486 // default isolate if needed. |
| 493 static StackGuard* GetDefaultIsolateStackGuard(); | 487 static StackGuard* GetDefaultIsolateStackGuard(); |
| 494 | 488 |
| 495 // Returns the key used to store the pointer to the current isolate. | 489 // Returns the key used to store the pointer to the current isolate. |
| 496 // Used internally for V8 threads that do not execute JavaScript but still | 490 // Used internally for V8 threads that do not execute JavaScript but still |
| 497 // are part of the domain of an isolate (like the context switcher). | 491 // are part of the domain of an isolate (like the context switcher). |
| 498 static Thread::LocalStorageKey isolate_key(); | 492 static Thread::LocalStorageKey isolate_key() { |
| 493 return isolate_key_; |
| 494 } |
| 499 | 495 |
| 500 // Returns the key used to store process-wide thread IDs. | 496 // Returns the key used to store process-wide thread IDs. |
| 501 static Thread::LocalStorageKey thread_id_key(); | 497 static Thread::LocalStorageKey thread_id_key() { |
| 498 return thread_id_key_; |
| 499 } |
| 502 | 500 |
| 503 static Thread::LocalStorageKey per_isolate_thread_data_key(); | 501 static Thread::LocalStorageKey per_isolate_thread_data_key(); |
| 504 | 502 |
| 505 // If a client attempts to create a Locker without specifying an isolate, | 503 // If a client attempts to create a Locker without specifying an isolate, |
| 506 // we assume that the client is using legacy behavior. Set up the current | 504 // we assume that the client is using legacy behavior. Set up the current |
| 507 // thread to be inside the implicit isolate (or fail a check if we have | 505 // thread to be inside the implicit isolate (or fail a check if we have |
| 508 // switched to non-legacy behavior). | 506 // switched to non-legacy behavior). |
| 509 static void EnterDefaultIsolate(); | 507 static void EnterDefaultIsolate(); |
| 510 | 508 |
| 511 // Mutex for serializing access to break control structures. | 509 // Mutex for serializing access to break control structures. |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 | 1073 |
| 1076 int entry_count; | 1074 int entry_count; |
| 1077 PerIsolateThreadData* previous_thread_data; | 1075 PerIsolateThreadData* previous_thread_data; |
| 1078 Isolate* previous_isolate; | 1076 Isolate* previous_isolate; |
| 1079 EntryStackItem* previous_item; | 1077 EntryStackItem* previous_item; |
| 1080 | 1078 |
| 1081 private: | 1079 private: |
| 1082 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); | 1080 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1083 }; | 1081 }; |
| 1084 | 1082 |
| 1083 // This mutex protects highest_thread_id_, thread_data_table_ and |
| 1084 // default_isolate_. |
| 1085 static Mutex* process_wide_mutex_; |
| 1086 |
| 1087 static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1088 static Thread::LocalStorageKey isolate_key_; |
| 1089 static Thread::LocalStorageKey thread_id_key_; |
| 1090 static Isolate* default_isolate_; |
| 1091 static ThreadDataTable* thread_data_table_; |
| 1092 |
| 1085 void Deinit(); | 1093 void Deinit(); |
| 1086 | 1094 |
| 1087 static void SetIsolateThreadLocals(Isolate* isolate, | 1095 static void SetIsolateThreadLocals(Isolate* isolate, |
| 1088 PerIsolateThreadData* data); | 1096 PerIsolateThreadData* data); |
| 1089 | 1097 |
| 1090 enum State { | 1098 enum State { |
| 1091 UNINITIALIZED, // Some components may not have been allocated. | 1099 UNINITIALIZED, // Some components may not have been allocated. |
| 1092 INITIALIZED // All components are fully initialized. | 1100 INITIALIZED // All components are fully initialized. |
| 1093 }; | 1101 }; |
| 1094 | 1102 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 | 1406 |
| 1399 // Mark the global context with out of memory. | 1407 // Mark the global context with out of memory. |
| 1400 inline void Context::mark_out_of_memory() { | 1408 inline void Context::mark_out_of_memory() { |
| 1401 global_context()->set_out_of_memory(HEAP->true_value()); | 1409 global_context()->set_out_of_memory(HEAP->true_value()); |
| 1402 } | 1410 } |
| 1403 | 1411 |
| 1404 | 1412 |
| 1405 } } // namespace v8::internal | 1413 } } // namespace v8::internal |
| 1406 | 1414 |
| 1407 #endif // V8_ISOLATE_H_ | 1415 #endif // V8_ISOLATE_H_ |
| OLD | NEW |