V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
serializer-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_SERIALIZER_ALLOCATOR_H_
6 #define V8_SNAPSHOT_SERIALIZER_ALLOCATOR_H_
7 
8 #include "src/snapshot/serializer-common.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class Serializer;
14 
15 class SerializerAllocator final {
16  public:
17  explicit SerializerAllocator(Serializer* serializer);
18 
19  SerializerReference Allocate(AllocationSpace space, uint32_t size);
20  SerializerReference AllocateMap();
21  SerializerReference AllocateLargeObject(uint32_t size);
22  SerializerReference AllocateOffHeapBackingStore();
23 
24  void UseCustomChunkSize(uint32_t chunk_size);
25 
26 #ifdef DEBUG
27  bool BackReferenceIsAlreadyAllocated(
28  SerializerReference back_reference) const;
29 #endif
30 
31  std::vector<SerializedData::Reservation> EncodeReservations() const;
32 
33  void OutputStatistics();
34 
35  private:
36  // We try to not exceed this size for every chunk. We will not succeed for
37  // larger objects though.
38  uint32_t TargetChunkSize(int space);
39 
40  static constexpr int kNumberOfPreallocatedSpaces =
41  SerializerDeserializer::kNumberOfPreallocatedSpaces;
42  static constexpr int kNumberOfSpaces =
43  SerializerDeserializer::kNumberOfSpaces;
44 
45  // Objects from the same space are put into chunks for bulk-allocation
46  // when deserializing. We have to make sure that each chunk fits into a
47  // page. So we track the chunk size in pending_chunk_ of a space, but
48  // when it exceeds a page, we complete the current chunk and start a new one.
49  uint32_t pending_chunk_[kNumberOfPreallocatedSpaces];
50  std::vector<uint32_t> completed_chunks_[kNumberOfPreallocatedSpaces];
51 
52  // Number of maps that we need to allocate.
53  uint32_t num_maps_ = 0;
54 
55  // We map serialized large objects to indexes for back-referencing.
56  uint32_t large_objects_total_size_ = 0;
57  uint32_t seen_large_objects_index_ = 0;
58 
59  // Used to keep track of the off-heap backing stores used by TypedArrays/
60  // ArrayBuffers. Note that the index begins at 1 and not 0, because when a
61  // TypedArray has an on-heap backing store, the backing_store pointer in the
62  // corresponding ArrayBuffer will be null, which makes it indistinguishable
63  // from index 0.
64  uint32_t seen_backing_stores_index_ = 1;
65 
66  uint32_t custom_chunk_size_ = 0;
67 
68  // The current serializer.
69  Serializer* const serializer_;
70 
71  DISALLOW_COPY_AND_ASSIGN(SerializerAllocator)
72 };
73 
74 } // namespace internal
75 } // namespace v8
76 
77 #endif // V8_SNAPSHOT_SERIALIZER_ALLOCATOR_H_
Definition: libplatform.h:13