Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//@ requireOptions("--useSamplingProfiler=true", "--sampleInterval=50")

// jsc creates the thread of an agent with WTF::Thread::create(), so that thread has an alternate
// signal stack, and the signal handlers of JSC run on it: the one that turns a fault in Wasm code
// into a trap, and the one that jettisons the code a VM trap stopped in. Both wait for locks that
// the sampling profiler holds while it suspends the thread. If the profiler cannot suspend a thread
// that runs on its alternate signal stack, this test does not finish.

const numberOfTraps = 20000;
const numberOfTimeLimits = 30;
Comment on lines +9 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Maintainers get a new stress test that breaks the JSTests/README.md rules for new tests: it runs well over the 200 ms budget in every configuration and ignores testLoopCount. The agent waits 30 times for a 5 ms time limit (at least 150 ms) and then takes 20000 Wasm traps under a 50 us sampling interval, with both counts hard-coded at JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:9-10. Fix: size the two loops from testLoopCount / wasmTestLoopCount (or cut them so the test stays under 200 ms with --report-execution-time in every run-jsc-stress-tests configuration), and since it embeds a Wasm module, consider JSTests/wasm/stress per the same README.

Why this was flagged

JSTests/CLAUDE.md imports JSTests/README.md, whose rules for new tests are: tests must run under 200 ms in all configurations (rule 1), use testLoopCount or wasmTestLoopCount for iteration counts (rule 2), and put wasm-involving tests in JSTests/wasm/stress. The new file JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:9-10 hard-codes numberOfTraps = 20000 and numberOfTimeLimits = 30, and JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:47 calls $vm.callWithTimeLimit(() => { for (;;) { } }, 5) thirty times, which alone spends at least 150 ms; the 20000 SIGSEGV-driven Wasm traps under --sampleInterval=50 add more. run-jsc-stress-tests runs every stress test in multiple configurations (no-cjit, ftl-eager, etc.), so each run of the CI test job on the Linux x64 and arm64 LTO lanes pays this repeatedly. On the base branch this file does not exist. The PR description reports the test passes 10 of 10 runs but gives no execution time, so the 200 ms rule is not shown to hold.

Verification: nit. Trigger: the new stress test runs whenever run-javascriptcore-tests / run-jsc-stress-tests JSTests/stress executes (the fork's Linux x64/arm64 CI lanes do this), in every default stress configuration.


$.agent.start(`
function takeWasmTraps()
{
if (typeof WebAssembly !== "object")
return ${numberOfTraps};

// (module (memory 1) (func (export "load") (param i32) (result i32) (i32.load (local.get 0))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 nit (optional): The new test builds and runs a WebAssembly module, but JSTests/README.md says tests that involve wasm belong in JSTests/wasm/stress, not JSTests/stress. Fix: move the file under JSTests/wasm/stress (keeping the WebAssembly-absent fallback at line 14 if the runner still lists it for non-wasm builds), or split the Wasm trap half from the time-limit half.

Why this was flagged

JSTests/README.md, imported by JSTests/CLAUDE.md, states "Put tests that only target JS behavior in JSTests/stress and tests that involve wasm in JSTests/wasm/stress." The new file at JSTests/stress/sampling-profiler-thread-on-alternate-signal-stack.js:18-26 compiles a hand-encoded Wasm module and calls its export 20000 times at line 31 to take Wasm traps. The test therefore involves wasm but is placed in JSTests/stress, which the guidance reserves for JS-only behaviour. This is a convention slip only; no runtime failure follows from it.

Verification: nit. Triggering condition: any time the file is added as-is. The rule is real: /home/claude/webkit/JSTests/README.md:15 (imported by /home/claude/webkit/JSTests/CLAUDE.md:1 via @ README.md) says under "Adding Tests": "Put tests that only target JS behavior in JSTests/stress and tests that involve wasm in JSTests/wasm/stress."

const module = new WebAssembly.Module(new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f,
0x03, 0x02, 0x01, 0x00,
0x05, 0x03, 0x01, 0x00, 0x01,
0x07, 0x08, 0x01, 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x00, 0x00,
0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x28, 0x02, 0x00, 0x0b,
]));
const { load } = new WebAssembly.Instance(module).exports;

let traps = 0;
for (let i = 0; i < ${numberOfTraps}; ++i) {
try {
load(0x7fff0000);
} catch (error) {
if (!(error instanceof WebAssembly.RuntimeError))
throw error;
++traps;
}
}
return traps;
}

function runIntoTimeLimits()
{
let timeLimits = 0;
for (let i = 0; i < ${numberOfTimeLimits}; ++i) {
try {
$vm.callWithTimeLimit(() => { for (;;) { } }, 5);
} catch (error) {
if (!(error instanceof RangeError) || error.message !== "timed out")
throw error;
++timeLimits;
}
}
return timeLimits;
}

let report;
try {
report = "traps: " + takeWasmTraps() + ", time limits: " + runIntoTimeLimits();
} catch (error) {
report = "error: " + error;
}
$.agent.report(report);
`);

let report;
while (!(report = $.agent.getReport()))
$.agent.sleep(1);

const expected = "traps: " + numberOfTraps + ", time limits: " + numberOfTimeLimits;
if (report !== expected)
throw new Error("expected '" + expected + "' but the agent reported '" + report + "'");
Loading
Loading