From 6d92511162c3d4419670dba440e785206bbb7b76 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Tue, 25 Jun 2013 08:11:50 +0000 Subject: [PATCH] Reland "Remove IsInitialized checks from inlined API functions." The initialization sequence in Blink has been adapted to use explicit isolate initialization instead of through calling v8::Null() as the first API call. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/17642011 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15311 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 22 +++++++++++----------- src/api.cc | 10 ++++++++++ src/isolate.cc | 2 -- test/cctest/test-api.cc | 45 --------------------------------------------- 4 files changed, 21 insertions(+), 58 deletions(-) diff --git a/include/v8.h b/include/v8.h index de3a40f..7074cc0 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5347,7 +5347,6 @@ class Internals { static const int kExternalTwoByteRepresentationTag = 0x02; static const int kExternalAsciiRepresentationTag = 0x06; - static const int kIsolateStateOffset = 0; static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; static const int kIsolateRootsOffset = 3 * kApiPointerSize; static const int kUndefinedValueRootIndex = 5; @@ -5372,6 +5371,12 @@ class Internals { static const int kUndefinedOddballKind = 5; static const int kNullOddballKind = 3; +#ifdef V8_ENABLE_CHECKS + static void CheckInitialized(v8::Isolate* isolate); +#else + static void CheckInitialized(v8::Isolate* isolate) { } +#endif + V8_INLINE(static bool HasHeapObjectTag(internal::Object* value)) { return ((reinterpret_cast(value) & kHeapObjectTagMask) == kHeapObjectTag); @@ -5405,11 +5410,6 @@ class Internals { return representation == kExternalTwoByteRepresentationTag; } - V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) { - uint8_t* addr = reinterpret_cast(isolate) + kIsolateStateOffset; - return *reinterpret_cast(addr) == 1; - } - V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) { uint8_t* addr = reinterpret_cast(obj) + kNodeFlagsOffset; return *addr & (1 << shift); @@ -5985,7 +5985,7 @@ String* String::Cast(v8::Value* value) { Local String::Empty(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; - if (!I::IsInitialized(isolate)) return Empty(); + I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); return Local(reinterpret_cast(slot)); } @@ -6354,7 +6354,7 @@ ReturnValue PropertyCallbackInfo::GetReturnValue() const { Handle Undefined(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; - if (!I::IsInitialized(isolate)) return Undefined(); + I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); return Handle(reinterpret_cast(slot)); } @@ -6363,7 +6363,7 @@ Handle Undefined(Isolate* isolate) { Handle Null(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; - if (!I::IsInitialized(isolate)) return Null(); + I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); return Handle(reinterpret_cast(slot)); } @@ -6372,7 +6372,7 @@ Handle Null(Isolate* isolate) { Handle True(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; - if (!I::IsInitialized(isolate)) return True(); + I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); return Handle(reinterpret_cast(slot)); } @@ -6381,7 +6381,7 @@ Handle True(Isolate* isolate) { Handle False(Isolate* isolate) { typedef internal::Object* S; typedef internal::Internals I; - if (!I::IsInitialized(isolate)) return False(); + I::CheckInitialized(isolate); S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); return Handle(reinterpret_cast(slot)); } diff --git a/src/api.cc b/src/api.cc index a138e39..5804130 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2903,6 +2903,16 @@ Local Value::ToInteger() const { } +#ifdef V8_ENABLE_CHECKS +void i::Internals::CheckInitialized(v8::Isolate* external_isolate) { + i::Isolate* isolate = reinterpret_cast(external_isolate); + ApiCheck(isolate != NULL && isolate->IsInitialized() && !i::V8::IsDead(), + "v8::internal::Internals::CheckInitialized()", + "Isolate is not initialized or V8 has died"); +} +#endif + + void External::CheckCast(v8::Value* that) { if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return; ApiCheck(Utils::OpenHandle(that)->IsExternal(), diff --git a/src/isolate.cc b/src/isolate.cc index 17e8017..564fd7b 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -2216,8 +2216,6 @@ bool Isolate::Init(Deserializer* des) { LOG(this, LogCompiledFunctions()); } - CHECK_EQ(static_cast(OFFSET_OF(Isolate, state_)), - Internals::kIsolateStateOffset); CHECK_EQ(static_cast(OFFSET_OF(Isolate, embedder_data_)), Internals::kIsolateEmbedderDataOffset); CHECK_EQ(static_cast(OFFSET_OF(Isolate, heap_.roots_)), diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index e417477..c39b429 100755 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -18826,13 +18826,6 @@ TEST(PrimaryStubCache) { } -static int fatal_error_callback_counter = 0; -static void CountingErrorCallback(const char* location, const char* message) { - printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message); - fatal_error_callback_counter++; -} - - TEST(StaticGetters) { LocalContext context; i::Factory* factory = i::Isolate::Current()->factory(); @@ -18850,31 +18843,6 @@ TEST(StaticGetters) { i::Handle false_value = factory->false_value(); CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); - - // Test after-death behavior. - CHECK(i::Internals::IsInitialized(isolate)); - CHECK_EQ(0, fatal_error_callback_counter); - v8::V8::SetFatalErrorHandler(CountingErrorCallback); - v8::Utils::ReportApiFailure("StaticGetters()", "Kill V8"); - i::Isolate::Current()->TearDown(); - CHECK(!i::Internals::IsInitialized(isolate)); - CHECK_EQ(1, fatal_error_callback_counter); - CHECK(v8::Undefined().IsEmpty()); - CHECK_EQ(2, fatal_error_callback_counter); - CHECK(v8::Undefined(isolate).IsEmpty()); - CHECK_EQ(3, fatal_error_callback_counter); - CHECK(v8::Null().IsEmpty()); - CHECK_EQ(4, fatal_error_callback_counter); - CHECK(v8::Null(isolate).IsEmpty()); - CHECK_EQ(5, fatal_error_callback_counter); - CHECK(v8::True().IsEmpty()); - CHECK_EQ(6, fatal_error_callback_counter); - CHECK(v8::True(isolate).IsEmpty()); - CHECK_EQ(7, fatal_error_callback_counter); - CHECK(v8::False().IsEmpty()); - CHECK_EQ(8, fatal_error_callback_counter); - CHECK(v8::False(isolate).IsEmpty()); - CHECK_EQ(9, fatal_error_callback_counter); } @@ -18904,19 +18872,6 @@ TEST(StringEmpty) { i::Handle empty_string = factory->empty_string(); CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); - - // Test after-death behavior. - CHECK(i::Internals::IsInitialized(isolate)); - CHECK_EQ(0, fatal_error_callback_counter); - v8::V8::SetFatalErrorHandler(CountingErrorCallback); - v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); - i::Isolate::Current()->TearDown(); - CHECK(!i::Internals::IsInitialized(isolate)); - CHECK_EQ(1, fatal_error_callback_counter); - CHECK(v8::String::Empty().IsEmpty()); - CHECK_EQ(2, fatal_error_callback_counter); - CHECK(v8::String::Empty(isolate).IsEmpty()); - CHECK_EQ(3, fatal_error_callback_counter); } -- 2.7.4