Skip to content

testFFI: wait for the concurrent compiler in the FTL warm-up loop - #943

Merged
Jarred-Sumner merged 1 commit into
mainfrom
robobun/fecaef2f/testffi-wait-for-jit-plans
Oct 30, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
robobun/fecaef2f/testffi-wait-for-jit-plans

Conversation

@robobun

@robobun robobun commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • In Bun's CI, testOptimizingTierPointerArgumentWithNonViewCells fails on the first try and passes on the retry: FAIL: vendor/WebKit/Source/JavaScriptCore/ffi/tests/testFFI.cpp:2414: installedInFTL(). Since AOT: fixes for modules, classes and Workers, WebKit upgrade, shorter compiler docs bun#47129 it shows in 131 of 150 Bun builds.
  • The warm-up loop (testFFI.cpp:2407) calls hot until its FTL code is installed, at most 5,000,000 times. Those calls take about 0.2 s. The DFG and the FTL compile on another thread. If that thread needs more time, the loop ends first.

Fix

  • The loop calls Heap::completeAllJITPlans() after each call. A compile that the call started is finished and installed before the next call.
  • Correct because the limit now counts calls only. The tier-up thresholds decide how many calls the loop needs.
  • Verified with release builds of testFFI from main and from this branch. gdb holds the JIT worker thread for 0.3 s and for 2 s at the start of each compile: main fails with the message above, this branch passes. Without the hold, both pass all 1,509,957 checks.

Background

  • JSC runs a hot function in tiers: LLInt, Baseline, DFG, FTL. The DFG and the FTL compile on a JIT worklist thread. The main thread runs the older code until the new code is installed.
  • Heap::completeAllJITPlans() blocks until the worklist has no compile for this VM, then installs the results. With no compile in flight it returns after one counter check.
  • Considered a time limit in place of the call count. The test then still depends on machine speed.
Notes

What Bun's CI shows. 381 builds from 2026-10-28 06:00 to 2026-10-29 21:00 UTC.

  • test/js/bun/jsc-stress/testFFI.test.ts failed a first try 270 times. Each time it was this one test function. 268 passed on the first retry, 2 on the second. No build was red from it.
  • By lane: Debian 13 x64 117, Ubuntu 25.04 x64 101, Debian 13 aarch64 29, Ubuntu 25.04 aarch64 23.
  • By base commit: 3 of 231 builds before AOT: fixes for modules, classes and Workers, WebKit upgrade, shorter compiler docs bun#47129, 131 of 150 after it.
  • Two forms. In 135 runs only line 2414 fails (installedInFTL()). In the other 135, line 2415 fails too (FFI::g_ffiCompileCounts.ftlCallFFI.load() > ftlLoweringsBefore), so the FTL had not lowered the call when the loop ended.

Reproduction. The prebuilt testFFI of autobuild-8c6c963e3c49 (linux-amd64-lto-aot), gdb in non-stop mode, a breakpoint that sleeps in the stopped thread and then continues. The main thread runs during the sleep.

  • A sleep at JSC::FTL::compile gives the first form: only line 2414 fails.
  • A sleep at JSC::DFG::Plan::compileInThreadImpl gives the second form: lines 2414 and 2415 fail.
  • A sleep of 0.1 s at each compile fails. A sleep of 0.05 s passes. A breakpoint with no sleep passes.
  • The warm-up loop takes 0.19 s to 0.25 s at every tier. Measured with the tier-up thresholds set out of reach (JSC_thresholdForJITAfterWarmUp, JSC_thresholdForOptimizeAfterWarmUp, JSC_thresholdForFTLOptimizeAfterWarmUp at 2000000000).

The builds compared. testFFI.cpp of main and of this branch, compiled with the flags of the prebuilt's compile_commands.json (-O3, no LTO) and linked with the static libraries of the linux-amd64-aot prebuilt.

  • No hold: both pass, 1,509,957 checks each.
  • Hold of 0.3 s and of 2 s at JSC::DFG::Plan::compileInThreadImpl: main fails lines 2414 and 2415, this branch passes.
  • Hold of 0.3 s and of 2 s at JSC::FTL::compile: main fails line 2414, this branch passes.
  • With the FTL threshold out of reach the test still fails at the limit on both builds. The loop takes 0.21 s on this branch and 0.20 s on main.
  • Six runs with the pages of the binary dropped from the page cache before each run, and four runs on one CPU (taskset -c 0): this branch passes all.
  • A debug build of this branch with assertions and ASAN (the linux-amd64-debug-asan-aot prebuilt) passes the test: 1,500,246 checks, no assertion fails.

Not proven. Why the compiler thread is slow on the first try in Bun's CI. The change in oven-sh/bun#47129 put tests that build many executables into the same shards. A likely cause is that the first run reads the pages of the compilers from disk. This was not measured on a CI machine.

After the merge. Bun gets the change with its next WebKit upgrade.

testOptimizingTierPointerArgumentWithNonViewCells calls a function until
its FTL code is installed, at most 5,000,000 times. Those calls take
about 0.2 s. The DFG and the FTL compile on another thread. When that
thread needs more time than the calls take, the loop ends first and the
test fails:

    FAIL: vendor/WebKit/Source/JavaScriptCore/ffi/tests/testFFI.cpp:2414: installedInFTL()

