Line data Source code
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 : #ifndef V8_SNAPSHOT_STARTUP_SERIALIZER_H_
6 : #define V8_SNAPSHOT_STARTUP_SERIALIZER_H_
7 :
8 : #include <unordered_set>
9 :
10 : #include "src/snapshot/roots-serializer.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : class HeapObject;
16 : class SnapshotByteSink;
17 : class ReadOnlySerializer;
18 :
19 : class V8_EXPORT_PRIVATE StartupSerializer : public RootsSerializer {
20 : public:
21 : StartupSerializer(Isolate* isolate, ReadOnlySerializer* read_only_serializer);
22 : ~StartupSerializer() override;
23 :
24 : // Serialize the current state of the heap. The order is:
25 : // 1) Strong roots
26 : // 2) Builtins and bytecode handlers
27 : // 3) Partial snapshot cache
28 : // 4) Weak references (e.g. the string table)
29 : void SerializeStrongReferences();
30 : void SerializeWeakReferencesAndDeferred();
31 :
32 : // If |obj| can be serialized in the read-only snapshot then add it to the
33 : // read-only object cache if not already present and emits a
34 : // ReadOnlyObjectCache bytecode into |sink|. Returns whether this was
35 : // successful.
36 : bool SerializeUsingReadOnlyObjectCache(SnapshotByteSink* sink,
37 : HeapObject obj);
38 :
39 : // Adds |obj| to the partial snapshot object cache if not already present and
40 : // emits a PartialSnapshotCache bytecode into |sink|.
41 : void SerializeUsingPartialSnapshotCache(SnapshotByteSink* sink,
42 : HeapObject obj);
43 :
44 : private:
45 : void SerializeObject(HeapObject o) override;
46 :
47 : ReadOnlySerializer* read_only_serializer_;
48 : std::vector<AccessorInfo> accessor_infos_;
49 : std::vector<CallHandlerInfo> call_handler_infos_;
50 :
51 : DISALLOW_COPY_AND_ASSIGN(StartupSerializer);
52 : };
53 :
54 392 : class SerializedHandleChecker : public RootVisitor {
55 : public:
56 : SerializedHandleChecker(Isolate* isolate, std::vector<Context>* contexts);
57 : void VisitRootPointers(Root root, const char* description,
58 : FullObjectSlot start, FullObjectSlot end) override;
59 : bool CheckGlobalAndEternalHandles();
60 :
61 : private:
62 : void AddToSet(FixedArray serialized);
63 :
64 : Isolate* isolate_;
65 : std::unordered_set<Object, Object::Hasher> serialized_;
66 : bool ok_ = true;
67 : };
68 :
69 : } // namespace internal
70 : } // namespace v8
71 :
72 : #endif // V8_SNAPSHOT_STARTUP_SERIALIZER_H_
|