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