Reviewers: mvstanton,

Description:
Fix serializing ICs.

[email protected]

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

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

Affected files (+28, -23 lines):
  M src/builtins.cc
  M src/code-stubs.h
  M src/factory.cc
  M src/serialize.h
  M src/serialize.cc
  A + test/mjsunit/serialize-ic.js


Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 4a393cb27c50e057bf74f69efb99e046dfb1cb45..f17dbfb56066fc8b407768e8663b17f89ee4748d 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1567,7 +1567,7 @@ void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) {
       // Move the code into the object heap.
       CodeDesc desc;
       masm.GetCode(&desc);
-      Code::Flags flags =  functions[i].flags;
+      Code::Flags flags = functions[i].flags;
       Handle<Code> code =
           isolate->factory()->NewCode(desc, flags, masm.CodeObject());
       // Log the event and add the code to the builtins array.
Index: src/code-stubs.h
diff --git a/src/code-stubs.h b/src/code-stubs.h
index f9016f180b5b2aee5d33f7cbd4aec6607a23b1fb..5c35108eb7217870cce8d43dbc01c89efcffd776 100644
--- a/src/code-stubs.h
+++ b/src/code-stubs.h
@@ -135,10 +135,10 @@ namespace internal {
 class CodeStub BASE_EMBEDDED {
  public:
   enum Major {
+    NoCache = 0,  // marker for stubs that do custom caching
 #define DEF_ENUM(name) name,
     CODE_STUB_LIST(DEF_ENUM)
 #undef DEF_ENUM
-    NoCache,  // marker for stubs that do custom caching
     NUMBER_OF_IDS
   };

Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 45a79c1b3cc4477be0bdc3cfdc4825ba35cd1e1a..d8c20b036270f8d4576ceb5c0415197a4d37aee2 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1463,6 +1463,7 @@ Handle<Code> Factory::NewCode(const CodeDesc& desc,
   if (code->kind() == Code::OPTIMIZED_FUNCTION) {
     code->set_marked_for_deoptimization(false);
   }
+  if (code->IsCodeStubOrIC()) code->set_stub_key(0);

   if (is_debug) {
     DCHECK(code->kind() == Code::FUNCTION);
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index 2b0815e2cc4664fa8a067b6a3df8695d8eadef5f..dabf85c7a22aef9dbafca48889a1bc93cd1dfb3e 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -1871,15 +1871,25 @@ void CodeSerializer::SerializeObject(Object* o, HowToCode how_to_code,

   if (heap_object->IsCode()) {
     Code* code_object = Code::cast(heap_object);
-    DCHECK(!code_object->is_optimized_code());
-    if (code_object->kind() == Code::BUILTIN) {
-      SerializeBuiltin(code_object, how_to_code, where_to_point, skip);
-      return;
-    } else if (code_object->IsCodeStubOrIC()) {
-      SerializeCodeStub(code_object, how_to_code, where_to_point, skip);
-      return;
+    switch (code_object->kind()) {
+      case Code::OPTIMIZED_FUNCTION:  // No optimized code compiled yet.
+      case Code::HANDLER:             // No handlers patched in yet.
+ case Code::REGEXP: // No regexp literals initialized yet.
+      case Code::NUMBER_OF_KINDS:     // Pseudo enum value.
+        CHECK(false);
+      case Code::BUILTIN:
+        SerializeBuiltin(code_object, how_to_code, where_to_point, skip);
+        return;
+      case Code::STUB:
+        SerializeCodeStub(code_object, how_to_code, where_to_point, skip);
+        return;
+#define IC_KIND_CASE(KIND) case Code::KIND:
+        IC_KIND_LIST(IC_KIND_CASE)
+#undef IC_KIND_CASE
+      case Code::FUNCTION:
+ SerializeHeapObject(code_object, how_to_code, where_to_point, skip);
+        return;
     }
-    code_object->ClearInlineCaches();
   }

   if (heap_object == source_) {
@@ -1944,20 +1954,13 @@ void CodeSerializer::SerializeBuiltin(Code* builtin, HowToCode how_to_code,
 }


-void CodeSerializer::SerializeCodeStub(Code* code, HowToCode how_to_code,
+void CodeSerializer::SerializeCodeStub(Code* stub, HowToCode how_to_code,
WhereToPoint where_to_point, int skip) {
   DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) ||
          (how_to_code == kPlain && where_to_point == kInnerPointer) ||
          (how_to_code == kFromCode && where_to_point == kInnerPointer));
-  uint32_t stub_key = code->stub_key();
-
-  if (stub_key == CodeStub::NoCacheKey()) {
-    if (FLAG_trace_code_serializer) {
-      PrintF("Encoding uncacheable code stub as heap object\n");
-    }
-    SerializeHeapObject(code, how_to_code, where_to_point, skip);
-    return;
-  }
+  uint32_t stub_key = stub->stub_key();
+  DCHECK(CodeStub::MajorKeyFromKey(stub_key) != CodeStub::NoCache);

   if (skip != 0) {
     sink_->Put(kSkip, "SkipFromSerializeCodeStub");
Index: src/serialize.h
diff --git a/src/serialize.h b/src/serialize.h
index 76eb34e3d26e07aa4a87a85ea0489a1bfae53bf0..b4be185c6e508713ede160bcc68d5c156e9ba8ed 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -635,7 +635,7 @@ class CodeSerializer : public Serializer {
  private:
   void SerializeBuiltin(Code* builtin, HowToCode how_to_code,
                         WhereToPoint where_to_point, int skip);
-  void SerializeCodeStub(Code* code, HowToCode how_to_code,
+  void SerializeCodeStub(Code* stub, HowToCode how_to_code,
                          WhereToPoint where_to_point, int skip);
void SerializeSourceObject(HowToCode how_to_code, WhereToPoint where_to_point,
                              int skip);
Index: test/mjsunit/serialize-ic.js
diff --git a/test/mjsunit/deserialize-reference.js b/test/mjsunit/serialize-ic.js
similarity index 78%
copy from test/mjsunit/deserialize-reference.js
copy to test/mjsunit/serialize-ic.js
index b03201315932eab59e38c135d219192e6dcdf0eb..8f20b2758fd6eb0c3002fb50ce164eab88ea95bb 100644
--- a/test/mjsunit/deserialize-reference.js
+++ b/test/mjsunit/serialize-ic.js
@@ -4,5 +4,6 @@

 // Flags: --cache=code --serialize-toplevel

-var a = "123";
-assertEquals(a, "123");
+var foo = [];
+foo[0] = "bar";
+assertEquals(["bar"], foo);


--
--
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