// Copyright 2017 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. #include "src/snapshot/object-deserializer.h" #include "src/codegen/assembler-inl.h" #include "src/execution/isolate.h" #include "src/heap/heap-inl.h" #include "src/objects/allocation-site-inl.h" #include "src/objects/objects.h" #include "src/objects/slots.h" #include "src/snapshot/code-serializer.h" namespace v8 { namespace internal { ObjectDeserializer::ObjectDeserializer(const SerializedCodeData* data) : Deserializer(data, true) {} MaybeHandle ObjectDeserializer::DeserializeSharedFunctionInfo( Isolate* isolate, const SerializedCodeData* data, Handle source) { ObjectDeserializer d(data); d.AddAttachedObject(source); Handle result; return d.Deserialize(isolate).ToHandle(&result) ? Handle::cast(result) : MaybeHandle(); } MaybeHandle ObjectDeserializer::DeserializeSharedFunctionInfoOffThread( LocalIsolate* isolate, const SerializedCodeData* data, Handle source) { // TODO(leszeks): Add LocalHeap support to deserializer UNREACHABLE(); } MaybeHandle ObjectDeserializer::Deserialize(Isolate* isolate) { Initialize(isolate); if (!allocator()->ReserveSpace()) return MaybeHandle(); DCHECK(deserializing_user_code()); HandleScope scope(isolate); Handle result; { DisallowHeapAllocation no_gc; Object root; VisitRootPointer(Root::kStartupObjectCache, nullptr, FullObjectSlot(&root)); DeserializeDeferredObjects(); CHECK(new_code_objects().empty()); LinkAllocationSites(); LogNewMapEvents(); result = handle(HeapObject::cast(root), isolate); allocator()->RegisterDeserializedObjectsForBlackAllocation(); } Rehash(); CommitPostProcessedObjects(); return scope.CloseAndEscape(result); } void ObjectDeserializer::CommitPostProcessedObjects() { for (Handle buffer : new_off_heap_array_buffers()) { uint32_t store_index = buffer->GetBackingStoreRefForDeserialization(); auto bs = backing_store(store_index); SharedFlag shared = bs && bs->is_shared() ? SharedFlag::kShared : SharedFlag::kNotShared; buffer->Setup(shared, bs); } for (Handle