From: yangguo@chromium.org Date: Mon, 29 Sep 2014 07:14:05 +0000 (+0000) Subject: Fix serializing ICs. X-Git-Tag: upstream/4.7.83~6665 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=667f15a1047eeadf4cbadbb50dafe6541745cdc3;p=platform%2Fupstream%2Fv8.git Fix serializing ICs. R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/587213002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24262 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/builtins.cc b/src/builtins.cc index d0c19e5..f921640 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -1562,7 +1562,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 = isolate->factory()->NewCode(desc, flags, masm.CodeObject()); // Log the event and add the code to the builtins array. diff --git a/src/code-stubs.h b/src/code-stubs.h index 3b31399..b127782 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -136,10 +136,12 @@ namespace internal { class CodeStub BASE_EMBEDDED { public: enum Major { + // TODO(mvstanton): eliminate the NoCache key by getting rid + // of the non-monomorphic-cache. + 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 }; diff --git a/src/serialize.cc b/src/serialize.cc index 894a1be..a2dde9b 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -1894,15 +1894,26 @@ 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 + // TODO(yangguo): add special handling to canonicalize ICs. + case Code::FUNCTION: + SerializeHeapObject(code_object, how_to_code, where_to_point, skip); + return; } - code_object->ClearInlineCaches(); } if (heap_object == source_) { @@ -1967,20 +1978,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"); diff --git a/src/serialize.h b/src/serialize.h index 7831536..b6ad82c 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -607,7 +607,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); diff --git a/test/mjsunit/serialize-ic.js b/test/mjsunit/serialize-ic.js new file mode 100644 index 0000000..8f20b27 --- /dev/null +++ b/test/mjsunit/serialize-ic.js @@ -0,0 +1,9 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --cache=code --serialize-toplevel + +var foo = []; +foo[0] = "bar"; +assertEquals(["bar"], foo);