From: svenpanne@chromium.org Date: Tue, 6 May 2014 13:06:12 +0000 (+0000) Subject: Revert "Removed default Isolate." X-Git-Tag: upstream/4.7.83~9249 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9e373e8c95ff097fc843d44d42b1b15691adb60;p=platform%2Fupstream%2Fv8.git Revert "Removed default Isolate." This reverts commit r21167, cctest/test-serialize has to be fixed first. TBR=dcarney@chromium.org Review URL: https://codereview.chromium.org/267163002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21170 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/api.cc b/src/api.cc index 1ea45ff..1fc270c 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4958,6 +4958,12 @@ void v8::V8::SetArrayBufferAllocator( bool v8::V8::Dispose() { + i::Isolate* isolate = i::Isolate::Current(); + if (!Utils::ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), + "v8::V8::Dispose()", + "Use v8::Isolate::Dispose() for non-default isolate.")) { + return false; + } i::V8::TearDown(); return true; } diff --git a/src/d8.cc b/src/d8.cc index 2661fa0..396d68b 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -1659,7 +1659,7 @@ int Shell::Main(int argc, char* argv[]) { v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); } int result = 0; - Isolate* isolate = Isolate::New(); + Isolate* isolate = Isolate::GetCurrent(); #ifndef V8_SHARED v8::ResourceConstraints constraints; constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory(), @@ -1669,7 +1669,6 @@ int Shell::Main(int argc, char* argv[]) { #endif DumbLineEditor dumb_line_editor(isolate); { - Isolate::Scope scope(isolate); Initialize(isolate); #ifdef ENABLE_VTUNE_JIT_INTERFACE vTune::InitializeVtuneForV8(); diff --git a/src/isolate.cc b/src/isolate.cc index dd7235b..d93639b 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -103,6 +103,7 @@ v8::TryCatch* ThreadLocalTop::TryCatchHandler() { } +Isolate* Isolate::default_isolate_ = NULL; Thread::LocalStorageKey Isolate::isolate_key_; Thread::LocalStorageKey Isolate::thread_id_key_; Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; @@ -165,7 +166,7 @@ void Isolate::SetCrashIfDefaultIsolateInitialized() { void Isolate::EnsureDefaultIsolate() { LockGuard lock_guard(&process_wide_mutex_); CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized); - if (thread_data_table_ == NULL) { + if (default_isolate_ == NULL) { isolate_key_ = Thread::CreateThreadLocalKey(); thread_id_key_ = Thread::CreateThreadLocalKey(); per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); @@ -173,6 +174,12 @@ void Isolate::EnsureDefaultIsolate() { 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_); } } @@ -1516,7 +1523,9 @@ void Isolate::TearDown() { serialize_partial_snapshot_cache_ = NULL; } - delete this; + if (!IsDefaultIsolate()) { + delete this; + } // Restore the previous current isolate. SetIsolateThreadLocals(saved_isolate, saved_data); diff --git a/src/isolate.h b/src/isolate.h index 97854f2..5b1e77f 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -478,6 +478,8 @@ class Isolate { static void GlobalTearDown(); + 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 @@ -1132,12 +1134,14 @@ class Isolate { DISALLOW_COPY_AND_ASSIGN(EntryStackItem); }; - // This mutex protects highest_thread_id_ and thread_data_table_. + // This mutex protects highest_thread_id_, thread_data_table_ and + // default_isolate_. static Mutex process_wide_mutex_; 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. diff --git a/src/log.cc b/src/log.cc index 623e08d..88dae56 100644 --- a/src/log.cc +++ b/src/log.cc @@ -1936,48 +1936,58 @@ void Logger::LogAccessorCallbacks() { static void AddIsolateIdIfNeeded(Isolate* isolate, StringStream* stream) { - if (FLAG_logfile_per_isolate) stream->Add("isolate-%p-", isolate); + if (isolate->IsDefaultIsolate() || !FLAG_logfile_per_isolate) return; + stream->Add("isolate-%p-", isolate); } static SmartArrayPointer PrepareLogFileName( Isolate* isolate, const char* file_name) { - HeapStringAllocator allocator; - StringStream stream(&allocator); - AddIsolateIdIfNeeded(isolate, &stream); - for (const char* p = file_name; *p; p++) { - if (*p == '%') { - p++; - switch (*p) { - case '\0': - // If there's a % at the end of the string we back up - // one character so we can escape the loop properly. - p--; - break; - case 'p': - stream.Add("%d", OS::GetCurrentProcessId()); - break; - case 't': { - // %t expands to the current time in milliseconds. - double time = OS::TimeCurrentMillis(); - stream.Add("%.0f", FmtElm(time)); - break; + if (strchr(file_name, '%') != NULL || !isolate->IsDefaultIsolate()) { + // If there's a '%' in the log file name we have to expand + // placeholders. + HeapStringAllocator allocator; + StringStream stream(&allocator); + AddIsolateIdIfNeeded(isolate, &stream); + for (const char* p = file_name; *p; p++) { + if (*p == '%') { + p++; + switch (*p) { + case '\0': + // If there's a % at the end of the string we back up + // one character so we can escape the loop properly. + p--; + break; + case 'p': + stream.Add("%d", OS::GetCurrentProcessId()); + break; + case 't': { + // %t expands to the current time in milliseconds. + double time = OS::TimeCurrentMillis(); + stream.Add("%.0f", FmtElm(time)); + break; + } + case '%': + // %% expands (contracts really) to %. + stream.Put('%'); + break; + default: + // All other %'s expand to themselves. + stream.Put('%'); + stream.Put(*p); + break; } - case '%': - // %% expands (contracts really) to %. - stream.Put('%'); - break; - default: - // All other %'s expand to themselves. - stream.Put('%'); - stream.Put(*p); - break; + } else { + stream.Put(*p); } - } else { - stream.Put(*p); } + return SmartArrayPointer(stream.ToCString()); } - return SmartArrayPointer(stream.ToCString()); + int length = StrLength(file_name); + char* str = NewArray(length + 1); + OS::MemCopy(str, file_name, length); + str[length] = '\0'; + return SmartArrayPointer(str); } diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc index ef0a282..a8bf871 100644 --- a/src/mksnapshot.cc +++ b/src/mksnapshot.cc @@ -393,10 +393,6 @@ int main(int argc, char** argv) { isolate->Exit(); isolate->Dispose(); - // TODO(svenpanne) Alas, we can't cleanly dispose V8 here, because - // Serializer::code_address_map_ is static (a.k.a. a global variable), and - // disposing that would involve accessing the Isolate just disposed. - // code_address_map_ really has to be an instance variable... - // V8::Dispose(); + V8::Dispose(); return 0; } diff --git a/src/v8.cc b/src/v8.cc index 9cca201..f8156ec 100644 --- a/src/v8.cc +++ b/src/v8.cc @@ -53,6 +53,16 @@ bool V8::Initialize(Deserializer* des) { void V8::TearDown() { + Isolate* isolate = Isolate::Current(); + ASSERT(isolate->IsDefaultIsolate()); + if (!isolate->IsInitialized()) return; + + // 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. + isolate->TearDown(); + delete isolate; + Bootstrapper::TearDownExtensions(); ElementsAccessor::TearDown(); LOperand::TearDownCaches(); diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index 299c596..b1cf5ab 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -152,7 +152,6 @@ int main(int argc, char* argv[]) { i::TraceExtension trace_extension; v8::RegisterExtension(&trace_extension); - v8::V8::Initialize(); int tests_run = 0; bool print_run_count = true; for (int i = 1; i < argc; i++) { diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 1dd4337..df70d5c 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -19269,6 +19269,7 @@ TEST(IsolateNewDispose) { v8::Isolate* current_isolate = CcTest::isolate(); v8::Isolate* isolate = v8::Isolate::New(); CHECK(isolate != NULL); + CHECK(!reinterpret_cast(isolate)->IsDefaultIsolate()); CHECK(current_isolate != isolate); CHECK(current_isolate == CcTest::isolate()); @@ -22338,7 +22339,6 @@ TEST(EventLogging) { TEST(Promises) { i::FLAG_harmony_promises = true; - i::FLAG_harmony_weak_collections = true; // Implied LocalContext context; v8::Isolate* isolate = context->GetIsolate(); diff --git a/test/cctest/test-microtask-delivery.cc b/test/cctest/test-microtask-delivery.cc index 21177f7..cfe5d69 100644 --- a/test/cctest/test-microtask-delivery.cc +++ b/test/cctest/test-microtask-delivery.cc @@ -37,7 +37,6 @@ class HarmonyIsolate { public: HarmonyIsolate() { i::FLAG_harmony_promises = true; - i::FLAG_harmony_weak_collections = true; // Implied isolate_ = Isolate::New(); isolate_->Enter(); }