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

Side by Side Diff: src/isolate.cc

Issue 378513002: Reland^3 r22105 "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/sampler.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() { Isolate::EnsureDefaultIsolate(); }
177 } static_initializer;
178
179 162
180 Address Isolate::get_address_from_id(Isolate::AddressId id) { 163 Address Isolate::get_address_from_id(Isolate::AddressId id) {
181 return isolate_addresses_[id]; 164 return isolate_addresses_[id];
182 } 165 }
183 166
184 167
185 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { 168 char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) {
186 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); 169 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage);
187 Iterate(v, thread); 170 Iterate(v, thread);
188 return thread_storage + sizeof(ThreadLocalTop); 171 return thread_storage + sizeof(ThreadLocalTop);
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 // the isolate can access it in their destructors without having a 1509 // the isolate can access it in their destructors without having a
1527 // direct pointer. We don't use Enter/Exit here to avoid 1510 // direct pointer. We don't use Enter/Exit here to avoid
1528 // initializing the thread data. 1511 // initializing the thread data.
1529 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); 1512 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
1530 Isolate* saved_isolate = UncheckedCurrent(); 1513 Isolate* saved_isolate = UncheckedCurrent();
1531 SetIsolateThreadLocals(this, NULL); 1514 SetIsolateThreadLocals(this, NULL);
1532 1515
1533 Deinit(); 1516 Deinit();
1534 1517
1535 { 1518 {
1536 base::LockGuard<base::Mutex> lock_guard(&process_wide_mutex_); 1519 base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
1537 thread_data_table_->RemoveAllThreads(this); 1520 thread_data_table_->RemoveAllThreads(this);
1538 } 1521 }
1539 1522
1540 if (serialize_partial_snapshot_cache_ != NULL) { 1523 if (serialize_partial_snapshot_cache_ != NULL) {
1541 delete[] serialize_partial_snapshot_cache_; 1524 delete[] serialize_partial_snapshot_cache_;
1542 serialize_partial_snapshot_cache_ = NULL; 1525 serialize_partial_snapshot_cache_ = NULL;
1543 } 1526 }
1544 1527
1545 delete this; 1528 delete this;
1546 1529
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 set_serialize_partial_snapshot_cache_capacity(new_capacity); 1610 set_serialize_partial_snapshot_cache_capacity(new_capacity);
1628 } 1611 }
1629 1612
1630 serialize_partial_snapshot_cache()[length] = obj; 1613 serialize_partial_snapshot_cache()[length] = obj;
1631 set_serialize_partial_snapshot_cache_length(length + 1); 1614 set_serialize_partial_snapshot_cache_length(length + 1);
1632 } 1615 }
1633 1616
1634 1617
1635 void Isolate::SetIsolateThreadLocals(Isolate* isolate, 1618 void Isolate::SetIsolateThreadLocals(Isolate* isolate,
1636 PerIsolateThreadData* data) { 1619 PerIsolateThreadData* data) {
1620 EnsureInitialized();
1637 base::Thread::SetThreadLocal(isolate_key_, isolate); 1621 base::Thread::SetThreadLocal(isolate_key_, isolate);
1638 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data); 1622 base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
1639 } 1623 }
1640 1624
1641 1625
1642 Isolate::~Isolate() { 1626 Isolate::~Isolate() {
1643 TRACE_ISOLATE(destructor); 1627 TRACE_ISOLATE(destructor);
1644 1628
1645 // Has to be called while counters_ are still alive 1629 // Has to be called while counters_ are still alive
1646 runtime_zone_.DeleteKeptSegment(); 1630 runtime_zone_.DeleteKeptSegment();
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 if (prev_ && prev_->Intercept(flag)) return true; 2347 if (prev_ && prev_->Intercept(flag)) return true;
2364 // Then check whether this scope intercepts. 2348 // Then check whether this scope intercepts.
2365 if ((flag & intercept_mask_)) { 2349 if ((flag & intercept_mask_)) {
2366 intercepted_flags_ |= flag; 2350 intercepted_flags_ |= flag;
2367 return true; 2351 return true;
2368 } 2352 }
2369 return false; 2353 return false;
2370 } 2354 }
2371 2355
2372 } } // namespace v8::internal 2356 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/sampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698