| 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 { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 LiteralsArray* literals = function->literals(); | 96 LiteralsArray* literals = function->literals(); |
| 97 for (int i = 0; i < literals->literals_count(); i++) { | 97 for (int i = 0; i < literals->literals_count(); i++) { |
| 98 literals->set_literal_undefined(i); | 98 literals->set_literal_undefined(i); |
| 99 } | 99 } |
| 100 function->ClearTypeFeedbackInfo(); | 100 function->ClearTypeFeedbackInfo(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 if (obj->IsJSObject()) { | 103 if (obj->IsJSObject()) { |
| 104 JSObject* jsobj = JSObject::cast(obj); | 104 JSObject* jsobj = JSObject::cast(obj); |
| 105 if (jsobj->GetInternalFieldCount() > 0) { | 105 if (jsobj->GetInternalFieldCount() > 0) { |
| 106 DCHECK_NOT_NULL(serialize_internal_fields_); | 106 DCHECK_NOT_NULL(serialize_internal_fields_.callback); |
| 107 internal_field_holders_.Add(jsobj); | 107 internal_field_holders_.Add(jsobj); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Object has not yet been serialized. Serialize it here. | 111 // Object has not yet been serialized. Serialize it here. |
| 112 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); | 112 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); |
| 113 serializer.Serialize(); | 113 serializer.Serialize(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 116 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
| 117 // Scripts should be referred only through shared function infos. We can't | 117 // Scripts should be referred only through shared function infos. We can't |
| 118 // allow them to be part of the partial snapshot because they contain a | 118 // allow them to be part of the partial snapshot because they contain a |
| 119 // unique ID, and deserializing several partial snapshots containing script | 119 // unique ID, and deserializing several partial snapshots containing script |
| 120 // would cause dupes. | 120 // would cause dupes. |
| 121 DCHECK(!o->IsScript()); | 121 DCHECK(!o->IsScript()); |
| 122 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || | 122 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || |
| 123 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || | 123 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || |
| 124 o->IsTemplateInfo() || | 124 o->IsTemplateInfo() || |
| 125 o->map() == | 125 o->map() == |
| 126 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); | 126 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void PartialSerializer::SerializeInternalFields() { | 129 void PartialSerializer::SerializeInternalFields() { |
| 130 int count = internal_field_holders_.length(); | 130 int count = internal_field_holders_.length(); |
| 131 if (count == 0) return; | 131 if (count == 0) return; |
| 132 DisallowHeapAllocation no_gc; | 132 DisallowHeapAllocation no_gc; |
| 133 DisallowJavascriptExecution no_js(isolate()); | 133 DisallowJavascriptExecution no_js(isolate()); |
| 134 DisallowCompilation no_compile(isolate()); | 134 DisallowCompilation no_compile(isolate()); |
| 135 DCHECK_NOT_NULL(serialize_internal_fields_); | 135 DCHECK_NOT_NULL(serialize_internal_fields_.callback); |
| 136 sink_.Put(kInternalFieldsData, "internal fields data"); | 136 sink_.Put(kInternalFieldsData, "internal fields data"); |
| 137 while (internal_field_holders_.length() > 0) { | 137 while (internal_field_holders_.length() > 0) { |
| 138 HandleScope scope(isolate()); | 138 HandleScope scope(isolate()); |
| 139 Handle<JSObject> obj(internal_field_holders_.RemoveLast(), isolate()); | 139 Handle<JSObject> obj(internal_field_holders_.RemoveLast(), isolate()); |
| 140 SerializerReference reference = reference_map_.Lookup(*obj); | 140 SerializerReference reference = reference_map_.Lookup(*obj); |
| 141 DCHECK(reference.is_back_reference()); | 141 DCHECK(reference.is_back_reference()); |
| 142 int internal_fields_count = obj->GetInternalFieldCount(); | 142 int internal_fields_count = obj->GetInternalFieldCount(); |
| 143 for (int i = 0; i < internal_fields_count; i++) { | 143 for (int i = 0; i < internal_fields_count; i++) { |
| 144 if (obj->GetInternalField(i)->IsHeapObject()) continue; | 144 if (obj->GetInternalField(i)->IsHeapObject()) continue; |
| 145 StartupData data = serialize_internal_fields_(v8::Utils::ToLocal(obj), i); | 145 StartupData data = serialize_internal_fields_.callback( |
| 146 v8::Utils::ToLocal(obj), i, serialize_internal_fields_.data); |
| 146 sink_.Put(kNewObject + reference.space(), "internal field holder"); | 147 sink_.Put(kNewObject + reference.space(), "internal field holder"); |
| 147 PutBackReference(*obj, reference); | 148 PutBackReference(*obj, reference); |
| 148 sink_.PutInt(i, "internal field index"); | 149 sink_.PutInt(i, "internal field index"); |
| 149 sink_.PutInt(data.raw_size, "internal fields data size"); | 150 sink_.PutInt(data.raw_size, "internal fields data size"); |
| 150 sink_.PutRaw(reinterpret_cast<const byte*>(data.data), data.raw_size, | 151 sink_.PutRaw(reinterpret_cast<const byte*>(data.data), data.raw_size, |
| 151 "internal fields data"); | 152 "internal fields data"); |
| 152 delete[] data.data; | 153 delete[] data.data; |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 sink_.Put(kSynchronize, "Finished with internal fields data"); | 156 sink_.Put(kSynchronize, "Finished with internal fields data"); |
| 156 } | 157 } |
| 157 | 158 |
| 158 } // namespace internal | 159 } // namespace internal |
| 159 } // namespace v8 | 160 } // namespace v8 |
| OLD | NEW |