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 "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "ast.h" | 9 #include "ast.h" |
10 #include "bootstrapper.h" | 10 #include "bootstrapper.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 #endif | 96 #endif |
97 thread_id_ = ThreadId::Current(); | 97 thread_id_ = ThreadId::Current(); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { | 101 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
102 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); | 102 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
103 } | 103 } |
104 | 104 |
105 | 105 |
| 106 Isolate* Isolate::default_isolate_ = NULL; |
106 Thread::LocalStorageKey Isolate::isolate_key_; | 107 Thread::LocalStorageKey Isolate::isolate_key_; |
107 Thread::LocalStorageKey Isolate::thread_id_key_; | 108 Thread::LocalStorageKey Isolate::thread_id_key_; |
108 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 109 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
109 #ifdef DEBUG | 110 #ifdef DEBUG |
110 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; | 111 Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; |
111 #endif // DEBUG | 112 #endif // DEBUG |
112 Mutex Isolate::process_wide_mutex_; | 113 Mutex Isolate::process_wide_mutex_; |
113 // TODO(dcarney): Remove with default isolate. | 114 // TODO(dcarney): Remove with default isolate. |
114 enum DefaultIsolateStatus { | 115 enum DefaultIsolateStatus { |
115 kDefaultIsolateUninitialized, | 116 kDefaultIsolateUninitialized, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void Isolate::SetCrashIfDefaultIsolateInitialized() { | 159 void Isolate::SetCrashIfDefaultIsolateInitialized() { |
159 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 160 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
160 CHECK(default_isolate_status_ != kDefaultIsolateInitialized); | 161 CHECK(default_isolate_status_ != kDefaultIsolateInitialized); |
161 default_isolate_status_ = kDefaultIsolateCrashIfInitialized; | 162 default_isolate_status_ = kDefaultIsolateCrashIfInitialized; |
162 } | 163 } |
163 | 164 |
164 | 165 |
165 void Isolate::EnsureDefaultIsolate() { | 166 void Isolate::EnsureDefaultIsolate() { |
166 LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 167 LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
167 CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized); | 168 CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized); |
168 if (thread_data_table_ == NULL) { | 169 if (default_isolate_ == NULL) { |
169 isolate_key_ = Thread::CreateThreadLocalKey(); | 170 isolate_key_ = Thread::CreateThreadLocalKey(); |
170 thread_id_key_ = Thread::CreateThreadLocalKey(); | 171 thread_id_key_ = Thread::CreateThreadLocalKey(); |
171 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | 172 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
172 #ifdef DEBUG | 173 #ifdef DEBUG |
173 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); | 174 PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey(); |
174 #endif // DEBUG | 175 #endif // DEBUG |
175 thread_data_table_ = new Isolate::ThreadDataTable(); | 176 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 177 default_isolate_ = new Isolate(); |
| 178 } |
| 179 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
| 180 // because a non-null thread data may be already set. |
| 181 if (Thread::GetThreadLocal(isolate_key_) == NULL) { |
| 182 Thread::SetThreadLocal(isolate_key_, default_isolate_); |
176 } | 183 } |
177 } | 184 } |
178 | 185 |
179 struct StaticInitializer { | 186 struct StaticInitializer { |
180 StaticInitializer() { | 187 StaticInitializer() { |
181 Isolate::EnsureDefaultIsolate(); | 188 Isolate::EnsureDefaultIsolate(); |
182 } | 189 } |
183 } static_initializer; | 190 } static_initializer; |
184 | 191 |
185 | 192 |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 | 1516 |
1510 { LockGuard<Mutex> lock_guard(&process_wide_mutex_); | 1517 { LockGuard<Mutex> lock_guard(&process_wide_mutex_); |
1511 thread_data_table_->RemoveAllThreads(this); | 1518 thread_data_table_->RemoveAllThreads(this); |
1512 } | 1519 } |
1513 | 1520 |
1514 if (serialize_partial_snapshot_cache_ != NULL) { | 1521 if (serialize_partial_snapshot_cache_ != NULL) { |
1515 delete[] serialize_partial_snapshot_cache_; | 1522 delete[] serialize_partial_snapshot_cache_; |
1516 serialize_partial_snapshot_cache_ = NULL; | 1523 serialize_partial_snapshot_cache_ = NULL; |
1517 } | 1524 } |
1518 | 1525 |
1519 delete this; | 1526 if (!IsDefaultIsolate()) { |
| 1527 delete this; |
| 1528 } |
1520 | 1529 |
1521 // Restore the previous current isolate. | 1530 // Restore the previous current isolate. |
1522 SetIsolateThreadLocals(saved_isolate, saved_data); | 1531 SetIsolateThreadLocals(saved_isolate, saved_data); |
1523 } | 1532 } |
1524 | 1533 |
1525 | 1534 |
1526 void Isolate::GlobalTearDown() { | 1535 void Isolate::GlobalTearDown() { |
1527 delete thread_data_table_; | 1536 delete thread_data_table_; |
1528 } | 1537 } |
1529 | 1538 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 ASSERT(handle_scope_implementer()->CallDepthIsZero()); | 2248 ASSERT(handle_scope_implementer()->CallDepthIsZero()); |
2240 | 2249 |
2241 // Increase call depth to prevent recursive callbacks. | 2250 // Increase call depth to prevent recursive callbacks. |
2242 handle_scope_implementer()->IncrementCallDepth(); | 2251 handle_scope_implementer()->IncrementCallDepth(); |
2243 Execution::RunMicrotasks(this); | 2252 Execution::RunMicrotasks(this); |
2244 handle_scope_implementer()->DecrementCallDepth(); | 2253 handle_scope_implementer()->DecrementCallDepth(); |
2245 } | 2254 } |
2246 | 2255 |
2247 | 2256 |
2248 } } // namespace v8::internal | 2257 } } // namespace v8::internal |
OLD | NEW |