Line data Source code
1 : // Copyright 2017 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_BUILTIN_DESERIALIZER_H_
6 : #define V8_SNAPSHOT_BUILTIN_DESERIALIZER_H_
7 :
8 : #include "src/snapshot/builtin-deserializer-allocator.h"
9 : #include "src/snapshot/deserializer.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 : class BuiltinSnapshotData;
15 :
16 : // Deserializes the builtins blob.
17 155730 : class BuiltinDeserializer final
18 : : public Deserializer<BuiltinDeserializerAllocator> {
19 : public:
20 : BuiltinDeserializer(Isolate* isolate, const BuiltinSnapshotData* data);
21 :
22 : // Builtins deserialization is tightly integrated with deserialization of the
23 : // startup blob. In particular, we need to ensure that no GC can occur
24 : // between startup- and builtins deserialization, as all builtins have been
25 : // pre-allocated and their pointers may not be invalidated.
26 : //
27 : // After this, the instruction cache must be flushed by the caller (we don't
28 : // do it ourselves since the startup serializer batch-flushes all code pages).
29 : void DeserializeEagerBuiltins();
30 :
31 : // Deserializes the single given builtin. This is used whenever a builtin is
32 : // lazily deserialized at runtime.
33 : Code* DeserializeBuiltin(int builtin_id);
34 :
35 : private:
36 : // Deserializes the single given builtin. Assumes that reservations have
37 : // already been allocated.
38 : Code* DeserializeBuiltinRaw(int builtin_id);
39 :
40 :
41 : // Extracts the size builtin Code objects (baked into the snapshot).
42 : uint32_t ExtractBuiltinSize(int builtin_id);
43 :
44 : // BuiltinDeserializer implements its own builtin iteration logic. Make sure
45 : // the RootVisitor API is not used accidentally.
46 0 : void VisitRootPointers(Root root, Object** start, Object** end) override {
47 0 : UNREACHABLE();
48 : }
49 :
50 : int CurrentBuiltinId() const { return current_builtin_id_; }
51 :
52 : private:
53 : // Stores the builtin currently being deserialized. We need this to determine
54 : // where to 'allocate' from during deserialization.
55 : static const int kNoBuiltinId = -1;
56 : int current_builtin_id_ = kNoBuiltinId;
57 :
58 : // The offsets of each builtin within the serialized data. Equivalent to
59 : // BuiltinSerializer::builtin_offsets_ but on the deserialization side.
60 : Vector<const uint32_t> builtin_offsets_;
61 :
62 : // For current_builtin_id_.
63 : friend class DeserializingBuiltinScope;
64 :
65 : // For isolate(), IsLazyDeserializationEnabled(), CurrentBuiltinId() and
66 : // ExtractBuiltinSize().
67 : friend class BuiltinDeserializerAllocator;
68 : };
69 :
70 : } // namespace internal
71 : } // namespace v8
72 :
73 : #endif // V8_SNAPSHOT_BUILTIN_DESERIALIZER_H_
|