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

Side by Side Diff: src/snapshot/startup-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/startup-serializer.h ('k') | test/cctest/test-serialize.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/startup-serializer.h" 5 #include "src/snapshot/startup-serializer.h"
6 6
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 #include "src/v8threads.h" 8 #include "src/v8threads.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 StartupSerializer::StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) 13 StartupSerializer::StartupSerializer(
14 Isolate* isolate, SnapshotByteSink* sink,
15 FunctionCodeHandling function_code_handling)
14 : Serializer(isolate, sink), 16 : Serializer(isolate, sink),
15 root_index_wave_front_(0), 17 root_index_wave_front_(0),
16 serializing_builtins_(false) { 18 serializing_builtins_(false),
17 // Clear the cache of objects used by the partial snapshot. After the 19 function_code_handling_(function_code_handling) {
18 // strong roots have been serialized we can create a partial snapshot
19 // which will repopulate the cache with objects needed by that partial
20 // snapshot.
21 isolate->partial_snapshot_cache()->Clear();
22 InitializeCodeAddressMap(); 20 InitializeCodeAddressMap();
23 } 21 }
24 22
25 StartupSerializer::~StartupSerializer() { 23 StartupSerializer::~StartupSerializer() {
26 OutputStatistics("StartupSerializer"); 24 OutputStatistics("StartupSerializer");
27 } 25 }
28 26
29 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, 27 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
30 WhereToPoint where_to_point, int skip) { 28 WhereToPoint where_to_point, int skip) {
31 DCHECK(!obj->IsJSFunction()); 29 DCHECK(!obj->IsJSFunction());
32 30
33 if (obj->IsCode()) { 31 if (obj->IsCode()) {
34 Code* code = Code::cast(obj); 32 Code* code = Code::cast(obj);
35 // If the function code is compiled (either as native code or bytecode), 33 // If the function code is compiled (either as native code or bytecode),
36 // replace it with lazy-compile builtin. Only exception is when we are 34 // replace it with lazy-compile builtin. Only exception is when we are
37 // serializing the canonical interpreter-entry-trampoline builtin. 35 // serializing the canonical interpreter-entry-trampoline builtin.
38 if (code->kind() == Code::FUNCTION || 36 if (function_code_handling_ == CLEAR_FUNCTION_CODE &&
39 (!serializing_builtins_ && code->is_interpreter_entry_trampoline())) { 37 (code->kind() == Code::FUNCTION ||
38 (!serializing_builtins_ && code->is_interpreter_entry_trampoline()))) {
40 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); 39 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy);
41 } 40 }
42 } else if (obj->IsBytecodeArray()) { 41 } else if (obj->IsBytecodeArray()) {
43 obj = isolate()->heap()->undefined_value(); 42 obj = isolate()->heap()->undefined_value();
44 } 43 }
45 44
46 int root_index = root_index_map_.Lookup(obj); 45 int root_index = root_index_map_.Lookup(obj);
47 bool is_immortal_immovable_root = false; 46 bool is_immortal_immovable_root = false;
48 // We can only encode roots as such if it has already been serialized. 47 // We can only encode roots as such if it has already been serialized.
49 // That applies to root indices below the wave front. 48 // That applies to root indices below the wave front.
(...skipping 18 matching lines...) Expand all
68 if (is_immortal_immovable_root) { 67 if (is_immortal_immovable_root) {
69 // Make sure that the immortal immovable root has been included in the first 68 // Make sure that the immortal immovable root has been included in the first
70 // chunk of its reserved space , so that it is deserialized onto the first 69 // chunk of its reserved space , so that it is deserialized onto the first
71 // page of its space and stays immortal immovable. 70 // page of its space and stays immortal immovable.
72 BackReference ref = back_reference_map_.Lookup(obj); 71 BackReference ref = back_reference_map_.Lookup(obj);
73 CHECK(ref.is_valid() && ref.chunk_index() == 0); 72 CHECK(ref.is_valid() && ref.chunk_index() == 0);
74 } 73 }
75 } 74 }
76 75
77 void StartupSerializer::SerializeWeakReferencesAndDeferred() { 76 void StartupSerializer::SerializeWeakReferencesAndDeferred() {
78 // This phase comes right after the serialization (of the snapshot). 77 // This comes right after serialization of the partial snapshot, where we
79 // After we have done the partial serialization the partial snapshot cache 78 // add entries to the partial snapshot cache of the startup snapshot. Add
80 // will contain some references needed to decode the partial snapshot. We 79 // one entry with 'undefined' to terminate the partial snapshot cache.
81 // add one entry with 'undefined' which is the sentinel that the deserializer
82 // uses to know it is done deserializing the array.
83 Object* undefined = isolate()->heap()->undefined_value(); 80 Object* undefined = isolate()->heap()->undefined_value();
84 VisitPointer(&undefined); 81 VisitPointer(&undefined);
85 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); 82 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL);
86 SerializeDeferredObjects(); 83 SerializeDeferredObjects();
87 Pad(); 84 Pad();
88 } 85 }
89 86
90 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) { 87 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
91 // We expect the builtins tag after builtins have been serialized. 88 // We expect the builtins tag after builtins have been serialized.
92 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins); 89 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins);
93 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope); 90 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope);
94 sink_->Put(kSynchronize, "Synchronize"); 91 sink_->Put(kSynchronize, "Synchronize");
95 } 92 }
96 93
97 void StartupSerializer::SerializeStrongReferences() { 94 void StartupSerializer::SerializeStrongReferences() {
98 Isolate* isolate = this->isolate(); 95 Isolate* isolate = this->isolate();
99 // No active threads. 96 // No active threads.
100 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse()); 97 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
101 // No active or weak handles. 98 // No active or weak handles.
102 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); 99 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());
103 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); 100 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles());
104 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles()); 101 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles());
105 // We don't support serializing installed extensions. 102 // We don't support serializing installed extensions.
106 CHECK(!isolate->has_installed_extensions()); 103 CHECK(!isolate->has_installed_extensions());
107 isolate->heap()->IterateSmiRoots(this); 104 isolate->heap()->IterateSmiRoots(this);
108 isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); 105 isolate->heap()->IterateStrongRoots(this,
106 VISIT_ONLY_STRONG_FOR_SERIALIZATION);
109 } 107 }
110 108
111 void StartupSerializer::VisitPointers(Object** start, Object** end) { 109 void StartupSerializer::VisitPointers(Object** start, Object** end) {
112 for (Object** current = start; current < end; current++) { 110 for (Object** current = start; current < end; current++) {
113 if (start == isolate()->heap()->roots_array_start()) { 111 if (start == isolate()->heap()->roots_array_start()) {
114 root_index_wave_front_ = 112 root_index_wave_front_ =
115 Max(root_index_wave_front_, static_cast<intptr_t>(current - start)); 113 Max(root_index_wave_front_, static_cast<intptr_t>(current - start));
116 } 114 }
117 if (ShouldBeSkipped(current)) { 115 if (ShouldBeSkipped(current)) {
118 sink_->Put(kSkip, "Skip"); 116 sink_->Put(kSkip, "Skip");
119 sink_->PutInt(kPointerSize, "SkipOneWord"); 117 sink_->PutInt(kPointerSize, "SkipOneWord");
120 } else if ((*current)->IsSmi()) { 118 } else if ((*current)->IsSmi()) {
121 sink_->Put(kOnePointerRawData, "Smi"); 119 sink_->Put(kOnePointerRawData, "Smi");
122 for (int i = 0; i < kPointerSize; i++) { 120 for (int i = 0; i < kPointerSize; i++) {
123 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte"); 121 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
124 } 122 }
125 } else { 123 } else {
126 SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0); 124 SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0);
127 } 125 }
128 } 126 }
129 } 127 }
130 128
131 } // namespace internal 129 } // namespace internal
132 } // namespace v8 130 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/startup-serializer.h ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698