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

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

Issue 1805903002: [serializer] Add API to warm up startup snapshot with an additional script. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix comment Created 4 years, 9 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
« no previous file with comments | « src/snapshot/partial-serializer.h ('k') | src/snapshot/serializer-common.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12 PartialSerializer::PartialSerializer(Isolate* isolate, 12 PartialSerializer::PartialSerializer(Isolate* isolate,
13 Serializer* startup_snapshot_serializer, 13 Serializer* startup_snapshot_serializer,
14 SnapshotByteSink* sink) 14 SnapshotByteSink* sink)
15 : Serializer(isolate, sink), 15 : Serializer(isolate, sink),
16 startup_serializer_(startup_snapshot_serializer), 16 startup_serializer_(startup_snapshot_serializer),
17 global_object_(NULL) { 17 global_object_(NULL),
18 next_partial_cache_index_(0) {
18 InitializeCodeAddressMap(); 19 InitializeCodeAddressMap();
19 } 20 }
20 21
21 PartialSerializer::~PartialSerializer() { 22 PartialSerializer::~PartialSerializer() {
22 OutputStatistics("PartialSerializer"); 23 OutputStatistics("PartialSerializer");
23 } 24 }
24 25
25 void PartialSerializer::Serialize(Object** o) { 26 void PartialSerializer::Serialize(Object** o) {
26 if ((*o)->IsContext()) { 27 if ((*o)->IsContext()) {
27 Context* context = Context::cast(*o); 28 Context* context = Context::cast(*o);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 FixedArray* literals = JSFunction::cast(obj)->literals(); 88 FixedArray* literals = JSFunction::cast(obj)->literals();
88 for (int i = 0; i < literals->length(); i++) literals->set_undefined(i); 89 for (int i = 0; i < literals->length(); i++) literals->set_undefined(i);
89 } 90 }
90 91
91 // Object has not yet been serialized. Serialize it here. 92 // Object has not yet been serialized. Serialize it here.
92 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); 93 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point);
93 serializer.Serialize(); 94 serializer.Serialize();
94 } 95 }
95 96
96 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { 97 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
97 Isolate* isolate = this->isolate(); 98 int index = partial_cache_index_map_.LookupOrInsert(
98 List<Object*>* cache = isolate->partial_snapshot_cache(); 99 heap_object, next_partial_cache_index_);
99 int new_index = cache->length();
100
101 int index = partial_cache_index_map_.LookupOrInsert(heap_object, new_index);
102 if (index == PartialCacheIndexMap::kInvalidIndex) { 100 if (index == PartialCacheIndexMap::kInvalidIndex) {
103 // We didn't find the object in the cache. So we add it to the cache and 101 // This object is not part of the partial snapshot cache yet. Add it to the
104 // then visit the pointer so that it becomes part of the startup snapshot 102 // startup snapshot so we can refer to it via partial snapshot index from
105 // and we can refer to it from the partial snapshot. 103 // the partial snapshot.
106 cache->Add(heap_object);
107 startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object)); 104 startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object));
108 // We don't recurse from the startup snapshot generator into the partial 105 return next_partial_cache_index_++;
109 // snapshot generator.
110 return new_index;
111 } 106 }
112 return index; 107 return index;
113 } 108 }
114 109
115 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) { 110 bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) {
116 // Scripts should be referred only through shared function infos. We can't 111 // Scripts should be referred only through shared function infos. We can't
117 // allow them to be part of the partial snapshot because they contain a 112 // allow them to be part of the partial snapshot because they contain a
118 // unique ID, and deserializing several partial snapshots containing script 113 // unique ID, and deserializing several partial snapshots containing script
119 // would cause dupes. 114 // would cause dupes.
120 DCHECK(!o->IsScript()); 115 DCHECK(!o->IsScript());
121 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || 116 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() ||
122 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || 117 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() ||
123 o->map() == 118 o->map() ==
124 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); 119 startup_serializer_->isolate()->heap()->fixed_cow_array_map();
125 } 120 }
126 121
127 } // namespace internal 122 } // namespace internal
128 } // namespace v8 123 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/partial-serializer.h ('k') | src/snapshot/serializer-common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698