V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
deserializer-allocator.h
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/snapshot/serializer-common.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class Deserializer;
16 class StartupDeserializer;
17 
18 class DeserializerAllocator final {
19  public:
20  explicit DeserializerAllocator(Deserializer* deserializer);
21 
22  // ------- Allocation Methods -------
23  // Methods related to memory allocation during deserialization.
24 
25  Address Allocate(AllocationSpace space, int size);
26 
27  void MoveToNextChunk(AllocationSpace space);
28  void SetAlignment(AllocationAlignment alignment) {
29  DCHECK_EQ(kWordAligned, next_alignment_);
30  DCHECK_LE(kWordAligned, alignment);
31  DCHECK_LE(alignment, kDoubleUnaligned);
32  next_alignment_ = static_cast<AllocationAlignment>(alignment);
33  }
34 
35  void set_next_reference_is_weak(bool next_reference_is_weak) {
36  next_reference_is_weak_ = next_reference_is_weak;
37  }
38 
39  bool GetAndClearNextReferenceIsWeak() {
40  bool saved = next_reference_is_weak_;
41  next_reference_is_weak_ = false;
42  return saved;
43  }
44 
45 #ifdef DEBUG
46  bool next_reference_is_weak() const { return next_reference_is_weak_; }
47 #endif
48 
49  HeapObject* GetMap(uint32_t index);
50  HeapObject* GetLargeObject(uint32_t index);
51  HeapObject* GetObject(AllocationSpace space, uint32_t chunk_index,
52  uint32_t chunk_offset);
53 
54  // ------- Reservation Methods -------
55  // Methods related to memory reservations (prior to deserialization).
56 
57  void DecodeReservation(const std::vector<SerializedData::Reservation>& res);
58  bool ReserveSpace();
59 
60  bool ReservationsAreFullyUsed() const;
61 
62  // ------- Misc Utility Methods -------
63 
64  void RegisterDeserializedObjectsForBlackAllocation();
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  bool next_reference_is_weak_ = false;
89 
90  // All required maps are pre-allocated during reservation. {next_map_index_}
91  // stores the index of the next map to return from allocation.
92  uint32_t next_map_index_ = 0;
93  std::vector<Address> allocated_maps_;
94 
95  // Allocated large objects are kept in this map and may be fetched later as
96  // back-references.
97  std::vector<HeapObject*> deserialized_large_objects_;
98 
99  // The current deserializer.
100  Deserializer* const deserializer_;
101 
102  DISALLOW_COPY_AND_ASSIGN(DeserializerAllocator)
103 };
104 
105 } // namespace internal
106 } // namespace v8
107 
108 #endif // V8_SNAPSHOT_DESERIALIZER_ALLOCATOR_H_
Definition: libplatform.h:13