Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/snapshot/partial-serializer.cc

Issue 2055203002: [snapshot] support multiple contexts in the same snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@sinkmember
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/snapshot/partial-serializer.h" 5 #include "src/snapshot/partial-serializer.h"
6 #include "src/snapshot/startup-serializer.h"
6 7
7 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
8 9
9 namespace v8 { 10 namespace v8 {
10 namespace internal { 11 namespace internal {
11 12
12 PartialSerializer::PartialSerializer(Isolate* isolate, 13 PartialSerializer::PartialSerializer(Isolate* isolate,
13 Serializer* startup_snapshot_serializer) 14 StartupSerializer* startup_serializer)
14 : Serializer(isolate), 15 : Serializer(isolate), startup_serializer_(startup_serializer) {
15 startup_serializer_(startup_snapshot_serializer),
16 next_partial_cache_index_(0) {
17 InitializeCodeAddressMap(); 16 InitializeCodeAddressMap();
18 } 17 }
19 18
20 PartialSerializer::~PartialSerializer() { 19 PartialSerializer::~PartialSerializer() {
21 OutputStatistics("PartialSerializer"); 20 OutputStatistics("PartialSerializer");
22 } 21 }
23 22
24 void PartialSerializer::Serialize(Object** o) { 23 void PartialSerializer::Serialize(Object** o) {
25 if ((*o)->IsContext()) { 24 if ((*o)->IsContext()) {
26 Context* context = Context::cast(*o); 25 Context* context = Context::cast(*o);
(...skipping 27 matching lines...) Expand all
54 53
55 int root_index = root_index_map_.Lookup(obj); 54 int root_index = root_index_map_.Lookup(obj);
56 if (root_index != RootIndexMap::kInvalidRootIndex) { 55 if (root_index != RootIndexMap::kInvalidRootIndex) {
57 PutRoot(root_index, obj, how_to_code, where_to_point, skip); 56 PutRoot(root_index, obj, how_to_code, where_to_point, skip);
58 return; 57 return;
59 } 58 }
60 59
61 if (ShouldBeInThePartialSnapshotCache(obj)) { 60 if (ShouldBeInThePartialSnapshotCache(obj)) {
62 FlushSkip(skip); 61 FlushSkip(skip);
63 62
64 int cache_index = PartialSnapshotCacheIndex(obj); 63 int cache_index = startup_serializer_->PartialSnapshotCacheIndex(obj);
65 sink_.Put(kPartialSnapshotCache + how_to_code + where_to_point, 64 sink_.Put(kPartialSnapshotCache + how_to_code + where_to_point,
66 "PartialSnapshotCache"); 65 "PartialSnapshotCache");
67 sink_.PutInt(cache_index, "partial_snapshot_cache_index"); 66 sink_.PutInt(cache_index, "partial_snapshot_cache_index");
68 return; 67 return;
69 } 68 }
70 69
71 // Pointers from the partial snapshot to the objects in the startup snapshot 70 // Pointers from the partial snapshot to the objects in the startup snapshot
72 // should go through the root array or through the partial snapshot cache. 71 // should go through the root array or through the partial snapshot cache.
73 // If this is not the case you may have to add something to the root array. 72 // If this is not the case you may have to add something to the root array.
74 DCHECK(!startup_serializer_->reference_map()->Lookup(obj).is_valid()); 73 DCHECK(!startup_serializer_->reference_map()->Lookup(obj).is_valid());
(...skipping 11 matching lines...) Expand all
86 for (int i = 0; i < literals->literals_count(); i++) { 85 for (int i = 0; i < literals->literals_count(); i++) {
87 literals->set_literal_undefined(i); 86 literals->set_literal_undefined(i);
88 } 87 }
89 } 88 }
90 89
91 // Object has not yet been serialized. Serialize it here. 90 // Object has not yet been serialized. Serialize it here.
92 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); 91 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point);
93 serializer.Serialize(); 92 serializer.Serialize();
94 } 93 }
95 94
96 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
97 int index = partial_cache_index_map_.LookupOrInsert(
98 heap_object, next_partial_cache_index_);
99 if (index == PartialCacheIndexMap::kInvalidIndex) {
100 // This object is not part of the partial snapshot cache yet. Add it to the
101 // startup snapshot so we can refer to it via partial snapshot index from
102 // the partial snapshot.
103 startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
104 return next_partial_cache_index_++;
105 }
106 return index;
107 }
108
109 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { 95 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) {
110 // Scripts should be referred only through shared function infos. We can't 96 // Scripts should be referred only through shared function infos. We can't
111 // allow them to be part of the partial snapshot because they contain a 97 // allow them to be part of the partial snapshot because they contain a
112 // unique ID, and deserializing several partial snapshots containing script 98 // unique ID, and deserializing several partial snapshots containing script
113 // would cause dupes. 99 // would cause dupes.
114 DCHECK(!o->IsScript()); 100 DCHECK(!o->IsScript());
115 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || 101 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() ||
116 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || 102 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() ||
117 o->map() == 103 o->map() ==
118 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); 104 startup_serializer_->isolate()->heap()->fixed_cow_array_map();
119 } 105 }
120 106
121 } // namespace internal 107 } // namespace internal
122 } // namespace v8 108 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698