5 #include "src/snapshot/object-deserializer.h" 7 #include "src/assembler-inl.h" 8 #include "src/code-stubs.h" 9 #include "src/isolate.h" 10 #include "src/objects.h" 11 #include "src/objects/slots.h" 12 #include "src/snapshot/code-serializer.h" 17 ObjectDeserializer::ObjectDeserializer(
const SerializedCodeData* data)
18 : Deserializer(data, true) {}
20 MaybeHandle<SharedFunctionInfo>
21 ObjectDeserializer::DeserializeSharedFunctionInfo(
22 Isolate* isolate,
const SerializedCodeData* data, Handle<String> source) {
23 ObjectDeserializer d(data);
25 d.AddAttachedObject(source);
27 Vector<const uint32_t> code_stub_keys = data->CodeStubKeys();
28 for (
int i = 0;
i < code_stub_keys.length();
i++) {
30 CodeStub::GetCode(isolate, code_stub_keys[
i]).ToHandleChecked());
33 Handle<HeapObject> result;
34 return d.Deserialize(isolate).ToHandle(&result)
35 ? Handle<SharedFunctionInfo>::cast(result)
36 : MaybeHandle<SharedFunctionInfo>();
39 MaybeHandle<HeapObject> ObjectDeserializer::Deserialize(Isolate* isolate) {
42 if (!allocator()->ReserveSpace())
return MaybeHandle<HeapObject>();
44 DCHECK(deserializing_user_code());
45 HandleScope scope(isolate);
46 Handle<HeapObject> result;
48 DisallowHeapAllocation no_gc;
50 VisitRootPointer(Root::kPartialSnapshotCache,
nullptr, ObjectSlot(&root));
51 DeserializeDeferredObjects();
53 LinkAllocationSites();
55 result = handle(HeapObject::cast(root), isolate);
57 allocator()->RegisterDeserializedObjectsForBlackAllocation();
59 CommitPostProcessedObjects();
60 return scope.CloseAndEscape(result);
63 void ObjectDeserializer::FlushICache() {
64 DCHECK(deserializing_user_code());
65 for (Code code : new_code_objects()) {
67 WriteBarrierForCode(code);
68 Assembler::FlushICache(code->raw_instruction_start(),
69 code->raw_instruction_size());
73 void ObjectDeserializer::CommitPostProcessedObjects() {
74 CHECK_LE(new_internalized_strings().size(), kMaxInt);
75 StringTable::EnsureCapacityForDeserialization(
76 isolate(), static_cast<int>(new_internalized_strings().size()));
77 for (Handle<String>
string : new_internalized_strings()) {
78 DisallowHeapAllocation no_gc;
79 StringTableInsertionKey key(*
string);
81 StringTable::ForwardStringIfExists(isolate(), &key, *
string).is_null());
82 StringTable::AddKeyNoResize(isolate(), &key);
85 Heap* heap = isolate()->heap();
86 Factory* factory = isolate()->factory();
87 for (Handle<Script> script : new_scripts()) {
89 script->set_id(isolate()->heap()->NextScriptId());
90 LogScriptEvents(*script);
92 Handle<WeakArrayList> list = factory->script_list();
93 list = WeakArrayList::AddToEnd(isolate(), list,
94 MaybeObjectHandle::Weak(script));
95 heap->SetRootScriptList(*list);
99 void ObjectDeserializer::LinkAllocationSites() {
100 DisallowHeapAllocation no_gc;
101 Heap* heap = isolate()->heap();
104 for (AllocationSite* site : new_allocation_sites()) {
105 if (!site->HasWeakNext())
continue;
109 if (heap->allocation_sites_list() == Smi::kZero) {
110 site->set_weak_next(ReadOnlyRoots(heap).undefined_value());
112 site->set_weak_next(heap->allocation_sites_list());
114 heap->set_allocation_sites_list(site);