Revert "lazy instantiation of the default isolate" and "build fix for 17049".

This reverts r17049 and r17060.

TBR=dcarney@chromium.org

Review URL: https://codereview.chromium.org/25697002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17066 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f5890e02
......@@ -5007,13 +5007,14 @@ void v8::V8::SetArrayBufferAllocator(
bool v8::V8::Dispose() {
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
if (!ApiCheck(isolate == NULL || isolate->IsDefaultIsolate(),
i::Isolate* isolate = i::Isolate::Current();
if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(),
"v8::V8::Dispose()",
"Use v8::Isolate::Dispose() for a non-default isolate.")) {
return false;
}
return i::V8::TearDown();
i::V8::TearDown();
return true;
}
......@@ -6487,10 +6488,6 @@ void V8::CancelTerminateExecution(Isolate* isolate) {
Isolate* Isolate::GetCurrent() {
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
if (isolate == NULL) {
isolate = i::Isolate::EnsureDefaultIsolate(true);
ASSERT(isolate == i::Isolate::UncheckedCurrent());
}
return reinterpret_cast<Isolate*>(isolate);
}
......
......@@ -330,6 +330,7 @@ void Isolate::PreallocatedStorageDelete(void* p) {
storage->LinkTo(&free_list_);
}
Isolate* Isolate::default_isolate_ = NULL;
Thread::LocalStorageKey Isolate::isolate_key_;
Thread::LocalStorageKey Isolate::thread_id_key_;
Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
......@@ -347,7 +348,6 @@ static DefaultIsolateStatus default_isolate_status_
= kDefaultIsolateUninitialized;
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
Atomic32 Isolate::isolate_counter_ = 0;
Atomic32 Isolate::living_isolates_ = 0;
Isolate::PerIsolateThreadData*
Isolate::FindOrAllocatePerThreadDataForThisThread() {
......@@ -390,75 +390,61 @@ void Isolate::SetCrashIfDefaultIsolateInitialized() {
}
Isolate* Isolate::EnsureDefaultIsolate(bool must_be_null) {
static Isolate* default_isolate_ = NULL;
void Isolate::EnsureDefaultIsolate() {
LockGuard<Mutex> lock_guard(&process_wide_mutex_);
CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
if (must_be_null) {
CHECK(default_isolate_ == NULL);
}
if (default_isolate_ == NULL) {
default_isolate_ = new Isolate(true);
isolate_key_ = Thread::CreateThreadLocalKey();
thread_id_key_ = Thread::CreateThreadLocalKey();
per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
#ifdef DEBUG
PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey();
#endif // DEBUG
thread_data_table_ = new Isolate::ThreadDataTable();
default_isolate_ = new Isolate();
}
// Can't use SetIsolateThreadLocals(default_isolate_, NULL) here
// because a non-null thread data may be already set.
if (Thread::GetThreadLocal(isolate_key_) == NULL) {
Thread::SetThreadLocal(isolate_key_, default_isolate_);
}
return default_isolate_;
}
void Isolate::InitializeThreadLocalStorage() {
// Double checked locking on existence of thread_data_table_.
if (thread_data_table_ != NULL) return;
LockGuard<Mutex> lock_guard(&process_wide_mutex_);
if (thread_data_table_ != NULL) return;
isolate_key_ = Thread::CreateThreadLocalKey();
thread_id_key_ = Thread::CreateThreadLocalKey();
per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey();
#ifdef DEBUG
PerThreadAssertScopeBase::thread_local_key = Thread::CreateThreadLocalKey();
#endif // DEBUG
thread_data_table_ = new Isolate::ThreadDataTable();
CHECK(thread_data_table_ != NULL);
}
// TODO(dcarney): Remove this with default_isolate_ and Isolate::Current.
struct StaticInitializer {
StaticInitializer() {
Isolate::InitializeThreadLocalStorage();
Isolate::EnsureDefaultIsolate();
}
} static_initializer;
#ifdef ENABLE_DEBUGGER_SUPPORT
Debugger* Isolate::GetDefaultIsolateDebugger() {
return EnsureDefaultIsolate()->debugger();
EnsureDefaultIsolate();
return default_isolate_->debugger();
}
#endif
StackGuard* Isolate::GetDefaultIsolateStackGuard() {
return EnsureDefaultIsolate()->stack_guard();
EnsureDefaultIsolate();
return default_isolate_->stack_guard();
}
void Isolate::EnterDefaultIsolate() {
Isolate* default_isolate = EnsureDefaultIsolate();
ASSERT(default_isolate != NULL);
EnsureDefaultIsolate();
ASSERT(default_isolate_ != NULL);
PerIsolateThreadData* data = CurrentPerIsolateThreadData();
// If not yet in default isolate - enter it.
if (data == NULL || data->isolate() != default_isolate) {
default_isolate->Enter();
if (data == NULL || data->isolate() != default_isolate_) {
default_isolate_->Enter();
}
}
v8::Isolate* Isolate::GetDefaultIsolateForLocking() {
return reinterpret_cast<v8::Isolate*>(EnsureDefaultIsolate());
EnsureDefaultIsolate();
return reinterpret_cast<v8::Isolate*>(default_isolate_);
}
......@@ -1748,7 +1734,7 @@ void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
#endif
Isolate::Isolate(bool is_default_isolate)
Isolate::Isolate()
: state_(UNINITIALIZED),
embedder_data_(NULL),
entry_stack_(NULL),
......@@ -1798,7 +1784,6 @@ Isolate::Isolate(bool is_default_isolate)
has_fatal_error_(false),
use_crankshaft_(true),
initialized_from_snapshot_(false),
is_default_isolate_(is_default_isolate),
cpu_profiler_(NULL),
heap_profiler_(NULL),
function_entry_hook_(NULL),
......@@ -1806,10 +1791,7 @@ Isolate::Isolate(bool is_default_isolate)
optimizing_compiler_thread_(NULL),
sweeper_thread_(NULL),
stress_deopt_count_(0) {
InitializeThreadLocalStorage();
id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1);
NoBarrier_AtomicIncrement(&living_isolates_, 1);
TRACE_ISOLATE(constructor);
memset(isolate_addresses_, 0,
......@@ -1992,7 +1974,7 @@ Isolate::~Isolate() {
// The entry stack must be empty when we get here,
// except for the default isolate, where it can
// still contain up to one entry stack item
ASSERT(entry_stack_ == NULL || is_default_isolate_);
ASSERT(entry_stack_ == NULL || this == default_isolate_);
ASSERT(entry_stack_ == NULL || entry_stack_->previous_item == NULL);
delete entry_stack_;
......@@ -2077,8 +2059,6 @@ Isolate::~Isolate() {
delete debug_;
debug_ = NULL;
#endif
NoBarrier_AtomicIncrement(&living_isolates_, -1);
}
......
......@@ -491,17 +491,14 @@ class Isolate {
static void GlobalTearDown();
bool IsDefaultIsolate() const { return is_default_isolate_; }
bool IsDefaultIsolate() const { return this == default_isolate_; }
static void SetCrashIfDefaultIsolateInitialized();
// Ensures that process-wide resources and the default isolate have been
// allocated. It is only necessary to call this method in rare cases, for
// example if you are using V8 from within the body of a static initializer.
// Safe to call multiple times.
static Isolate* EnsureDefaultIsolate(bool must_be_null = false);
// Initialize all thread local variables
static void InitializeThreadLocalStorage();
static void EnsureDefaultIsolate();
// Find the PerThread for this particular (isolate, thread) combination
// If one does not yet exist, return null.
......@@ -1140,12 +1137,8 @@ class Isolate {
// Given an address occupied by a live code object, return that object.
Object* FindCodeObject(Address a);
static Atomic32 GetLivingIsolates() {
return Acquire_Load(&living_isolates_);
}
private:
explicit Isolate(bool is_default_isolate = false);
Isolate();
friend struct GlobalState;
friend struct InitializeGlobalState;
......@@ -1210,11 +1203,11 @@ class Isolate {
static Thread::LocalStorageKey per_isolate_thread_data_key_;
static Thread::LocalStorageKey isolate_key_;
static Thread::LocalStorageKey thread_id_key_;
static Isolate* default_isolate_;
static ThreadDataTable* thread_data_table_;
// A global counter for all generated Isolates, might overflow.
static Atomic32 isolate_counter_;
static Atomic32 living_isolates_;
void Deinit();
......@@ -1326,9 +1319,6 @@ class Isolate {
// True if this isolate was initialized from a snapshot.
bool initialized_from_snapshot_;
// True only for the default isolate.
bool is_default_isolate_;
// Time stamp at initialization.
double time_millis_at_init_;
......
......@@ -79,24 +79,16 @@ bool V8::Initialize(Deserializer* des) {
}
bool V8::TearDown() {
Isolate* isolate = Isolate::UncheckedCurrent();
if (isolate != NULL) {
ASSERT(isolate->IsDefaultIsolate());
if (isolate->IsInitialized()) isolate->TearDown();
delete isolate;
}
// V8 was never initialized, nothing to do.
if (Acquire_Load(&init_once) == ONCE_STATE_UNINITIALIZED) return true;
// TODO(dcarney): Everything below this should be in some sort of mutex...
Atomic32 living_isolates = Isolate::GetLivingIsolates();
void V8::TearDown() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate->IsDefaultIsolate());
if (!isolate->IsInitialized()) return;
// All isolates have to be torn down before clearing the LOperand
// The isolate has to be torn down before clearing the LOperand
// caches so that the optimizing compiler thread (if running)
// doesn't see an inconsistent view of the lithium instructions.
if (living_isolates != 0) return false;
isolate->TearDown();
delete isolate;
ElementsAccessor::TearDown();
LOperand::TearDownCaches();
......@@ -108,7 +100,6 @@ bool V8::TearDown() {
call_completed_callbacks_ = NULL;
Sampler::TearDown();
return true;
}
......
......@@ -81,7 +81,7 @@ class V8 : public AllStatic {
// initial state is created by reading the deserialized data into an
// empty heap.
static bool Initialize(Deserializer* des);
static bool TearDown();
static void TearDown();
// Report process out of memory. Implementation found in api.cc.
static void FatalProcessOutOfMemory(const char* location,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment