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