v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
serializer-deserializer.cc
Go to the documentation of this file.
1// Copyright 2020 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
9
10namespace v8 {
11namespace internal {
12
13namespace {
15void IterateObjectCache(Isolate* isolate, std::vector<Tagged<Object>>* cache,
16 Root root_id, RootVisitor* visitor) {
17 for (size_t i = 0;; ++i) {
18 // Extend the array ready to get a value when deserializing.
19 if (cache->size() <= i) cache->push_back(Smi::zero());
20 // During deserialization, the visitor populates the object cache and
21 // eventually terminates the cache with undefined.
22 visitor->VisitRootPointer(root_id, nullptr, FullObjectSlot(&cache->at(i)));
23 // We may see objects in trusted space here (outside of the main pointer
24 // compression cage), so have to use SafeEquals.
25 Tagged<Object> undefined = ReadOnlyRoots(isolate).undefined_value();
26 if (cache->at(i).SafeEquals(undefined)) break;
27 }
28}
29} // namespace
30
31// The startup and shared heap object caches are terminated by undefined. We
32// visit these caches...
33// - during deserialization to populate it.
34// - during normal GC to keep its content alive.
35// - not during serialization. The context serializer adds to it explicitly.
37 RootVisitor* visitor) {
38 IterateObjectCache(isolate, isolate->startup_object_cache(),
39 Root::kStartupObjectCache, visitor);
40}
41
43 Isolate* isolate, RootVisitor* visitor) {
44 IterateObjectCache(isolate, isolate->shared_heap_object_cache(),
45 Root::kSharedHeapObjectCache, visitor);
46}
47
49 SlotType slot_type) {
50 // HeapObjects' map slots cannot be deferred as objects are expected to have a
51 // valid map immediately.
52 if (slot_type == SlotType::kMapSlot) {
53 DCHECK(IsMap(o));
54 return false;
55 }
56 // * Internalized strings cannot be deferred as they might be
57 // converted to thin strings during post processing, at which point forward
58 // references to the now-thin string will already have been written.
59 // * JS objects with embedder fields cannot be deferred because the
60 // serialize/deserialize callbacks need the back reference immediately to
61 // identify the object.
62 // * ByteArray cannot be deferred as JSTypedArray needs the base_pointer
63 // ByteArray immediately if it's on heap.
64 // * Non-empty EmbdderDataArrays cannot be deferred because the serialize
65 // and deserialize callbacks need the back reference immediately to
66 // identify the object.
67 // TODO(leszeks): Could we defer string serialization if forward references
68 // were resolved after object post processing?
69 return !IsInternalizedString(o) &&
70 !(IsJSObject(o) && Cast<JSObject>(o)->GetEmbedderFieldCount() > 0) &&
71 !IsByteArray(o) &&
72 !(IsEmbedderDataArray(o) && Cast<EmbedderDataArray>(o)->length() > 0);
73}
74
76 Isolate* isolate, Tagged<AccessorInfo> accessor_info) {
78 accessor_info->init_getter_redirection(isolate);
79}
80
82 Isolate* isolate, Tagged<FunctionTemplateInfo> function_template_info) {
84 function_template_info->init_callback_redirection(isolate);
85}
86
87} // namespace internal
88} // namespace v8
static void IterateStartupObjectCache(Isolate *isolate, RootVisitor *visitor)
void RestoreExternalReferenceRedirector(Isolate *isolate, Tagged< AccessorInfo > accessor_info)
static void IterateSharedHeapObjectCache(Isolate *isolate, RootVisitor *visitor)
static bool CanBeDeferred(Tagged< HeapObject > o, SlotType slot_type)
static constexpr Tagged< Smi > zero()
Definition smi.h:99
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK(condition)
Definition logging.h:482
#define DISABLE_CFI_PERF
Definition macros.h:197