| 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 C | 443 #undef C |
| 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 return reinterpret_cast<PerIsolateThreadData*>( | 450 return reinterpret_cast<PerIsolateThreadData*>( |
| 451 Thread::GetThreadLocal(per_isolate_thread_data_key_)); | 451 Thread::GetThreadLocal(per_isolate_thread_data_key())); |
| 452 } | 452 } |
| 453 | 453 |
| 454 // Returns the isolate inside which the current thread is running. | 454 // Returns the isolate inside which the current thread is running. |
| 455 INLINE(static Isolate* Current()) { | 455 INLINE(static Isolate* Current()) { |
| 456 Isolate* isolate = reinterpret_cast<Isolate*>( | 456 Isolate* isolate = reinterpret_cast<Isolate*>( |
| 457 Thread::GetExistingThreadLocal(isolate_key_)); | 457 Thread::GetExistingThreadLocal(isolate_key())); |
| 458 ASSERT(isolate != NULL); | 458 ASSERT(isolate != NULL); |
| 459 return isolate; | 459 return isolate; |
| 460 } | 460 } |
| 461 | 461 |
| 462 INLINE(static Isolate* UncheckedCurrent()) { | 462 INLINE(static Isolate* UncheckedCurrent()) { |
| 463 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key_)); | 463 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key())); |
| 464 } | 464 } |
| 465 | 465 |
| 466 // Usually called by Init(), but can be called early e.g. to allow | 466 // Usually called by Init(), but can be called early e.g. to allow |
| 467 // testing components that require logging but not the whole | 467 // testing components that require logging but not the whole |
| 468 // isolate. | 468 // isolate. |
| 469 // | 469 // |
| 470 // Safe to call more than once. | 470 // Safe to call more than once. |
| 471 void InitializeLoggingAndCounters(); | 471 void InitializeLoggingAndCounters(); |
| 472 | 472 |
| 473 bool Init(Deserializer* des); | 473 bool Init(Deserializer* des); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 501 #endif | 501 #endif |
| 502 | 502 |
| 503 // Get the stack guard from the default isolate. Preinitializes the | 503 // Get the stack guard from the default isolate. Preinitializes the |
| 504 // default isolate if needed. | 504 // default isolate if needed. |
| 505 static StackGuard* GetDefaultIsolateStackGuard(); | 505 static StackGuard* GetDefaultIsolateStackGuard(); |
| 506 | 506 |
| 507 // Returns the key used to store the pointer to the current isolate. | 507 // Returns the key used to store the pointer to the current isolate. |
| 508 // Used internally for V8 threads that do not execute JavaScript but still | 508 // Used internally for V8 threads that do not execute JavaScript but still |
| 509 // are part of the domain of an isolate (like the context switcher). | 509 // are part of the domain of an isolate (like the context switcher). |
| 510 static Thread::LocalStorageKey isolate_key() { | 510 static Thread::LocalStorageKey isolate_key() { |
| 511 EnsureDefaultIsolate(); |
| 511 return isolate_key_; | 512 return isolate_key_; |
| 512 } | 513 } |
| 513 | 514 |
| 514 // Returns the key used to store process-wide thread IDs. | 515 // Returns the key used to store process-wide thread IDs. |
| 515 static Thread::LocalStorageKey thread_id_key() { | 516 static Thread::LocalStorageKey thread_id_key() { |
| 517 EnsureDefaultIsolate(); |
| 516 return thread_id_key_; | 518 return thread_id_key_; |
| 517 } | 519 } |
| 518 | 520 |
| 521 static Thread::LocalStorageKey per_isolate_thread_data_key() { |
| 522 EnsureDefaultIsolate(); |
| 523 return per_isolate_thread_data_key_; |
| 524 } |
| 525 |
| 526 static Isolate::ThreadDataTable* thread_data_table() { |
| 527 EnsureDefaultIsolate(); |
| 528 return thread_data_table_; |
| 529 } |
| 530 |
| 519 // If a client attempts to create a Locker without specifying an isolate, | 531 // If a client attempts to create a Locker without specifying an isolate, |
| 520 // we assume that the client is using legacy behavior. Set up the current | 532 // we assume that the client is using legacy behavior. Set up the current |
| 521 // thread to be inside the implicit isolate (or fail a check if we have | 533 // thread to be inside the implicit isolate (or fail a check if we have |
| 522 // switched to non-legacy behavior). | 534 // switched to non-legacy behavior). |
| 523 static void EnterDefaultIsolate(); | 535 static void EnterDefaultIsolate(); |
| 524 | 536 |
| 525 // Mutex for serializing access to break control structures. | 537 // Mutex for serializing access to break control structures. |
| 526 Mutex* break_access() { return break_access_; } | 538 Mutex* break_access() { return break_access_; } |
| 527 | 539 |
| 528 // Mutex for serializing access to debugger. | 540 // Mutex for serializing access to debugger. |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 | 1086 |
| 1075 int entry_count; | 1087 int entry_count; |
| 1076 PerIsolateThreadData* previous_thread_data; | 1088 PerIsolateThreadData* previous_thread_data; |
| 1077 Isolate* previous_isolate; | 1089 Isolate* previous_isolate; |
| 1078 EntryStackItem* previous_item; | 1090 EntryStackItem* previous_item; |
| 1079 | 1091 |
| 1080 private: | 1092 private: |
| 1081 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); | 1093 DISALLOW_COPY_AND_ASSIGN(EntryStackItem); |
| 1082 }; | 1094 }; |
| 1083 | 1095 |
| 1084 // This mutex protects highest_thread_id_, thread_data_table_ and | |
| 1085 // default_isolate_. | |
| 1086 static Mutex* process_wide_mutex_; | |
| 1087 | |
| 1088 static Thread::LocalStorageKey per_isolate_thread_data_key_; | 1096 static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1089 static Thread::LocalStorageKey isolate_key_; | 1097 static Thread::LocalStorageKey isolate_key_; |
| 1090 static Thread::LocalStorageKey thread_id_key_; | 1098 static Thread::LocalStorageKey thread_id_key_; |
| 1091 static Isolate* default_isolate_; | 1099 static Isolate* default_isolate_; |
| 1092 static ThreadDataTable* thread_data_table_; | 1100 static ThreadDataTable* thread_data_table_; |
| 1093 | 1101 |
| 1094 void Deinit(); | 1102 void Deinit(); |
| 1095 | 1103 |
| 1096 static void SetIsolateThreadLocals(Isolate* isolate, | 1104 static void SetIsolateThreadLocals(Isolate* isolate, |
| 1097 PerIsolateThreadData* data); | 1105 PerIsolateThreadData* data); |
| 1098 | 1106 |
| 1099 enum State { | 1107 enum State { |
| 1100 UNINITIALIZED, // Some components may not have been allocated. | 1108 UNINITIALIZED, // Some components may not have been allocated. |
| 1101 INITIALIZED // All components are fully initialized. | 1109 INITIALIZED // All components are fully initialized. |
| 1102 }; | 1110 }; |
| 1103 | 1111 |
| 1104 State state_; | 1112 State state_; |
| 1105 EntryStackItem* entry_stack_; | 1113 EntryStackItem* entry_stack_; |
| 1106 | 1114 |
| 1107 // Allocate and insert PerIsolateThreadData into the ThreadDataTable | 1115 // Allocate and insert PerIsolateThreadData into the ThreadDataTable |
| 1108 // (regardless of whether such data already exists). | 1116 // (regardless of whether such data already exists). |
| 1109 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id); | 1117 PerIsolateThreadData* AllocatePerIsolateThreadData(ThreadId thread_id); |
| 1110 | 1118 |
| 1111 // Find the PerThread for this particular (isolate, thread) combination. | 1119 // Find the PerThread for this particular (isolate, thread) combination. |
| 1112 // If one does not yet exist, allocate a new one. | 1120 // If one does not yet exist, allocate a new one. |
| 1113 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); | 1121 PerIsolateThreadData* FindOrAllocatePerThreadDataForThisThread(); |
| 1114 | 1122 |
| 1115 // PreInits and returns a default isolate. Needed when a new thread tries | 1123 // PreInits and returns a default isolate. Needed when a new thread tries |
| 1116 // to create a Locker for the first time (the lock itself is in the isolate). | 1124 // to create a Locker for the first time (the lock itself is in the isolate). |
| 1117 static Isolate* GetDefaultIsolateForLocking(); | 1125 static Isolate* GetDefaultIsolateForLocking(); |
| 1118 | 1126 |
| 1119 // Initializes the current thread to run this Isolate. | 1127 // Initializes the current thread to run this Isolate. |
| 1120 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate | 1128 // Not thread-safe. Multiple threads should not Enter/Exit the same isolate |
| 1121 // at the same time, this should be prevented using external locking. | 1129 // at the same time, this should be prevented using external locking. |
| 1122 void Enter(); | 1130 void Enter(); |
| 1123 | 1131 |
| 1124 // Exits the current thread. The previosuly entered Isolate is restored | 1132 // Exits the current thread. The previosuly entered Isolate is restored |
| 1125 // for the thread. | 1133 // for the thread. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 | 1412 |
| 1405 // Mark the global context with out of memory. | 1413 // Mark the global context with out of memory. |
| 1406 inline void Context::mark_out_of_memory() { | 1414 inline void Context::mark_out_of_memory() { |
| 1407 global_context()->set_out_of_memory(HEAP->true_value()); | 1415 global_context()->set_out_of_memory(HEAP->true_value()); |
| 1408 } | 1416 } |
| 1409 | 1417 |
| 1410 | 1418 |
| 1411 } } // namespace v8::internal | 1419 } } // namespace v8::internal |
| 1412 | 1420 |
| 1413 #endif // V8_ISOLATE_H_ | 1421 #endif // V8_ISOLATE_H_ |
| OLD | NEW |