v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
object-deserializer.cc
Go to the documentation of this file.
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
8#include "src/heap/heap-inl.h"
12#include "src/objects/objects.h"
14
15namespace v8 {
16namespace internal {
17
19 const SerializedCodeData* data)
20 : Deserializer(isolate, data->Payload(), data->GetMagicNumber(), true,
21 false) {}
22
25 Isolate* isolate, const SerializedCodeData* data,
26 DirectHandle<String> source) {
27 ObjectDeserializer d(isolate, data);
28
29 d.AddAttachedObject(source);
30
32 return d.Deserialize().ToHandle(&result)
35}
36
54
56 for (DirectHandle<Script> script : new_scripts()) {
57 // Assign a new script id to avoid collision.
58 script->set_id(isolate()->GetNextScriptId());
59 LogScriptEvents(*script);
60 // Add script to list.
61 Handle<WeakArrayList> list = isolate()->factory()->script_list();
62 list = WeakArrayList::AddToEnd(isolate(), list,
64 isolate()->heap()->SetRootScriptList(*list);
65 }
66}
67
70 Heap* heap = isolate()->heap();
71 // Allocation sites are present in the snapshot, and must be linked into
72 // a list at deserialization time.
74 if (!site->HasWeakNext()) continue;
77 // TODO(mvstanton): consider treating the heap()->allocation_sites_list()
78 // as a (weak) root. If this root is relocated correctly, this becomes
79 // unnecessary.
80 if (heap->allocation_sites_list() == Smi::zero()) {
81 site_with_next->set_weak_next(ReadOnlyRoots(heap).undefined_value());
82 } else {
83 site_with_next->set_weak_next(
85 heap->allocation_sites_list()));
86 }
87 heap->set_allocation_sites_list(*site_with_next);
88 }
89}
90
92 LocalIsolate* isolate, const SerializedCodeData* data)
93 : Deserializer(isolate, data->Payload(), data->GetMagicNumber(), true,
94 false) {}
95
98 LocalIsolate* isolate, const SerializedCodeData* data,
99 std::vector<IndirectHandle<Script>>* deserialized_scripts) {
100 OffThreadObjectDeserializer d(isolate, data);
101
102 // Attach the empty string as the source.
103 d.AddAttachedObject(isolate->factory()->empty_string());
104
106 if (!d.Deserialize(deserialized_scripts).ToHandle(&result)) {
108 }
110}
111
113 std::vector<IndirectHandle<Script>>* deserialized_scripts) {
115 LocalHandleScope scope(isolate());
117 {
118 result = ReadObject();
120 CHECK(new_code_objects().empty());
121 CHECK(new_allocation_sites().empty());
122 CHECK(new_maps().empty());
124 }
125
126 Rehash();
127
128 // TODO(leszeks): Figure out a better way of dealing with scripts.
129 CHECK_EQ(new_scripts().size(), 1);
130 for (DirectHandle<Script> script : new_scripts()) {
131 // Assign a new script id to avoid collision.
132 script->set_id(isolate()->GetNextScriptId());
133 LogScriptEvents(*script);
134 deserialized_scripts->push_back(
135 isolate()->heap()->NewPersistentHandle(script));
136 }
137
138 return scope.CloseAndEscape(result);
139}
140
141} // namespace internal
142} // namespace v8
base::Vector< const DirectHandle< InstructionStream > > new_code_objects() const
DirectHandle< HeapObject > ReadObject()
void LogScriptEvents(Tagged< Script > script)
base::Vector< const DirectHandle< AllocationSite > > new_allocation_sites() const
base::Vector< const DirectHandle< Map > > new_maps() const
base::Vector< const DirectHandle< Script > > new_scripts() const
HandleType< T > CloseAndEscape(HandleType< T > handle_value)
V8_INLINE void SetRootScriptList(Tagged< Object > value)
Definition heap-inl.h:126
v8::internal::Factory * factory()
Definition isolate.h:1527
HandleType< T > CloseAndEscape(HandleType< T > handle_value)
static MaybeObjectDirectHandle Weak(Tagged< Object > object, Isolate *isolate)
ObjectDeserializer(Isolate *isolate, const SerializedCodeData *data)
static MaybeDirectHandle< SharedFunctionInfo > DeserializeSharedFunctionInfo(Isolate *isolate, const SerializedCodeData *data, DirectHandle< String > source)
MaybeDirectHandle< HeapObject > Deserialize()
MaybeDirectHandle< HeapObject > Deserialize(std::vector< IndirectHandle< Script > > *deserialized_scripts)
OffThreadObjectDeserializer(LocalIsolate *isolate, const SerializedCodeData *data)
static MaybeDirectHandle< SharedFunctionInfo > DeserializeSharedFunctionInfo(LocalIsolate *isolate, const SerializedCodeData *data, std::vector< IndirectHandle< Script > > *deserialized_scripts)
static constexpr Tagged< Smi > zero()
Definition smi.h:99
NEVER_READ_ONLY_SPACE static V8_EXPORT_PRIVATE Handle< WeakArrayList > AddToEnd(Isolate *isolate, Handle< WeakArrayList > array, MaybeObjectDirectHandle value)
ZoneVector< RpoNumber > & result
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482