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

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

Issue 1751863002: [serializer] split up src/snapshot/serialize.* (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/snapshot/startup-serializer.h"
6
7 #include "src/objects-inl.h"
8 #include "src/v8threads.h"
9
10 namespace v8 {
11 namespace internal {
12
13 StartupSerializer::StartupSerializer(Isolate* isolate, SnapshotByteSink* sink)
14 : Serializer(isolate, sink),
15 root_index_wave_front_(0),
16 serializing_builtins_(false) {
17 // Clear the cache of objects used by the partial snapshot. After the
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();
23 }
24
25 StartupSerializer::~StartupSerializer() {
26 OutputStatistics("StartupSerializer");
27 }
28
29 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
30 WhereToPoint where_to_point, int skip) {
31 DCHECK(!obj->IsJSFunction());
32
33 if (obj->IsCode()) {
34 Code* code = Code::cast(obj);
35 // 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
37 // serializing the canonical interpreter-entry-trampoline builtin.
38 if (code->kind() == Code::FUNCTION ||
39 (!serializing_builtins_ && code->is_interpreter_entry_trampoline())) {
40 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy);
41 }
42 } else if (obj->IsBytecodeArray()) {
43 obj = isolate()->heap()->undefined_value();
44 }
45
46 int root_index = root_index_map_.Lookup(obj);
47 bool is_immortal_immovable_root = false;
48 // We can only encode roots as such if it has already been serialized.
49 // That applies to root indices below the wave front.
50 if (root_index != RootIndexMap::kInvalidRootIndex) {
51 if (root_index < root_index_wave_front_) {
52 PutRoot(root_index, obj, how_to_code, where_to_point, skip);
53 return;
54 } else {
55 is_immortal_immovable_root = Heap::RootIsImmortalImmovable(root_index);
56 }
57 }
58
59 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return;
60
61 FlushSkip(skip);
62
63 // Object has not yet been serialized. Serialize it here.
64 ObjectSerializer object_serializer(this, obj, sink_, how_to_code,
65 where_to_point);
66 object_serializer.Serialize();
67
68 if (is_immortal_immovable_root) {
69 // 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
71 // page of its space and stays immortal immovable.
72 BackReference ref = back_reference_map_.Lookup(obj);
73 CHECK(ref.is_valid() && ref.chunk_index() == 0);
74 }
75 }
76
77 void StartupSerializer::SerializeWeakReferencesAndDeferred() {
78 // This phase comes right after the serialization (of the snapshot).
79 // After we have done the partial serialization the partial snapshot cache
80 // will contain some references needed to decode the partial snapshot. We
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();
84 VisitPointer(&undefined);
85 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL);
86 SerializeDeferredObjects();
87 Pad();
88 }
89
90 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
91 // We expect the builtins tag after builtins have been serialized.
92 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins);
93 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope);
94 sink_->Put(kSynchronize, "Synchronize");
95 }
96
97 void StartupSerializer::SerializeStrongReferences() {
98 Isolate* isolate = this->isolate();
99 // No active threads.
100 CHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
101 // No active or weak handles.
102 CHECK(isolate->handle_scope_implementer()->blocks()->is_empty());
103 CHECK_EQ(0, isolate->global_handles()->NumberOfWeakHandles());
104 CHECK_EQ(0, isolate->eternal_handles()->NumberOfHandles());
105 // We don't support serializing installed extensions.
106 CHECK(!isolate->has_installed_extensions());
107 isolate->heap()->IterateSmiRoots(this);
108 isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
109 }
110
111 void StartupSerializer::VisitPointers(Object** start, Object** end) {
112 for (Object** current = start; current < end; current++) {
113 if (start == isolate()->heap()->roots_array_start()) {
114 root_index_wave_front_ =
115 Max(root_index_wave_front_, static_cast<intptr_t>(current - start));
116 }
117 if (ShouldBeSkipped(current)) {
118 sink_->Put(kSkip, "Skip");
119 sink_->PutInt(kPointerSize, "SkipOneWord");
120 } else if ((*current)->IsSmi()) {
121 sink_->Put(kOnePointerRawData, "Smi");
122 for (int i = 0; i < kPointerSize; i++) {
123 sink_->Put(reinterpret_cast<byte*>(current)[i], "Byte");
124 }
125 } else {
126 SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0);
127 }
128 }
129 }
130
131 } // namespace internal
132 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698