Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 C(context_address) \ | 127 C(context_address) \ |
| 128 C(pending_exception_address) \ | 128 C(pending_exception_address) \ |
| 129 C(external_caught_exception_address) | 129 C(external_caught_exception_address) |
| 130 | 130 |
| 131 #ifdef ENABLE_LOGGING_AND_PROFILING | 131 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 132 #define ISOLATE_ADDRESS_LIST_PROF(C) \ | 132 #define ISOLATE_ADDRESS_LIST_PROF(C) \ |
| 133 C(js_entry_sp_address) | 133 C(js_entry_sp_address) |
| 134 #else | 134 #else |
| 135 #define ISOLATE_ADDRESS_LIST_PROF(C) | 135 #define ISOLATE_ADDRESS_LIST_PROF(C) |
| 136 #endif | 136 #endif |
| 137 | 137 |
|
Vitaly Repeshko
2011/04/11 19:28:52
Style nit: two blank lines between top-level decla
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 138 // Platform-independent, reliable thread identifier | |
|
Vitaly Repeshko
2011/04/11 19:28:52
nit: Comments that are full sentences should start
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 139 class ThreadId { | |
| 140 public: | |
| 141 // Creates an invalid ThreadId | |
| 142 ThreadId() : id_(kInvalidId) {} | |
| 143 | |
| 144 // Returns ThreadId for current thread | |
| 145 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } | |
| 146 | |
| 147 // Returns invalid ThreadId (guaranteed not to be equal to any thread) | |
| 148 static ThreadId Invalid() { return ThreadId(kInvalidId); } | |
|
Vitaly Repeshko
2011/04/11 19:28:52
!thread_id.Equals(ThreadId::Invalid()) seems to be
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 149 | |
| 150 // Compares ThreadIds for equality | |
| 151 INLINE(bool Equals(const ThreadId& other) const) { | |
| 152 return id_ == other.id_; | |
| 153 } | |
| 154 | |
| 155 // Converts ThreadId to an integer representation | |
| 156 // (required for public API: V8::V8::GetCurrentThreadId). | |
| 157 int ToInteger() const { return id_; } | |
| 158 | |
| 159 // Converts ThreadId to an integer representation | |
| 160 // (required for public API: V8::V8::TerminateExecution). | |
| 161 static ThreadId FromInteger(int id) { return ThreadId(id); } | |
| 162 | |
| 163 private: | |
| 164 int id_; | |
|
Vitaly Repeshko
2011/04/11 19:28:52
Please sort these following the rules in http://go
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 165 static const int kInvalidId = -1; | |
| 166 static Mutex* thread_id_process_wide_mutex_; | |
| 167 static int highest_thread_id_; | |
| 168 | |
| 169 explicit ThreadId(int id) : id_(id) {} | |
| 170 | |
| 171 static int AllocateThreadId(); | |
| 172 static int GetCurrentThreadId(); | |
| 173 friend class Isolate; | |
| 174 }; | |
| 138 | 175 |
|
Vitaly Repeshko
2011/04/11 19:28:52
Two blank lines.
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 139 class ThreadLocalTop BASE_EMBEDDED { | 176 class ThreadLocalTop BASE_EMBEDDED { |
| 140 public: | 177 public: |
| 141 // Initialize the thread data. | 178 // Initialize the thread data. |
| 142 void Initialize(); | 179 void Initialize(); |
| 143 | 180 |
| 144 // Get the top C++ try catch handler or NULL if none are registered. | 181 // Get the top C++ try catch handler or NULL if none are registered. |
| 145 // | 182 // |
| 146 // This method is not guarenteed to return an address that can be | 183 // This method is not guarenteed to return an address that can be |
| 147 // used for comparison with addresses into the JS stack. If such an | 184 // used for comparison with addresses into the JS stack. If such an |
| 148 // address is needed, use try_catch_handler_address. | 185 // address is needed, use try_catch_handler_address. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 169 | 206 |
| 170 void Free() { | 207 void Free() { |
| 171 ASSERT(!has_pending_message_); | 208 ASSERT(!has_pending_message_); |
| 172 ASSERT(!external_caught_exception_); | 209 ASSERT(!external_caught_exception_); |
| 173 ASSERT(try_catch_handler_address_ == NULL); | 210 ASSERT(try_catch_handler_address_ == NULL); |
| 174 } | 211 } |
| 175 | 212 |
| 176 // The context where the current execution method is created and for variable | 213 // The context where the current execution method is created and for variable |
| 177 // lookups. | 214 // lookups. |
| 178 Context* context_; | 215 Context* context_; |
| 179 int thread_id_; | 216 ThreadId thread_id_; |
| 180 MaybeObject* pending_exception_; | 217 MaybeObject* pending_exception_; |
| 181 bool has_pending_message_; | 218 bool has_pending_message_; |
| 182 const char* pending_message_; | 219 const char* pending_message_; |
| 183 Object* pending_message_obj_; | 220 Object* pending_message_obj_; |
| 184 Script* pending_message_script_; | 221 Script* pending_message_script_; |
| 185 int pending_message_start_pos_; | 222 int pending_message_start_pos_; |
| 186 int pending_message_end_pos_; | 223 int pending_message_end_pos_; |
| 187 // Use a separate value for scheduled exceptions to preserve the | 224 // Use a separate value for scheduled exceptions to preserve the |
| 188 // invariants that hold about pending_exception. We may want to | 225 // invariants that hold about pending_exception. We may want to |
| 189 // unify them later. | 226 // unify them later. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 ISOLATE_DEBUGGER_INIT_LIST(V) | 363 ISOLATE_DEBUGGER_INIT_LIST(V) |
| 327 | 364 |
| 328 class Isolate { | 365 class Isolate { |
| 329 // These forward declarations are required to make the friend declarations in | 366 // These forward declarations are required to make the friend declarations in |
| 330 // PerIsolateThreadData work on some older versions of gcc. | 367 // PerIsolateThreadData work on some older versions of gcc. |
| 331 class ThreadDataTable; | 368 class ThreadDataTable; |
| 332 class EntryStackItem; | 369 class EntryStackItem; |
| 333 public: | 370 public: |
| 334 ~Isolate(); | 371 ~Isolate(); |
| 335 | 372 |
| 336 typedef int ThreadId; | |
| 337 | |
| 338 // A thread has a PerIsolateThreadData instance for each isolate that it has | 373 // A thread has a PerIsolateThreadData instance for each isolate that it has |
| 339 // entered. That instance is allocated when the isolate is initially entered | 374 // entered. That instance is allocated when the isolate is initially entered |
| 340 // and reused on subsequent entries. | 375 // and reused on subsequent entries. |
| 341 class PerIsolateThreadData { | 376 class PerIsolateThreadData { |
| 342 public: | 377 public: |
| 343 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) | 378 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) |
| 344 : isolate_(isolate), | 379 : isolate_(isolate), |
| 345 thread_id_(thread_id), | 380 thread_id_(thread_id), |
| 346 stack_limit_(0), | 381 stack_limit_(0), |
| 347 thread_state_(NULL), | 382 thread_state_(NULL), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 360 | 395 |
| 361 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ | 396 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ |
| 362 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) | 397 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) |
| 363 Simulator* simulator() const { return simulator_; } | 398 Simulator* simulator() const { return simulator_; } |
| 364 void set_simulator(Simulator* simulator) { | 399 void set_simulator(Simulator* simulator) { |
| 365 simulator_ = simulator; | 400 simulator_ = simulator; |
| 366 } | 401 } |
| 367 #endif | 402 #endif |
| 368 | 403 |
| 369 bool Matches(Isolate* isolate, ThreadId thread_id) const { | 404 bool Matches(Isolate* isolate, ThreadId thread_id) const { |
| 370 return isolate_ == isolate && thread_id_ == thread_id; | 405 return isolate_ == isolate && thread_id_.Equals(thread_id); |
| 371 } | 406 } |
| 372 | 407 |
| 373 private: | 408 private: |
| 374 Isolate* isolate_; | 409 Isolate* isolate_; |
| 375 ThreadId thread_id_; | 410 ThreadId thread_id_; |
| 376 uintptr_t stack_limit_; | 411 uintptr_t stack_limit_; |
| 377 ThreadState* thread_state_; | 412 ThreadState* thread_state_; |
| 378 | 413 |
| 379 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ | 414 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ |
| 380 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) | 415 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 // default isolate if needed. | 482 // default isolate if needed. |
| 448 static StackGuard* GetDefaultIsolateStackGuard(); | 483 static StackGuard* GetDefaultIsolateStackGuard(); |
| 449 | 484 |
| 450 // Returns the key used to store the pointer to the current isolate. | 485 // Returns the key used to store the pointer to the current isolate. |
| 451 // Used internally for V8 threads that do not execute JavaScript but still | 486 // Used internally for V8 threads that do not execute JavaScript but still |
| 452 // are part of the domain of an isolate (like the context switcher). | 487 // are part of the domain of an isolate (like the context switcher). |
| 453 static Thread::LocalStorageKey isolate_key() { | 488 static Thread::LocalStorageKey isolate_key() { |
| 454 return isolate_key_; | 489 return isolate_key_; |
| 455 } | 490 } |
| 456 | 491 |
| 457 // Returns the key used to store process-wide thread IDs. | |
| 458 static Thread::LocalStorageKey thread_id_key() { | 492 static Thread::LocalStorageKey thread_id_key() { |
|
Vitaly Repeshko
2011/04/11 19:28:52
Restore the comment.
Dmitry Lomov
2011/04/11 21:41:14
Done.
Dmitry Lomov
2011/04/11 21:41:14
Done.
| |
| 459 return thread_id_key_; | 493 return thread_id_key_; |
| 460 } | 494 } |
| 461 | 495 |
| 462 // Atomically allocates a new thread ID. | |
| 463 static ThreadId AllocateThreadId(); | |
| 464 | |
| 465 // If a client attempts to create a Locker without specifying an isolate, | 496 // If a client attempts to create a Locker without specifying an isolate, |
| 466 // we assume that the client is using legacy behavior. Set up the current | 497 // we assume that the client is using legacy behavior. Set up the current |
| 467 // thread to be inside the implicit isolate (or fail a check if we have | 498 // thread to be inside the implicit isolate (or fail a check if we have |
| 468 // switched to non-legacy behavior). | 499 // switched to non-legacy behavior). |
| 469 static void EnterDefaultIsolate(); | 500 static void EnterDefaultIsolate(); |
| 470 | 501 |
| 471 // Debug. | 502 // Debug. |
| 472 // Mutex for serializing access to break control structures. | 503 // Mutex for serializing access to break control structures. |
| 473 Mutex* break_access() { return break_access_; } | 504 Mutex* break_access() { return break_access_; } |
| 474 | 505 |
| 475 Address get_address_from_id(AddressId id); | 506 Address get_address_from_id(AddressId id); |
| 476 | 507 |
| 477 // Access to top context (where the current function object was created). | 508 // Access to top context (where the current function object was created). |
| 478 Context* context() { return thread_local_top_.context_; } | 509 Context* context() { return thread_local_top_.context_; } |
| 479 void set_context(Context* context) { | 510 void set_context(Context* context) { |
| 480 thread_local_top_.context_ = context; | 511 thread_local_top_.context_ = context; |
| 481 } | 512 } |
| 482 Context** context_address() { return &thread_local_top_.context_; } | 513 Context** context_address() { return &thread_local_top_.context_; } |
| 483 | 514 |
| 484 SaveContext* save_context() {return thread_local_top_.save_context_; } | 515 SaveContext* save_context() {return thread_local_top_.save_context_; } |
| 485 void set_save_context(SaveContext* save) { | 516 void set_save_context(SaveContext* save) { |
| 486 thread_local_top_.save_context_ = save; | 517 thread_local_top_.save_context_ = save; |
| 487 } | 518 } |
| 488 | 519 |
| 489 // Access to current thread id. | 520 // Access to current thread id. |
| 490 int thread_id() { return thread_local_top_.thread_id_; } | 521 ThreadId thread_id() { return thread_local_top_.thread_id_; } |
| 491 void set_thread_id(int id) { thread_local_top_.thread_id_ = id; } | 522 void set_thread_id(ThreadId id) { thread_local_top_.thread_id_ = id; } |
| 492 | 523 |
| 493 // Interface to pending exception. | 524 // Interface to pending exception. |
| 494 MaybeObject* pending_exception() { | 525 MaybeObject* pending_exception() { |
| 495 ASSERT(has_pending_exception()); | 526 ASSERT(has_pending_exception()); |
| 496 return thread_local_top_.pending_exception_; | 527 return thread_local_top_.pending_exception_; |
| 497 } | 528 } |
| 498 bool external_caught_exception() { | 529 bool external_caught_exception() { |
| 499 return thread_local_top_.external_caught_exception_; | 530 return thread_local_top_.external_caught_exception_; |
| 500 } | 531 } |
| 501 void set_external_caught_exception(bool value) { | 532 void set_external_caught_exception(bool value) { |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 | 1027 |
| 997 // This mutex protects highest_thread_id_, thread_data_table_ and | 1028 // This mutex protects highest_thread_id_, thread_data_table_ and |
| 998 // default_isolate_. | 1029 // default_isolate_. |
| 999 static Mutex* process_wide_mutex_; | 1030 static Mutex* process_wide_mutex_; |
| 1000 | 1031 |
| 1001 static Thread::LocalStorageKey per_isolate_thread_data_key_; | 1032 static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 1002 static Thread::LocalStorageKey isolate_key_; | 1033 static Thread::LocalStorageKey isolate_key_; |
| 1003 static Thread::LocalStorageKey thread_id_key_; | 1034 static Thread::LocalStorageKey thread_id_key_; |
| 1004 static Isolate* default_isolate_; | 1035 static Isolate* default_isolate_; |
| 1005 static ThreadDataTable* thread_data_table_; | 1036 static ThreadDataTable* thread_data_table_; |
| 1006 static ThreadId highest_thread_id_; | |
| 1007 | 1037 |
| 1008 bool PreInit(); | 1038 bool PreInit(); |
| 1009 | 1039 |
| 1010 void Deinit(); | 1040 void Deinit(); |
| 1011 | 1041 |
| 1012 static void SetIsolateThreadLocals(Isolate* isolate, | 1042 static void SetIsolateThreadLocals(Isolate* isolate, |
| 1013 PerIsolateThreadData* data); | 1043 PerIsolateThreadData* data); |
| 1014 | 1044 |
| 1015 enum State { | 1045 enum State { |
| 1016 UNINITIALIZED, // Some components may not have been allocated. | 1046 UNINITIALIZED, // Some components may not have been allocated. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 // between compilation units. | 1186 // between compilation units. |
| 1157 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 1187 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1158 static const intptr_t name##_debug_offset_; | 1188 static const intptr_t name##_debug_offset_; |
| 1159 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 1189 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1160 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 1190 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1161 #undef ISOLATE_FIELD_OFFSET | 1191 #undef ISOLATE_FIELD_OFFSET |
| 1162 #endif | 1192 #endif |
| 1163 | 1193 |
| 1164 friend class ExecutionAccess; | 1194 friend class ExecutionAccess; |
| 1165 friend class IsolateInitializer; | 1195 friend class IsolateInitializer; |
| 1196 friend class ThreadId; | |
| 1166 friend class v8::Isolate; | 1197 friend class v8::Isolate; |
| 1167 friend class v8::Locker; | 1198 friend class v8::Locker; |
| 1168 | 1199 |
| 1169 DISALLOW_COPY_AND_ASSIGN(Isolate); | 1200 DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 1170 }; | 1201 }; |
| 1171 | 1202 |
| 1172 | 1203 |
| 1173 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the | 1204 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the |
| 1174 // class as a work around for a bug in the generated code found with these | 1205 // class as a work around for a bug in the generated code found with these |
| 1175 // versions of GCC. See V8 issue 122 for details. | 1206 // versions of GCC. See V8 issue 122 for details. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 | 1369 |
| 1339 } } // namespace v8::internal | 1370 } } // namespace v8::internal |
| 1340 | 1371 |
| 1341 // TODO(isolates): Get rid of these -inl.h includes and place them only where | 1372 // TODO(isolates): Get rid of these -inl.h includes and place them only where |
| 1342 // they're needed. | 1373 // they're needed. |
| 1343 #include "allocation-inl.h" | 1374 #include "allocation-inl.h" |
| 1344 #include "zone-inl.h" | 1375 #include "zone-inl.h" |
| 1345 #include "frames-inl.h" | 1376 #include "frames-inl.h" |
| 1346 | 1377 |
| 1347 #endif // V8_ISOLATE_H_ | 1378 #endif // V8_ISOLATE_H_ |
| OLD | NEW |