| Index: src/snapshot/code-serializer.cc
|
| diff --git a/src/snapshot/code-serializer.cc b/src/snapshot/code-serializer.cc
|
| index 71a8fcbe7ce487abb607195c9d50fb012a42273c..1a2e077407eaf0bd36c8115451f19e9827eeb205 100644
|
| --- a/src/snapshot/code-serializer.cc
|
| +++ b/src/snapshot/code-serializer.cc
|
| @@ -76,7 +76,7 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
|
| #define IC_KIND_CASE(KIND) case Code::KIND:
|
| IC_KIND_LIST(IC_KIND_CASE)
|
| #undef IC_KIND_CASE
|
| - SerializeCodeStub(code_object->stub_key(), how_to_code, where_to_point);
|
| + SerializeCodeStub(code_object, how_to_code, where_to_point);
|
| return;
|
| case Code::FUNCTION:
|
| DCHECK(code_object->has_reloc_info_for_serialization());
|
| @@ -128,34 +128,23 @@ void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code,
|
| sink_->PutInt(builtin_index, "builtin_index");
|
| }
|
|
|
| -void CodeSerializer::SerializeCodeStub(uint32_t stub_key, HowToCode how_to_code,
|
| +void CodeSerializer::SerializeCodeStub(Code* code_stub, HowToCode how_to_code,
|
| WhereToPoint where_to_point) {
|
| - 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));
|
| + // We only arrive here if we have not encountered this code stub before.
|
| + DCHECK(!reference_map()->Lookup(code_stub).is_valid());
|
| + uint32_t stub_key = code_stub->stub_key();
|
| DCHECK(CodeStub::MajorKeyFromKey(stub_key) != CodeStub::NoCache);
|
| DCHECK(!CodeStub::GetCode(isolate(), stub_key).is_null());
|
| + stub_keys_.Add(stub_key);
|
|
|
| - int index = AddCodeStubKey(stub_key) + kCodeStubsBaseIndex;
|
| -
|
| + SerializerReference reference =
|
| + reference_map()->AddAttachedReference(code_stub);
|
| if (FLAG_trace_serializer) {
|
| - PrintF(" Encoding code stub %s as %d\n",
|
| - CodeStub::MajorName(CodeStub::MajorKeyFromKey(stub_key)), index);
|
| + PrintF(" Encoding code stub %s as attached reference %d\n",
|
| + CodeStub::MajorName(CodeStub::MajorKeyFromKey(stub_key)),
|
| + reference.attached_reference_index());
|
| }
|
| -
|
| - sink_->Put(kAttachedReference + how_to_code + where_to_point, "CodeStub");
|
| - sink_->PutInt(index, "CodeStub key");
|
| -}
|
| -
|
| -int CodeSerializer::AddCodeStubKey(uint32_t stub_key) {
|
| - // TODO(yangguo) Maybe we need a hash table for a faster lookup than O(n^2).
|
| - int index = 0;
|
| - while (index < stub_keys_.length()) {
|
| - if (stub_keys_[index] == stub_key) return index;
|
| - index++;
|
| - }
|
| - stub_keys_.Add(stub_key);
|
| - return index;
|
| + PutAttachedReference(reference, how_to_code, where_to_point);
|
| }
|
|
|
| MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
|
| @@ -173,19 +162,14 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
|
| return MaybeHandle<SharedFunctionInfo>();
|
| }
|
|
|
| - // Prepare and register list of attached objects.
|
| + Deserializer deserializer(scd.get());
|
| + deserializer.AddAttachedObject(source);
|
| Vector<const uint32_t> code_stub_keys = scd->CodeStubKeys();
|
| - Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New(
|
| - code_stub_keys.length() + kCodeStubsBaseIndex);
|
| - attached_objects[kSourceObjectIndex] = source;
|
| for (int i = 0; i < code_stub_keys.length(); i++) {
|
| - attached_objects[i + kCodeStubsBaseIndex] =
|
| - CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked();
|
| + deserializer.AddAttachedObject(
|
| + CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked());
|
| }
|
|
|
| - Deserializer deserializer(scd.get());
|
| - deserializer.SetAttachedObjects(attached_objects);
|
| -
|
| // Deserialize.
|
| Handle<SharedFunctionInfo> result;
|
| if (!deserializer.DeserializeCode(isolate).ToHandle(&result)) {
|
|
|