Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: src/isolate.cc

Issue 362893006: Revert "Reland 22105 "Remove static initializer from isolate"" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 39
40 base::Atomic32 ThreadId::highest_thread_id_ = 0; 40 base::Atomic32 ThreadId::highest_thread_id_ = 0;
41 41
42 int ThreadId::AllocateThreadId() { 42 int ThreadId::AllocateThreadId() {
43 int new_id = base::NoBarrier_AtomicIncrement(&highest_thread_id_, 1); 43 int new_id = base::NoBarrier_AtomicIncrement(&highest_thread_id_, 1);
44 return new_id; 44 return new_id;
45 } 45 }
46 46
47 47
48 int ThreadId::GetCurrentThreadId() { 48 int ThreadId::GetCurrentThreadId() {
49 Isolate::EnsureInitialized();
50 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); 49 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
51 if (thread_id == 0) { 50 if (thread_id == 0) {
52 thread_id = AllocateThreadId(); 51 thread_id = AllocateThreadId();
53 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); 52 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id);
54 } 53 }
55 return thread_id; 54 return thread_id;
56 } 55 }
57 56
58 57
59 ThreadLocalTop::ThreadLocalTop() { 58 ThreadLocalTop::ThreadLocalTop() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 thread_id_ = ThreadId::Current(); 97 thread_id_ = ThreadId::Current();
99 } 98 }
100 99
101 100
102 base::Thread::LocalStorageKey Isolate::isolate_key_; 101 base::Thread::LocalStorageKey Isolate::isolate_key_;
103 base::Thread::LocalStorageKey Isolate::thread_id_key_; 102 base::Thread::LocalStorageKey Isolate::thread_id_key_;
104 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; 103 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
105 #ifdef DEBUG 104 #ifdef DEBUG
106 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; 105 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
107 #endif // DEBUG 106 #endif // DEBUG
108 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER; 107 base::Mutex Isolate::process_wide_mutex_;
108 // TODO(dcarney): Remove with default isolate.
109 enum DefaultIsolateStatus {
110 kDefaultIsolateUninitialized,
111 kDefaultIsolateInitialized,
112 kDefaultIsolateCrashIfInitialized
113 };
114 static DefaultIsolateStatus default_isolate_status_
115 = kDefaultIsolateUninitialized;
109 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; 116 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
110 base::Atomic32 Isolate::isolate_counter_ = 0; 117 base::Atomic32 Isolate::isolate_counter_ = 0;
111 118
112 Isolate::PerIsolateThreadData* 119 Isolate::PerIsolateThreadData*
113 Isolate::FindOrAllocatePerThreadDataForThisThread() { 120 Isolate::FindOrAllocatePerThreadDataForThisThread() {
114 EnsureInitialized();
115 ThreadId thread_id = ThreadId::Current(); 121 ThreadId thread_id = ThreadId::Current();
116 PerIsolateThreadData* per_thread = NULL; 122 PerIsolateThreadData* per_thread = NULL;
117 { 123 {
118 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); 124 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
119 per_thread = thread_data_table_->Lookup(this, thread_id); 125 per_thread = thread_data_table_->Lookup(this, thread_id);
120 if (per_thread == NULL) { 126 if (per_thread == NULL) {
121 per_thread = new PerIsolateThreadData(this, thread_id); 127 per_thread = new PerIsolateThreadData(this, thread_id);
122 thread_data_table_->Insert(per_thread); 128 thread_data_table_->Insert(per_thread);
123 } 129 }
124 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); 130 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
125 } 131 }
126 return per_thread; 132 return per_thread;
127 } 133 }
128 134
129 135
130 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { 136 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
131 ThreadId thread_id = ThreadId::Current(); 137 ThreadId thread_id = ThreadId::Current();
132 return FindPerThreadDataForThread(thread_id); 138 return FindPerThreadDataForThread(thread_id);
133 } 139 }
134 140
135 141
136 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( 142 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
137 ThreadId thread_id) { 143 ThreadId thread_id) {
138 EnsureInitialized();
139 PerIsolateThreadData* per_thread = NULL; 144 PerIsolateThreadData* per_thread = NULL;
140 { 145 {
141 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); 146 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
142 per_thread = thread_data_table_->Lookup(this, thread_id); 147 per_thread = thread_data_table_->Lookup(this, thread_id);
143 } 148 }
144 return per_thread; 149 return per_thread;
145 } 150 }
146 151
147 152
148 void Isolate::EnsureInitialized() { 153 void Isolate::SetCrashIfDefaultIsolateInitialized() {
149 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); 154 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
155 CHECK(default_isolate_status_ != kDefaultIsolateInitialized);
156 default_isolate_status_ = kDefaultIsolateCrashIfInitialized;
157 }
158
159
160 void Isolate::EnsureDefaultIsolate() {
161 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
162 CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
150 if (thread_data_table_ == NULL) { 163 if (thread_data_table_ == NULL) {
151 isolate_key_ = base::Thread::CreateThreadLocalKey(); 164 isolate_key_ = base::Thread::CreateThreadLocalKey();
152 thread_id_key_ = base::Thread::CreateThreadLocalKey(); 165 thread_id_key_ = base::Thread::CreateThreadLocalKey();
153 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); 166 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
154 #ifdef DEBUG 167 #ifdef DEBUG
155 PerThreadAssertScopeBase::thread_local_key = 168 PerThreadAssertScopeBase::thread_local_key =
156 base::Thread::CreateThreadLocalKey(); 169 base::Thread::CreateThreadLocalKey();
157 #endif // DEBUG 170 #endif // DEBUG
158 thread_data_table_ = new Isolate::ThreadDataTable(); 171 thread_data_table_ = new Isolate::ThreadDataTable();
159 } 172 }
160 } 173 }
161 174
175 struct StaticInitializer {
176 StaticInitializer() {
177 Isolate::EnsureDefaultIsolate();
178 }
179 } static_initializer;
180
162 181
163 Address Isolate::get_address_from_id(Isolate::AddressId id) { 182 Address Isolate::get_address_from_id(Isolate::AddressId id) {
164 return isolate_addresses_[id]; 183 return isolate_addresses_[id];
165 } 184 }
166 185
167 186
168 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { 187 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) {
169 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); 188 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage);
170 Iterate(v, thread); 189 Iterate(v, thread);
171 return thread_storage + sizeof(ThreadLocalTop); 190 return thread_storage + sizeof(ThreadLocalTop);
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 // Temporarily set this isolate as current so that various parts of 1520 // Temporarily set this isolate as current so that various parts of
1502 // the isolate can access it in their destructors without having a 1521 // the isolate can access it in their destructors without having a
1503 // direct pointer. We don't use Enter/Exit here to avoid 1522 // direct pointer. We don't use Enter/Exit here to avoid
1504 // initializing the thread data. 1523 // initializing the thread data.
1505 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1524 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1506 Isolate* saved_isolate = UncheckedCurrent(); 1525 Isolate* saved_isolate = UncheckedCurrent();
1507 SetIsolateThreadLocals(this, NULL); 1526 SetIsolateThreadLocals(this, NULL);
1508 1527
1509 Deinit(); 1528 Deinit();
1510 1529
1511 { base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer()); 1530 { base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_);
1512 thread_data_table_->RemoveAllThreads(this); 1531 thread_data_table_->RemoveAllThreads(this);
1513 } 1532 }
1514 1533
1515 if (serialize_partial_snapshot_cache_ != NULL) { 1534 if (serialize_partial_snapshot_cache_ != NULL) {
1516 delete[] serialize_partial_snapshot_cache_; 1535 delete[] serialize_partial_snapshot_cache_;
1517 serialize_partial_snapshot_cache_ = NULL; 1536 serialize_partial_snapshot_cache_ = NULL;
1518 } 1537 }
1519 1538
1520 delete this; 1539 delete this;
1521 1540
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 set_serialize_partial_snapshot_cache_capacity(new_capacity); 1621 set_serialize_partial_snapshot_cache_capacity(new_capacity);
1603 } 1622 }
1604 1623
1605 serialize_partial_snapshot_cache()[length] = obj; 1624 serialize_partial_snapshot_cache()[length] = obj;
1606 set_serialize_partial_snapshot_cache_length(length + 1); 1625 set_serialize_partial_snapshot_cache_length(length + 1);
1607 } 1626 }
1608 1627
1609 1628
1610 void Isolate::SetIsolateThreadLocals(Isolate* isolate, 1629 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
1611 PerIsolateThreadData* data) { 1630 PerIsolateThreadData* data) {
1612 EnsureInitialized();
1613 base::Thread::SetThreadLocal(isolate_key_, isolate); 1631 base::Thread::SetThreadLocal(isolate_key_, isolate);
1614 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); 1632 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1615 } 1633 }
1616 1634
1617 1635
1618 Isolate::~Isolate() { 1636 Isolate::~Isolate() {
1619 TRACE_ISOLATE(destructor); 1637 TRACE_ISOLATE(destructor);
1620 1638
1621 // Has to be called while counters_ are still alive 1639 // Has to be called while counters_ are still alive
1622 runtime_zone_.DeleteKeptSegment(); 1640 runtime_zone_.DeleteKeptSegment();
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 // The simulator uses a separate JS stack. 2362 // The simulator uses a separate JS stack.
2345 Address jssp_address = Simulator::current(isolate_)->get_sp(); 2363 Address jssp_address = Simulator::current(isolate_)->get_sp();
2346 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); 2364 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address);
2347 if (jssp < stack_guard->real_jslimit()) return true; 2365 if (jssp < stack_guard->real_jslimit()) return true;
2348 #endif // USE_SIMULATOR 2366 #endif // USE_SIMULATOR
2349 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); 2367 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit();
2350 } 2368 }
2351 2369
2352 2370
2353 } } // namespace v8::internal 2371 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698