| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 base::Atomic32 ThreadId::highest_thread_id_ = 0; | 42 base::Atomic32 ThreadId::highest_thread_id_ = 0; |
| 43 | 43 |
| 44 int ThreadId::AllocateThreadId() { | 44 int ThreadId::AllocateThreadId() { |
| 45 int new_id = base::NoBarrier_AtomicIncrement(&highest_thread_id_, 1); | 45 int new_id = base::NoBarrier_AtomicIncrement(&highest_thread_id_, 1); |
| 46 return new_id; | 46 return new_id; |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| 50 int ThreadId::GetCurrentThreadId() { | 50 int ThreadId::GetCurrentThreadId() { |
| 51 Isolate::EnsureInitialized(); | |
| 52 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); | 51 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); |
| 53 if (thread_id == 0) { | 52 if (thread_id == 0) { |
| 54 thread_id = AllocateThreadId(); | 53 thread_id = AllocateThreadId(); |
| 55 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); | 54 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); |
| 56 } | 55 } |
| 57 return thread_id; | 56 return thread_id; |
| 58 } | 57 } |
| 59 | 58 |
| 60 | 59 |
| 61 ThreadLocalTop::ThreadLocalTop() { | 60 ThreadLocalTop::ThreadLocalTop() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 while (promise_on_stack_) isolate_->PopPromise(); | 106 while (promise_on_stack_) isolate_->PopPromise(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 | 109 |
| 111 base::Thread::LocalStorageKey Isolate::isolate_key_; | 110 base::Thread::LocalStorageKey Isolate::isolate_key_; |
| 112 base::Thread::LocalStorageKey Isolate::thread_id_key_; | 111 base::Thread::LocalStorageKey Isolate::thread_id_key_; |
| 113 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 112 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
| 114 #ifdef DEBUG | 113 #ifdef DEBUG |
| 115 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 114 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
| 116 #endif // DEBUG | 115 #endif // DEBUG |
| 117 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER; | 116 base::LazyMutex Isolate::thread_data_table_mutex_ = LAZY_MUTEX_INITIALIZER; |
| 118 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 117 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
| 119 base::Atomic32 Isolate::isolate_counter_ = 0; | 118 base::Atomic32 Isolate::isolate_counter_ = 0; |
| 120 | 119 |
| 121 Isolate::PerIsolateThreadData* | 120 Isolate::PerIsolateThreadData* |
| 122 Isolate::FindOrAllocatePerThreadDataForThisThread() { | 121 Isolate::FindOrAllocatePerThreadDataForThisThread() { |
| 123 EnsureInitialized(); | |
| 124 ThreadId thread_id = ThreadId::Current(); | 122 ThreadId thread_id = ThreadId::Current(); |
| 125 PerIsolateThreadData* per_thread = NULL; | 123 PerIsolateThreadData* per_thread = NULL; |
| 126 { | 124 { |
| 127 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); | 125 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); |
| 128 per_thread = thread_data_table_->Lookup(this, thread_id); | 126 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 129 if (per_thread == NULL) { | 127 if (per_thread == NULL) { |
| 130 per_thread = new PerIsolateThreadData(this, thread_id); | 128 per_thread = new PerIsolateThreadData(this, thread_id); |
| 131 thread_data_table_->Insert(per_thread); | 129 thread_data_table_->Insert(per_thread); |
| 132 } | 130 } |
| 133 DCHECK(thread_data_table_->Lookup(this, thread_id) == per_thread); | 131 DCHECK(thread_data_table_->Lookup(this, thread_id) == per_thread); |
| 134 } | 132 } |
| 135 return per_thread; | 133 return per_thread; |
| 136 } | 134 } |
| 137 | 135 |
| 138 | 136 |
| 139 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { | 137 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { |
| 140 ThreadId thread_id = ThreadId::Current(); | 138 ThreadId thread_id = ThreadId::Current(); |
| 141 return FindPerThreadDataForThread(thread_id); | 139 return FindPerThreadDataForThread(thread_id); |
| 142 } | 140 } |
| 143 | 141 |
| 144 | 142 |
| 145 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( | 143 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( |
| 146 ThreadId thread_id) { | 144 ThreadId thread_id) { |
| 147 EnsureInitialized(); | |
| 148 PerIsolateThreadData* per_thread = NULL; | 145 PerIsolateThreadData* per_thread = NULL; |
| 149 { | 146 { |
| 150 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); | 147 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); |
| 151 per_thread = thread_data_table_->Lookup(this, thread_id); | 148 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 152 } | 149 } |
| 153 return per_thread; | 150 return per_thread; |
| 154 } | 151 } |
| 155 | 152 |
| 156 | 153 |
| 157 void Isolate::EnsureInitialized() { | 154 void Isolate::InitializeOncePerProcess() { |
| 158 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); | 155 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); |
| 159 if (thread_data_table_ == NULL) { | 156 CHECK(thread_data_table_ == NULL); |
| 160 isolate_key_ = base::Thread::CreateThreadLocalKey(); | 157 isolate_key_ = base::Thread::CreateThreadLocalKey(); |
| 161 thread_id_key_ = base::Thread::CreateThreadLocalKey(); | 158 thread_id_key_ = base::Thread::CreateThreadLocalKey(); |
| 162 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); | 159 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); |
| 163 #ifdef DEBUG | 160 #ifdef DEBUG |
| 164 PerThreadAssertScopeBase::thread_local_key = | 161 PerThreadAssertScopeBase::thread_local_key = |
| 165 base::Thread::CreateThreadLocalKey(); | 162 base::Thread::CreateThreadLocalKey(); |
| 166 #endif // DEBUG | 163 #endif // DEBUG |
| 167 thread_data_table_ = new Isolate::ThreadDataTable(); | 164 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 168 } | |
| 169 } | 165 } |
| 170 | 166 |
| 171 | 167 |
| 172 Address Isolate::get_address_from_id(Isolate::AddressId id) { | 168 Address Isolate::get_address_from_id(Isolate::AddressId id) { |
| 173 return isolate_addresses_[id]; | 169 return isolate_addresses_[id]; |
| 174 } | 170 } |
| 175 | 171 |
| 176 | 172 |
| 177 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { | 173 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
| 178 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); | 174 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 cpu_profiler_(NULL), | 1510 cpu_profiler_(NULL), |
| 1515 heap_profiler_(NULL), | 1511 heap_profiler_(NULL), |
| 1516 function_entry_hook_(NULL), | 1512 function_entry_hook_(NULL), |
| 1517 deferred_handles_head_(NULL), | 1513 deferred_handles_head_(NULL), |
| 1518 optimizing_compiler_thread_(NULL), | 1514 optimizing_compiler_thread_(NULL), |
| 1519 sweeper_thread_(NULL), | 1515 sweeper_thread_(NULL), |
| 1520 num_sweeper_threads_(0), | 1516 num_sweeper_threads_(0), |
| 1521 stress_deopt_count_(0), | 1517 stress_deopt_count_(0), |
| 1522 next_optimization_id_(0), | 1518 next_optimization_id_(0), |
| 1523 use_counter_callback_(NULL) { | 1519 use_counter_callback_(NULL) { |
| 1520 { |
| 1521 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); |
| 1522 CHECK(thread_data_table_); |
| 1523 } |
| 1524 id_ = base::NoBarrier_AtomicIncrement(&isolate_counter_, 1); | 1524 id_ = base::NoBarrier_AtomicIncrement(&isolate_counter_, 1); |
| 1525 TRACE_ISOLATE(constructor); | 1525 TRACE_ISOLATE(constructor); |
| 1526 | 1526 |
| 1527 memset(isolate_addresses_, 0, | 1527 memset(isolate_addresses_, 0, |
| 1528 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); | 1528 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); |
| 1529 | 1529 |
| 1530 heap_.isolate_ = this; | 1530 heap_.isolate_ = this; |
| 1531 stack_guard_.isolate_ = this; | 1531 stack_guard_.isolate_ = this; |
| 1532 | 1532 |
| 1533 // ThreadManager is initialized early to support locking an isolate | 1533 // ThreadManager is initialized early to support locking an isolate |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1564 // the isolate can access it in their destructors without having a | 1564 // the isolate can access it in their destructors without having a |
| 1565 // direct pointer. We don't use Enter/Exit here to avoid | 1565 // direct pointer. We don't use Enter/Exit here to avoid |
| 1566 // initializing the thread data. | 1566 // initializing the thread data. |
| 1567 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); | 1567 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); |
| 1568 Isolate* saved_isolate = UncheckedCurrent(); | 1568 Isolate* saved_isolate = UncheckedCurrent(); |
| 1569 SetIsolateThreadLocals(this, NULL); | 1569 SetIsolateThreadLocals(this, NULL); |
| 1570 | 1570 |
| 1571 Deinit(); | 1571 Deinit(); |
| 1572 | 1572 |
| 1573 { | 1573 { |
| 1574 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); | 1574 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); |
| 1575 thread_data_table_->RemoveAllThreads(this); | 1575 thread_data_table_->RemoveAllThreads(this); |
| 1576 } | 1576 } |
| 1577 | 1577 |
| 1578 if (serialize_partial_snapshot_cache_ != NULL) { | 1578 if (serialize_partial_snapshot_cache_ != NULL) { |
| 1579 delete[] serialize_partial_snapshot_cache_; | 1579 delete[] serialize_partial_snapshot_cache_; |
| 1580 serialize_partial_snapshot_cache_ = NULL; | 1580 serialize_partial_snapshot_cache_ = NULL; |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 delete this; | 1583 delete this; |
| 1584 | 1584 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 set_serialize_partial_snapshot_cache_capacity(new_capacity); | 1669 set_serialize_partial_snapshot_cache_capacity(new_capacity); |
| 1670 } | 1670 } |
| 1671 | 1671 |
| 1672 serialize_partial_snapshot_cache()[length] = obj; | 1672 serialize_partial_snapshot_cache()[length] = obj; |
| 1673 set_serialize_partial_snapshot_cache_length(length + 1); | 1673 set_serialize_partial_snapshot_cache_length(length + 1); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 | 1676 |
| 1677 void Isolate::SetIsolateThreadLocals(Isolate* isolate, | 1677 void Isolate::SetIsolateThreadLocals(Isolate* isolate, |
| 1678 PerIsolateThreadData* data) { | 1678 PerIsolateThreadData* data) { |
| 1679 EnsureInitialized(); | |
| 1680 base::Thread::SetThreadLocal(isolate_key_, isolate); | 1679 base::Thread::SetThreadLocal(isolate_key_, isolate); |
| 1681 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); | 1680 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
| 1682 } | 1681 } |
| 1683 | 1682 |
| 1684 | 1683 |
| 1685 Isolate::~Isolate() { | 1684 Isolate::~Isolate() { |
| 1686 TRACE_ISOLATE(destructor); | 1685 TRACE_ISOLATE(destructor); |
| 1687 | 1686 |
| 1688 // Has to be called while counters_ are still alive | 1687 // Has to be called while counters_ are still alive |
| 1689 runtime_zone_.DeleteKeptSegment(); | 1688 runtime_zone_.DeleteKeptSegment(); |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 if (prev_ && prev_->Intercept(flag)) return true; | 2380 if (prev_ && prev_->Intercept(flag)) return true; |
| 2382 // Then check whether this scope intercepts. | 2381 // Then check whether this scope intercepts. |
| 2383 if ((flag & intercept_mask_)) { | 2382 if ((flag & intercept_mask_)) { |
| 2384 intercepted_flags_ |= flag; | 2383 intercepted_flags_ |= flag; |
| 2385 return true; | 2384 return true; |
| 2386 } | 2385 } |
| 2387 return false; | 2386 return false; |
| 2388 } | 2387 } |
| 2389 | 2388 |
| 2390 } } // namespace v8::internal | 2389 } } // namespace v8::internal |
| OLD | NEW |