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

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: 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') | test/mjsunit/wasm/grow-memory.js » ('J')
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..6410646850ab122a971a0764e5f703cbe30944eb 100644
--- a/src/runtime/runtime-wasm.cc
+++ b/src/runtime/runtime-wasm.cc
@@ -86,14 +86,23 @@ 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);
}
+#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 before detaching old
+ // buffer
+ memcpy(new_mem_start, old_mem_start, old_size);
old_buffer->set_is_external(true);
isolate->heap()->UnregisterArrayBuffer(*old_buffer);
gdeepti 2016/09/08 06:04:47 Is this the right way to deal with the old buffer?
Michael Lippautz 2016/09/08 09:43:31 UnregisterArrayBuffer will make the GC stop tracki
ahaas 2016/09/08 12:23:33 Hi Deepti, I talked with Ben about it, and we thin
gdeepti 2016/09/08 22:44:50 Thanks for explaining that, I've removed the code
- // Zero initializing uninitialized memory from realloc
- memset(new_mem_start + old_size, 0, new_size - old_size);
}
Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
@@ -102,7 +111,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') | test/mjsunit/wasm/grow-memory.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698