• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_HEAP_MEMORY_CHUNK_LAYOUT_H_
6 #define V8_HEAP_MEMORY_CHUNK_LAYOUT_H_
7 
8 #include "src/heap/heap.h"
9 #include "src/heap/list.h"
10 #include "src/heap/slot-set.h"
11 
12 #ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING
13 #include "src/heap/object-start-bitmap.h"
14 #endif
15 
16 namespace v8 {
17 namespace internal {
18 
19 class Bitmap;
20 class CodeObjectRegistry;
21 class FreeListCategory;
22 class Heap;
23 class TypedSlotsSet;
24 class SlotSet;
25 
26 enum RememberedSetType {
27   OLD_TO_NEW,
28   OLD_TO_OLD,
29   NUMBER_OF_REMEMBERED_SET_TYPES
30 };
31 
32 class V8_EXPORT_PRIVATE MemoryChunkLayout {
33  public:
34   static const int kNumSets = NUMBER_OF_REMEMBERED_SET_TYPES;
35   static const int kNumTypes = ExternalBackingStoreType::kNumTypes;
36 #define FIELD(Type, Name) \
37   k##Name##Offset, k##Name##End = k##Name##Offset + sizeof(Type) - 1
38   enum Header {
39     // BasicMemoryChunk fields:
40     FIELD(size_t, Size),
41     FIELD(uintptr_t, Flags),
42     FIELD(Heap*, Heap),
43     FIELD(Address, AreaStart),
44     FIELD(Address, AreaEnd),
45     FIELD(size_t, AllocatedBytes),
46     FIELD(size_t, WastedMemory),
47     FIELD(std::atomic<intptr_t>, HighWaterMark),
48     FIELD(Address, Owner),
49     FIELD(VirtualMemory, Reservation),
50     // MemoryChunk fields:
51     FIELD(SlotSet* [kNumSets], SlotSet),
52     FIELD(std::atomic<size_t>, ProgressBar),
53     FIELD(std::atomic<intptr_t>, LiveByteCount),
54     FIELD(SlotSet*, SweepingSlotSet),
55     FIELD(TypedSlotsSet* [kNumSets], TypedSlotSet),
56     FIELD(void* [kNumSets], InvalidatedSlots),
57     FIELD(base::Mutex*, Mutex),
58     FIELD(std::atomic<intptr_t>, ConcurrentSweeping),
59     FIELD(base::Mutex*, PageProtectionChangeMutex),
60     FIELD(uintptr_t, WriteUnprotectCounter),
61     FIELD(std::atomic<size_t>[kNumTypes], ExternalBackingStoreBytes),
62     FIELD(heap::ListNode<MemoryChunk>, ListNode),
63     FIELD(FreeListCategory**, Categories),
64     FIELD(std::atomic<intptr_t>, YoungGenerationLiveByteCount),
65     FIELD(Bitmap*, YoungGenerationBitmap),
66     FIELD(CodeObjectRegistry*, CodeObjectRegistry),
67     FIELD(PossiblyEmptyBuckets, PossiblyEmptyBuckets),
68 #ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING
69     FIELD(ObjectStartBitmap, ObjectStartBitmap),
70 #endif
71     kMarkingBitmapOffset,
72     kMemoryChunkHeaderSize = kMarkingBitmapOffset,
73     kMemoryChunkHeaderStart = kSlotSetOffset,
74     kBasicMemoryChunkHeaderSize = kMemoryChunkHeaderStart,
75     kBasicMemoryChunkHeaderStart = 0,
76   };
77   static size_t CodePageGuardStartOffset();
78   static size_t CodePageGuardSize();
79   static intptr_t ObjectStartOffsetInCodePage();
80   static intptr_t ObjectEndOffsetInCodePage();
81   static size_t AllocatableMemoryInCodePage();
82   static intptr_t ObjectStartOffsetInDataPage();
83   static size_t AllocatableMemoryInDataPage();
84   static size_t ObjectStartOffsetInMemoryChunk(AllocationSpace space);
85   static size_t AllocatableMemoryInMemoryChunk(AllocationSpace space);
86 
87   static int MaxRegularCodeObjectSize();
88 };
89 
90 }  // namespace internal
91 }  // namespace v8
92 
93 #endif  // V8_HEAP_MEMORY_CHUNK_LAYOUT_H_
94