5#ifndef V8_OBJECTS_BACKING_STORE_H_
6#define V8_OBJECTS_BACKING_STORE_H_
20class WasmMemoryObject;
37struct SharedWasmMemoryData;
51 static std::unique_ptr<BackingStore> Allocate(
Isolate* isolate,
56#if V8_ENABLE_WEBASSEMBLY
58 static std::unique_ptr<BackingStore> AllocateWasmMemory(
59 Isolate* isolate,
size_t initial_pages,
size_t maximum_pages,
68 static std::unique_ptr<BackingStore> TryAllocateAndPartiallyCommitMemory(
69 Isolate* isolate,
size_t byte_length,
size_t max_byte_length,
70 size_t page_size,
size_t initial_pages,
size_t maximum_pages,
72 bool has_guard_regions =
false);
75 static std::unique_ptr<BackingStore> WrapAllocation(
76 void* allocation_base,
size_t allocation_length,
81 static std::unique_ptr<BackingStore> EmptyBackingStore(
SharedFlag shared);
92 std::memory_order memory_order = std::memory_order_relaxed)
const {
93 return byte_length_.load(memory_order);
97 bool is_shared()
const {
return has_flag(kIsShared); }
105 return byte_capacity_ == 0;
110 ResizeOrGrowResult ResizeInPlace(
Isolate* isolate,
size_t new_byte_length);
111 ResizeOrGrowResult GrowInPlace(
Isolate* isolate,
size_t new_byte_length);
113#if V8_ENABLE_WEBASSEMBLY
133 void MakeWasmMemoryResizableByJS(
bool resizable);
136 std::optional<size_t> GrowWasmMemoryInPlace(
Isolate* isolate,
142 std::unique_ptr<BackingStore> CopyWasmMemory(
Isolate* isolate,
149 void AttachSharedWasmMemoryObject(
155 void BroadcastSharedWasmMemoryGrow(
Isolate* isolate)
const;
159 static void RemoveSharedWasmMemoryObjects(
Isolate* isolate);
162 static void UpdateSharedWasmMemoryObjects(
Isolate* isolate);
168 if (has_flag(kIsShared)) {
176 if (has_flag(kEmptyDeleter)) {
181 return byte_length();
184 uint32_t
id()
const {
return id_; }
202 size_t byte_length,
size_t max_byte_length,
size_t byte_capacity,
204 bool is_wasm_memory64,
bool has_guard_regions,
205 bool custom_deleter,
bool empty_deleter);
208 void SetAllocatorFromIsolate(
Isolate* isolate);
215 return flags_.load(std::memory_order_relaxed).contains(flag);
219 flags_.load(std::memory_order_relaxed);
220 while (!
flags_.compare_exchange_weak(old_flags, old_flags | flag,
221 std::memory_order_relaxed)) {
227 flags_.load(std::memory_order_relaxed);
228 while (!
flags_.compare_exchange_weak(old_flags, old_flags - flag,
229 std::memory_order_relaxed)) {
235 return has_flag(kHoldsSharedPtrToAllocater);
240 void* buffer_start_ =
nullptr;
265 std::shared_ptr<v8::ArrayBuffer::Allocator>
278 } type_specific_data_;
280 std::atomic<base::EnumSet<Flag, uint16_t>>
flags_;
291 static void Register(std::shared_ptr<BackingStore> backing_store);
void(*)(void *data, size_t length, void *deleter_data) DeleterCallback
void * buffer_start() const
BackingStore(const BackingStore &)=delete
@ kHoldsSharedPtrToAllocater
void clear_flag(Flag flag)
std::atomic< base::EnumSet< Flag, uint16_t > > flags_
bool custom_deleter() const
bool globally_registered() const
bool holds_shared_ptr_to_allocator() const
size_t max_byte_length() const
bool is_wasm_memory() const
std::atomic< size_t > byte_length_
bool has_flag(Flag flag) const
BackingStore & operator=(const BackingStore &)=delete
bool has_guard_regions() const
size_t PerIsolateAccountingLength()
bool is_resizable_by_js() const
size_t byte_length(std::memory_order memory_order=std::memory_order_relaxed) const
size_t byte_capacity() const
bool is_wasm_memory64() const
static void Purge(Isolate *isolate)
static void Register(std::shared_ptr< BackingStore > backing_store)
static void AddSharedWasmMemoryObject(Isolate *isolate, BackingStore *backing_store, DirectHandle< WasmMemoryObject > memory_object)
static void Unregister(BackingStore *backing_store)
static void BroadcastSharedWasmMemoryGrow(Isolate *isolate, const BackingStore *backing_store)
static void UpdateSharedWasmMemoryObjects(Isolate *isolate)
cppgc::PageAllocator * page_allocator_
V8_INLINE void * EmptyBackingStoreBuffer()
#define DCHECK_GE(v1, v2)
#define V8_EXPORT_PRIVATE
v8::BackingStore::DeleterCallback callback
std::shared_ptr< v8::ArrayBuffer::Allocator > v8_api_array_buffer_allocator_shared
SharedWasmMemoryData * shared_wasm_memory_data
v8::ArrayBuffer::Allocator * v8_api_array_buffer_allocator