v8/test/mjsunit/wasm/empirical_max_memory.js
Ben L. Titzer dab1076535 [wasm] Prepare to support 4GiB memories
This is a preparatory CL that refactors the WASM memory allocation path,
the WasmGraphBuilder, and several points of contact for ArrayBuffers to
allow them to eventually be up to 4GiB.

1.) Refactor definition of constants to prepare for memories of size 2^32
2.) Refactor WasmInstanceObject fields memory_size and memory_mask to
    be stored as uintptr_t
3.) Refactor WasmGraphBuilder to use 64-bit comparisons for bounds checks
4.) Refactor JSArrayBuffer accessor methods to use size_t properly.
5.) Add empirical maximum memory and array buffer size tests

R=mstarzinger@chromium.org
BUG=v8:7881

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I78a49069cfa89757cc93f0a30b1c1a99c4b2edba
Reviewed-on: https://chromium-review.googlesource.com/1112003
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54646}
2018-07-24 13:55:43 +00:00

86 lines
2.5 KiB
JavaScript

// Copyright 2018 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.
// Flags: --expose-wasm
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
let k1MiB = 1 * 1024 * 1024;
let k1GiB = 1 * 1024 * 1024 * 1024;
let k4GiB = 4 * k1GiB;
let kMaxMemory = 2 * k1GiB - kPageSize; // TODO(titzer): raise this to 4GiB
(function Test() {
var memory;
function BuildAccessors(type, load_opcode, store_opcode) {
builder = new WasmModuleBuilder();
builder.addImportedMemory("i", "mem");
builder.addFunction("load", makeSig([kWasmI32], [type]))
.addBody([ // --
kExprGetLocal, 0, // --
load_opcode, 0, 0, // --
]) // --
.exportFunc();
builder.addFunction("store", makeSig([kWasmI32, type], []))
.addBody([ // --
kExprGetLocal, 0, // --
kExprGetLocal, 1, // --
store_opcode, 0, 0, // --
]) // --
.exportFunc();
let i = builder.instantiate({i: {mem: memory}});
return {load: i.exports.load, store: i.exports.store};
}
function probe(a, f) {
print("------------------------");
let stride = kPageSize;
let max = kMaxMemory;
for (let i = 0; i < max; i += stride) {
a.store(i, f(i));
}
for (let i = 0; i < max; i += stride) {
// print(`${i} = ${f(i)}`);
assertEquals(f(i), a.load(i));
}
}
try {
let kPages = kMaxMemory / kPageSize;
memory = new WebAssembly.Memory({initial: kPages, maximum: kPages});
} catch (e) {
print("OOM: sorry, best effort max memory size test.");
return;
}
assertEquals(kMaxMemory, memory.buffer.byteLength);
{
let a = BuildAccessors(kWasmI32, kExprI32LoadMem, kExprI32StoreMem);
probe(a, i => (0xaabbccee ^ ((i >> 11) * 0x110005)) | 0);
}
{
let a = BuildAccessors(kWasmI32, kExprI32LoadMem16U, kExprI32StoreMem16);
probe(a, i => (0xccee ^ ((i >> 11) * 0x110005)) & 0xFFFF);
}
{
let a = BuildAccessors(kWasmI32, kExprI32LoadMem8U, kExprI32StoreMem8);
probe(a, i => (0xee ^ ((i >> 11) * 0x05)) & 0xFF);
}
{
let a = BuildAccessors(kWasmF64, kExprF64LoadMem, kExprF64StoreMem);
probe(a, i => 0xaabbccee ^ ((i >> 11) * 0x110005));
}
{
let a = BuildAccessors(kWasmF32, kExprF32LoadMem, kExprF32StoreMem);
probe(a, i => Math.fround(0xaabbccee ^ ((i >> 11) * 0x110005)));
}
})();