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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 FreeStoreAllocationPolicy::Delete(p); | 323 FreeStoreAllocationPolicy::Delete(p); |
324 return; | 324 return; |
325 } | 325 } |
326 PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1; | 326 PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1; |
327 ASSERT(storage->next_->previous_ == storage); | 327 ASSERT(storage->next_->previous_ == storage); |
328 ASSERT(storage->previous_->next_ == storage); | 328 ASSERT(storage->previous_->next_ == storage); |
329 storage->Unlink(); | 329 storage->Unlink(); |
330 storage->LinkTo(&free_list_); | 330 storage->LinkTo(&free_list_); |
331 } | 331 } |
332 | 332 |
| 333 Isolate* Isolate::default_isolate_ = NULL; |
333 Thread::LocalStorageKey Isolate::isolate_key_; | 334 Thread::LocalStorageKey Isolate::isolate_key_; |
334 Thread::LocalStorageKey Isolate::thread_id_key_; | 335 Thread::LocalStorageKey Isolate::thread_id_key_; |
335 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 336 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
336 #ifdef DEBUG | 337 #ifdef DEBUG |
337 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 338 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
338 #endif // DEBUG | 339 #endif // DEBUG |
339 Mutex Isolate::process_wide_mutex_; | 340 Mutex Isolate::process_wide_mutex_; |
340 // TODO(dcarney): Remove with default isolate. | 341 // TODO(dcarney): Remove with default isolate. |
341 enum DefaultIsolateStatus { | 342 enum DefaultIsolateStatus { |
342 kDefaultIsolateUninitialized, | 343 kDefaultIsolateUninitialized, |
343 kDefaultIsolateInitialized, | 344 kDefaultIsolateInitialized, |
344 kDefaultIsolateCrashIfInitialized | 345 kDefaultIsolateCrashIfInitialized |
345 }; | 346 }; |
346 static DefaultIsolateStatus default_isolate_status_ | 347 static DefaultIsolateStatus default_isolate_status_ |
347 = kDefaultIsolateUninitialized; | 348 = kDefaultIsolateUninitialized; |
348 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 349 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
349 Atomic32 Isolate::isolate_counter_ = 0; | 350 Atomic32 Isolate::isolate_counter_ = 0; |
350 Atomic32 Isolate::living_isolates_ = 0; | |
351 | 351 |
352 Isolate::PerIsolateThreadData* | 352 Isolate::PerIsolateThreadData* |
353 Isolate::FindOrAllocatePerThreadDataForThisThread() { | 353 Isolate::FindOrAllocatePerThreadDataForThisThread() { |
354 ThreadId thread_id = ThreadId::Current(); | 354 ThreadId thread_id = ThreadId::Current(); |
355 PerIsolateThreadData* per_thread = NULL; | 355 PerIsolateThreadData* per_thread = NULL; |
356 { | 356 { |
357 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 357 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
358 per_thread = thread_data_table_->Lookup(this, thread_id); | 358 per_thread = thread_data_table_->Lookup(this, thread_id); |
359 if (per_thread == NULL) { | 359 if (per_thread == NULL) { |
360 per_thread = new PerIsolateThreadData(this, thread_id); | 360 per_thread = new PerIsolateThreadData(this, thread_id); |
(...skipping 22 matching lines...) Expand all Loading... |
383 } | 383 } |
384 | 384 |
385 | 385 |
386 void Isolate::SetCrashIfDefaultIsolateInitialized() { | 386 void Isolate::SetCrashIfDefaultIsolateInitialized() { |
387 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 387 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
388 CHECK(default_isolate_status_ != kDefaultIsolateInitialized); | 388 CHECK(default_isolate_status_ != kDefaultIsolateInitialized); |
389 default_isolate_status_ = kDefaultIsolateCrashIfInitialized; | 389 default_isolate_status_ = kDefaultIsolateCrashIfInitialized; |
390 } | 390 } |
391 | 391 |
392 | 392 |
393 Isolate* Isolate::EnsureDefaultIsolate(bool must_be_null) { | 393 void Isolate::EnsureDefaultIsolate() { |
394 static Isolate* default_isolate_ = NULL; | |
395 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 394 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
396 CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized); | 395 CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized); |
397 if (must_be_null) { | |
398 CHECK(default_isolate_ == NULL); | |
399 } | |
400 if (default_isolate_ == NULL) { | 396 if (default_isolate_ == NULL) { |
401 default_isolate_ = new Isolate(true); | 397 isolate_key_ = Thread::CreateThreadLocalKey(); |
| 398 thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 399 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 400 #ifdef DEBUG |
| 401 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); |
| 402 #endif // DEBUG |
| 403 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 404 default_isolate_ = new Isolate(); |
402 } | 405 } |
403 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here | 406 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
404 // because a non-null thread data may be already set. | 407 // because a non-null thread data may be already set. |
405 if (Thread::GetThreadLocal(isolate_key_) == NULL) { | 408 if (Thread::GetThreadLocal(isolate_key_) == NULL) { |
406 Thread::SetThreadLocal(isolate_key_, default_isolate_); | 409 Thread::SetThreadLocal(isolate_key_, default_isolate_); |
407 } | 410 } |
408 | |
409 return default_isolate_; | |
410 } | 411 } |
411 | 412 |
412 | |
413 void Isolate::InitializeThreadLocalStorage() { | |
414 // Double checked locking on existence of thread_data_table_. | |
415 if (thread_data_table_ != NULL) return; | |
416 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | |
417 if (thread_data_table_ != NULL) return; | |
418 isolate_key_ = Thread::CreateThreadLocalKey(); | |
419 thread_id_key_ = Thread::CreateThreadLocalKey(); | |
420 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | |
421 #ifdef DEBUG | |
422 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); | |
423 #endif // DEBUG | |
424 thread_data_table_ = new Isolate::ThreadDataTable(); | |
425 CHECK(thread_data_table_ != NULL); | |
426 } | |
427 | |
428 | |
429 // TODO(dcarney): Remove this with default_isolate_ and Isolate::Current. | |
430 struct StaticInitializer { | 413 struct StaticInitializer { |
431 StaticInitializer() { | 414 StaticInitializer() { |
432 Isolate::InitializeThreadLocalStorage(); | 415 Isolate::EnsureDefaultIsolate(); |
433 } | 416 } |
434 } static_initializer; | 417 } static_initializer; |
435 | 418 |
436 #ifdef ENABLE_DEBUGGER_SUPPORT | 419 #ifdef ENABLE_DEBUGGER_SUPPORT |
437 Debugger* Isolate::GetDefaultIsolateDebugger() { | 420 Debugger* Isolate::GetDefaultIsolateDebugger() { |
438 return EnsureDefaultIsolate()->debugger(); | 421 EnsureDefaultIsolate(); |
| 422 return default_isolate_->debugger(); |
439 } | 423 } |
440 #endif | 424 #endif |
441 | 425 |
442 | 426 |
443 StackGuard* Isolate::GetDefaultIsolateStackGuard() { | 427 StackGuard* Isolate::GetDefaultIsolateStackGuard() { |
444 return EnsureDefaultIsolate()->stack_guard(); | 428 EnsureDefaultIsolate(); |
| 429 return default_isolate_->stack_guard(); |
445 } | 430 } |
446 | 431 |
447 | 432 |
448 void Isolate::EnterDefaultIsolate() { | 433 void Isolate::EnterDefaultIsolate() { |
449 Isolate* default_isolate = EnsureDefaultIsolate(); | 434 EnsureDefaultIsolate(); |
450 ASSERT(default_isolate != NULL); | 435 ASSERT(default_isolate_ != NULL); |
451 | 436 |
452 PerIsolateThreadData* data = CurrentPerIsolateThreadData(); | 437 PerIsolateThreadData* data = CurrentPerIsolateThreadData(); |
453 // If not yet in default isolate - enter it. | 438 // If not yet in default isolate - enter it. |
454 if (data == NULL || data->isolate() != default_isolate) { | 439 if (data == NULL || data->isolate() != default_isolate_) { |
455 default_isolate->Enter(); | 440 default_isolate_->Enter(); |
456 } | 441 } |
457 } | 442 } |
458 | 443 |
459 | 444 |
460 v8::Isolate* Isolate::GetDefaultIsolateForLocking() { | 445 v8::Isolate* Isolate::GetDefaultIsolateForLocking() { |
461 return reinterpret_cast<v8::Isolate*>(EnsureDefaultIsolate()); | 446 EnsureDefaultIsolate(); |
| 447 return reinterpret_cast<v8::Isolate*>(default_isolate_); |
462 } | 448 } |
463 | 449 |
464 | 450 |
465 Address Isolate::get_address_from_id(Isolate::AddressId id) { | 451 Address Isolate::get_address_from_id(Isolate::AddressId id) { |
466 return isolate_addresses_[id]; | 452 return isolate_addresses_[id]; |
467 } | 453 } |
468 | 454 |
469 | 455 |
470 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { | 456 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
471 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); | 457 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 if (FLAG_trace_isolates) { \ | 1727 if (FLAG_trace_isolates) { \ |
1742 PrintF("Isolate %p (id %d)" #tag "\n", \ | 1728 PrintF("Isolate %p (id %d)" #tag "\n", \ |
1743 reinterpret_cast<void*>(this), id()); \ | 1729 reinterpret_cast<void*>(this), id()); \ |
1744 } \ | 1730 } \ |
1745 } while (false) | 1731 } while (false) |
1746 #else | 1732 #else |
1747 #define TRACE_ISOLATE(tag) | 1733 #define TRACE_ISOLATE(tag) |
1748 #endif | 1734 #endif |
1749 | 1735 |
1750 | 1736 |
1751 Isolate::Isolate(bool is_default_isolate) | 1737 Isolate::Isolate() |
1752 : state_(UNINITIALIZED), | 1738 : state_(UNINITIALIZED), |
1753 embedder_data_(NULL), | 1739 embedder_data_(NULL), |
1754 entry_stack_(NULL), | 1740 entry_stack_(NULL), |
1755 stack_trace_nesting_level_(0), | 1741 stack_trace_nesting_level_(0), |
1756 incomplete_message_(NULL), | 1742 incomplete_message_(NULL), |
1757 preallocated_memory_thread_(NULL), | 1743 preallocated_memory_thread_(NULL), |
1758 preallocated_message_space_(NULL), | 1744 preallocated_message_space_(NULL), |
1759 bootstrapper_(NULL), | 1745 bootstrapper_(NULL), |
1760 runtime_profiler_(NULL), | 1746 runtime_profiler_(NULL), |
1761 compilation_cache_(NULL), | 1747 compilation_cache_(NULL), |
(...skipping 29 matching lines...) Expand all Loading... |
1791 string_tracker_(NULL), | 1777 string_tracker_(NULL), |
1792 regexp_stack_(NULL), | 1778 regexp_stack_(NULL), |
1793 date_cache_(NULL), | 1779 date_cache_(NULL), |
1794 code_stub_interface_descriptors_(NULL), | 1780 code_stub_interface_descriptors_(NULL), |
1795 // TODO(bmeurer) Initialized lazily because it depends on flags; can | 1781 // TODO(bmeurer) Initialized lazily because it depends on flags; can |
1796 // be fixed once the default isolate cleanup is done. | 1782 // be fixed once the default isolate cleanup is done. |
1797 random_number_generator_(NULL), | 1783 random_number_generator_(NULL), |
1798 has_fatal_error_(false), | 1784 has_fatal_error_(false), |
1799 use_crankshaft_(true), | 1785 use_crankshaft_(true), |
1800 initialized_from_snapshot_(false), | 1786 initialized_from_snapshot_(false), |
1801 is_default_isolate_(is_default_isolate), | |
1802 cpu_profiler_(NULL), | 1787 cpu_profiler_(NULL), |
1803 heap_profiler_(NULL), | 1788 heap_profiler_(NULL), |
1804 function_entry_hook_(NULL), | 1789 function_entry_hook_(NULL), |
1805 deferred_handles_head_(NULL), | 1790 deferred_handles_head_(NULL), |
1806 optimizing_compiler_thread_(NULL), | 1791 optimizing_compiler_thread_(NULL), |
1807 sweeper_thread_(NULL), | 1792 sweeper_thread_(NULL), |
1808 stress_deopt_count_(0) { | 1793 stress_deopt_count_(0) { |
1809 InitializeThreadLocalStorage(); | |
1810 | |
1811 id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1); | 1794 id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1); |
1812 NoBarrier_AtomicIncrement(&living_isolates_, 1); | |
1813 TRACE_ISOLATE(constructor); | 1795 TRACE_ISOLATE(constructor); |
1814 | 1796 |
1815 memset(isolate_addresses_, 0, | 1797 memset(isolate_addresses_, 0, |
1816 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); | 1798 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); |
1817 | 1799 |
1818 heap_.isolate_ = this; | 1800 heap_.isolate_ = this; |
1819 stack_guard_.isolate_ = this; | 1801 stack_guard_.isolate_ = this; |
1820 | 1802 |
1821 // ThreadManager is initialized early to support locking an isolate | 1803 // ThreadManager is initialized early to support locking an isolate |
1822 // before it is entered. | 1804 // before it is entered. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 | 1967 |
1986 Isolate::~Isolate() { | 1968 Isolate::~Isolate() { |
1987 TRACE_ISOLATE(destructor); | 1969 TRACE_ISOLATE(destructor); |
1988 | 1970 |
1989 // Has to be called while counters_ are still alive | 1971 // Has to be called while counters_ are still alive |
1990 runtime_zone_.DeleteKeptSegment(); | 1972 runtime_zone_.DeleteKeptSegment(); |
1991 | 1973 |
1992 // The entry stack must be empty when we get here, | 1974 // The entry stack must be empty when we get here, |
1993 // except for the default isolate, where it can | 1975 // except for the default isolate, where it can |
1994 // still contain up to one entry stack item | 1976 // still contain up to one entry stack item |
1995 ASSERT(entry_stack_ == NULL || is_default_isolate_); | 1977 ASSERT(entry_stack_ == NULL || this == default_isolate_); |
1996 ASSERT(entry_stack_ == NULL || entry_stack_->previous_item == NULL); | 1978 ASSERT(entry_stack_ == NULL || entry_stack_->previous_item == NULL); |
1997 | 1979 |
1998 delete entry_stack_; | 1980 delete entry_stack_; |
1999 entry_stack_ = NULL; | 1981 entry_stack_ = NULL; |
2000 | 1982 |
2001 delete[] assembler_spare_buffer_; | 1983 delete[] assembler_spare_buffer_; |
2002 assembler_spare_buffer_ = NULL; | 1984 assembler_spare_buffer_ = NULL; |
2003 | 1985 |
2004 delete unicode_cache_; | 1986 delete unicode_cache_; |
2005 unicode_cache_ = NULL; | 1987 unicode_cache_ = NULL; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 | 2052 |
2071 delete random_number_generator_; | 2053 delete random_number_generator_; |
2072 random_number_generator_ = NULL; | 2054 random_number_generator_ = NULL; |
2073 | 2055 |
2074 #ifdef ENABLE_DEBUGGER_SUPPORT | 2056 #ifdef ENABLE_DEBUGGER_SUPPORT |
2075 delete debugger_; | 2057 delete debugger_; |
2076 debugger_ = NULL; | 2058 debugger_ = NULL; |
2077 delete debug_; | 2059 delete debug_; |
2078 debug_ = NULL; | 2060 debug_ = NULL; |
2079 #endif | 2061 #endif |
2080 | |
2081 NoBarrier_AtomicIncrement(&living_isolates_, -1); | |
2082 } | 2062 } |
2083 | 2063 |
2084 | 2064 |
2085 void Isolate::InitializeThreadLocal() { | 2065 void Isolate::InitializeThreadLocal() { |
2086 thread_local_top_.isolate_ = this; | 2066 thread_local_top_.isolate_ = this; |
2087 thread_local_top_.Initialize(); | 2067 thread_local_top_.Initialize(); |
2088 } | 2068 } |
2089 | 2069 |
2090 | 2070 |
2091 void Isolate::PropagatePendingExceptionToExternalTryCatch() { | 2071 void Isolate::PropagatePendingExceptionToExternalTryCatch() { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2534 | 2514 |
2535 #ifdef DEBUG | 2515 #ifdef DEBUG |
2536 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 2516 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
2537 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 2517 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
2538 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 2518 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
2539 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 2519 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
2540 #undef ISOLATE_FIELD_OFFSET | 2520 #undef ISOLATE_FIELD_OFFSET |
2541 #endif | 2521 #endif |
2542 | 2522 |
2543 } } // namespace v8::internal | 2523 } } // namespace v8::internal |
OLD | NEW |