| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_ISOLATE_H_ | 5 #ifndef V8_ISOLATE_H_ |
| 6 #define V8_ISOLATE_H_ | 6 #define V8_ISOLATE_H_ |
| 7 | 7 |
| 8 #include "include/v8-debug.h" | 8 #include "include/v8-debug.h" |
| 9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
| 10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 enum AddressId { | 440 enum AddressId { |
| 441 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, | 441 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, |
| 442 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) | 442 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) |
| 443 #undef DECLARE_ENUM | 443 #undef DECLARE_ENUM |
| 444 kIsolateAddressCount | 444 kIsolateAddressCount |
| 445 }; | 445 }; |
| 446 | 446 |
| 447 // Returns the PerIsolateThreadData for the current thread (or NULL if one is | 447 // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 448 // not currently set). | 448 // not currently set). |
| 449 static PerIsolateThreadData* CurrentPerIsolateThreadData() { | 449 static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 450 EnsureInitialized(); |
| 450 return reinterpret_cast<PerIsolateThreadData*>( | 451 return reinterpret_cast<PerIsolateThreadData*>( |
| 451 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); | 452 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
| 452 } | 453 } |
| 453 | 454 |
| 454 // Returns the isolate inside which the current thread is running. | 455 // Returns the isolate inside which the current thread is running. |
| 455 INLINE(static Isolate* Current()) { | 456 INLINE(static Isolate* Current()) { |
| 457 EnsureInitialized(); |
| 456 Isolate* isolate = reinterpret_cast<Isolate*>( | 458 Isolate* isolate = reinterpret_cast<Isolate*>( |
| 457 base::Thread::GetExistingThreadLocal(isolate_key_)); | 459 base::Thread::GetExistingThreadLocal(isolate_key_)); |
| 458 ASSERT(isolate != NULL); | 460 ASSERT(isolate != NULL); |
| 459 return isolate; | 461 return isolate; |
| 460 } | 462 } |
| 461 | 463 |
| 462 INLINE(static Isolate* UncheckedCurrent()) { | 464 INLINE(static Isolate* UncheckedCurrent()) { |
| 465 EnsureInitialized(); |
| 463 return reinterpret_cast<Isolate*>( | 466 return reinterpret_cast<Isolate*>( |
| 464 base::Thread::GetThreadLocal(isolate_key_)); | 467 base::Thread::GetThreadLocal(isolate_key_)); |
| 465 } | 468 } |
| 469 |
| 470 // Like UncheckedCurrent, but skips the check that |isolate_key_| was |
| 471 // initialized. Callers have to ensure that themselves. |
| 472 INLINE(static Isolate* UnsafeCurrent()) { |
| 473 return reinterpret_cast<Isolate*>( |
| 474 base::Thread::GetThreadLocal(isolate_key_)); |
| 475 } |
| 466 | 476 |
| 467 // Usually called by Init(), but can be called early e.g. to allow | 477 // Usually called by Init(), but can be called early e.g. to allow |
| 468 // testing components that require logging but not the whole | 478 // testing components that require logging but not the whole |
| 469 // isolate. | 479 // isolate. |
| 470 // | 480 // |
| 471 // Safe to call more than once. | 481 // Safe to call more than once. |
| 472 void InitializeLoggingAndCounters(); | 482 void InitializeLoggingAndCounters(); |
| 473 | 483 |
| 474 bool Init(Deserializer* des); | 484 bool Init(Deserializer* des); |
| 475 | 485 |
| 476 bool IsInitialized() { return state_ == INITIALIZED; } | 486 bool IsInitialized() { return state_ == INITIALIZED; } |
| 477 | 487 |
| 478 // True if at least one thread Enter'ed this isolate. | 488 // True if at least one thread Enter'ed this isolate. |
| 479 bool IsInUse() { return entry_stack_ != NULL; } | 489 bool IsInUse() { return entry_stack_ != NULL; } |
| 480 | 490 |
| 481 // Destroys the non-default isolates. | 491 // Destroys the non-default isolates. |
| 482 // Sets default isolate into "has_been_disposed" state rather then destroying, | 492 // Sets default isolate into "has_been_disposed" state rather then destroying, |
| 483 // for legacy API reasons. | 493 // for legacy API reasons. |
| 484 void TearDown(); | 494 void TearDown(); |
| 485 | 495 |
| 486 static void GlobalTearDown(); | 496 static void GlobalTearDown(); |
| 487 | 497 |
| 488 static void SetCrashIfDefaultIsolateInitialized(); | |
| 489 // Ensures that process-wide resources and the default isolate have been | |
| 490 // allocated. It is only necessary to call this method in rare cases, for | |
| 491 // example if you are using V8 from within the body of a static initializer. | |
| 492 // Safe to call multiple times. | |
| 493 static void EnsureDefaultIsolate(); | |
| 494 | |
| 495 // Find the PerThread for this particular (isolate, thread) combination | 498 // Find the PerThread for this particular (isolate, thread) combination |
| 496 // If one does not yet exist, return null. | 499 // If one does not yet exist, return null. |
| 497 PerIsolateThreadData* FindPerThreadDataForThisThread(); | 500 PerIsolateThreadData* FindPerThreadDataForThisThread(); |
| 498 | 501 |
| 499 // Find the PerThread for given (isolate, thread) combination | 502 // Find the PerThread for given (isolate, thread) combination |
| 500 // If one does not yet exist, return null. | 503 // If one does not yet exist, return null. |
| 501 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); | 504 PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id); |
| 502 | 505 |
| 503 // Returns the key used to store the pointer to the current isolate. | 506 // Returns the key used to store the pointer to the current isolate. |
| 504 // Used internally for V8 threads that do not execute JavaScript but still | 507 // Used internally for V8 threads that do not execute JavaScript but still |
| 505 // are part of the domain of an isolate (like the context switcher). | 508 // are part of the domain of an isolate (like the context switcher). |
| 506 static base::Thread::LocalStorageKey isolate_key() { | 509 static base::Thread::LocalStorageKey isolate_key() { |
| 510 EnsureInitialized(); |
| 507 return isolate_key_; | 511 return isolate_key_; |
| 508 } | 512 } |
| 509 | 513 |
| 510 // Returns the key used to store process-wide thread IDs. | 514 // Returns the key used to store process-wide thread IDs. |
| 511 static base::Thread::LocalStorageKey thread_id_key() { | 515 static base::Thread::LocalStorageKey thread_id_key() { |
| 516 EnsureInitialized(); |
| 512 return thread_id_key_; | 517 return thread_id_key_; |
| 513 } | 518 } |
| 514 | 519 |
| 515 static base::Thread::LocalStorageKey per_isolate_thread_data_key(); | 520 static base::Thread::LocalStorageKey per_isolate_thread_data_key(); |
| 516 | 521 |
| 517 // Mutex for serializing access to break control structures. | 522 // Mutex for serializing access to break control structures. |
| 518 base::RecursiveMutex* break_access() { return &break_access_; } | 523 base::RecursiveMutex* break_access() { return &break_access_; } |
| 519 | 524 |
| 520 Address get_address_from_id(AddressId id); | 525 Address get_address_from_id(AddressId id); |
| 521 | 526 |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 void RemoveCallCompletedCallback(CallCompletedCallback callback); | 1087 void RemoveCallCompletedCallback(CallCompletedCallback callback); |
| 1083 void FireCallCompletedCallback(); | 1088 void FireCallCompletedCallback(); |
| 1084 | 1089 |
| 1085 void EnqueueMicrotask(Handle<Object> microtask); | 1090 void EnqueueMicrotask(Handle<Object> microtask); |
| 1086 void RunMicrotasks(); | 1091 void RunMicrotasks(); |
| 1087 | 1092 |
| 1088 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); | 1093 void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); |
| 1089 void CountUsage(v8::Isolate::UseCounterFeature feature); | 1094 void CountUsage(v8::Isolate::UseCounterFeature feature); |
| 1090 | 1095 |
| 1091 private: | 1096 private: |
| 1097 static void EnsureInitialized(); |
| 1098 |
| 1092 Isolate(); | 1099 Isolate(); |
| 1093 | 1100 |
| 1094 friend struct GlobalState; | 1101 friend struct GlobalState; |
| 1095 friend struct InitializeGlobalState; | 1102 friend struct InitializeGlobalState; |
| 1096 | 1103 |
| 1097 enum State { | 1104 enum State { |
| 1098 UNINITIALIZED, // Some components may not have been allocated. | 1105 UNINITIALIZED, // Some components may not have been allocated. |
| 1099 INITIALIZED // All components are fully initialized. | 1106 INITIALIZED // All components are fully initialized. |
| 1100 }; | 1107 }; |
| 1101 | 1108 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 int entry_count; | 1148 int entry_count; |
| 1142 PerIsolateThreadData* previous_thread_data; | 1149 PerIsolateThreadData* previous_thread_data; |
| 1143 Isolate* previous_isolate; | 1150 Isolate* previous_isolate; |
| 1144 EntryStackItem* previous_item; | 1151 EntryStackItem* previous_item; |
| 1145 | 1152 |
| 1146 private: | 1153 private: |
| 1147 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); | 1154 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1148 }; | 1155 }; |
| 1149 | 1156 |
| 1150 // This mutex protects highest_thread_id_ and thread_data_table_. | 1157 // This mutex protects highest_thread_id_ and thread_data_table_. |
| 1151 static base::Mutex process_wide_mutex_; | 1158 static base::LazyMutex process_wide_mutex_; |
| 1152 | 1159 |
| 1153 static base::Thread::LocalStorageKey per_isolate_thread_data_key_; | 1160 static base::Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1154 static base::Thread::LocalStorageKey isolate_key_; | 1161 static base::Thread::LocalStorageKey isolate_key_; |
| 1155 static base::Thread::LocalStorageKey thread_id_key_; | 1162 static base::Thread::LocalStorageKey thread_id_key_; |
| 1156 static ThreadDataTable* thread_data_table_; | 1163 static ThreadDataTable* thread_data_table_; |
| 1157 | 1164 |
| 1158 // A global counter for all generated Isolates, might overflow. | 1165 // A global counter for all generated Isolates, might overflow. |
| 1159 static base::Atomic32 isolate_counter_; | 1166 static base::Atomic32 isolate_counter_; |
| 1160 | 1167 |
| 1161 void Deinit(); | 1168 void Deinit(); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 } | 1521 } |
| 1515 | 1522 |
| 1516 EmbeddedVector<char, 128> filename_; | 1523 EmbeddedVector<char, 128> filename_; |
| 1517 FILE* file_; | 1524 FILE* file_; |
| 1518 int scope_depth_; | 1525 int scope_depth_; |
| 1519 }; | 1526 }; |
| 1520 | 1527 |
| 1521 } } // namespace v8::internal | 1528 } } // namespace v8::internal |
| 1522 | 1529 |
| 1523 #endif // V8_ISOLATE_H_ | 1530 #endif // V8_ISOLATE_H_ |
| OLD | NEW |