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

Side by Side Diff: src/isolate.cc

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