The loop now calls Heap::completeAllJITPlans() after each call. A compile
that a call started is finished and installed before the next call, so
the limit counts calls and not the time the compiler takes.
@robobun

robobun commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

How to reproduce the failure with a prebuilt testFFI (Linux x64, gdb):

# stall.gdb
set pagination off
set confirm off
set non-stop on
python
import gdb, time, os
class Stall(gdb.Breakpoint):
    def stop(self):
        # Only the thread at the breakpoint sleeps. The main thread continues to call the function.
        time.sleep(float(os.environ["STALL_SECONDS"]))
        return False
Stall(os.environ["STALL_AT"])
end
run
quit
STALL_AT='JSC::DFG::Plan::compileInThreadImpl' STALL_SECONDS=0.3 \
  gdb -q -batch -x stall.gdb --args ./testFFI testOptimizingTierPointerArgumentWithNonViewCells
  • main: FAIL: ...testFFI.cpp:2414: installedInFTL() and line 2415. With STALL_AT='JSC::FTL::compile' only line 2414 fails.
  • This branch: OK: 1500246 checks passed, 0 failed. with 0.3 s and with 2 s.

CI on d7d0490. The 76 build lanes pass. The testFFI step passes on all six test lanes. Four test lanes are red in the run-javascriptcore-tests step, which does not run testFFI:

  • linux-amd64-lto-aot and linux-amd64-lto-hardened-aot are red in that step on main (7aede06) too.
  • linux-arm64-lto and linux-arm64-lto-hardened-aot are red in this run only. Both pass on main.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

The FFI test now includes a comment describing concurrent DFG/FTL compilation and when the test completes JIT plans during warmup.

Changes

FFI test documentation

Layer / File(s) Summary
Document warmup compilation behavior
Source/JavaScriptCore/ffi/tests/testFFI.cpp
A comment explains that DFG/FTL compilation runs on another thread and that the test completes JIT plans during warmup.

Possibly related PRs

  • oven-sh/WebKit#898: Changes concurrent FTL compilation handling during tier-up, which relates to the compilation timing documented by this test.

Suggested reviewers: jarred-sumner

Priority: Low

Merge Risk: Minimal · up to d7d04

The FFI warm-up change is ready to merge with no identified correctness or availability risk.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: waiting for concurrent compilation during the FTL warm-up loop in testFFI.
Description check Passed The description clearly explains the failure, root cause, fix, validation, and scope. It does not include the template's explicit Bugzilla link, reviewer line, or a separate changed-file/function list…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the failure, root cause, fix, validation, and scope. It does not include the template's explicit Bugzilla link, reviewer line, or a separate changed-file/function list, but the required technical information is largely present.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Preview build of d7d0490: autobuild-preview-pr-943-d7d0490d

@robobun

robobun commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

I reached the same change from the Bun side (vm.heap.completeAllJITPlans() after each warm-up call), so I will not open a second pull request. Two things from that work are not in this one yet.

A reproduction without a debugger. Evict testFFI from the page cache and limit the reads of its cgroup. The compiler thread then waits for the disk during its first compiles, and the main thread does not.

# once
echo +io > /sys/fs/cgroup/cgroup.subtree_control
mkdir /sys/fs/cgroup/slowio
echo "254:0 riops=2000" > /sys/fs/cgroup/slowio/io.max   # 254:0 is the disk that holds testFFI
# each run
python3 -c 'import os,sys; fd=os.open(sys.argv[1],os.O_RDONLY); os.posix_fadvise(fd,0,0,os.POSIX_FADV_DONTNEED)' ./testFFI
sh -c 'echo $$ > /sys/fs/cgroup/slowio/cgroup.procs; exec ./testFFI'
bin/testFFI of linux-amd64-lto-aot result
autobuild-8c6c963e3c, autobuild-f495db1d24, autobuild-fcc1ea0973, 6 runs each 17 of 18 fail, at line 2414 or at lines 2414 and 2415
autobuild-preview-pr-943-d7d0490d 10 of 10 pass
  • With JSC_reportCompileTimes=1 the three compiles of hot take about 200 ms, 400 ms and 400 ms in the runs of this branch. With a warm cache they take 0.2 ms, 0.4 ms and 1.1 ms. The 5,000,000 calls take 190 ms.
  • With a warm cache and no limit, autobuild-8c6c963e3c fails 0 of 184 runs.

This agrees with the cause that the description leaves open. So does the CI data:

The state of the page cache on a CI machine is still not measured.

Heap::completeAllJITPlans() is not exported. The fixtures and the FFI functions that testFFI calls are all inline or JS_EXPORT_PRIVATE, which lets it link against a JavaScriptCore that is not static. Every lane is static, so nothing fails today. My branch has the annotation:

8c6c963...robobun/8ba1e0ae/testffi-wait-for-tier-up

It is one commit: the same call in the loop, plus JS_EXPORT_PRIVATE on Heap::completeAllJITPlans() in Heap.h. It starts at 8c6c963, the commit that Bun pins now. A build of it links into Bun's main without the pending WebKit upgrade, if the fix is wanted there sooner.

@Jarred-Sumner
Jarred-Sumner merged commit e669162 into main Oct 30, 2026
83 of 87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants