node/deps/v8/test/filecheck/js-wasm-wrapper-inlining-lazy-deopt.js
Michaël Zasso c2843b722c
deps: update V8 to 14.2.231.9
PR-URL: https://github.com/nodejs/node/pull/60111
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-10-23 07:36:34 +02:00

70 lines
2.2 KiB
JavaScript

// Copyright 2025 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: --turbolev --no-maglev --turbolev-inline-js-wasm-wrappers
// Flags: --allow-natives-syntax --trace-deopt --trace-deopt-verbose
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
d8.file.execute('test/mjsunit/mjsunit.js');
const iterationCount = 100;
let arrayIndex = 0;
function createWasmModuleForLazyDeopt(returnType, createValue, callback) {
let builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
let index = builder.addArray(kWasmI32, true);
assertEquals(arrayIndex, index);
let callbackIndex = builder.addImport('env', 'callback', kSig_v_i);
builder.addFunction("triggerDeopt", makeSig([kWasmI32], [returnType]))
.addLocals(kWasmI32, 1)
.addBody([
...wasmI32Const(1032),
...wasmI32Const(1032),
kExprI32LoadMem, 0, 0,
kExprI32Const, 1,
kExprI32Add,
kExprLocalTee, 1,
kExprI32StoreMem, 0, 0,
kExprBlock, kWasmVoid,
kExprLocalGet, 1,
...wasmI32Const(iterationCount),
kExprI32Ne,
kExprBrIf, 0,
kExprLocalGet, 0,
kExprCallFunction, callbackIndex,
kExprEnd,
...createValue,
]).exportFunc();
return builder.instantiate({ env: { callback } });
}
{ // Test with a f32 result, which needs materialization.
var globalForI32 = 0;
let { triggerDeopt } = createWasmModuleForLazyDeopt(kWasmF32,
[...wasmF32Const(3.14)], () => globalForI32 = 1).exports;
function test(arg0) {
var result = 0;
for (let i = 0; i < iterationCount + 5; i++) {
if (i == 2) % OptimizeOsr();
result = triggerDeopt(arg0 + globalForI32);
}
return result;
}
%PrepareFunctionForOptimization(test);
assertEqualsDelta(3.14, test(0));
%OptimizeFunctionOnNextCall(test);
// CHECK: [marking dependent code {{.*}} <Code TURBOFAN_JS> ({{.*}} <SharedFunctionInfo test>)
// CHECK: [bailout (kind: deopt-lazy, reason: (unknown))
// CHECK: reading JS to Wasm builtin continuation frame test
// CHECK: translating BuiltinContinuation to JSToWasmLazyDeoptContinuation
// CHECK: Materialization {{.*}} <HeapNumber 3.14>
assertEqualsDelta(3.14, test(0));
}