V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
roots-serializer.cc
1 // Copyright 2018 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 
5 #include "src/snapshot/roots-serializer.h"
6 
7 #include "src/heap/heap.h"
8 #include "src/isolate.h"
9 #include "src/objects-inl.h"
10 #include "src/objects/slots.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 RootsSerializer::RootsSerializer(Isolate* isolate,
16  RootIndex first_root_to_be_serialized)
17  : Serializer(isolate),
18  first_root_to_be_serialized_(first_root_to_be_serialized),
19  can_be_rehashed_(true) {
20  for (size_t i = 0; i < static_cast<size_t>(first_root_to_be_serialized);
21  ++i) {
22  root_has_been_serialized_[i] = true;
23  }
24 }
25 
26 int RootsSerializer::SerializeInObjectCache(HeapObject* heap_object) {
27  int index;
28  if (!object_cache_index_map_.LookupOrInsert(heap_object, &index)) {
29  // This object is not part of the object cache yet. Add it to the cache so
30  // we can refer to it via cache index from the delegating snapshot.
31  SerializeObject(heap_object, kPlain, kStartOfObject, 0);
32  }
33  return index;
34 }
35 
36 void RootsSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
37  sink_.Put(kSynchronize, "Synchronize");
38 }
39 
40 void RootsSerializer::VisitRootPointers(Root root, const char* description,
41  ObjectSlot start, ObjectSlot end) {
42  RootsTable& roots_table = isolate()->heap()->roots_table();
43  if (start ==
44  roots_table.begin() + static_cast<int>(first_root_to_be_serialized_)) {
45  // Serializing the root list needs special handling:
46  // - Only root list elements that have been fully serialized can be
47  // referenced using kRootArray bytecodes.
48  for (ObjectSlot current = start; current < end; ++current) {
49  SerializeRootObject(*current);
50  size_t root_index = current - roots_table.begin();
51  root_has_been_serialized_.set(root_index);
52  }
53  } else {
54  Serializer::VisitRootPointers(root, description, start, end);
55  }
56 }
57 
58 void RootsSerializer::CheckRehashability(HeapObject* obj) {
59  if (!can_be_rehashed_) return;
60  if (!obj->NeedsRehashing()) return;
61  if (obj->CanBeRehashed()) return;
62  can_be_rehashed_ = false;
63 }
64 
65 } // namespace internal
66 } // namespace v8
Definition: libplatform.h:13