mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 00:11:20 +00:00

PR-URL: https://github.com/nodejs/node/pull/47251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
// Copyright 2023 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: --experimental-wasm-gc --allow-natives-syntax --turbofan
|
|
// Flags: --no-always-turbofan --no-always-sparkplug --expose-gc
|
|
// Flags: --stress-compaction --experimental-wasm-js-inlining
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
(function TestStressCompactionWasmStubCallRelocation() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
let struct = builder.addStruct([makeField(kWasmI32, true)]);
|
|
|
|
builder.addFunction('getElementNull', makeSig([kWasmExternRef], [kWasmI32]))
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kGCPrefix, kExprExternInternalize,
|
|
kGCPrefix, kExprRefCast, struct,
|
|
kGCPrefix, kExprStructGet, struct, 0])
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate({});
|
|
let wasm = instance.exports;
|
|
|
|
const trap = kTrapIllegalCast;
|
|
// getElementNull calls the TrapIllegalCast built-in.
|
|
const getNull = () => wasm.getElementNull(null);
|
|
|
|
// Build feedback vector.
|
|
%PrepareFunctionForOptimization(getNull);
|
|
for (let i = 0; i < 10; ++i) {
|
|
assertTraps(trap, getNull)
|
|
}
|
|
// Optimize function causing the wasm function with the built-in to be inlined
|
|
// into the JavaScript TurboFan code. The built-in is encoded as a jump with
|
|
// a 32 bit offset relative to the pc (on some platforms).
|
|
%OptimizeFunctionOnNextCall(getNull);
|
|
assertTraps(trap, getNull)
|
|
assertOptimized(getNull);
|
|
// Force gc(). It is necessary to call gc() multiple times and the flag
|
|
// --stress-compaction has to be set as well to cause a relocation of the JS
|
|
// function.
|
|
gc();
|
|
gc();
|
|
gc();
|
|
// The optimized function is not GCed.
|
|
assertOptimized(getNull);
|
|
// Calling getNull() again calls the relative built-in. If it still succeeds,
|
|
// the jump to the built-in was relocated successfully.
|
|
assertTraps(trap, getNull)
|
|
assertOptimized(getNull);
|
|
})();
|