Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: src/runtime/runtime-wasm.cc

Issue 2319983002: [wasm] GrowMemory should use array_buffer_allocator instead of realloc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review changes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/grow-memory.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-wasm.cc
diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc
index 6fc72767ea57bba5cbb4fe9c9be65433ebb4bca0..5727e2d021fe219cc1bd1351ed4b1f828d500528 100644
--- a/src/runtime/runtime-wasm.cc
+++ b/src/runtime/runtime-wasm.cc
@@ -86,14 +86,20 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) {
return *isolate->factory()->NewNumberFromInt(-1);
}
- new_mem_start = static_cast<Address>(realloc(old_mem_start, new_size));
+ new_mem_start =
+ static_cast<Address>(isolate->array_buffer_allocator()->Allocate(
+ static_cast<uint32_t>(new_size)));
if (new_mem_start == NULL) {
return *isolate->factory()->NewNumberFromInt(-1);
}
- old_buffer->set_is_external(true);
- isolate->heap()->UnregisterArrayBuffer(*old_buffer);
- // Zero initializing uninitialized memory from realloc
- memset(new_mem_start + old_size, 0, new_size - old_size);
+#if DEBUG
+ // Double check the API allocator actually zero-initialized the memory.
+ for (size_t i = old_size; i < new_size; i++) {
+ DCHECK_EQ(0, new_mem_start[i]);
+ }
+#endif
+ // Copy contents of the old buffer to the new buffer
+ memcpy(new_mem_start, old_mem_start, old_size);
}
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
@@ -102,7 +108,6 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
// Set new buffer to be wasm memory
module_object->SetInternalField(kWasmMemArrayBuffer, *buffer);
-
CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start,
new_mem_start, old_size, new_size));
« no previous file with comments | « no previous file | test/mjsunit/wasm/grow-memory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698