v8/test/mjsunit/wasm/lazy-compilation.js
Clemens Hammacher bb64e34f0c [wasm] Add "freeze" flag to test lazy compilation
In order to test that we don't repeatedly go through the
WasmCompileLazy runtime function, add a flag to the
LazyCompilationOrchestrator to "freeze" it, i.e. disallow any further
lazy compilation.
In tests, use this flag to first call a method, then freeze lazy
compilation, then call the method again to assert that no further lazy
compilation is triggered.

This test currently fails with --wasm-jit-to-native, so disable it for
that variant.

R=titzer@chromium.org
CC=mtrofin@chromium.org

Bug: v8:7140, chromium:788441, v8:5991
Change-Id: I18a40d302c24041740d8a54351d06ed968f4beec
Reviewed-on: https://chromium-review.googlesource.com/796430
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49734}
2017-11-30 08:54:12 +00:00

101 lines
3.5 KiB
JavaScript

// Copyright 2017 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: --wasm-lazy-compilation --allow-natives-syntax
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
(function importFromOtherInstance() {
print(arguments.callee.name);
const builder1 = new WasmModuleBuilder();
builder1.addFunction('func', kSig_v_v).addBody([]).exportFunc();
const instance1 = builder1.instantiate();
const builder2 = new WasmModuleBuilder();
builder2.addImport('mod', 'fn', kSig_v_v);
builder2.instantiate({mod: {fn: instance1.exports.func}});
})();
(function testWasmToWasmWithDifferentMemory() {
print(arguments.callee.name);
const builder1 = new WasmModuleBuilder();
builder1.addMemory(1, 1, true);
builder1.addFunction('store', kSig_v_i)
.addBody([
kExprI32Const, 0, // i32.const 1
kExprGetLocal, 0, // get_local 0
kExprI32StoreMem, 0, 0, // i32.store offset=0 align=0
])
.exportFunc();
const instance1 = builder1.instantiate();
const mem1 = new Int32Array(instance1.exports.memory.buffer);
const builder2 = new WasmModuleBuilder();
builder2.addMemory(1, 1, true);
builder2.addImport('mod', 'store', kSig_v_i);
builder2.addFunction('call_store', kSig_v_i)
.addBody([kExprGetLocal, 0, kExprCallFunction, 0])
.exportFunc();
const instance2 = builder2.instantiate({mod: {store: instance1.exports.store}});
const mem2 = new Int32Array(instance2.exports.memory.buffer);
assertEquals(0, mem1[0]);
assertEquals(0, mem2[0]);
instance2.exports.call_store(3);
assertEquals(3, mem1[0]);
assertEquals(0, mem2[0]);
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.call_store(7);
assertEquals(7, mem1[0]);
})();
(function exportImportedFunction() {
print(arguments.callee.name);
const builder1 = new WasmModuleBuilder();
builder1.addFunction('foo', kSig_v_v).addBody([]).exportAs('foo');
const instance1 = builder1.instantiate();
const builder2 = new WasmModuleBuilder();
const imp_idx = builder2.addImport('A', 'foo', kSig_v_v);
builder2.addExport('foo', imp_idx);
const instance2 = builder2.instantiate({A: instance1.exports});
instance2.exports.foo();
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.foo();
})();
(function exportImportedFunctionWithDifferentMemory() {
print(arguments.callee.name);
const builder1 = new WasmModuleBuilder();
builder1.addMemory(1, 1, true);
builder1.addFunction('store', kSig_v_i)
.addBody([
kExprI32Const, 0, // i32.const 1
kExprGetLocal, 0, // get_local 0
kExprI32StoreMem, 0, 0, // i32.store offset=0 align=0
])
.exportFunc();
const instance1 = builder1.instantiate();
const mem1 = new Int32Array(instance1.exports.memory.buffer);
const builder2 = new WasmModuleBuilder();
builder2.addMemory(1, 1, true);
const imp_idx = builder2.addImport('A', 'store', kSig_v_i);
builder2.addExport('exp_store', imp_idx);
const instance2 = builder2.instantiate({A: instance1.exports});
const mem2 = new Int32Array(instance2.exports.memory.buffer);
instance2.exports.exp_store(3);
assertEquals(3, mem1[0]);
assertEquals(0, mem2[0]);
%FreezeWasmLazyCompilation(instance1);
%FreezeWasmLazyCompilation(instance2);
instance2.exports.exp_store(7);
assertEquals(7, mem1[0]);
})();