v8/test/mjsunit/empirical_max_arraybuffer.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

102 lines
3.2 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.
let kMax31BitSmi = (1 << 30) - 1;
let k1MiB = 1 * 1024 * 1024;
let k1GiB = 1 * 1024 * 1024 * 1024;
let k4GiB = 4 * k1GiB;
let kPageSize = 65536;
let kMaxArrayBufferSize = 2 * k1GiB - kPageSize; // TODO(titzer): raise this to 4GiB
let kStrideLength = 65536;
(function Test() {
var buffer;
try {
buffer = new ArrayBuffer(kMaxArrayBufferSize);
} catch (e) {
print("OOM: sorry, best effort max array buffer size test!");
return;
}
print("Allocated " + buffer.byteLength + " bytes");
assertEquals(kMaxArrayBufferSize, buffer.byteLength);
function probe(view, stride, f) {
print("--------------------");
let max = view.length;
for (let i = 0; i < max; i += stride) {
view[i] = f(i);
}
for (let i = 0; i < max; i += stride) {
// print(`${i} = ${f(i)}`);
assertEquals(f(i), view[i]);
}
}
{
// Make an uint32 view and probe it.
let elemSize = 4;
let viewSize = kMaxArrayBufferSize / elemSize;
// TODO(titzer): view sizes are limited to 31 bit SMIs. fix.
if (viewSize <= kMax31BitSmi) {
let uint32 = new Uint32Array(buffer);
assertEquals(kMaxArrayBufferSize / elemSize, uint32.length);
probe(uint32, kStrideLength / elemSize,
i => (0xaabbccee ^ ((i >> 11) * 0x110005)) >>> 0);
}
}
{
// Make an uint16 view and probe it.
let elemSize = 2;
let viewSize = kMaxArrayBufferSize / elemSize;
// TODO(titzer): view sizes are limited to 31 bit SMIs. fix.
if (viewSize <= kMax31BitSmi) {
let uint16 = new Uint16Array(buffer);
assertEquals(kMaxArrayBufferSize / elemSize, uint16.length);
probe(uint16, kStrideLength / elemSize,
i => (0xccee ^ ((i >> 11) * 0x110005)) & 0xFFFF);
}
}
{
// Make an uint8 view and probe it.
let elemSize = 1;
let viewSize = kMaxArrayBufferSize / elemSize;
// TODO(titzer): view sizes are limited to 31 bit SMIs. fix.
if (viewSize <= kMax31BitSmi) {
let uint8 = new Uint8Array(buffer);
assertEquals(kMaxArrayBufferSize / elemSize, uint8.length);
probe(uint8, kStrideLength / elemSize,
i => (0xee ^ ((i >> 11) * 0x05)) & 0xFF);
}
}
{
// Make a float64 view and probe it.
let elemSize = 8;
let viewSize = kMaxArrayBufferSize / elemSize;
// TODO(titzer): view sizes are limited to 31 bit SMIs. fix.
if (viewSize <= kMax31BitSmi) {
let float64 = new Float64Array(buffer);
assertEquals(kMaxArrayBufferSize / elemSize, float64.length);
probe(float64, kStrideLength / elemSize,
i => 0xaabbccee ^ ((i >> 11) * 0x110005));
}
}
{
// Make a float32 view and probe it.
let elemSize = 4;
let viewSize = kMaxArrayBufferSize / elemSize;
// TODO(titzer): view sizes are limited to 31 bit SMIs. fix.
if (viewSize <= kMax31BitSmi) {
let float32 = new Float32Array(buffer);
assertEquals(kMaxArrayBufferSize / elemSize, float32.length);
probe(float32, kStrideLength / elemSize,
i => Math.fround(0xaabbccee ^ ((i >> 11) * 0x110005)));
}
}
})();