OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/snapshot/partial-serializer.h" | 5 #include "src/snapshot/partial-serializer.h" |
6 #include "src/snapshot/startup-serializer.h" | 6 #include "src/snapshot/startup-serializer.h" |
7 | 7 |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 PartialSerializer::PartialSerializer(Isolate* isolate, | 13 PartialSerializer::PartialSerializer( |
14 StartupSerializer* startup_serializer) | 14 Isolate* isolate, StartupSerializer* startup_serializer, |
15 : Serializer(isolate), startup_serializer_(startup_serializer) { | 15 v8::SerializeInternalFieldsCallback callback) |
16 : Serializer(isolate), | |
17 startup_serializer_(startup_serializer), | |
18 serialize_internal_fields_(callback) { | |
16 InitializeCodeAddressMap(); | 19 InitializeCodeAddressMap(); |
17 } | 20 } |
18 | 21 |
19 PartialSerializer::~PartialSerializer() { | 22 PartialSerializer::~PartialSerializer() { |
20 OutputStatistics("PartialSerializer"); | 23 OutputStatistics("PartialSerializer"); |
21 } | 24 } |
22 | 25 |
23 void PartialSerializer::Serialize(Object** o) { | 26 void PartialSerializer::Serialize(Object** o) { |
24 if ((*o)->IsContext()) { | 27 if ((*o)->IsContext()) { |
25 Context* context = Context::cast(*o); | 28 Context* context = Context::cast(*o); |
26 reference_map()->AddAttachedReference(context->global_proxy()); | 29 reference_map()->AddAttachedReference(context->global_proxy()); |
27 // The bootstrap snapshot has a code-stub context. When serializing the | 30 // The bootstrap snapshot has a code-stub context. When serializing the |
28 // partial snapshot, it is chained into the weak context list on the isolate | 31 // partial snapshot, it is chained into the weak context list on the isolate |
29 // and it's next context pointer may point to the code-stub context. Clear | 32 // and it's next context pointer may point to the code-stub context. Clear |
30 // it before serializing, it will get re-added to the context list | 33 // it before serializing, it will get re-added to the context list |
31 // explicitly when it's loaded. | 34 // explicitly when it's loaded. |
32 if (context->IsNativeContext()) { | 35 if (context->IsNativeContext()) { |
33 context->set(Context::NEXT_CONTEXT_LINK, | 36 context->set(Context::NEXT_CONTEXT_LINK, |
34 isolate_->heap()->undefined_value()); | 37 isolate_->heap()->undefined_value()); |
35 DCHECK(!context->global_object()->IsUndefined(context->GetIsolate())); | 38 DCHECK(!context->global_object()->IsUndefined(context->GetIsolate())); |
36 // Reset math random cache to get fresh random numbers. | 39 // Reset math random cache to get fresh random numbers. |
37 context->set_math_random_index(Smi::kZero); | 40 context->set_math_random_index(Smi::kZero); |
38 context->set_math_random_cache(isolate_->heap()->undefined_value()); | 41 context->set_math_random_cache(isolate_->heap()->undefined_value()); |
39 } | 42 } |
40 } | 43 } |
41 VisitPointer(o); | 44 VisitPointer(o); |
42 SerializeDeferredObjects(); | 45 SerializeDeferredObjects(); |
46 SerializeInternalFields(); | |
43 Pad(); | 47 Pad(); |
44 } | 48 } |
45 | 49 |
46 void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 50 void PartialSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
47 WhereToPoint where_to_point, int skip) { | 51 WhereToPoint where_to_point, int skip) { |
48 if (obj->IsMap()) { | 52 if (obj->IsMap()) { |
49 // The code-caches link to context-specific code objects, which | 53 // The code-caches link to context-specific code objects, which |
50 // the startup and context serializes cannot currently handle. | 54 // the startup and context serializes cannot currently handle. |
51 DCHECK(Map::cast(obj)->code_cache() == obj->GetHeap()->empty_fixed_array()); | 55 DCHECK(Map::cast(obj)->code_cache() == obj->GetHeap()->empty_fixed_array()); |
52 } | 56 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 // Clear literal boilerplates. | 93 // Clear literal boilerplates. |
90 if (obj->IsJSFunction()) { | 94 if (obj->IsJSFunction()) { |
91 JSFunction* function = JSFunction::cast(obj); | 95 JSFunction* function = JSFunction::cast(obj); |
92 LiteralsArray* literals = function->literals(); | 96 LiteralsArray* literals = function->literals(); |
93 for (int i = 0; i < literals->literals_count(); i++) { | 97 for (int i = 0; i < literals->literals_count(); i++) { |
94 literals->set_literal_undefined(i); | 98 literals->set_literal_undefined(i); |
95 } | 99 } |
96 function->ClearTypeFeedbackInfo(); | 100 function->ClearTypeFeedbackInfo(); |
97 } | 101 } |
98 | 102 |
103 if (obj->IsJSObject()) { | |
104 JSObject* jsobj = JSObject::cast(obj); | |
105 if (jsobj->GetInternalFieldCount() > 0) internal_field_holders_.Add(jsobj); | |
106 } | |
107 | |
99 // Object has not yet been serialized. Serialize it here. | 108 // Object has not yet been serialized. Serialize it here. |
100 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); | 109 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); |
101 serializer.Serialize(); | 110 serializer.Serialize(); |
102 } | 111 } |
103 | 112 |
104 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 113 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
105 // Scripts should be referred only through shared function infos. We can't | 114 // Scripts should be referred only through shared function infos. We can't |
106 // allow them to be part of the partial snapshot because they contain a | 115 // allow them to be part of the partial snapshot because they contain a |
107 // unique ID, and deserializing several partial snapshots containing script | 116 // unique ID, and deserializing several partial snapshots containing script |
108 // would cause dupes. | 117 // would cause dupes. |
109 DCHECK(!o->IsScript()); | 118 DCHECK(!o->IsScript()); |
110 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || | 119 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || |
111 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || | 120 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || |
112 o->map() == | 121 o->map() == |
113 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); | 122 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); |
114 } | 123 } |
115 | 124 |
125 void PartialSerializer::SerializeInternalFields() { | |
126 int count = internal_field_holders_.length(); | |
127 if (count == 0) return; | |
128 DisallowHeapAllocation no_gc; | |
129 DisallowJavascriptExecution no_js(isolate()); | |
130 DisallowCompilation no_compile(isolate()); | |
131 DCHECK_NOT_NULL(serialize_internal_fields_); | |
132 sink_.Put(kInternalFieldsData, "internal fields data"); | |
133 for (int i = 0; i < count; i++) { | |
134 HandleScope scope(isolate()); | |
135 Handle<JSObject> obj(internal_field_holders_[i], isolate()); | |
136 SerializerReference reference = reference_map_.Lookup(*obj); | |
137 DCHECK(reference.is_back_reference()); | |
138 int internal_fields_count = obj->GetInternalFieldCount(); | |
139 for (int i = 0; i < internal_fields_count; i++) { | |
peria
2016/10/27 12:54:31
should we use j for the inner loop?
Yang
2016/10/27 13:01:56
good point.
| |
140 if (obj->GetInternalField(i)->IsHeapObject()) continue; | |
141 StartupData data = serialize_internal_fields_(v8::Utils::ToLocal(obj), i); | |
142 sink_.Put(kNewObject + reference.space(), "internal field holder"); | |
143 PutBackReference(*obj, reference); | |
144 sink_.PutInt(i, "internal field index"); | |
145 sink_.PutInt(data.raw_size, "internal fields data size"); | |
146 sink_.PutRaw(reinterpret_cast<const byte*>(data.data), data.raw_size, | |
147 "internal fields data"); | |
148 delete[] data.data; | |
149 } | |
150 } | |
151 sink_.Put(kSynchronize, "Finished with internal fields data"); | |
152 } | |
153 | |
116 } // namespace internal | 154 } // namespace internal |
117 } // namespace v8 | 155 } // namespace v8 |
OLD | NEW |