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_ALLOCATOR_H_
6 : #define V8_SNAPSHOT_BUILTIN_DESERIALIZER_ALLOCATOR_H_
7 :
8 : #include <unordered_set>
9 :
10 : #include "src/globals.h"
11 : #include "src/heap/heap.h"
12 : #include "src/snapshot/serializer-common.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : template <class AllocatorT>
18 : class Deserializer;
19 :
20 : class BuiltinDeserializer;
21 :
22 : class BuiltinDeserializerAllocator final {
23 : public:
24 : BuiltinDeserializerAllocator(
25 : Deserializer<BuiltinDeserializerAllocator>* deserializer);
26 :
27 : // ------- Allocation Methods -------
28 : // Methods related to memory allocation during deserialization.
29 :
30 : // Allocation works differently here than in other deserializers. Instead of
31 : // a statically-known memory area determined at serialization-time, our
32 : // memory requirements here are determined at runtime. Another major
33 : // difference is that we create builtin Code objects up-front (before
34 : // deserialization) in order to avoid having to patch builtin references
35 : // later on. See also the kBuiltin case in deserializer.cc.
36 : //
37 : // Allocate simply returns the pre-allocated object prepared by
38 : // InitializeBuiltinsTable.
39 : Address Allocate(AllocationSpace space, int size);
40 :
41 0 : void MoveToNextChunk(AllocationSpace space) { UNREACHABLE(); }
42 0 : void SetAlignment(AllocationAlignment alignment) { UNREACHABLE(); }
43 :
44 0 : HeapObject* GetMap(uint32_t index) { UNREACHABLE(); }
45 0 : HeapObject* GetLargeObject(uint32_t index) { UNREACHABLE(); }
46 0 : HeapObject* GetObject(AllocationSpace space, uint32_t chunk_index,
47 : uint32_t chunk_offset) {
48 0 : UNREACHABLE();
49 : }
50 :
51 : // ------- Reservation Methods -------
52 : // Methods related to memory reservations (prior to deserialization).
53 :
54 : // Builtin deserialization does not bake reservations into the snapshot, hence
55 : // this is a nop.
56 : void DecodeReservation(Vector<const SerializedData::Reservation> res) {}
57 :
58 : // These methods are used to pre-allocate builtin objects prior to
59 : // deserialization.
60 : // TODO(jgruber): Refactor reservation/allocation logic in deserializers to
61 : // make this less messy.
62 : Heap::Reservation CreateReservationsForEagerBuiltins();
63 : void InitializeBuiltinsTable(const Heap::Reservation& reservation);
64 :
65 : // Creates reservations and initializes the builtins table in preparation for
66 : // lazily deserializing a single builtin.
67 : void ReserveAndInitializeBuiltinsTableForBuiltin(int builtin_id);
68 :
69 : #ifdef DEBUG
70 : bool ReservationsAreFullyUsed() const;
71 : #endif
72 :
73 : // For SortMapDescriptors();
74 0 : const std::vector<Address>& GetAllocatedMaps() const {
75 0 : static std::vector<Address> empty_vector(0);
76 0 : return empty_vector;
77 : }
78 :
79 : private:
80 : Isolate* isolate() const;
81 : BuiltinDeserializer* deserializer() const;
82 :
83 : // Used after memory allocation prior to isolate initialization, to register
84 : // the newly created object in code space and add it to the builtins table.
85 : void InitializeBuiltinFromReservation(const Heap::Chunk& chunk,
86 : int builtin_id);
87 :
88 : #ifdef DEBUG
89 : void RegisterBuiltinReservation(int builtin_id);
90 : void RegisterBuiltinAllocation(int builtin_id);
91 : std::unordered_set<int> unused_reservations_;
92 : #endif
93 :
94 : private:
95 : // The current deserializer. Note that this always points to a
96 : // BuiltinDeserializer instance, but we can't perform the cast during
97 : // construction since that makes vtable-based checks fail.
98 : Deserializer<BuiltinDeserializerAllocator>* const deserializer_;
99 :
100 : DISALLOW_COPY_AND_ASSIGN(BuiltinDeserializerAllocator)
101 : };
102 :
103 : } // namespace internal
104 : } // namespace v8
105 :
106 : #endif // V8_SNAPSHOT_BUILTIN_DESERIALIZER_ALLOCATOR_H_
|