5#ifndef V8_HEAP_CPPGC_OBJECT_ALLOCATOR_H_
6#define V8_HEAP_CPPGC_OBJECT_ALLOCATOR_H_
25class PreFinalizerHandler;
38class GarbageCollector;
43 static constexpr size_t kSmallestSpaceSize = 32;
48 inline void* AllocateObject(
size_t size,
GCInfoIndex gcinfo);
49 inline void* AllocateObject(
size_t size,
AlignVal alignment,
51 inline void* AllocateObject(
size_t size,
GCInfoIndex gcinfo,
53 inline void* AllocateObject(
size_t size,
AlignVal alignment,
56 void ResetLinearAllocationBuffers();
57 void MarkAllPagesAsYoung();
59#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
60 void UpdateAllocationTimeout();
61 int get_allocation_timeout_for_testing()
const {
62 return *allocation_timeout_;
67 bool in_disallow_gc_scope()
const;
92 bool TryRefillLinearAllocationBufferFromFreeList(
NormalPageSpace&,
size_t);
95#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
96 void TriggerGCOnAllocationTimeoutIfNeeded();
105#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
108 std::optional<int> allocation_timeout_;
114#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
115 TriggerGCOnAllocationTimeoutIfNeeded();
117 const size_t allocation_size =
122 allocation_size, gcinfo);
128#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
129 TriggerGCOnAllocationTimeoutIfNeeded();
131 const size_t allocation_size =
136 allocation_size, alignment, gcinfo);
142#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
143 TriggerGCOnAllocationTimeoutIfNeeded();
145 const size_t allocation_size =
149 allocation_size, gcinfo);
156#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
157 TriggerGCOnAllocationTimeoutIfNeeded();
159 const size_t allocation_size =
163 allocation_size, alignment, gcinfo);
170 "should be half the next larger size");
202 constexpr size_t kAlignmentMask = kAlignment - 1;
206 space.linear_allocation_buffer();
207 const size_t current_lab_size = current_lab.
size();
210 bool lab_allocation_will_succeed =
211 current_lab_size >= size &&
212 (
reinterpret_cast<uintptr_t
>(current_lab.start() +
214 kAlignmentMask) == 0;
217 if (!lab_allocation_will_succeed &&
218 (current_lab_size >= (size + kPaddingSize))) {
219 void* filler_memory = current_lab.Allocate(kPaddingSize);
224 lab_allocation_will_succeed =
true;
231 DCHECK_EQ(0u,
reinterpret_cast<uintptr_t
>(
object) & kAlignmentMask);
240 space.linear_allocation_buffer();
246 void* raw = current_lab.
Allocate(size);
247#if !defined(V8_USE_MEMORY_SANITIZER) && !defined(V8_USE_ADDRESS_SANITIZER) && \
262 return header->ObjectStart();
AllocationHandle()=default
static BasePage * FromPayload(void *)
static Filler & CreateAt(void *memory, size_t size)
Address Allocate(size_t alloc_size)
static NormalPageSpace & From(BaseSpace &space)
static NormalPage * From(BasePage *page)
PlatformAwareObjectStartBitmap & object_start_bitmap()
void V8_PRESERVE_MOST OutOfLineAllocateGCSafePoint(NormalPageSpace &, size_t, AlignVal, GCInfoIndex, void **)
static constexpr size_t kSmallestSpaceSize
void * AllocateObjectOnSpace(NormalPageSpace &, size_t, GCInfoIndex)
std::align_val_t AlignVal
bool in_disallow_gc_scope() const
PageBackend & page_backend_
static RawHeap::RegularSpaceType GetInitialSpaceIndexForSize(size_t size)
GarbageCollector & garbage_collector_
PreFinalizerHandler & prefinalizer_handler_
StatsCollector & stats_collector_
void * OutOfLineAllocate(NormalPageSpace &, size_t, AlignVal, GCInfoIndex)
FatalOutOfMemoryHandler & oom_handler_
void * AllocateObject(size_t size, GCInfoIndex gcinfo)
BaseSpace * CustomSpace(CustomSpaceIndex space_index)
BaseSpace * Space(RegularSpaceType type)
constexpr size_t kAllocationGranularity
static constexpr size_t kMaxSupportedAlignment
std::align_val_t AlignVal
V8_INLINE void SetMemoryAccessible(void *address, size_t size)
const uint8_t * ConstAddress
constexpr size_t kAllocationGranularity
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
constexpr T RoundUp(T x, intptr_t m)
#define V8_EXPORT_PRIVATE
#define V8_UNLIKELY(condition)