Commit 064a3b18 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[arraybuffer] Remove unused allocation mode internally.

This is just derived from is_wasm_memory.

Change-Id: I2f77fb5e32e325c51de9af4228ca33313c21abc6
Reviewed-on: https://chromium-review.googlesource.com/1126107Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54230}
parent 1813e3d5
......@@ -67,7 +67,7 @@ void LocalArrayBufferTracker::Free(Callback should_free) {
if (should_free(buffer)) {
JSArrayBuffer::FreeBackingStore(
isolate, {it->second.backing_store, length, it->second.backing_store,
buffer->allocation_mode(), buffer->is_wasm_memory()});
buffer->is_wasm_memory()});
it = array_buffers_.erase(it);
freed_memory += length;
} else {
......
......@@ -61,7 +61,7 @@ void LocalArrayBufferTracker::Process(Callback callback) {
// based on the backing store.
backing_stores_to_free.emplace_back(
it->second.backing_store, it->second.length, it->second.backing_store,
old_buffer->allocation_mode(), old_buffer->is_wasm_memory());
old_buffer->is_wasm_memory());
old_page->DecrementExternalBackingStoreBytes(
ExternalBackingStoreType::kArrayBuffer, it->second.length);
......
......@@ -18604,9 +18604,8 @@ void JSArrayBuffer::FreeBackingStoreFromMainThread() {
if (allocation_base() == nullptr) {
return;
}
FreeBackingStore(GetIsolate(),
{allocation_base(), allocation_length(), backing_store(),
allocation_mode(), is_wasm_memory()});
FreeBackingStore(GetIsolate(), {allocation_base(), allocation_length(),
backing_store(), is_wasm_memory()});
// Zero out the backing store and allocation base to avoid dangling
// pointers.
set_backing_store(nullptr);
......@@ -18614,16 +18613,10 @@ void JSArrayBuffer::FreeBackingStoreFromMainThread() {
// static
void JSArrayBuffer::FreeBackingStore(Isolate* isolate, Allocation allocation) {
if (allocation.mode == ArrayBuffer::Allocator::AllocationMode::kReservation) {
bool needs_free = true;
if (allocation.is_wasm_memory) {
wasm::WasmMemoryTracker* memory_tracker =
isolate->wasm_engine()->memory_tracker();
if (memory_tracker->FreeMemoryIfIsWasmMemory(allocation.backing_store)) {
needs_free = false;
}
}
if (needs_free) {
if (allocation.is_wasm_memory) {
wasm::WasmMemoryTracker* memory_tracker =
isolate->wasm_engine()->memory_tracker();
if (!memory_tracker->FreeMemoryIfIsWasmMemory(allocation.backing_store)) {
CHECK(FreePages(allocation.allocation_base, allocation.length));
}
} else {
......
......@@ -104,12 +104,6 @@ void* JSArrayBuffer::allocation_base() const {
return backing_store();
}
ArrayBuffer::Allocator::AllocationMode JSArrayBuffer::allocation_mode() const {
using AllocationMode = ArrayBuffer::Allocator::AllocationMode;
return is_wasm_memory() ? AllocationMode::kReservation
: AllocationMode::kNormal;
}
bool JSArrayBuffer::is_wasm_memory() const {
bool const is_wasm_memory = IsWasmMemory::decode(bit_field());
DCHECK_EQ(is_wasm_memory,
......
......@@ -170,23 +170,19 @@ class JSArrayBuffer : public JSObject {
void Neuter();
inline ArrayBuffer::Allocator::AllocationMode allocation_mode() const;
struct Allocation {
using AllocationMode = ArrayBuffer::Allocator::AllocationMode;
Allocation(void* allocation_base, size_t length, void* backing_store,
AllocationMode mode, bool is_wasm_memory)
bool is_wasm_memory)
: allocation_base(allocation_base),
length(length),
backing_store(backing_store),
mode(mode),
is_wasm_memory(is_wasm_memory) {}
void* allocation_base;
size_t length;
void* backing_store;
AllocationMode mode;
bool is_wasm_memory;
};
......
......@@ -800,9 +800,9 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMemMemSize) {
int32_t result = WasmMemoryObject::Grow(isolate, mem_obj, 0);
CHECK_EQ(16, result);
constexpr bool is_wasm_memory = true;
const JSArrayBuffer::Allocation allocation{
contents.AllocationBase(), contents.AllocationLength(), contents.Data(),
contents.AllocationMode(), is_wasm_memory};
const JSArrayBuffer::Allocation allocation{contents.AllocationBase(),
contents.AllocationLength(),
contents.Data(), is_wasm_memory};
JSArrayBuffer::FreeBackingStore(isolate, allocation);
}
Cleanup();
......@@ -819,9 +819,9 @@ TEST(Run_WasmModule_Buffer_Externalized_Detach) {
auto const contents = v8::Utils::ToLocal(buffer)->Externalize();
wasm::DetachMemoryBuffer(isolate, buffer, true);
constexpr bool is_wasm_memory = true;
const JSArrayBuffer::Allocation allocation{
contents.AllocationBase(), contents.AllocationLength(), contents.Data(),
contents.AllocationMode(), is_wasm_memory};
const JSArrayBuffer::Allocation allocation{contents.AllocationBase(),
contents.AllocationLength(),
contents.Data(), is_wasm_memory};
JSArrayBuffer::FreeBackingStore(isolate, allocation);
}
Cleanup();
......@@ -838,9 +838,9 @@ TEST(Run_WasmModule_Buffer_Externalized_Regression_UseAfterFree) {
WasmMemoryObject::Grow(isolate, mem, 0);
constexpr bool is_wasm_memory = true;
JSArrayBuffer::FreeBackingStore(
isolate, JSArrayBuffer::Allocation(
contents.AllocationBase(), contents.AllocationLength(),
contents.Data(), contents.AllocationMode(), is_wasm_memory));
isolate, JSArrayBuffer::Allocation(contents.AllocationBase(),
contents.AllocationLength(),
contents.Data(), is_wasm_memory));
// Make sure we can write to the buffer without crashing
uint32_t* int_buffer =
reinterpret_cast<uint32_t*>(mem->array_buffer()->backing_store());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment