Commit 7cae8253 authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Simplify checking of externalized buffer on Grow

Change-Id: I62eaed997f4bf590f6cc09f3cb874340e1cd7ac6
Bug: v8:8564
Reviewed-on: https://chromium-review.googlesource.com/c/1447493Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59257}
parent 889730af
...@@ -916,30 +916,7 @@ MaybeHandle<JSArrayBuffer> MemoryGrowBuffer(Isolate* isolate, ...@@ -916,30 +916,7 @@ MaybeHandle<JSArrayBuffer> MemoryGrowBuffer(Isolate* isolate,
// Blink's array buffers. The connection between the two is lost, which can // Blink's array buffers. The connection between the two is lost, which can
// lead to Blink not knowing about the other reference to the buffer and // lead to Blink not knowing about the other reference to the buffer and
// freeing it too early. // freeing it too early.
if (!old_buffer->is_external() && if (old_buffer->is_external() || new_size > old_buffer->allocation_length()) {
((new_size < old_buffer->allocation_length()) || old_size == new_size)) {
if (old_size != new_size) {
DCHECK_NOT_NULL(old_buffer->backing_store());
// If adjusting permissions fails, propagate error back to return
// failure to grow.
if (!i::SetPermissions(GetPlatformPageAllocator(), old_mem_start,
new_size, PageAllocator::kReadWrite)) {
return {};
}
DCHECK_GE(new_size, old_size);
reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(new_size - old_size);
}
// NOTE: We must allocate a new array buffer here because the spec
// assumes that ArrayBuffers do not change size.
void* backing_store = old_buffer->backing_store();
bool is_external = old_buffer->is_external();
// Disconnect buffer early so GC won't free it.
i::wasm::DetachMemoryBuffer(isolate, old_buffer, false);
Handle<JSArrayBuffer> new_buffer =
wasm::SetupArrayBuffer(isolate, backing_store, new_size, is_external);
return new_buffer;
} else {
// We couldn't reuse the old backing store, so create a new one and copy the // We couldn't reuse the old backing store, so create a new one and copy the
// old contents in. // old contents in.
Handle<JSArrayBuffer> new_buffer; Handle<JSArrayBuffer> new_buffer;
...@@ -961,6 +938,28 @@ MaybeHandle<JSArrayBuffer> MemoryGrowBuffer(Isolate* isolate, ...@@ -961,6 +938,28 @@ MaybeHandle<JSArrayBuffer> MemoryGrowBuffer(Isolate* isolate,
constexpr bool free_memory = true; constexpr bool free_memory = true;
i::wasm::DetachMemoryBuffer(isolate, old_buffer, free_memory); i::wasm::DetachMemoryBuffer(isolate, old_buffer, free_memory);
return new_buffer; return new_buffer;
} else {
if (old_size != new_size) {
DCHECK_NOT_NULL(old_buffer->backing_store());
// If adjusting permissions fails, propagate error back to return
// failure to grow.
if (!i::SetPermissions(GetPlatformPageAllocator(), old_mem_start,
new_size, PageAllocator::kReadWrite)) {
return {};
}
DCHECK_GE(new_size, old_size);
reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(new_size - old_size);
}
// NOTE: We must allocate a new array buffer here because the spec
// assumes that ArrayBuffers do not change size.
void* backing_store = old_buffer->backing_store();
bool is_external = old_buffer->is_external();
// Disconnect buffer early so GC won't free it.
i::wasm::DetachMemoryBuffer(isolate, old_buffer, false);
Handle<JSArrayBuffer> new_buffer =
wasm::SetupArrayBuffer(isolate, backing_store, new_size, is_external);
return new_buffer;
} }
} }
......
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