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

Side by Side Diff: src/isolate.cc

Issue 2860009: [Isolates] Add a preprocessor flag to guard using TLS for the global isolate.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: fixes Created 10 years, 6 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') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2010 the V8 project authors. All rights reserved. 1 // Copyright 2006-2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 #include "serialize.h" 37 #include "serialize.h"
38 #include "scopeinfo.h" 38 #include "scopeinfo.h"
39 #include "simulator.h" 39 #include "simulator.h"
40 #include "stub-cache.h" 40 #include "stub-cache.h"
41 #include "oprofile-agent.h" 41 #include "oprofile-agent.h"
42 42
43 namespace v8 { 43 namespace v8 {
44 namespace internal { 44 namespace internal {
45 45
46 46
47 Isolate* Isolate::global_isolate = NULL; 47 #ifdef V8_USE_TLS_FOR_GLOBAL_ISOLATE
48 Thread::LocalStorageKey Isolate::global_isolate_key_;
49
50
51 Isolate* Isolate::InitThreadForGlobalIsolate() {
52 ASSERT(global_isolate_ != NULL);
53 Thread::SetThreadLocal(global_isolate_key_, global_isolate_);
54 return global_isolate_;
55 }
56 #endif
57
58 Isolate* Isolate::global_isolate_ = NULL;
48 int Isolate::number_of_isolates_ = 0; 59 int Isolate::number_of_isolates_ = 0;
49 60
50 61
51 class IsolateInitializer { 62 class IsolateInitializer {
52 public: 63 public:
53 IsolateInitializer() { 64 IsolateInitializer() {
54 Isolate::InitOnce(); 65 Isolate::InitOnce();
55 } 66 }
56 }; 67 };
57 68
58 69
59 static IsolateInitializer isolate_initializer; 70 static IsolateInitializer isolate_initializer;
60 71
61 72
62 void Isolate::InitOnce() { 73 void Isolate::InitOnce() {
63 ASSERT(global_isolate == NULL); 74 ASSERT(global_isolate_ == NULL);
64 global_isolate = new Isolate(); 75 #ifdef V8_USE_TLS_FOR_GLOBAL_ISOLATE
65 CHECK(global_isolate->PreInit()); 76 global_isolate_key_ = Thread::CreateThreadLocalKey();
77 #endif
78 global_isolate_ = new Isolate();
79 CHECK(global_isolate_->PreInit());
66 } 80 }
67 81
68 82
69 Isolate* Isolate::Create(Deserializer* des) { 83 Isolate* Isolate::Create(Deserializer* des) {
70 // While we're still building out support for isolates, only support 84 // While we're still building out support for isolates, only support
71 // one single global isolate. 85 // one single global isolate.
72 86
73 if (global_isolate != NULL) { 87 if (global_isolate_ != NULL) {
74 // Allow for two-phase initialization. 88 // Allow for two-phase initialization.
75 ASSERT(global_isolate->state_ != INITIALIZED); 89 ASSERT(global_isolate_->state_ != INITIALIZED);
76 } else { 90 } else {
77 global_isolate = new Isolate(); 91 global_isolate_ = new Isolate();
78 } 92 }
79 93
80 if (global_isolate->Init(des)) { 94 if (global_isolate_->Init(des)) {
81 ++number_of_isolates_; 95 ++number_of_isolates_;
82 return global_isolate; 96 return global_isolate_;
83 } else { 97 } else {
84 delete global_isolate; 98 delete global_isolate_;
85 global_isolate = NULL; 99 global_isolate_ = NULL;
100 #ifdef V8_USE_TLS_FOR_GLOBAL_ISOLATE
101 Thread::SetThreadLocal(global_isolate_key_, NULL);
102 #endif
86 return NULL; 103 return NULL;
87 } 104 }
88 } 105 }
89 106
90 107
91 Isolate::Isolate() 108 Isolate::Isolate()
92 : state_(UNINITIALIZED), 109 : state_(UNINITIALIZED),
93 bootstrapper_(NULL), 110 bootstrapper_(NULL),
94 cpu_features_(NULL), 111 cpu_features_(NULL),
95 break_access_(OS::CreateMutex()), 112 break_access_(OS::CreateMutex()),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 cpu_features_ = NULL; 149 cpu_features_ = NULL;
133 delete bootstrapper_; 150 delete bootstrapper_;
134 bootstrapper_ = NULL; 151 bootstrapper_ = NULL;
135 152
136 if (state_ == INITIALIZED) --number_of_isolates_; 153 if (state_ == INITIALIZED) --number_of_isolates_;
137 } 154 }
138 155
139 156
140 bool Isolate::PreInit() { 157 bool Isolate::PreInit() {
141 if (state_ != UNINITIALIZED) return true; 158 if (state_ != UNINITIALIZED) return true;
142 ASSERT(global_isolate == this); 159 ASSERT(global_isolate_ == this);
160
161 #ifdef V8_USE_TLS_FOR_GLOBAL_ISOLATE
162 InitThreadForGlobalIsolate();
163 #endif
143 164
144 // Safe after setting Heap::isolate_, initializing StackGuard and 165 // Safe after setting Heap::isolate_, initializing StackGuard and
145 // ensuring that Isolate::Current() == this. 166 // ensuring that Isolate::Current() == this.
146 heap_.SetStackLimits(); 167 heap_.SetStackLimits();
147 168
148 #ifdef DEBUG 169 #ifdef DEBUG
149 DisallowAllocationFailure disallow_allocation_failure; 170 DisallowAllocationFailure disallow_allocation_failure;
150 #endif 171 #endif
151 bootstrapper_ = new Bootstrapper(); 172 bootstrapper_ = new Bootstrapper();
152 cpu_features_ = new CpuFeatures(); 173 cpu_features_ = new CpuFeatures();
153 handle_scope_implementer_ = new HandleScopeImplementer(); 174 handle_scope_implementer_ = new HandleScopeImplementer();
154 stub_cache_ = new StubCache(); 175 stub_cache_ = new StubCache();
155 state_ = PREINITIALIZED; 176 state_ = PREINITIALIZED;
156 return true; 177 return true;
157 } 178 }
158 179
159 180
160 bool Isolate::Init(Deserializer* des) { 181 bool Isolate::Init(Deserializer* des) {
161 ASSERT(global_isolate == this); 182 ASSERT(global_isolate_ == this);
162 183
163 bool create_heap_objects = des == NULL; 184 bool create_heap_objects = des == NULL;
164 185
165 #ifdef DEBUG 186 #ifdef DEBUG
166 // The initialization process does not handle memory exhaustion. 187 // The initialization process does not handle memory exhaustion.
167 DisallowAllocationFailure disallow_allocation_failure; 188 DisallowAllocationFailure disallow_allocation_failure;
168 #endif 189 #endif
169 190
170 if (state_ == UNINITIALIZED && !PreInit()) return false; 191 if (state_ == UNINITIALIZED && !PreInit()) return false;
171 192
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 LOG(LogCodeObjects()); 257 LOG(LogCodeObjects());
237 LOG(LogCompiledFunctions()); 258 LOG(LogCompiledFunctions());
238 } 259 }
239 260
240 state_ = INITIALIZED; 261 state_ = INITIALIZED;
241 return true; 262 return true;
242 } 263 }
243 264
244 265
245 } } // namespace v8::internal 266 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698