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

Unified Diff: src/isolate.cc

Issue 3601010: [Isolates] Allow running multiple isolates in shell and use this in tests. (Closed)
Patch Set: Created 10 years, 2 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
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 1113a9138247ad71e0c57a43ec444cbc73b622a6..74653649d20c9acfb82d49602848698d04dc2b33 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -247,6 +247,8 @@ void Isolate::EnsureDefaultIsolate() {
thread_data_table_ = new Isolate::ThreadDataTable();
default_isolate_ = new Isolate();
}
+ // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here
+ // becase a non-null thread data may be already set.
Thread::SetThreadLocal(isolate_key_, default_isolate_);
CHECK(default_isolate_->PreInit());
}
@@ -389,11 +391,22 @@ Isolate::Isolate()
}
void Isolate::TearDown() {
+ // Temporarily set this isolate as current so that various parts of
+ // the isolate can access it in their destructors without having a
+ // direct pointer. We don't use Enter/Exit here to avoid
+ // initializing the thread data.
+ PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData();
+ Isolate* saved_isolate = UncheckedCurrent();
+ SetIsolateThreadLocals(this, NULL);
+
Deinit();
if (!IsDefaultIsolate()) {
delete this;
}
+
+ // Restore the previous current isolate.
+ SetIsolateThreadLocals(saved_isolate, saved_data);
}
@@ -422,6 +435,14 @@ void Isolate::Deinit() {
}
}
+
+void Isolate::SetIsolateThreadLocals(Isolate* isolate,
+ PerIsolateThreadData* data) {
+ Thread::SetThreadLocal(isolate_key_, isolate);
+ Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
+}
+
+
Isolate::~Isolate() {
#ifdef ENABLE_LOGGING_AND_PROFILING
delete producer_heap_profile_;
@@ -701,8 +722,7 @@ void Isolate::Enter() {
entry_stack_);
entry_stack_ = item;
- Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
- Thread::SetThreadLocal(isolate_key_, this);
+ SetIsolateThreadLocals(this, data);
CHECK(PreInit());
@@ -732,8 +752,7 @@ void Isolate::Exit() {
delete item;
// Reinit the current thread for the isolate it was running before this one.
- Thread::SetThreadLocal(per_isolate_thread_data_key_, previous_thread_data);
- Thread::SetThreadLocal(isolate_key_, previous_isolate);
+ SetIsolateThreadLocals(previous_isolate, previous_thread_data);
}
} } // namespace v8::internal

Powered by Google App Engine
This is Rietveld 408576698