Reviewers: Jakob,

Description:
Do not reverse lookup code stubs dictionary.


[email protected]

Please review this at https://codereview.chromium.org/407383004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+43, -46 lines):
  M src/compiler.cc
  M src/debug.cc
  M src/disassembler.cc
  M src/objects.h
  M src/objects.cc
  M src/serialize.cc


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 8d59dbca2dc90c185eb9eede87562f6bdf69387e..b1a7f6ef26cf7510d4d8b11669508867319c659c 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -961,7 +961,8 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
   Handle<SharedFunctionInfo> result;
   if (extension == NULL) {
     if (FLAG_serialize_toplevel &&
-        compile_options == ScriptCompiler::kConsumeCodeCache) {
+        compile_options == ScriptCompiler::kConsumeCodeCache &&
+        !isolate->debug()->is_loaded()) {
       return CodeSerializer::Deserialize(isolate, *cached_data, source);
     } else {
       maybe_result = compilation_cache->LookupScript(
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index e908126d895c3132c82ffe8f0aa1ecc606aac36c..3586a1836db64cf8ae8f721af0b6bdf33bbd5982 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -622,7 +622,14 @@ void ScriptCache::Add(Handle<Script> script) {
   HashMap::Entry* entry =
       HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
   if (entry->value != NULL) {
-    ASSERT(*script == *reinterpret_cast<Script**>(entry->value));
+#ifdef DEBUG
+    // The code deserializer may introduce duplicate Script objects.
+    // Assert that the Script objects with the same id have the same name.
+    Handle<Script> found(reinterpret_cast<Script**>(entry->value));
+    ASSERT(script->id() == found->id());
+    ASSERT(!script->name()->IsString() ||
+ String::cast(script->name())->Equals(String::cast(found->name())));
+#endif
     return;
   }
   // Globalize the script object, make it weak and use the location of the
@@ -1482,17 +1489,7 @@ void Debug::PrepareStep(StepAction step_action,
       bool is_call_ic = call_function_stub->kind() == Code::CALL_IC;

       // Find out number of arguments from the stub minor key.
-      // Reverse lookup required as the minor key cannot be retrieved
-      // from the code object.
-      Handle<Object> obj(
-          isolate_->heap()->code_stubs()->SlowReverseLookup(
-              *call_function_stub),
-          isolate_);
-      ASSERT(!obj.is_null());
-      ASSERT(!(*obj)->IsUndefined());
-      ASSERT(obj->IsSmi());
-      // Get the STUB key and extract major and minor key.
-      uint32_t key = Smi::cast(*obj)->value();
+      uint32_t key = call_function_stub->stub_key();
       // Argc in the stub is the number of arguments passed - not the
       // expected arguments of the called function.
       int call_function_arg_count = is_call_ic
Index: src/disassembler.cc
diff --git a/src/disassembler.cc b/src/disassembler.cc
index f1c28e8199f52d835cb619092f9214c6417096f3..d58e1b073f0f2a0a43eafafe2e65573904296ba0 100644
--- a/src/disassembler.cc
+++ b/src/disassembler.cc
@@ -95,7 +95,6 @@ static int DecodeIt(Isolate* isolate,
   SealHandleScope shs(isolate);
   DisallowHeapAllocation no_alloc;
   ExternalReferenceEncoder ref_encoder(isolate);
-  Heap* heap = isolate->heap();

   v8::internal::EmbeddedVector<char, 128> decode_buffer;
   v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer;
@@ -226,29 +225,21 @@ static int DecodeIt(Isolate* isolate,
             out.AddFormatted(", %s", Code::StubType2String(type));
           }
         } else if (kind == Code::STUB || kind == Code::HANDLER) {
-          // Reverse lookup required as the minor key cannot be retrieved
-          // from the code object.
-          Object* obj = heap->code_stubs()->SlowReverseLookup(code);
-          if (obj != heap->undefined_value()) {
-            ASSERT(obj->IsSmi());
-            // Get the STUB key and extract major and minor key.
-            uint32_t key = Smi::cast(obj)->value();
-            uint32_t minor_key = CodeStub::MinorKeyFromKey(key);
-            CodeStub::Major major_key = CodeStub::GetMajorKey(code);
-            ASSERT(major_key == CodeStub::MajorKeyFromKey(key));
-            out.AddFormatted(" %s, %s, ",
-                             Code::Kind2String(kind),
-                             CodeStub::MajorName(major_key, false));
-            switch (major_key) {
-              case CodeStub::CallFunction: {
-                int argc =
-                    CallFunctionStub::ExtractArgcFromMinorKey(minor_key);
-                out.AddFormatted("argc = %d", argc);
-                break;
-              }
-              default:
-                out.AddFormatted("minor: %d", minor_key);
+          // Get the STUB key and extract major and minor key.
+          uint32_t key = code->stub_key();
+          uint32_t minor_key = CodeStub::MinorKeyFromKey(key);
+          CodeStub::Major major_key = CodeStub::GetMajorKey(code);
+          ASSERT(major_key == CodeStub::MajorKeyFromKey(key));
+          out.AddFormatted(" %s, %s, ", Code::Kind2String(kind),
+                           CodeStub::MajorName(major_key, false));
+          switch (major_key) {
+            case CodeStub::CallFunction: {
+ int argc = CallFunctionStub::ExtractArgcFromMinorKey(minor_key);
+              out.AddFormatted("argc = %d", argc);
+              break;
             }
+            default:
+              out.AddFormatted("minor: %d", minor_key);
           }
         } else {
           out.AddFormatted(" %s", Code::Kind2String(kind));
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 0f9ea21d378b541e211b3939028ffeac31b49f37..a527d282a3eeeb756e527cb5470ce0d3284e59af 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10284,16 +10284,21 @@ Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) {
 // collector will call the weak callback on the global handle
 // associated with the wrapper and get rid of both the wrapper and the
 // handle.
-static void ClearWrapperCache(
+static void ClearWrapperCacheWeakCallback(
     const v8::WeakCallbackData<v8::Value, void>& data) {
   Object** location = reinterpret_cast<Object**>(data.GetParameter());
   JSValue* wrapper = JSValue::cast(*location);
-  Foreign* foreign = Script::cast(wrapper->value())->wrapper();
+  Script::cast(wrapper->value())->ClearWrapperCache();
+}
+
+
+void Script::ClearWrapperCache() {
+  Foreign* foreign = wrapper();
+ Object** location = reinterpret_cast<Object**>(foreign->foreign_address()); ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
   foreign->set_foreign_address(0);
   GlobalHandles::Destroy(location);
-  Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
-  isolate->counters()->script_wrappers()->Decrement();
+  GetIsolate()->counters()->script_wrappers()->Decrement();
 }


@@ -10318,7 +10323,7 @@ Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
   Handle<Object> handle = isolate->global_handles()->Create(*result);
   GlobalHandles::MakeWeak(handle.location(),
                           reinterpret_cast<void*>(handle.location()),
-                          &ClearWrapperCache);
+                          &ClearWrapperCacheWeakCallback);
   script->wrapper()->set_foreign_address(
       reinterpret_cast<Address>(handle.location()));
   return result;
@@ -14593,10 +14598,6 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
     SlowReverseLookup(Object* value);

 template Object*
-Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
-    SlowReverseLookup(Object* value);
-
-template Object*
 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
     SlowReverseLookup(Object* value);

Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 629a951314d16f947d4908636f5ade363e433cfa..e32b51d2ff06cff2fb9a5fbb9f0704fdf094fb58 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -6934,6 +6934,7 @@ class Script: public Struct {

   // Get the JS object wrapping the given script; create it if none exists.
   static Handle<JSObject> GetWrapper(Handle<Script> script);
+  void ClearWrapperCache();

   // Dispatched behavior.
   DECLARE_PRINTER(Script)
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index 4156dfbf626fef88ebe2ec6c55f84240bf8a869e..bb24f00aabf176ac4b7cf76eaa376cde0e0f1fec 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -1962,6 +1962,13 @@ void CodeSerializer::SerializeObject(Object* o, HowToCode how_to_code,
     return;
   }

+  if (heap_object->IsScript()) {
+    // The wrapper cache uses a Foreign object to point to a global handle.
+ // However, the object visitor expects foreign objects to point to external
+    // references.  Clear the cache to avoid this issue.
+    Script::cast(heap_object)->ClearWrapperCache();
+  }
+
   if (skip != 0) {
     sink_->Put(kSkip, "SkipFromSerializeObject");
     sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
@@ -2016,7 +2023,6 @@ Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate,
   for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
     deserializer.set_reservation(i, scd.GetReservation(i));
   }
-  DisallowHeapAllocation no_gc;

   // Prepare and register list of attached objects.
   Vector<Object*> attached_objects = Vector<Object*>::New(1);


--
--
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/d/optout.

Reply via email to