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