| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 138 | 138 |
| 139 // Platform-independent, reliable thread identifier. |
| 140 class ThreadId { |
| 141 public: |
| 142 // Creates an invalid ThreadId. |
| 143 ThreadId() : id_(kInvalidId) {} |
| 144 |
| 145 // Returns ThreadId for current thread. |
| 146 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } |
| 147 |
| 148 // Returns invalid ThreadId (guaranteed not to be equal to any thread). |
| 149 static ThreadId Invalid() { return ThreadId(kInvalidId); } |
| 150 |
| 151 // Compares ThreadIds for equality. |
| 152 INLINE(bool Equals(const ThreadId& other) const) { |
| 153 return id_ == other.id_; |
| 154 } |
| 155 |
| 156 // Checks whether this ThreadId refers to any thread. |
| 157 INLINE(bool IsValid() const) { |
| 158 return id_ != kInvalidId; |
| 159 } |
| 160 |
| 161 // Converts ThreadId to an integer representation |
| 162 // (required for public API: V8::V8::GetCurrentThreadId). |
| 163 int ToInteger() const { return id_; } |
| 164 |
| 165 // Converts ThreadId to an integer representation |
| 166 // (required for public API: V8::V8::TerminateExecution). |
| 167 static ThreadId FromInteger(int id) { return ThreadId(id); } |
| 168 |
| 169 private: |
| 170 static const int kInvalidId = -1; |
| 171 |
| 172 explicit ThreadId(int id) : id_(id) {} |
| 173 |
| 174 static int AllocateThreadId(); |
| 175 |
| 176 static int GetCurrentThreadId(); |
| 177 |
| 178 int id_; |
| 179 |
| 180 static Atomic32 highest_thread_id_; |
| 181 |
| 182 friend class Isolate; |
| 183 }; |
| 184 |
| 185 |
| 139 class ThreadLocalTop BASE_EMBEDDED { | 186 class ThreadLocalTop BASE_EMBEDDED { |
| 140 public: | 187 public: |
| 141 // Initialize the thread data. | 188 // Initialize the thread data. |
| 142 void Initialize(); | 189 void Initialize(); |
| 143 | 190 |
| 144 // Get the top C++ try catch handler or NULL if none are registered. | 191 // Get the top C++ try catch handler or NULL if none are registered. |
| 145 // | 192 // |
| 146 // This method is not guarenteed to return an address that can be | 193 // 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 | 194 // used for comparison with addresses into the JS stack. If such an |
| 148 // address is needed, use try_catch_handler_address. | 195 // address is needed, use try_catch_handler_address. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 169 | 216 |
| 170 void Free() { | 217 void Free() { |
| 171 ASSERT(!has_pending_message_); | 218 ASSERT(!has_pending_message_); |
| 172 ASSERT(!external_caught_exception_); | 219 ASSERT(!external_caught_exception_); |
| 173 ASSERT(try_catch_handler_address_ == NULL); | 220 ASSERT(try_catch_handler_address_ == NULL); |
| 174 } | 221 } |
| 175 | 222 |
| 176 // The context where the current execution method is created and for variable | 223 // The context where the current execution method is created and for variable |
| 177 // lookups. | 224 // lookups. |
| 178 Context* context_; | 225 Context* context_; |
| 179 int thread_id_; | 226 ThreadId thread_id_; |
| 180 MaybeObject* pending_exception_; | 227 MaybeObject* pending_exception_; |
| 181 bool has_pending_message_; | 228 bool has_pending_message_; |
| 182 Object* pending_message_obj_; | 229 Object* pending_message_obj_; |
| 183 Script* pending_message_script_; | 230 Script* pending_message_script_; |
| 184 int pending_message_start_pos_; | 231 int pending_message_start_pos_; |
| 185 int pending_message_end_pos_; | 232 int pending_message_end_pos_; |
| 186 // Use a separate value for scheduled exceptions to preserve the | 233 // Use a separate value for scheduled exceptions to preserve the |
| 187 // invariants that hold about pending_exception. We may want to | 234 // invariants that hold about pending_exception. We may want to |
| 188 // unify them later. | 235 // unify them later. |
| 189 MaybeObject* scheduled_exception_; | 236 MaybeObject* scheduled_exception_; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 ISOLATE_DEBUGGER_INIT_LIST(V) | 369 ISOLATE_DEBUGGER_INIT_LIST(V) |
| 323 | 370 |
| 324 class Isolate { | 371 class Isolate { |
| 325 // These forward declarations are required to make the friend declarations in | 372 // These forward declarations are required to make the friend declarations in |
| 326 // PerIsolateThreadData work on some older versions of gcc. | 373 // PerIsolateThreadData work on some older versions of gcc. |
| 327 class ThreadDataTable; | 374 class ThreadDataTable; |
| 328 class EntryStackItem; | 375 class EntryStackItem; |
| 329 public: | 376 public: |
| 330 ~Isolate(); | 377 ~Isolate(); |
| 331 | 378 |
| 332 typedef int ThreadId; | |
| 333 | |
| 334 // A thread has a PerIsolateThreadData instance for each isolate that it has | 379 // A thread has a PerIsolateThreadData instance for each isolate that it has |
| 335 // entered. That instance is allocated when the isolate is initially entered | 380 // entered. That instance is allocated when the isolate is initially entered |
| 336 // and reused on subsequent entries. | 381 // and reused on subsequent entries. |
| 337 class PerIsolateThreadData { | 382 class PerIsolateThreadData { |
| 338 public: | 383 public: |
| 339 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) | 384 PerIsolateThreadData(Isolate* isolate, ThreadId thread_id) |
| 340 : isolate_(isolate), | 385 : isolate_(isolate), |
| 341 thread_id_(thread_id), | 386 thread_id_(thread_id), |
| 342 stack_limit_(0), | 387 stack_limit_(0), |
| 343 thread_state_(NULL), | 388 thread_state_(NULL), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 356 | 401 |
| 357 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ | 402 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ |
| 358 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) | 403 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) |
| 359 Simulator* simulator() const { return simulator_; } | 404 Simulator* simulator() const { return simulator_; } |
| 360 void set_simulator(Simulator* simulator) { | 405 void set_simulator(Simulator* simulator) { |
| 361 simulator_ = simulator; | 406 simulator_ = simulator; |
| 362 } | 407 } |
| 363 #endif | 408 #endif |
| 364 | 409 |
| 365 bool Matches(Isolate* isolate, ThreadId thread_id) const { | 410 bool Matches(Isolate* isolate, ThreadId thread_id) const { |
| 366 return isolate_ == isolate && thread_id_ == thread_id; | 411 return isolate_ == isolate && thread_id_.Equals(thread_id); |
| 367 } | 412 } |
| 368 | 413 |
| 369 private: | 414 private: |
| 370 Isolate* isolate_; | 415 Isolate* isolate_; |
| 371 ThreadId thread_id_; | 416 ThreadId thread_id_; |
| 372 uintptr_t stack_limit_; | 417 uintptr_t stack_limit_; |
| 373 ThreadState* thread_state_; | 418 ThreadState* thread_state_; |
| 374 | 419 |
| 375 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ | 420 #if !defined(__arm__) && defined(V8_TARGET_ARCH_ARM) || \ |
| 376 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) | 421 !defined(__mips__) && defined(V8_TARGET_ARCH_MIPS) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // are part of the domain of an isolate (like the context switcher). | 493 // are part of the domain of an isolate (like the context switcher). |
| 449 static Thread::LocalStorageKey isolate_key() { | 494 static Thread::LocalStorageKey isolate_key() { |
| 450 return isolate_key_; | 495 return isolate_key_; |
| 451 } | 496 } |
| 452 | 497 |
| 453 // Returns the key used to store process-wide thread IDs. | 498 // Returns the key used to store process-wide thread IDs. |
| 454 static Thread::LocalStorageKey thread_id_key() { | 499 static Thread::LocalStorageKey thread_id_key() { |
| 455 return thread_id_key_; | 500 return thread_id_key_; |
| 456 } | 501 } |
| 457 | 502 |
| 458 // Atomically allocates a new thread ID. | |
| 459 static ThreadId AllocateThreadId(); | |
| 460 | |
| 461 // If a client attempts to create a Locker without specifying an isolate, | 503 // If a client attempts to create a Locker without specifying an isolate, |
| 462 // we assume that the client is using legacy behavior. Set up the current | 504 // we assume that the client is using legacy behavior. Set up the current |
| 463 // thread to be inside the implicit isolate (or fail a check if we have | 505 // thread to be inside the implicit isolate (or fail a check if we have |
| 464 // switched to non-legacy behavior). | 506 // switched to non-legacy behavior). |
| 465 static void EnterDefaultIsolate(); | 507 static void EnterDefaultIsolate(); |
| 466 | 508 |
| 467 // Debug. | 509 // Debug. |
| 468 // Mutex for serializing access to break control structures. | 510 // Mutex for serializing access to break control structures. |
| 469 Mutex* break_access() { return break_access_; } | 511 Mutex* break_access() { return break_access_; } |
| 470 | 512 |
| 471 Address get_address_from_id(AddressId id); | 513 Address get_address_from_id(AddressId id); |
| 472 | 514 |
| 473 // Access to top context (where the current function object was created). | 515 // Access to top context (where the current function object was created). |
| 474 Context* context() { return thread_local_top_.context_; } | 516 Context* context() { return thread_local_top_.context_; } |
| 475 void set_context(Context* context) { | 517 void set_context(Context* context) { |
| 476 thread_local_top_.context_ = context; | 518 thread_local_top_.context_ = context; |
| 477 } | 519 } |
| 478 Context** context_address() { return &thread_local_top_.context_; } | 520 Context** context_address() { return &thread_local_top_.context_; } |
| 479 | 521 |
| 480 SaveContext* save_context() {return thread_local_top_.save_context_; } | 522 SaveContext* save_context() {return thread_local_top_.save_context_; } |
| 481 void set_save_context(SaveContext* save) { | 523 void set_save_context(SaveContext* save) { |
| 482 thread_local_top_.save_context_ = save; | 524 thread_local_top_.save_context_ = save; |
| 483 } | 525 } |
| 484 | 526 |
| 485 // Access to current thread id. | 527 // Access to current thread id. |
| 486 int thread_id() { return thread_local_top_.thread_id_; } | 528 ThreadId thread_id() { return thread_local_top_.thread_id_; } |
| 487 void set_thread_id(int id) { thread_local_top_.thread_id_ = id; } | 529 void set_thread_id(ThreadId id) { thread_local_top_.thread_id_ = id; } |
| 488 | 530 |
| 489 // Interface to pending exception. | 531 // Interface to pending exception. |
| 490 MaybeObject* pending_exception() { | 532 MaybeObject* pending_exception() { |
| 491 ASSERT(has_pending_exception()); | 533 ASSERT(has_pending_exception()); |
| 492 return thread_local_top_.pending_exception_; | 534 return thread_local_top_.pending_exception_; |
| 493 } | 535 } |
| 494 bool external_caught_exception() { | 536 bool external_caught_exception() { |
| 495 return thread_local_top_.external_caught_exception_; | 537 return thread_local_top_.external_caught_exception_; |
| 496 } | 538 } |
| 497 void set_external_caught_exception(bool value) { | 539 void set_external_caught_exception(bool value) { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 | 1031 |
| 990 // This mutex protects highest_thread_id_, thread_data_table_ and | 1032 // This mutex protects highest_thread_id_, thread_data_table_ and |
| 991 // default_isolate_. | 1033 // default_isolate_. |
| 992 static Mutex* process_wide_mutex_; | 1034 static Mutex* process_wide_mutex_; |
| 993 | 1035 |
| 994 static Thread::LocalStorageKey per_isolate_thread_data_key_; | 1036 static Thread::LocalStorageKey per_isolate_thread_data_key_; |
| 995 static Thread::LocalStorageKey isolate_key_; | 1037 static Thread::LocalStorageKey isolate_key_; |
| 996 static Thread::LocalStorageKey thread_id_key_; | 1038 static Thread::LocalStorageKey thread_id_key_; |
| 997 static Isolate* default_isolate_; | 1039 static Isolate* default_isolate_; |
| 998 static ThreadDataTable* thread_data_table_; | 1040 static ThreadDataTable* thread_data_table_; |
| 999 static ThreadId highest_thread_id_; | |
| 1000 | 1041 |
| 1001 bool PreInit(); | 1042 bool PreInit(); |
| 1002 | 1043 |
| 1003 void Deinit(); | 1044 void Deinit(); |
| 1004 | 1045 |
| 1005 static void SetIsolateThreadLocals(Isolate* isolate, | 1046 static void SetIsolateThreadLocals(Isolate* isolate, |
| 1006 PerIsolateThreadData* data); | 1047 PerIsolateThreadData* data); |
| 1007 | 1048 |
| 1008 enum State { | 1049 enum State { |
| 1009 UNINITIALIZED, // Some components may not have been allocated. | 1050 UNINITIALIZED, // Some components may not have been allocated. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 // between compilation units. | 1190 // between compilation units. |
| 1150 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 1191 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1151 static const intptr_t name##_debug_offset_; | 1192 static const intptr_t name##_debug_offset_; |
| 1152 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 1193 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1153 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 1194 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1154 #undef ISOLATE_FIELD_OFFSET | 1195 #undef ISOLATE_FIELD_OFFSET |
| 1155 #endif | 1196 #endif |
| 1156 | 1197 |
| 1157 friend class ExecutionAccess; | 1198 friend class ExecutionAccess; |
| 1158 friend class IsolateInitializer; | 1199 friend class IsolateInitializer; |
| 1200 friend class ThreadId; |
| 1159 friend class v8::Isolate; | 1201 friend class v8::Isolate; |
| 1160 friend class v8::Locker; | 1202 friend class v8::Locker; |
| 1161 | 1203 |
| 1162 DISALLOW_COPY_AND_ASSIGN(Isolate); | 1204 DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 1163 }; | 1205 }; |
| 1164 | 1206 |
| 1165 | 1207 |
| 1166 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the | 1208 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the |
| 1167 // class as a work around for a bug in the generated code found with these | 1209 // class as a work around for a bug in the generated code found with these |
| 1168 // versions of GCC. See V8 issue 122 for details. | 1210 // versions of GCC. See V8 issue 122 for details. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 | 1373 |
| 1332 } } // namespace v8::internal | 1374 } } // namespace v8::internal |
| 1333 | 1375 |
| 1334 // TODO(isolates): Get rid of these -inl.h includes and place them only where | 1376 // TODO(isolates): Get rid of these -inl.h includes and place them only where |
| 1335 // they're needed. | 1377 // they're needed. |
| 1336 #include "allocation-inl.h" | 1378 #include "allocation-inl.h" |
| 1337 #include "zone-inl.h" | 1379 #include "zone-inl.h" |
| 1338 #include "frames-inl.h" | 1380 #include "frames-inl.h" |
| 1339 | 1381 |
| 1340 #endif // V8_ISOLATE_H_ | 1382 #endif // V8_ISOLATE_H_ |
| OLD | NEW |