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(); |
51 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); | 52 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); |
52 if (thread_id == 0) { | 53 if (thread_id == 0) { |
53 thread_id = AllocateThreadId(); | 54 thread_id = AllocateThreadId(); |
54 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); | 55 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); |
55 } | 56 } |
56 return thread_id; | 57 return thread_id; |
57 } | 58 } |
58 | 59 |
59 | 60 |
60 ThreadLocalTop::ThreadLocalTop() { | 61 ThreadLocalTop::ThreadLocalTop() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 while (promise_on_stack_) isolate_->PopPromise(); | 107 while (promise_on_stack_) isolate_->PopPromise(); |
107 } | 108 } |
108 | 109 |
109 | 110 |
110 base::Thread::LocalStorageKey Isolate::isolate_key_; | 111 base::Thread::LocalStorageKey Isolate::isolate_key_; |
111 base::Thread::LocalStorageKey Isolate::thread_id_key_; | 112 base::Thread::LocalStorageKey Isolate::thread_id_key_; |
112 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 113 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
113 #ifdef DEBUG | 114 #ifdef DEBUG |
114 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 115 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
115 #endif // DEBUG | 116 #endif // DEBUG |
116 base::LazyMutex Isolate::thread_data_table_mutex_ = LAZY_MUTEX_INITIALIZER; | 117 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER; |
117 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 118 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
118 base::Atomic32 Isolate::isolate_counter_ = 0; | 119 base::Atomic32 Isolate::isolate_counter_ = 0; |
119 | 120 |
120 Isolate::PerIsolateThreadData* | 121 Isolate::PerIsolateThreadData* |
121 Isolate::FindOrAllocatePerThreadDataForThisThread() { | 122 Isolate::FindOrAllocatePerThreadDataForThisThread() { |
| 123 EnsureInitialized(); |
122 ThreadId thread_id = ThreadId::Current(); | 124 ThreadId thread_id = ThreadId::Current(); |
123 PerIsolateThreadData* per_thread = NULL; | 125 PerIsolateThreadData* per_thread = NULL; |
124 { | 126 { |
125 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); | 127 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); |
126 per_thread = thread_data_table_->Lookup(this, thread_id); | 128 per_thread = thread_data_table_->Lookup(this, thread_id); |
127 if (per_thread == NULL) { | 129 if (per_thread == NULL) { |
128 per_thread = new PerIsolateThreadData(this, thread_id); | 130 per_thread = new PerIsolateThreadData(this, thread_id); |
129 thread_data_table_->Insert(per_thread); | 131 thread_data_table_->Insert(per_thread); |
130 } | 132 } |
131 DCHECK(thread_data_table_->Lookup(this, thread_id) == per_thread); | 133 DCHECK(thread_data_table_->Lookup(this, thread_id) == per_thread); |
132 } | 134 } |
133 return per_thread; | 135 return per_thread; |
134 } | 136 } |
135 | 137 |
136 | 138 |
137 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { | 139 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { |
138 ThreadId thread_id = ThreadId::Current(); | 140 ThreadId thread_id = ThreadId::Current(); |
139 return FindPerThreadDataForThread(thread_id); | 141 return FindPerThreadDataForThread(thread_id); |
140 } | 142 } |
141 | 143 |
142 | 144 |
143 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( | 145 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( |
144 ThreadId thread_id) { | 146 ThreadId thread_id) { |
| 147 EnsureInitialized(); |
145 PerIsolateThreadData* per_thread = NULL; | 148 PerIsolateThreadData* per_thread = NULL; |
146 { | 149 { |
147 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); | 150 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); |
148 per_thread = thread_data_table_->Lookup(this, thread_id); | 151 per_thread = thread_data_table_->Lookup(this, thread_id); |
149 } | 152 } |
150 return per_thread; | 153 return per_thread; |
151 } | 154 } |
152 | 155 |
153 | 156 |
154 void Isolate::InitializeOncePerProcess() { | 157 void Isolate::EnsureInitialized() { |
155 base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer()); | 158 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); |
156 CHECK(thread_data_table_ == NULL); | 159 if (thread_data_table_ == NULL) { |
157 isolate_key_ = base::Thread::CreateThreadLocalKey(); | 160 isolate_key_ = base::Thread::CreateThreadLocalKey(); |
158 thread_id_key_ = base::Thread::CreateThreadLocalKey(); | 161 thread_id_key_ = base::Thread::CreateThreadLocalKey(); |
159 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); | 162 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); |
160 #ifdef DEBUG | 163 #ifdef DEBUG |
161 PerThreadAssertScopeBase::thread_local_key = | 164 PerThreadAssertScopeBase::thread_local_key = |
162 base::Thread::CreateThreadLocalKey(); | 165 base::Thread::CreateThreadLocalKey(); |
163 #endif // DEBUG | 166 #endif // DEBUG |
164 thread_data_table_ = new Isolate::ThreadDataTable(); | 167 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 168 } |
165 } | 169 } |
166 | 170 |
167 | 171 |
168 Address Isolate::get_address_from_id(Isolate::AddressId id) { | 172 Address Isolate::get_address_from_id(Isolate::AddressId id) { |
169 return isolate_addresses_[id]; | 173 return isolate_addresses_[id]; |
170 } | 174 } |
171 | 175 |
172 | 176 |
173 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { | 177 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
174 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); | 178 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 cpu_profiler_(NULL), | 1514 cpu_profiler_(NULL), |
1511 heap_profiler_(NULL), | 1515 heap_profiler_(NULL), |
1512 function_entry_hook_(NULL), | 1516 function_entry_hook_(NULL), |
1513 deferred_handles_head_(NULL), | 1517 deferred_handles_head_(NULL), |
1514 optimizing_compiler_thread_(NULL), | 1518 optimizing_compiler_thread_(NULL), |
1515 sweeper_thread_(NULL), | 1519 sweeper_thread_(NULL), |
1516 num_sweeper_threads_(0), | 1520 num_sweeper_threads_(0), |
1517 stress_deopt_count_(0), | 1521 stress_deopt_count_(0), |
1518 next_optimization_id_(0), | 1522 next_optimization_id_(0), |
1519 use_counter_callback_(NULL) { | 1523 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(thread_data_table_mutex_.Pointer()); | 1574 base::LockGuard<base::Mutex> lock_guard(process_wide_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(); |
1679 base::Thread::SetThreadLocal(isolate_key_, isolate); | 1680 base::Thread::SetThreadLocal(isolate_key_, isolate); |
1680 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); | 1681 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
1681 } | 1682 } |
1682 | 1683 |
1683 | 1684 |
1684 Isolate::~Isolate() { | 1685 Isolate::~Isolate() { |
1685 TRACE_ISOLATE(destructor); | 1686 TRACE_ISOLATE(destructor); |
1686 | 1687 |
1687 // Has to be called while counters_ are still alive | 1688 // Has to be called while counters_ are still alive |
1688 runtime_zone_.DeleteKeptSegment(); | 1689 runtime_zone_.DeleteKeptSegment(); |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2380 if (prev_ && prev_->Intercept(flag)) return true; | 2381 if (prev_ && prev_->Intercept(flag)) return true; |
2381 // Then check whether this scope intercepts. | 2382 // Then check whether this scope intercepts. |
2382 if ((flag & intercept_mask_)) { | 2383 if ((flag & intercept_mask_)) { |
2383 intercepted_flags_ |= flag; | 2384 intercepted_flags_ |= flag; |
2384 return true; | 2385 return true; |
2385 } | 2386 } |
2386 return false; | 2387 return false; |
2387 } | 2388 } |
2388 | 2389 |
2389 } } // namespace v8::internal | 2390 } } // namespace v8::internal |
OLD | NEW |