Line data Source code
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 502 : 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 1004 : can_be_rehashed_(true) {
20 132528 : for (size_t i = 0; i < static_cast<size_t>(first_root_to_be_serialized);
21 : ++i) {
22 132026 : root_has_been_serialized_[i] = true;
23 : }
24 502 : }
25 :
26 591567 : int RootsSerializer::SerializeInObjectCache(HeapObject heap_object) {
27 : int index;
28 591567 : 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 397702 : SerializeObject(heap_object, kPlain, kStartOfObject, 0);
32 : }
33 591567 : return index;
34 : }
35 :
36 4267 : void RootsSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
37 : sink_.Put(kSynchronize, "Synchronize");
38 4267 : }
39 :
40 384030 : void RootsSerializer::VisitRootPointers(Root root, const char* description,
41 : FullObjectSlot start,
42 : FullObjectSlot end) {
43 384030 : RootsTable& roots_table = isolate()->heap()->roots_table();
44 384030 : if (start ==
45 384030 : roots_table.begin() + static_cast<int>(first_root_to_be_serialized_)) {
46 : // Serializing the root list needs special handling:
47 : // - Only root list elements that have been fully serialized can be
48 : // referenced using kRootArray bytecodes.
49 146333 : for (FullObjectSlot current = start; current < end; ++current) {
50 145831 : SerializeRootObject(*current);
51 : size_t root_index = current - roots_table.begin();
52 145831 : root_has_been_serialized_.set(root_index);
53 : }
54 : } else {
55 383528 : Serializer::VisitRootPointers(root, description, start, end);
56 : }
57 384030 : }
58 :
59 1286637 : void RootsSerializer::CheckRehashability(HeapObject obj) {
60 1286637 : if (!can_be_rehashed_) return;
61 1286637 : if (!obj->NeedsRehashing()) return;
62 768 : if (obj->CanBeRehashed()) return;
63 0 : can_be_rehashed_ = false;
64 : }
65 :
66 : } // namespace internal
67 183867 : } // namespace v8
|