5#ifndef V8_HEAP_MEMORY_ALLOCATOR_H_
6#define V8_HEAP_MEMORY_ALLOCATOR_H_
12#include <unordered_set>
34class TestMemoryAllocatorScope;
39class ReadOnlyPageMetadata;
102 std::unique_ptr<::v8::PageAllocator::SharedMemoryMapping>
RemapSharedPage(
117 const size_t size =
Size();
132 switch (executable) {
147 size_t bytes_to_free,
Address new_area_end);
154 return executable_memory_.find(chunk) != executable_memory_.end();
310 switch (executable) {
313 std::memory_order_relaxed);
314 while ((low < ptr) &&
316 ptr, low, std::memory_order_acq_rel)) {
319 std::memory_order_relaxed);
320 while ((high > ptr) &&
322 ptr, high, std::memory_order_acq_rel)) {
327 while ((low < ptr) &&
329 ptr, low, std::memory_order_acq_rel)) {
333 while ((high > ptr) &&
335 ptr, high, std::memory_order_acq_rel)) {
354 DCHECK_EQ(executable_memory_.find(chunk), executable_memory_.end());
355 executable_memory_.insert(chunk);
360 DCHECK_NE(executable_memory_.find(chunk), executable_memory_.end());
361 executable_memory_.erase(chunk);
414 std::unordered_set<MutablePageMetadata*, base::hash<MutablePageMetadata*>>
421 std::unordered_set<const MemoryChunk*, base::hash<const MemoryChunk*>>
std::unique_ptr<::v8::PageAllocator::SharedMemoryMapping > RemapSharedPage(::v8::PageAllocator::SharedMemory *shared_memory, Address new_address)
void UnregisterMemoryChunk(MemoryChunkMetadata *chunk, Executability executable=NOT_EXECUTABLE)
void RegisterReadOnlyMemory(ReadOnlyPageMetadata *page)
void UnregisterReadOnlyPage(ReadOnlyPageMetadata *page)
static V8_EXPORT_PRIVATE size_t commit_page_size_bits_
void FreeMemoryRegion(v8::PageAllocator *page_allocator, Address addr, size_t size)
V8_EXPORT_PRIVATE const MemoryChunk * LookupChunkContainingAddress(Address addr) const
v8::PageAllocator * code_page_allocator_
V8_INLINE bool IsOutsideAllocatedSpace(Address address) const
base::Mutex chunks_mutex_
static V8_INLINE intptr_t GetCommitPageSizeBits()
void ReleaseQueuedPages()
V8_EXPORT_PRIVATE void TearDown()
V8_EXPORT_PRIVATE void Free(MemoryAllocator::FreeMode mode, MutablePageMetadata *chunk)
std::set< const MemoryChunk * > large_pages_
bool UncommitMemory(VirtualMemory *reservation)
v8::PageAllocator * trusted_page_allocator_
friend class heap::TestCodePageAllocatorScope
v8::PageAllocator * page_allocator(AllocationSpace space)
v8::PageAllocator * data_page_allocator_
std::atomic< Address > highest_executable_ever_allocated_
static V8_INLINE intptr_t GetCommitPageSize()
std::atomic< Address > highest_not_executable_ever_allocated_
V8_WARN_UNUSED_RESULT std::optional< MemoryChunkAllocationResult > AllocateUninitializedChunk(BaseSpace *space, size_t area_size, Executability executable, PageSize page_size)
void UnregisterSharedMemoryChunk(MemoryChunkMetadata *chunk)
V8_EXPORT_PRIVATE size_t GetSharedPooledChunksCount()
PageMetadata * InitializePagesInChunk(int chunk_id, int pages_in_chunk, PagedSpace *space)
v8::PageAllocator * trusted_page_allocator()
std::atomic< size_t > size_executable_
ReadOnlyPageMetadata * AllocateReadOnlyPage(ReadOnlySpace *space, Address hint=kNullAddress)
V8_EXPORT_PRIVATE LargePageMetadata * AllocateLargePage(LargeObjectSpace *space, size_t object_size, Executability executable)
static void DeleteMemoryChunk(MutablePageMetadata *metadata)
friend class heap::TestMemoryAllocatorScope
void PerformFreeMemory(MutablePageMetadata *chunk)
V8_WARN_UNUSED_RESULT std::optional< MemoryChunkAllocationResult > AllocateUninitializedChunkAt(BaseSpace *space, size_t area_size, Executability executable, Address hint, PageSize page_size)
v8::PageAllocator * code_page_allocator()
std::optional< VirtualMemory > reserved_chunk_at_virtual_memory_limit_
V8_EXPORT_PRIVATE size_t GetPooledChunksCount()
std::atomic< Address > lowest_not_executable_ever_allocated_
V8_EXPORT_PRIVATE PageMetadata * AllocatePage(MemoryAllocator::AllocationMode alloc_mode, Space *space, Executability executable)
void RecordMemoryChunkCreated(const MemoryChunk *chunk)
std::unordered_set< const MemoryChunk *, base::hash< const MemoryChunk * > > normal_pages_
static void InitializeOncePerProcess()
size_t SizeExecutable() const
V8_EXPORT_PRIVATE MemoryAllocator(Isolate *isolate, v8::PageAllocator *code_page_allocator, v8::PageAllocator *trusted_page_allocator, size_t max_capacity)
std::optional< MemoryChunkAllocationResult > AllocateUninitializedPageFromPool(Space *space)
std::atomic< size_t > size_
std::atomic< Address > lowest_executable_ever_allocated_
V8_WARN_UNUSED_RESULT bool SetPermissionsOnExecutableMemoryChunk(VirtualMemory *vm, Address start, size_t reserved_size)
std::vector< MutablePageMetadata * > queued_pages_to_be_freed_
void PartialFreeMemory(MemoryChunkMetadata *chunk, Address start_free, size_t bytes_to_free, Address new_area_end)
static V8_EXPORT_PRIVATE size_t commit_page_size_
Address AllocateAlignedMemory(size_t chunk_size, size_t area_size, size_t alignment, AllocationSpace space, Executability executable, void *hint, VirtualMemory *controller)
bool CommitMemory(VirtualMemory *reservation, Executability executable)
void PreFreeMemory(MutablePageMetadata *chunk)
void UpdateAllocatedSpaceLimits(Address low, Address high, Executability executable)
DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryAllocator)
static size_t ComputeChunkSize(size_t area_size, AllocationSpace space)
v8::PageAllocator * data_page_allocator()
void UnregisterMutableMemoryChunk(MutablePageMetadata *chunk)
void RecordMemoryChunkDestroyed(const MemoryChunk *chunk)
V8_INLINE bool IsOutsideAllocatedSpace(Address address, Executability executable) const
V8_EXPORT_PRIVATE size_t GetTotalPooledChunksCount()
void FreeReadOnlyPage(ReadOnlyPageMetadata *chunk)
V8_EXPORT_PRIVATE const MemoryChunk * LookupChunkContainingAddressInSafepoint(Address addr) const
V8_EXPORT_PRIVATE void ReleasePooledChunksImmediately()
Address HandleAllocationFailure(Executability executable)
V8_INLINE bool IsFlagSet(Flag flag) const
@ SHARED_TRUSTED_LO_SPACE
static constexpr Address kNullAddress
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define V8_EXPORT_PRIVATE
VirtualMemory reservation
#define V8_WARN_UNUSED_RESULT