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 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, HeapObject obj,
37 : HowToCode how_to_code,
38 : WhereToPoint where_to_point, int skip);
39 :
40 : // Adds |obj| to the partial snapshot object cache if not already present and
41 : // emits a PartialSnapshotCache bytecode into |sink|.
42 : void SerializeUsingPartialSnapshotCache(SnapshotByteSink* sink,
43 : HeapObject obj, HowToCode how_to_code,
44 : WhereToPoint where_to_point,
45 : int skip);
46 :
47 : private:
48 : void SerializeObject(HeapObject o, HowToCode how_to_code,
49 : WhereToPoint where_to_point, int skip) override;
50 :
51 : ReadOnlySerializer* read_only_serializer_;
52 : std::vector<AccessorInfo> accessor_infos_;
53 : std::vector<CallHandlerInfo> call_handler_infos_;
54 :
55 : DISALLOW_COPY_AND_ASSIGN(StartupSerializer);
56 : };
57 :
58 372 : class SerializedHandleChecker : public RootVisitor {
59 : public:
60 : SerializedHandleChecker(Isolate* isolate, std::vector<Context>* contexts);
61 : void VisitRootPointers(Root root, const char* description,
62 : FullObjectSlot start, FullObjectSlot end) override;
63 : bool CheckGlobalAndEternalHandles();
64 :
65 : private:
66 : void AddToSet(FixedArray serialized);
67 :
68 : Isolate* isolate_;
69 : std::unordered_set<Object, Object::Hasher> serialized_;
70 : bool ok_ = true;
71 : };
72 :
73 : } // namespace internal
74 : } // namespace v8
75 :
76 : #endif // V8_SNAPSHOT_STARTUP_SERIALIZER_H_
|