Revision: 11376
Author:   [email protected]
Date:     Wed Apr 18 09:07:08 2012
Log:      Make static API getters inlineable.

[email protected]
TEST=cctest/test-api/StaticGetters[AfterDeath]

Review URL: https://chromiumcodereview.appspot.com/10116024
http://code.google.com/p/v8/source/detail?r=11376

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

=======================================
--- /branches/bleeding_edge/include/v8.h        Wed Apr 18 08:51:34 2012
+++ /branches/bleeding_edge/include/v8.h        Wed Apr 18 09:07:08 2012
@@ -2561,6 +2561,11 @@
 Handle<Boolean> V8EXPORT True();
 Handle<Boolean> V8EXPORT False();

+inline Handle<Primitive> Undefined(Isolate* isolate);
+inline Handle<Primitive> Null(Isolate* isolate);
+inline Handle<Boolean> True(Isolate* isolate);
+inline Handle<Boolean> False(Isolate* isolate);
+

 /**
* A set of constraints that specifies the limits of the runtime's memory use.
@@ -3904,6 +3909,13 @@
   static const int kFullStringRepresentationMask = 0x07;
   static const int kExternalTwoByteRepresentationTag = 0x02;

+  static const int kIsolateStateOffset = 0;
+  static const int kIsolateRootsOffset = 2 * kApiPointerSize;
+  static const int kUndefinedValueRootIndex = 5;
+  static const int kNullValueRootIndex = 7;
+  static const int kTrueValueRootIndex = 8;
+  static const int kFalseValueRootIndex = 9;
+
   static const int kJSObjectType = 0xaa;
   static const int kFirstNonstringType = 0x80;
   static const int kOddballType = 0x82;
@@ -3955,6 +3967,16 @@
     int representation = (instance_type & kFullStringRepresentationMask);
     return representation == kExternalTwoByteRepresentationTag;
   }
+
+  static inline bool IsInitialized(v8::Isolate* isolate) {
+ uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
+    return *reinterpret_cast<int*>(addr) == 1;
+  }
+
+ static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) { + uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
+    return &reinterpret_cast<internal::Object**>(addr)[index];
+  }

   template <typename T>
   static inline T ReadField(Object* ptr, int offset) {
@@ -4376,6 +4398,42 @@
 Local<Object> AccessorInfo::Holder() const {
   return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
 }
+
+
+Handle<Primitive> Undefined(Isolate* isolate) {
+  typedef internal::Object* S;
+  typedef internal::Internals I;
+  if (!I::IsInitialized(isolate)) return Undefined();
+  S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
+  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
+}
+
+
+Handle<Primitive> Null(Isolate* isolate) {
+  typedef internal::Object* S;
+  typedef internal::Internals I;
+  if (!I::IsInitialized(isolate)) return Null();
+  S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
+  return Handle<Primitive>(reinterpret_cast<Primitive*>(slot));
+}
+
+
+Handle<Boolean> True(Isolate* isolate) {
+  typedef internal::Object* S;
+  typedef internal::Internals I;
+  if (!I::IsInitialized(isolate)) return True();
+  S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
+  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
+}
+
+
+Handle<Boolean> False(Isolate* isolate) {
+  typedef internal::Object* S;
+  typedef internal::Internals I;
+  if (!I::IsInitialized(isolate)) return False();
+  S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
+  return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
+}


 /**
=======================================
--- /branches/bleeding_edge/src/heap.h  Mon Apr 16 07:43:27 2012
+++ /branches/bleeding_edge/src/heap.h  Wed Apr 18 09:07:08 2012
@@ -1418,6 +1418,11 @@
     kRootListLength
   };

+ STATIC_CHECK(kUndefinedValueRootIndex == Internals::kUndefinedValueRootIndex);
+  STATIC_CHECK(kNullValueRootIndex == Internals::kNullValueRootIndex);
+  STATIC_CHECK(kTrueValueRootIndex == Internals::kTrueValueRootIndex);
+  STATIC_CHECK(kFalseValueRootIndex == Internals::kFalseValueRootIndex);
+
   MUST_USE_RESULT MaybeObject* NumberToString(
       Object* number, bool check_number_string_cache = true);
   MUST_USE_RESULT MaybeObject* Uint32ToString(
@@ -1612,6 +1617,8 @@
// more expedient to get at the isolate directly from within Heap methods.
   Isolate* isolate_;

+  Object* roots_[kRootListLength];
+
   intptr_t code_range_size_;
   int reserved_semispace_size_;
   int max_semispace_size_;
@@ -1727,8 +1734,6 @@
   // last GC.
   int old_gen_exhausted_;

-  Object* roots_[kRootListLength];
-
   Object* global_contexts_list_;

   StoreBufferRebuilder store_buffer_rebuilder_;
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Fri Mar 30 07:30:46 2012
+++ /branches/bleeding_edge/src/isolate.cc      Wed Apr 18 09:07:08 2012
@@ -1853,6 +1853,9 @@
     LOG(this, LogCodeObjects());
     LOG(this, LogCompiledFunctions());
   }
+
+  CHECK(OFFSET_OF(Isolate, state_) == Internals::kIsolateStateOffset);
+ CHECK(OFFSET_OF(Isolate, heap_.roots_) == Internals::kIsolateRootsOffset);

   state_ = INITIALIZED;
   time_millis_at_init_ = OS::TimeCurrentMillis();
=======================================
--- /branches/bleeding_edge/src/isolate.h       Fri Mar 30 07:30:46 2012
+++ /branches/bleeding_edge/src/isolate.h       Wed Apr 18 09:07:08 2012
@@ -1101,6 +1101,7 @@
   };

   State state_;
+  Heap heap_;
   EntryStackItem* entry_stack_;

   // Allocate and insert PerIsolateThreadData into the ThreadDataTable
@@ -1161,7 +1162,6 @@
   Mutex* break_access_;
   Atomic32 debugger_initialized_;
   Mutex* debugger_access_;
-  Heap heap_;
   Logger* logger_;
   StackGuard stack_guard_;
   StatsTable* stats_table_;
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Mon Apr 16 06:20:50 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Wed Apr 18 09:07:08 2012
@@ -16408,3 +16408,58 @@
   StubCacheHelper(false);
 }

+
+TEST(StaticGetters) {
+  v8::HandleScope scope;
+  LocalContext context;
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+  i::Handle<i::Object> undefined_value = FACTORY->undefined_value();
+  CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value);
+ CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value);
+  i::Handle<i::Object> null_value = FACTORY->null_value();
+  CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value);
+  CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
+  i::Handle<i::Object> true_value = FACTORY->true_value();
+  CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
+  CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
+  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);
+}
+
+
+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(StaticGettersAfterDeath) {
+  v8::HandleScope scope;
+  LocalContext context;
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
+  CHECK(i::Internals::IsInitialized(isolate));
+  CHECK_EQ(0, fatal_error_callback_counter);
+  v8::V8::SetFatalErrorHandler(CountingErrorCallback);
+  v8::Utils::ReportApiFailure("StaticGettersAfterDeath()", "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);
+}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to