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

Unified Diff: src/isolate.cc

Issue 469783002: Require V8 to be explicitly initialized before an Isolate is created (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 3 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
« no previous file with comments | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 66733cb67514c5012a79c022875145f86e3f261b..e96044532115b42e71c674384537a634f0eb377e 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -48,7 +48,6 @@ int ThreadId::AllocateThreadId() {
int ThreadId::GetCurrentThreadId() {
- Isolate::EnsureInitialized();
int thread_id = base::Thread::GetThreadLocalInt(Isolate::thread_id_key_);
if (thread_id == 0) {
thread_id = AllocateThreadId();
@@ -114,17 +113,16 @@ base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
#ifdef DEBUG
base::Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
#endif // DEBUG
-base::LazyMutex Isolate::process_wide_mutex_ = LAZY_MUTEX_INITIALIZER;
+base::LazyMutex Isolate::thread_data_table_mutex_ = LAZY_MUTEX_INITIALIZER;
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
base::Atomic32 Isolate::isolate_counter_ = 0;
Isolate::PerIsolateThreadData*
Isolate::FindOrAllocatePerThreadDataForThisThread() {
- EnsureInitialized();
ThreadId thread_id = ThreadId::Current();
PerIsolateThreadData* per_thread = NULL;
{
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
per_thread = thread_data_table_->Lookup(this, thread_id);
if (per_thread == NULL) {
per_thread = new PerIsolateThreadData(this, thread_id);
@@ -144,28 +142,26 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
ThreadId thread_id) {
- EnsureInitialized();
PerIsolateThreadData* per_thread = NULL;
{
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
per_thread = thread_data_table_->Lookup(this, thread_id);
}
return per_thread;
}
-void Isolate::EnsureInitialized() {
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
- if (thread_data_table_ == NULL) {
- isolate_key_ = base::Thread::CreateThreadLocalKey();
- thread_id_key_ = base::Thread::CreateThreadLocalKey();
- per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
+void Isolate::InitializeOncePerProcess() {
+ base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
+ CHECK(thread_data_table_ == NULL);
+ isolate_key_ = base::Thread::CreateThreadLocalKey();
+ thread_id_key_ = base::Thread::CreateThreadLocalKey();
+ per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
#ifdef DEBUG
- PerThreadAssertScopeBase::thread_local_key =
- base::Thread::CreateThreadLocalKey();
+ PerThreadAssertScopeBase::thread_local_key =
+ base::Thread::CreateThreadLocalKey();
#endif // DEBUG
- thread_data_table_ = new Isolate::ThreadDataTable();
- }
+ thread_data_table_ = new Isolate::ThreadDataTable();
}
@@ -1521,6 +1517,10 @@ Isolate::Isolate()
stress_deopt_count_(0),
next_optimization_id_(0),
use_counter_callback_(NULL) {
+ {
+ base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
+ CHECK(thread_data_table_);
+ }
id_ = base::NoBarrier_AtomicIncrement(&isolate_counter_, 1);
TRACE_ISOLATE(constructor);
@@ -1571,7 +1571,7 @@ void Isolate::TearDown() {
Deinit();
{
- base::LockGuard<base::Mutex> lock_guard(process_wide_mutex_.Pointer());
+ base::LockGuard<base::Mutex> lock_guard(thread_data_table_mutex_.Pointer());
thread_data_table_->RemoveAllThreads(this);
}
@@ -1676,7 +1676,6 @@ void Isolate::PushToPartialSnapshotCache(Object* obj) {
void Isolate::SetIsolateThreadLocals(Isolate* isolate,
PerIsolateThreadData* data) {
- EnsureInitialized();
base::Thread::SetThreadLocal(isolate_key_, isolate);
base::Thread::SetThreadLocal(per_isolate_thread_data_key_, data);
}
« no previous file with comments | « src/isolate.h ('k') | src/mksnapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698