bce81d6be0
At the moment a WebAssembly module can be serialized successfully when all functions were compiled with TurboFan. However, for some functions it may not be necessary to be compiled with TurboFan, e.g. for functions where Liftoff code is as good as TurboFan code. With this CL we allow WebAssembly modules to get serialized even when not all functions are compiled with TurboFan. Missing functions are marked as missing in the serlialization. Upon deserialization, missing functions either get compiled by Liftoff, or initialized with a lazy-compilation stub, depending on the V8 configuration. Bug: v8:11862 Change-Id: Ic833a17639bf841c5def6fe3c35173fe0376c246 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2960209 Commit-Queue: Andreas Haas <ahaas@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Cr-Commit-Position: refs/heads/master@{#75987}
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
// Copyright 2021 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: --allow-natives-syntax --liftoff --no-wasm-tier-up --expose-gc
|
|
// Compile functions 0 and 2 with Turbofan, the rest with Liftoff:
|
|
// Flags: --wasm-tier-mask-for-testing=5
|
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
const num_functions = 5;
|
|
|
|
function create_builder() {
|
|
const builder = new WasmModuleBuilder();
|
|
for (let i = 0; i < num_functions; ++i) {
|
|
builder.addFunction('f' + i, kSig_i_v)
|
|
.addBody(wasmI32Const(i))
|
|
.exportFunc();
|
|
}
|
|
return builder;
|
|
}
|
|
|
|
function check(instance) {
|
|
for (let i = 0; i < num_functions; ++i) {
|
|
const expect_liftoff = i != 0 && i != 2;
|
|
assertEquals(
|
|
expect_liftoff, %IsLiftoffFunction(instance.exports['f' + i]),
|
|
'function ' + i);
|
|
}
|
|
}
|
|
|
|
const wire_bytes = create_builder().toBuffer();
|
|
|
|
function testTierTestingFlag() {
|
|
print(arguments.callee.name);
|
|
const module = new WebAssembly.Module(wire_bytes);
|
|
const buff = %SerializeWasmModule(module);
|
|
const instance = new WebAssembly.Instance(module);
|
|
check(instance);
|
|
return buff;
|
|
};
|
|
|
|
const serialized_module = testTierTestingFlag();
|
|
// Do some GCs to make sure the first module got collected and removed from the
|
|
// module cache.
|
|
gc();
|
|
gc();
|
|
gc();
|
|
|
|
(function testSerializedModule() {
|
|
print(arguments.callee.name);
|
|
const module = %DeserializeWasmModule(serialized_module, wire_bytes);
|
|
|
|
const instance = new WebAssembly.Instance(module);
|
|
check(instance);
|
|
})();
|