v8/test/mjsunit/wasm/grow-huge-memory.js
Jakob Kummerow 20b892b5a0 [wasm] Fix memory growth to >2GB
There were a few places that still checked against the limit for
initial memory size rather than the limit for memory size after
growth (which was recently separated from the former).

Bug: v8:7881
Change-Id: Id17d86e2f7a5dfa4f1dd35153b0cefc01f72ed33
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2078574
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66496}
2020-02-28 11:48:37 +00:00

36 lines
1.2 KiB
JavaScript

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Save some memory on Linux; other platforms ignore this flag.
// Flags: --multi-mapped-mock-allocator
// Test that we can grow memories to sizes beyond 2GB.
load("test/mjsunit/wasm/wasm-module-builder.js");
function GetMemoryPages(memory) {
return memory.buffer.byteLength >>> 16;
}
(function TestGrowFromJS() {
let mem = new WebAssembly.Memory({initial: 200});
mem.grow(40000);
assertEquals(40200, GetMemoryPages(mem));
})();
(function TestGrowFromWasm() {
let builder = new WasmModuleBuilder();
builder.addMemory(200, 50000, true);
builder.addFunction("grow", kSig_i_v)
.addBody([
...wasmI32Const(40000), // Number of pages to grow by.
kExprMemoryGrow, kMemoryZero, // Grow memory.
kExprDrop, // Drop result of grow (old pages).
kExprMemorySize, kMemoryZero // Get the memory size.
]).exportFunc();
let instance = builder.instantiate();
assertEquals(40200, instance.exports.grow());
assertEquals(40200, GetMemoryPages(instance.exports.memory));
})();