| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 ISOLATE_DEBUGGER_INIT_LIST(V) | 355 ISOLATE_DEBUGGER_INIT_LIST(V) |
| 356 | 356 |
| 357 class Isolate { | 357 class Isolate { |
| 358 // These forward declarations are required to make the friend declarations in | 358 // These forward declarations are required to make the friend declarations in |
| 359 // PerIsolateThreadData work on some older versions of gcc. | 359 // PerIsolateThreadData work on some older versions of gcc. |
| 360 class ThreadDataTable; | 360 class ThreadDataTable; |
| 361 class EntryStackItem; | 361 class EntryStackItem; |
| 362 public: | 362 public: |
| 363 ~Isolate(); | 363 ~Isolate(); |
| 364 | 364 |
| 365 // Must be called during v8 initialization. |
| 366 static void GlobalSetup(); |
| 367 |
| 365 // A thread has a PerIsolateThreadData instance for each isolate that it has | 368 // A thread has a PerIsolateThreadData instance for each isolate that it has |
| 366 // entered. That instance is allocated when the isolate is initially entered | 369 // entered. That instance is allocated when the isolate is initially entered |
| 367 // and reused on subsequent entries. | 370 // and reused on subsequent entries. |
| 368 class PerIsolateThreadData { | 371 class PerIsolateThreadData { |
| 369 public: | 372 public: |
| 370 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) | 373 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) |
| 371 : isolate_(isolate), | 374 : isolate_(isolate), |
| 372 thread_id_(thread_id), | 375 thread_id_(thread_id), |
| 373 stack_limit_(0), | 376 stack_limit_(0), |
| 374 thread_state_(NULL), | 377 thread_state_(NULL), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, | 426 #define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address, |
| 424 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) | 427 FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM) |
| 425 #undef C | 428 #undef C |
| 426 kIsolateAddressCount | 429 kIsolateAddressCount |
| 427 }; | 430 }; |
| 428 | 431 |
| 429 // Returns the PerIsolateThreadData for the current thread (or NULL if one is | 432 // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 430 // not currently set). | 433 // not currently set). |
| 431 static PerIsolateThreadData* CurrentPerIsolateThreadData() { | 434 static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 432 return reinterpret_cast<PerIsolateThreadData*>( | 435 return reinterpret_cast<PerIsolateThreadData*>( |
| 433 Thread::GetThreadLocal(per_isolate_thread_data_key())); | 436 Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
| 434 } | 437 } |
| 435 | 438 |
| 436 // Returns the isolate inside which the current thread is running. | 439 // Returns the isolate inside which the current thread is running. |
| 437 INLINE(static Isolate* Current()) { | 440 INLINE(static Isolate* Current()) { |
| 438 const Thread::LocalStorageKey key = isolate_key(); | |
| 439 Isolate* isolate = reinterpret_cast<Isolate*>( | 441 Isolate* isolate = reinterpret_cast<Isolate*>( |
| 440 Thread::GetExistingThreadLocal(key)); | 442 Thread::GetExistingThreadLocal(isolate_key_)); |
| 441 if (!isolate) { | |
| 442 EnsureDefaultIsolate(); | |
| 443 isolate = reinterpret_cast<Isolate*>( | |
| 444 Thread::GetExistingThreadLocal(key)); | |
| 445 } | |
| 446 ASSERT(isolate != NULL); | 443 ASSERT(isolate != NULL); |
| 447 return isolate; | 444 return isolate; |
| 448 } | 445 } |
| 449 | 446 |
| 450 INLINE(static Isolate* UncheckedCurrent()) { | 447 INLINE(static Isolate* UncheckedCurrent()) { |
| 451 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key())); | 448 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_)); |
| 452 } | 449 } |
| 453 | 450 |
| 454 // Usually called by Init(), but can be called early e.g. to allow | 451 // Usually called by Init(), but can be called early e.g. to allow |
| 455 // testing components that require logging but not the whole | 452 // testing components that require logging but not the whole |
| 456 // isolate. | 453 // isolate. |
| 457 // | 454 // |
| 458 // Safe to call more than once. | 455 // Safe to call more than once. |
| 459 void InitializeLoggingAndCounters(); | 456 void InitializeLoggingAndCounters(); |
| 460 | 457 |
| 461 bool Init(Deserializer* des); | 458 bool Init(Deserializer* des); |
| 462 | 459 |
| 463 bool IsInitialized() { return state_ == INITIALIZED; } | 460 bool IsInitialized() { return state_ == INITIALIZED; } |
| 464 | 461 |
| 465 // True if at least one thread Enter'ed this isolate. | 462 // True if at least one thread Enter'ed this isolate. |
| 466 bool IsInUse() { return entry_stack_ != NULL; } | 463 bool IsInUse() { return entry_stack_ != NULL; } |
| 467 | 464 |
| 468 // Destroys the non-default isolates. | 465 // Destroys the non-default isolates. |
| 469 // Sets default isolate into "has_been_disposed" state rather then destroying, | 466 // Sets default isolate into "has_been_disposed" state rather then destroying, |
| 470 // for legacy API reasons. | 467 // for legacy API reasons. |
| 471 void TearDown(); | 468 void TearDown(); |
| 472 | 469 |
| 473 bool IsDefaultIsolate() const; | 470 bool IsDefaultIsolate() const { return this == default_isolate_; } |
| 474 | 471 |
| 475 // Ensures that process-wide resources and the default isolate have been | 472 // 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 | 473 // 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. | 474 // example if you are using V8 from within the body of a static initializer. |
| 478 // Safe to call multiple times. | 475 // Safe to call multiple times. |
| 479 static void EnsureDefaultIsolate(); | 476 static void EnsureDefaultIsolate(); |
| 480 | 477 |
| 481 // Find the PerThread for this particular (isolate, thread) combination | 478 // Find the PerThread for this particular (isolate, thread) combination |
| 482 // If one does not yet exist, return null. | 479 // If one does not yet exist, return null. |
| 483 PerIsolateThreadData* FindPerThreadDataForThisThread(); | 480 PerIsolateThreadData* FindPerThreadDataForThisThread(); |
| 484 | 481 |
| 485 #ifdef ENABLE_DEBUGGER_SUPPORT | 482 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 486 // Get the debugger from the default isolate. Preinitializes the | 483 // Get the debugger from the default isolate. Preinitializes the |
| 487 // default isolate if needed. | 484 // default isolate if needed. |
| 488 static Debugger* GetDefaultIsolateDebugger(); | 485 static Debugger* GetDefaultIsolateDebugger(); |
| 489 #endif | 486 #endif |
| 490 | 487 |
| 491 // Get the stack guard from the default isolate. Preinitializes the | 488 // Get the stack guard from the default isolate. Preinitializes the |
| 492 // default isolate if needed. | 489 // default isolate if needed. |
| 493 static StackGuard* GetDefaultIsolateStackGuard(); | 490 static StackGuard* GetDefaultIsolateStackGuard(); |
| 494 | 491 |
| 495 // Returns the key used to store the pointer to the current isolate. | 492 // 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 | 493 // 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). | 494 // are part of the domain of an isolate (like the context switcher). |
| 498 static Thread::LocalStorageKey isolate_key(); | 495 static Thread::LocalStorageKey isolate_key() { |
| 496 return isolate_key_; |
| 497 } |
| 499 | 498 |
| 500 // Returns the key used to store process-wide thread IDs. | 499 // Returns the key used to store process-wide thread IDs. |
| 501 static Thread::LocalStorageKey thread_id_key(); | 500 static Thread::LocalStorageKey thread_id_key() { |
| 501 return thread_id_key_; |
| 502 } |
| 502 | 503 |
| 503 static Thread::LocalStorageKey per_isolate_thread_data_key(); | 504 static Thread::LocalStorageKey per_isolate_thread_data_key(); |
| 504 | 505 |
| 505 // If a client attempts to create a Locker without specifying an isolate, | 506 // 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 | 507 // 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 | 508 // thread to be inside the implicit isolate (or fail a check if we have |
| 508 // switched to non-legacy behavior). | 509 // switched to non-legacy behavior). |
| 509 static void EnterDefaultIsolate(); | 510 static void EnterDefaultIsolate(); |
| 510 | 511 |
| 511 // Mutex for serializing access to break control structures. | 512 // Mutex for serializing access to break control structures. |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 | 1076 |
| 1076 int entry_count; | 1077 int entry_count; |
| 1077 PerIsolateThreadData* previous_thread_data; | 1078 PerIsolateThreadData* previous_thread_data; |
| 1078 Isolate* previous_isolate; | 1079 Isolate* previous_isolate; |
| 1079 EntryStackItem* previous_item; | 1080 EntryStackItem* previous_item; |
| 1080 | 1081 |
| 1081 private: | 1082 private: |
| 1082 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); | 1083 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1083 }; | 1084 }; |
| 1084 | 1085 |
| 1086 // This mutex protects highest_thread_id_, thread_data_table_ and |
| 1087 // default_isolate_. |
| 1088 static Mutex* process_wide_mutex_; |
| 1089 |
| 1090 static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1091 static Thread::LocalStorageKey isolate_key_; |
| 1092 static Thread::LocalStorageKey thread_id_key_; |
| 1093 static Isolate* default_isolate_; |
| 1094 static ThreadDataTable* thread_data_table_; |
| 1095 |
| 1085 void Deinit(); | 1096 void Deinit(); |
| 1086 | 1097 |
| 1087 static void SetIsolateThreadLocals(Isolate* isolate, | 1098 static void SetIsolateThreadLocals(Isolate* isolate, |
| 1088 PerIsolateThreadData* data); | 1099 PerIsolateThreadData* data); |
| 1089 | 1100 |
| 1090 enum State { | 1101 enum State { |
| 1091 UNINITIALIZED, // Some components may not have been allocated. | 1102 UNINITIALIZED, // Some components may not have been allocated. |
| 1092 INITIALIZED // All components are fully initialized. | 1103 INITIALIZED // All components are fully initialized. |
| 1093 }; | 1104 }; |
| 1094 | 1105 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 | 1409 |
| 1399 // Mark the global context with out of memory. | 1410 // Mark the global context with out of memory. |
| 1400 inline void Context::mark_out_of_memory() { | 1411 inline void Context::mark_out_of_memory() { |
| 1401 global_context()->set_out_of_memory(HEAP->true_value()); | 1412 global_context()->set_out_of_memory(HEAP->true_value()); |
| 1402 } | 1413 } |
| 1403 | 1414 |
| 1404 | 1415 |
| 1405 } } // namespace v8::internal | 1416 } } // namespace v8::internal |
| 1406 | 1417 |
| 1407 #endif // V8_ISOLATE_H_ | 1418 #endif // V8_ISOLATE_H_ |
| OLD | NEW |