Chromium Code Reviews| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 storage->LinkTo(&free_list_); | 336 storage->LinkTo(&free_list_); |
| 337 } | 337 } |
| 338 | 338 |
| 339 Isolate* Isolate::default_isolate_ = NULL; | 339 Isolate* Isolate::default_isolate_ = NULL; |
| 340 Thread::LocalStorageKey Isolate::isolate_key_; | 340 Thread::LocalStorageKey Isolate::isolate_key_; |
| 341 Thread::LocalStorageKey Isolate::thread_id_key_; | 341 Thread::LocalStorageKey Isolate::thread_id_key_; |
| 342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 342 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
| 343 #ifdef DEBUG | 343 #ifdef DEBUG |
| 344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 344 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
| 345 #endif // DEBUG | 345 #endif // DEBUG |
| 346 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); | 346 Mutex Isolate::process_wide_mutex_; |
| 347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 347 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
| 348 Atomic32 Isolate::isolate_counter_ = 0; | 348 Atomic32 Isolate::isolate_counter_ = 0; |
| 349 | 349 |
| 350 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( | 350 Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( |
| 351 ThreadId thread_id) { | 351 ThreadId thread_id) { |
| 352 ASSERT(!thread_id.Equals(ThreadId::Invalid())); | 352 ASSERT(!thread_id.Equals(ThreadId::Invalid())); |
| 353 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id); | 353 PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id); |
| 354 { | 354 { |
| 355 ScopedLock lock(process_wide_mutex_); | 355 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
| 356 ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL); | 356 ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL); |
| 357 thread_data_table_->Insert(per_thread); | 357 thread_data_table_->Insert(per_thread); |
| 358 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); | 358 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); |
| 359 } | 359 } |
| 360 return per_thread; | 360 return per_thread; |
| 361 } | 361 } |
| 362 | 362 |
| 363 | 363 |
| 364 Isolate::PerIsolateThreadData* | 364 Isolate::PerIsolateThreadData* |
| 365 Isolate::FindOrAllocatePerThreadDataForThisThread() { | 365 Isolate::FindOrAllocatePerThreadDataForThisThread() { |
| 366 ThreadId thread_id = ThreadId::Current(); | 366 ThreadId thread_id = ThreadId::Current(); |
| 367 PerIsolateThreadData* per_thread = NULL; | 367 PerIsolateThreadData* per_thread = NULL; |
| 368 { | 368 { |
| 369 ScopedLock lock(process_wide_mutex_); | 369 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
| 370 per_thread = thread_data_table_->Lookup(this, thread_id); | 370 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 371 if (per_thread == NULL) { | 371 } |
|
Michael Starzinger
2013/08/28 12:20:54
This introduces a potential race as we might alloc
Benedikt Meurer
2013/08/28 12:43:23
Done.
| |
| 372 per_thread = AllocatePerIsolateThreadData(thread_id); | 372 if (per_thread == NULL) { |
| 373 } | 373 per_thread = AllocatePerIsolateThreadData(thread_id); |
| 374 } | 374 } |
| 375 return per_thread; | 375 return per_thread; |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { | 379 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { |
| 380 ThreadId thread_id = ThreadId::Current(); | 380 ThreadId thread_id = ThreadId::Current(); |
| 381 return FindPerThreadDataForThread(thread_id); | 381 return FindPerThreadDataForThread(thread_id); |
| 382 } | 382 } |
| 383 | 383 |
| 384 | 384 |
| 385 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( | 385 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( |
| 386 ThreadId thread_id) { | 386 ThreadId thread_id) { |
| 387 PerIsolateThreadData* per_thread = NULL; | 387 PerIsolateThreadData* per_thread = NULL; |
| 388 { | 388 { |
| 389 ScopedLock lock(process_wide_mutex_); | 389 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
| 390 per_thread = thread_data_table_->Lookup(this, thread_id); | 390 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 391 } | 391 } |
| 392 return per_thread; | 392 return per_thread; |
| 393 } | 393 } |
| 394 | 394 |
| 395 | 395 |
| 396 void Isolate::EnsureDefaultIsolate() { | 396 void Isolate::EnsureDefaultIsolate() { |
| 397 ScopedLock lock(process_wide_mutex_); | 397 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
| 398 if (default_isolate_ == NULL) { | 398 if (default_isolate_ == NULL) { |
| 399 isolate_key_ = Thread::CreateThreadLocalKey(); | 399 isolate_key_ = Thread::CreateThreadLocalKey(); |
| 400 thread_id_key_ = Thread::CreateThreadLocalKey(); | 400 thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 401 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | 401 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 402 #ifdef DEBUG | 402 #ifdef DEBUG |
| 403 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); | 403 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); |
| 404 #endif // DEBUG | 404 #endif // DEBUG |
| 405 thread_data_table_ = new Isolate::ThreadDataTable(); | 405 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 406 default_isolate_ = new Isolate(); | 406 default_isolate_ = new Isolate(); |
| 407 } | 407 } |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1743 entry_stack_(NULL), | 1743 entry_stack_(NULL), |
| 1744 stack_trace_nesting_level_(0), | 1744 stack_trace_nesting_level_(0), |
| 1745 incomplete_message_(NULL), | 1745 incomplete_message_(NULL), |
| 1746 preallocated_memory_thread_(NULL), | 1746 preallocated_memory_thread_(NULL), |
| 1747 preallocated_message_space_(NULL), | 1747 preallocated_message_space_(NULL), |
| 1748 bootstrapper_(NULL), | 1748 bootstrapper_(NULL), |
| 1749 runtime_profiler_(NULL), | 1749 runtime_profiler_(NULL), |
| 1750 compilation_cache_(NULL), | 1750 compilation_cache_(NULL), |
| 1751 counters_(NULL), | 1751 counters_(NULL), |
| 1752 code_range_(NULL), | 1752 code_range_(NULL), |
| 1753 // Must be initialized early to allow v8::SetResourceConstraints calls. | 1753 // Must be initialized early to allow v8::SetResourceConstraints calls. |
|
Michael Starzinger
2013/08/28 12:20:54
Comment applied to the line being removed, let's a
Benedikt Meurer
2013/08/28 12:43:23
Done.
| |
| 1754 break_access_(OS::CreateMutex()), | |
| 1755 debugger_initialized_(false), | 1754 debugger_initialized_(false), |
| 1756 // Must be initialized early to allow v8::Debug calls. | 1755 // Must be initialized early to allow v8::Debug calls. |
|
Michael Starzinger
2013/08/28 12:20:54
Comment applied to the line being removed, let's a
Benedikt Meurer
2013/08/28 12:43:23
Done.
| |
| 1757 debugger_access_(OS::CreateMutex()), | |
| 1758 logger_(NULL), | 1756 logger_(NULL), |
| 1759 stats_table_(NULL), | 1757 stats_table_(NULL), |
| 1760 stub_cache_(NULL), | 1758 stub_cache_(NULL), |
| 1761 deoptimizer_data_(NULL), | 1759 deoptimizer_data_(NULL), |
| 1762 capture_stack_trace_for_uncaught_exceptions_(false), | 1760 capture_stack_trace_for_uncaught_exceptions_(false), |
| 1763 stack_trace_for_uncaught_exceptions_frame_limit_(0), | 1761 stack_trace_for_uncaught_exceptions_frame_limit_(0), |
| 1764 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), | 1762 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), |
| 1765 transcendental_cache_(NULL), | 1763 transcendental_cache_(NULL), |
| 1766 memory_allocator_(NULL), | 1764 memory_allocator_(NULL), |
| 1767 keyed_lookup_cache_(NULL), | 1765 keyed_lookup_cache_(NULL), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1847 // Temporarily set this isolate as current so that various parts of | 1845 // Temporarily set this isolate as current so that various parts of |
| 1848 // the isolate can access it in their destructors without having a | 1846 // the isolate can access it in their destructors without having a |
| 1849 // direct pointer. We don't use Enter/Exit here to avoid | 1847 // direct pointer. We don't use Enter/Exit here to avoid |
| 1850 // initializing the thread data. | 1848 // initializing the thread data. |
| 1851 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); | 1849 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); |
| 1852 Isolate* saved_isolate = UncheckedCurrent(); | 1850 Isolate* saved_isolate = UncheckedCurrent(); |
| 1853 SetIsolateThreadLocals(this, NULL); | 1851 SetIsolateThreadLocals(this, NULL); |
| 1854 | 1852 |
| 1855 Deinit(); | 1853 Deinit(); |
| 1856 | 1854 |
| 1857 { ScopedLock lock(process_wide_mutex_); | 1855 { LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
| 1858 thread_data_table_->RemoveAllThreads(this); | 1856 thread_data_table_->RemoveAllThreads(this); |
| 1859 } | 1857 } |
| 1860 | 1858 |
| 1861 if (serialize_partial_snapshot_cache_ != NULL) { | 1859 if (serialize_partial_snapshot_cache_ != NULL) { |
| 1862 delete[] serialize_partial_snapshot_cache_; | 1860 delete[] serialize_partial_snapshot_cache_; |
| 1863 serialize_partial_snapshot_cache_ = NULL; | 1861 serialize_partial_snapshot_cache_ = NULL; |
| 1864 } | 1862 } |
| 1865 | 1863 |
| 1866 if (!IsDefaultIsolate()) { | 1864 if (!IsDefaultIsolate()) { |
| 1867 delete this; | 1865 delete this; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2018 stats_table_ = NULL; | 2016 stats_table_ = NULL; |
| 2019 | 2017 |
| 2020 delete logger_; | 2018 delete logger_; |
| 2021 logger_ = NULL; | 2019 logger_ = NULL; |
| 2022 | 2020 |
| 2023 delete counters_; | 2021 delete counters_; |
| 2024 counters_ = NULL; | 2022 counters_ = NULL; |
| 2025 | 2023 |
| 2026 delete handle_scope_implementer_; | 2024 delete handle_scope_implementer_; |
| 2027 handle_scope_implementer_ = NULL; | 2025 handle_scope_implementer_ = NULL; |
| 2028 delete break_access_; | |
| 2029 break_access_ = NULL; | |
| 2030 delete debugger_access_; | |
| 2031 debugger_access_ = NULL; | |
| 2032 | 2026 |
| 2033 delete compilation_cache_; | 2027 delete compilation_cache_; |
| 2034 compilation_cache_ = NULL; | 2028 compilation_cache_ = NULL; |
| 2035 delete bootstrapper_; | 2029 delete bootstrapper_; |
| 2036 bootstrapper_ = NULL; | 2030 bootstrapper_ = NULL; |
| 2037 delete inner_pointer_to_code_cache_; | 2031 delete inner_pointer_to_code_cache_; |
| 2038 inner_pointer_to_code_cache_ = NULL; | 2032 inner_pointer_to_code_cache_ = NULL; |
| 2039 delete write_iterator_; | 2033 delete write_iterator_; |
| 2040 write_iterator_ = NULL; | 2034 write_iterator_ = NULL; |
| 2041 | 2035 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2120 logger_ = new Logger(this); | 2114 logger_ = new Logger(this); |
| 2121 } | 2115 } |
| 2122 if (counters_ == NULL) { | 2116 if (counters_ == NULL) { |
| 2123 counters_ = new Counters(this); | 2117 counters_ = new Counters(this); |
| 2124 } | 2118 } |
| 2125 } | 2119 } |
| 2126 | 2120 |
| 2127 | 2121 |
| 2128 void Isolate::InitializeDebugger() { | 2122 void Isolate::InitializeDebugger() { |
| 2129 #ifdef ENABLE_DEBUGGER_SUPPORT | 2123 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 2130 ScopedLock lock(debugger_access_); | 2124 LockGuard<RecursiveMutex> lock_guard(debugger_access()); |
| 2131 if (NoBarrier_Load(&debugger_initialized_)) return; | 2125 if (NoBarrier_Load(&debugger_initialized_)) return; |
| 2132 InitializeLoggingAndCounters(); | 2126 InitializeLoggingAndCounters(); |
| 2133 debug_ = new Debug(this); | 2127 debug_ = new Debug(this); |
| 2134 debugger_ = new Debugger(this); | 2128 debugger_ = new Debugger(this); |
| 2135 Release_Store(&debugger_initialized_, true); | 2129 Release_Store(&debugger_initialized_, true); |
| 2136 #endif | 2130 #endif |
| 2137 } | 2131 } |
| 2138 | 2132 |
| 2139 | 2133 |
| 2140 bool Isolate::Init(Deserializer* des) { | 2134 bool Isolate::Init(Deserializer* des) { |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2524 | 2518 |
| 2525 #ifdef DEBUG | 2519 #ifdef DEBUG |
| 2526 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 2520 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 2527 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 2521 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 2528 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 2522 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 2529 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 2523 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 2530 #undef ISOLATE_FIELD_OFFSET | 2524 #undef ISOLATE_FIELD_OFFSET |
| 2531 #endif | 2525 #endif |
| 2532 | 2526 |
| 2533 } } // namespace v8::internal | 2527 } } // namespace v8::internal |
| OLD | NEW |