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

Side by Side Diff: src/isolate.cc

Issue 365863003: Reland^2 r22105 "Remove static initializer from isolate" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates 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();
49 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_); 50 int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
50 if (thread_id == 0) { 51 if (thread_id == 0) {
51 thread_id = AllocateThreadId(); 52 thread_id = AllocateThreadId();
52 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); 53 base::Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id);
53 } 54 }
54 return thread_id; 55 return thread_id;
55 } 56 }
56 57
57 58
58 ThreadLocalTop::ThreadLocalTop() { 59 ThreadLocalTop::ThreadLocalTop() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 thread_id_ = ThreadId::Current(); 98 thread_id_ = ThreadId::Current();
98 } 99 }
99 100
100 101
101 base::Thread::LocalStorageKey Isolate::isolate_key_; 102 base::Thread::LocalStorageKey Isolate::isolate_key_;
102 base::Thread::LocalStorageKey Isolate::thread_id_key_; 103 base::Thread::LocalStorageKey Isolate::thread_id_key_;
103 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; 104 base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
104 #ifdef DEBUG 105 #ifdef DEBUG
105 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key; 106 base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
106 #endif // DEBUG 107 #endif // DEBUG
107 base::Mutex Isolate::process_wide_mutex_; 108 base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
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;
116 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; 109 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
117 base::Atomic32 Isolate::isolate_counter_ = 0; 110 base::Atomic32 Isolate::isolate_counter_ = 0;
118 111
119 Isolate::PerIsolateThreadData* 112 Isolate::PerIsolateThreadData*
120 Isolate::FindOrAllocatePerThreadDataForThisThread() { 113 Isolate::FindOrAllocatePerThreadDataForThisThread() {
114 EnsureInitialized();
121 ThreadId thread_id = ThreadId::Current(); 115 ThreadId thread_id = ThreadId::Current();
122 PerIsolateThreadData* per_thread = NULL; 116 PerIsolateThreadData* per_thread = NULL;
123 { 117 {
124 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_); 118 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
125 per_thread = thread_data_table_->Lookup(this, thread_id); 119 per_thread = thread_data_table_->Lookup(this, thread_id);
126 if (per_thread == NULL) { 120 if (per_thread == NULL) {
127 per_thread = new PerIsolateThreadData(this, thread_id); 121 per_thread = new PerIsolateThreadData(this, thread_id);
128 thread_data_table_->Insert(per_thread); 122 thread_data_table_->Insert(per_thread);
129 } 123 }
130 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); 124 ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread);
131 } 125 }
132 return per_thread; 126 return per_thread;
133 } 127 }
134 128
135 129
136 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { 130 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
137 ThreadId thread_id = ThreadId::Current(); 131 ThreadId thread_id = ThreadId::Current();
138 return FindPerThreadDataForThread(thread_id); 132 return FindPerThreadDataForThread(thread_id);
139 } 133 }
140 134
141 135
142 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread( 136 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
143 ThreadId thread_id) { 137 ThreadId thread_id) {
138 EnsureInitialized();
144 PerIsolateThreadData* per_thread = NULL; 139 PerIsolateThreadData* per_thread = NULL;
145 { 140 {
146 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_); 141 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
147 per_thread = thread_data_table_->Lookup(this, thread_id); 142 per_thread = thread_data_table_->Lookup(this, thread_id);
148 } 143 }
149 return per_thread; 144 return per_thread;
150 } 145 }
151 146
152 147
153 void Isolate::SetCrashIfDefaultIsolateInitialized() { 148 void Isolate::EnsureInitialized() {
154 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_); 149 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
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);
163 if (thread_data_table_ == NULL) { 150 if (thread_data_table_ == NULL) {
164 isolate_key_ = base::Thread::CreateThreadLocalKey(); 151 isolate_key_ = base::Thread::CreateThreadLocalKey();
165 thread_id_key_ = base::Thread::CreateThreadLocalKey(); 152 thread_id_key_ = base::Thread::CreateThreadLocalKey();
166 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey(); 153 per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
167 #ifdef DEBUG 154 #ifdef DEBUG
168 PerThreadAssertScopeBase::thread_local_key = 155 PerThreadAssertScopeBase::thread_local_key =
169 base::Thread::CreateThreadLocalKey(); 156 base::Thread::CreateThreadLocalKey();
170 #endif // DEBUG 157 #endif // DEBUG
171 thread_data_table_ = new Isolate::ThreadDataTable(); 158 thread_data_table_ = new Isolate::ThreadDataTable();
172 } 159 }
173 } 160 }
174 161
175 struct StaticInitializer {
176 StaticInitializer() {
177 Isolate::EnsureDefaultIsolate();
178 }
179 } static_initializer;
180
181 162
182 Address Isolate::get_address_from_id(Isolate::AddressId id) { 163 Address Isolate::get_address_from_id(Isolate::AddressId id) {
183 return isolate_addresses_[id]; 164 return isolate_addresses_[id];
184 } 165 }
185 166
186 167
187 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { 168 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) {
188 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); 169 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage);
189 Iterate(v, thread); 170 Iterate(v, thread);
190 return thread_storage + sizeof(ThreadLocalTop); 171 return thread_storage + sizeof(ThreadLocalTop);
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 // Temporarily set this isolate as current so that various parts of 1500 // Temporarily set this isolate as current so that various parts of
1520 // the isolate can access it in their destructors without having a 1501 // the isolate can access it in their destructors without having a
1521 // direct pointer. We don't use Enter/Exit here to avoid 1502 // direct pointer. We don't use Enter/Exit here to avoid
1522 // initializing the thread data. 1503 // initializing the thread data.
1523 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1504 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1524 Isolate* saved_isolate = UncheckedCurrent(); 1505 Isolate* saved_isolate = UncheckedCurrent();
1525 SetIsolateThreadLocals(this, NULL); 1506 SetIsolateThreadLocals(this, NULL);
1526 1507
1527 Deinit(); 1508 Deinit();
1528 1509
1529 { base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_); 1510 { base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
1530 thread_data_table_->RemoveAllThreads(this); 1511 thread_data_table_->RemoveAllThreads(this);
1531 } 1512 }
1532 1513
1533 if (serialize_partial_snapshot_cache_ != NULL) { 1514 if (serialize_partial_snapshot_cache_ != NULL) {
1534 delete[] serialize_partial_snapshot_cache_; 1515 delete[] serialize_partial_snapshot_cache_;
1535 serialize_partial_snapshot_cache_ = NULL; 1516 serialize_partial_snapshot_cache_ = NULL;
1536 } 1517 }
1537 1518
1538 delete this; 1519 delete this;
1539 1520
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 set_serialize_partial_snapshot_cache_capacity(new_capacity); 1601 set_serialize_partial_snapshot_cache_capacity(new_capacity);
1621 } 1602 }
1622 1603
1623 serialize_partial_snapshot_cache()[length] = obj; 1604 serialize_partial_snapshot_cache()[length] = obj;
1624 set_serialize_partial_snapshot_cache_length(length + 1); 1605 set_serialize_partial_snapshot_cache_length(length + 1);
1625 } 1606 }
1626 1607
1627 1608
1628 void Isolate::SetIsolateThreadLocals(Isolate* isolate, 1609 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
1629 PerIsolateThreadData* data) { 1610 PerIsolateThreadData* data) {
1611 EnsureInitialized();
1630 base::Thread::SetThreadLocal(isolate_key_, isolate); 1612 base::Thread::SetThreadLocal(isolate_key_, isolate);
1631 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); 1613 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1632 } 1614 }
1633 1615
1634 1616
1635 Isolate::~Isolate() { 1617 Isolate::~Isolate() {
1636 TRACE_ISOLATE(destructor); 1618 TRACE_ISOLATE(destructor);
1637 1619
1638 // Has to be called while counters_ are still alive 1620 // Has to be called while counters_ are still alive
1639 runtime_zone_.DeleteKeptSegment(); 1621 runtime_zone_.DeleteKeptSegment();
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 if (prev_ && prev_->Intercept(flag)) return true; 2354 if (prev_ && prev_->Intercept(flag)) return true;
2373 // Then check whether this scope intercepts. 2355 // Then check whether this scope intercepts.
2374 if ((flag & intercept_mask_)) { 2356 if ((flag & intercept_mask_)) {
2375 intercepted_flags_ |= flag; 2357 intercepted_flags_ |= flag;
2376 return true; 2358 return true;
2377 } 2359 }
2378 return false; 2360 return false;
2379 } 2361 }
2380 2362
2381 } } // namespace v8::internal 2363 } } // 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