OLD | NEW |
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( | 13 StartupSerializer::StartupSerializer( |
14 Isolate* isolate, SnapshotByteSink* sink, | 14 Isolate* isolate, |
15 v8::SnapshotCreator::FunctionCodeHandling function_code_handling) | 15 v8::SnapshotCreator::FunctionCodeHandling function_code_handling) |
16 : Serializer(isolate, sink), | 16 : Serializer(isolate), |
17 clear_function_code_(function_code_handling == | 17 clear_function_code_(function_code_handling == |
18 v8::SnapshotCreator::FunctionCodeHandling::kClear), | 18 v8::SnapshotCreator::FunctionCodeHandling::kClear), |
19 serializing_builtins_(false) { | 19 serializing_builtins_(false) { |
20 InitializeCodeAddressMap(); | 20 InitializeCodeAddressMap(); |
21 } | 21 } |
22 | 22 |
23 StartupSerializer::~StartupSerializer() { | 23 StartupSerializer::~StartupSerializer() { |
24 OutputStatistics("StartupSerializer"); | 24 OutputStatistics("StartupSerializer"); |
25 } | 25 } |
26 | 26 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 58 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
59 return; | 59 return; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; | 63 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; |
64 | 64 |
65 FlushSkip(skip); | 65 FlushSkip(skip); |
66 | 66 |
67 // Object has not yet been serialized. Serialize it here. | 67 // Object has not yet been serialized. Serialize it here. |
68 ObjectSerializer object_serializer(this, obj, sink_, how_to_code, | 68 ObjectSerializer object_serializer(this, obj, &sink_, how_to_code, |
69 where_to_point); | 69 where_to_point); |
70 object_serializer.Serialize(); | 70 object_serializer.Serialize(); |
71 | 71 |
72 if (serializing_immortal_immovables_roots_ && | 72 if (serializing_immortal_immovables_roots_ && |
73 root_index != RootIndexMap::kInvalidRootIndex) { | 73 root_index != RootIndexMap::kInvalidRootIndex) { |
74 // Make sure that the immortal immovable root has been included in the first | 74 // Make sure that the immortal immovable root has been included in the first |
75 // chunk of its reserved space , so that it is deserialized onto the first | 75 // chunk of its reserved space , so that it is deserialized onto the first |
76 // page of its space and stays immortal immovable. | 76 // page of its space and stays immortal immovable. |
77 SerializerReference ref = reference_map_.Lookup(obj); | 77 SerializerReference ref = reference_map_.Lookup(obj); |
78 CHECK(ref.is_back_reference() && ref.chunk_index() == 0); | 78 CHECK(ref.is_back_reference() && ref.chunk_index() == 0); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void StartupSerializer::SerializeWeakReferencesAndDeferred() { | 82 void StartupSerializer::SerializeWeakReferencesAndDeferred() { |
83 // This comes right after serialization of the partial snapshot, where we | 83 // This comes right after serialization of the partial snapshot, where we |
84 // add entries to the partial snapshot cache of the startup snapshot. Add | 84 // add entries to the partial snapshot cache of the startup snapshot. Add |
85 // one entry with 'undefined' to terminate the partial snapshot cache. | 85 // one entry with 'undefined' to terminate the partial snapshot cache. |
86 Object* undefined = isolate()->heap()->undefined_value(); | 86 Object* undefined = isolate()->heap()->undefined_value(); |
87 VisitPointer(&undefined); | 87 VisitPointer(&undefined); |
88 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); | 88 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); |
89 SerializeDeferredObjects(); | 89 SerializeDeferredObjects(); |
90 Pad(); | 90 Pad(); |
91 } | 91 } |
92 | 92 |
93 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) { | 93 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) { |
94 // We expect the builtins tag after builtins have been serialized. | 94 // We expect the builtins tag after builtins have been serialized. |
95 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins); | 95 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins); |
96 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope); | 96 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope); |
97 sink_->Put(kSynchronize, "Synchronize"); | 97 sink_.Put(kSynchronize, "Synchronize"); |
98 } | 98 } |
99 | 99 |
100 void StartupSerializer::SerializeStrongReferences() { | 100 void StartupSerializer::SerializeStrongReferences() { |
101 Isolate* isolate = this->isolate(); | 101 Isolate* isolate = this->isolate(); |
102 // No active threads. | 102 // No active threads. |
103 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse()); | 103 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse()); |
104 // No active or weak handles. | 104 // No active or weak handles. |
105 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); | 105 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty()); |
106 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); | 106 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles()); |
107 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles()); | 107 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (root_index == Heap::kStackLimitRootIndex || | 159 if (root_index == Heap::kStackLimitRootIndex || |
160 root_index == Heap::kRealStackLimitRootIndex) { | 160 root_index == Heap::kRealStackLimitRootIndex) { |
161 return true; | 161 return true; |
162 } | 162 } |
163 return Heap::RootIsImmortalImmovable(root_index) != | 163 return Heap::RootIsImmortalImmovable(root_index) != |
164 serializing_immortal_immovables_roots_; | 164 serializing_immortal_immovables_roots_; |
165 } | 165 } |
166 | 166 |
167 } // namespace internal | 167 } // namespace internal |
168 } // namespace v8 | 168 } // namespace v8 |
OLD | NEW |