Revision: 15311
Author:   [email protected]
Date:     Tue Jun 25 01:11:50 2013
Log:      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.

[email protected]

Review URL: https://codereview.chromium.org/17642011
http://code.google.com/p/v8/source/detail?r=15311

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Mon Jun 24 04:23:50 2013
+++ /branches/bleeding_edge/include/v8.h        Tue Jun 25 01:11:50 2013
@@ -5347,7 +5347,6 @@
   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 @@
   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<intptr_t>(value) & kHeapObjectTagMask) ==
             kHeapObjectTag);
@@ -5404,11 +5409,6 @@
     int representation = (instance_type & kFullStringRepresentationMask);
     return representation == kExternalTwoByteRepresentationTag;
   }
-
-  V8_INLINE(static bool IsInitialized(v8::Isolate* isolate)) {
- uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
-    return *reinterpret_cast<int*>(addr) == 1;
-  }

V8_INLINE(static uint8_t GetNodeFlag(internal::Object** obj, int shift)) {
       uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
@@ -5985,7 +5985,7 @@
 Local<String> 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<String>(reinterpret_cast<String*>(slot));
 }
@@ -6354,7 +6354,7 @@
 Handle<Primitive> 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<Primitive>(reinterpret_cast<Primitive*>(slot));
 }
@@ -6363,7 +6363,7 @@
 Handle<Primitive> 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<Primitive>(reinterpret_cast<Primitive*>(slot));
 }
@@ -6372,7 +6372,7 @@
 Handle<Boolean> 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<Boolean>(reinterpret_cast<Boolean*>(slot));
 }
@@ -6381,7 +6381,7 @@
 Handle<Boolean> 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<Boolean>(reinterpret_cast<Boolean*>(slot));
 }
=======================================
--- /branches/bleeding_edge/src/api.cc  Mon Jun 24 04:23:50 2013
+++ /branches/bleeding_edge/src/api.cc  Tue Jun 25 01:11:50 2013
@@ -2901,6 +2901,16 @@
   }
   return ToApiHandle<Integer>(num);
 }
+
+
+#ifdef V8_ENABLE_CHECKS
+void i::Internals::CheckInitialized(v8::Isolate* external_isolate) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(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) {
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Mon Jun 24 04:10:40 2013
+++ /branches/bleeding_edge/src/isolate.cc      Tue Jun 25 01:11:50 2013
@@ -2216,8 +2216,6 @@
     LOG(this, LogCompiledFunctions());
   }

-  CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, state_)),
-           Internals::kIsolateStateOffset);
   CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)),
            Internals::kIsolateEmbedderDataOffset);
   CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)),
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Mon Jun 24 04:23:50 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Jun 25 01:11:50 2013
@@ -18824,13 +18824,6 @@
 TEST(PrimaryStubCache) {
   StubCacheHelper(false);
 }
-
-
-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) {
@@ -18850,31 +18843,6 @@
   i::Handle<i::Object> 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 @@
   i::Handle<i::Object> 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);
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to