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

Unified Diff: src/isolate.cc

Issue 2715004: [Isolates]... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Address comments/make StackGuard::ThreadLocal::Initialize/Clear side-effects visible 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 side-by-side diff with in-line comments
Download patch
« src/execution.cc ('K') | « src/isolate.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
===================================================================
--- src/isolate.cc (revision 4831)
+++ src/isolate.cc (working copy)
@@ -46,15 +46,35 @@
int Isolate::number_of_isolates_ = 0;
+class IsolateInitializer {
+ public:
+ IsolateInitializer() {
+ Isolate::InitOnce();
+ }
+};
+
+
+static IsolateInitializer isolate_initializer;
+
+
void Isolate::InitOnce() {
+ ASSERT(global_isolate == NULL);
+ global_isolate = new Isolate();
+ ASSERT(global_isolate->PreInit());
}
Isolate* Isolate::Create(Deserializer* des) {
// While we're still building out support for isolates, only support
// one single global isolate.
- ASSERT(global_isolate == NULL);
- global_isolate = new Isolate();
+
+ if (global_isolate != NULL) {
+ // Allow for two-phase initialization.
+ ASSERT(global_isolate->state_ != INITIALIZED);
+ } else {
+ global_isolate = new Isolate();
+ }
+
if (global_isolate->Init(des)) {
++number_of_isolates_;
return global_isolate;
@@ -67,11 +87,16 @@
Isolate::Isolate()
- : initialized_(false),
+ : state_(UNINITIALIZED),
bootstrapper_(NULL),
+ break_access_(OS::CreateMutex()),
stub_cache_(NULL),
handle_scope_implementer_(NULL) {
+ heap_.isolate_ = this;
+ stack_guard_.isolate_ = this;
+
handle_scope_data_.Initialize();
+
#define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
name##_ = (initial_value);
ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE)
@@ -90,10 +115,29 @@
delete bootstrapper_;
bootstrapper_ = NULL;
- if (initialized_) --number_of_isolates_;
+ if (state_ == INITIALIZED) --number_of_isolates_;
}
+bool Isolate::PreInit() {
+ if (state_ != UNINITIALIZED) return true;
+ ASSERT(global_isolate == this);
+
+ // Safe after setting Heap::isolate_, initializing StackGuard and
+ // ensuring that Isolate::Current() == this.
+ heap()->SetStackLimits();
+
+#ifdef DEBUG
+ DisallowAllocationFailure disallow_allocation_failure;
+#endif
+ bootstrapper_ = new Bootstrapper();
+ handle_scope_implementer_ = new HandleScopeImplementer();
+ stub_cache_ = new StubCache();
+ state_ = PREINITIALIZED;
+ return true;
+}
+
+
bool Isolate::Init(Deserializer* des) {
ASSERT(global_isolate == this);
@@ -104,10 +148,7 @@
DisallowAllocationFailure disallow_allocation_failure;
#endif
- // Allocate per-isolate globals early.
- bootstrapper_ = new Bootstrapper();
- handle_scope_implementer_ = new HandleScopeImplementer();
- stub_cache_ = new StubCache();
+ if (state_ == UNINITIALIZED && !PreInit()) return false;
// Enable logging before setting up the heap
Logger::Setup();
@@ -127,7 +168,7 @@
// will ensure this too, but we don't have to use lockers if we are only
// using one thread.
ExecutionAccess lock;
- StackGuard::InitThread(lock);
+ stack_guard_.InitThread(lock);
}
// Setup the object heap
@@ -159,7 +200,7 @@
// Deserializing may put strange things in the root array's copy of the
// stack guard.
- Heap::SetStackLimits();
+ heap_.SetStackLimits();
// Setup the CPU support. Must be done after heap setup and after
// any deserialization because we have to have the initial heap
@@ -176,8 +217,7 @@
LOG(LogCompiledFunctions());
}
- initialized_ = true;
-
+ state_ = INITIALIZED;
return true;
}
« src/execution.cc ('K') | « src/isolate.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698