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_DEFAULT_DESERIALIZER_ALLOCATOR_H_
6 : #define V8_SNAPSHOT_DEFAULT_DESERIALIZER_ALLOCATOR_H_
7 :
8 : #include "src/globals.h"
9 : #include "src/heap/heap.h"
10 : #include "src/snapshot/serializer-common.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : template <class AllocatorT>
16 : class Deserializer;
17 :
18 : class BuiltinDeserializer;
19 : class StartupDeserializer;
20 :
21 416457 : class DefaultDeserializerAllocator final {
22 : public:
23 : DefaultDeserializerAllocator(
24 : Deserializer<DefaultDeserializerAllocator>* deserializer);
25 :
26 : // ------- Allocation Methods -------
27 : // Methods related to memory allocation during deserialization.
28 :
29 : Address Allocate(AllocationSpace space, int size);
30 :
31 : void MoveToNextChunk(AllocationSpace space);
32 : void SetAlignment(AllocationAlignment alignment) {
33 : DCHECK_EQ(kWordAligned, next_alignment_);
34 : DCHECK_LE(kWordAligned, alignment);
35 : DCHECK_LE(alignment, kDoubleUnaligned);
36 0 : next_alignment_ = static_cast<AllocationAlignment>(alignment);
37 : }
38 :
39 : HeapObject* GetMap(uint32_t index);
40 : HeapObject* GetLargeObject(uint32_t index);
41 : HeapObject* GetObject(AllocationSpace space, uint32_t chunk_index,
42 : uint32_t chunk_offset);
43 :
44 : // ------- Reservation Methods -------
45 : // Methods related to memory reservations (prior to deserialization).
46 :
47 : void DecodeReservation(Vector<const SerializedData::Reservation> res);
48 : bool ReserveSpace();
49 :
50 : // Atomically reserves space for the two given deserializers. Guarantees
51 : // reservation for both without garbage collection in-between.
52 : static bool ReserveSpace(StartupDeserializer* startup_deserializer,
53 : BuiltinDeserializer* builtin_deserializer);
54 :
55 : bool ReservationsAreFullyUsed() const;
56 :
57 : // ------- Misc Utility Methods -------
58 :
59 : void RegisterDeserializedObjectsForBlackAllocation();
60 :
61 : // For SortMapDescriptors();
62 : const std::vector<Address>& GetAllocatedMaps() const {
63 : return allocated_maps_;
64 : }
65 :
66 : private:
67 : Isolate* isolate() const;
68 :
69 : // Raw allocation without considering alignment.
70 : Address AllocateRaw(AllocationSpace space, int size);
71 :
72 : private:
73 : static constexpr int kNumberOfPreallocatedSpaces =
74 : SerializerDeserializer::kNumberOfPreallocatedSpaces;
75 : static constexpr int kNumberOfSpaces =
76 : SerializerDeserializer::kNumberOfSpaces;
77 :
78 : // The address of the next object that will be allocated in each space.
79 : // Each space has a number of chunks reserved by the GC, with each chunk
80 : // fitting into a page. Deserialized objects are allocated into the
81 : // current chunk of the target space by bumping up high water mark.
82 : Heap::Reservation reservations_[kNumberOfSpaces];
83 : uint32_t current_chunk_[kNumberOfPreallocatedSpaces];
84 : Address high_water_[kNumberOfPreallocatedSpaces];
85 :
86 : // The alignment of the next allocation.
87 : AllocationAlignment next_alignment_ = kWordAligned;
88 :
89 : // All required maps are pre-allocated during reservation. {next_map_index_}
90 : // stores the index of the next map to return from allocation.
91 : uint32_t next_map_index_ = 0;
92 : std::vector<Address> allocated_maps_;
93 :
94 : // Allocated large objects are kept in this map and may be fetched later as
95 : // back-references.
96 : std::vector<HeapObject*> deserialized_large_objects_;
97 :
98 : // The current deserializer.
99 : Deserializer<DefaultDeserializerAllocator>* const deserializer_;
100 :
101 : DISALLOW_COPY_AND_ASSIGN(DefaultDeserializerAllocator)
102 : };
103 :
104 : } // namespace internal
105 : } // namespace v8
106 :
107 : #endif // V8_SNAPSHOT_DEFAULT_DESERIALIZER_ALLOCATOR_H_
|