Repository navigation
testFFI: wait for the concurrent compiler in the FTL warm-up loop - #943
Conversation
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.
|
How to reproduce the failure with a prebuilt # 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
quitSTALL_AT='JSC::DFG::Plan::compileInThreadImpl' STALL_SECONDS=0.3 \
gdb -q -batch -x stall.gdb --args ./testFFI testOptimizingTierPointerArgumentWithNonViewCells
CI on d7d0490. The 76 build lanes pass. The
|
WalkthroughThe FFI test now includes a comment describing concurrent DFG/FTL compilation and when the test completes JIT plans during warmup. ChangesFFI test documentation
Possibly related PRs
Suggested reviewers: Priority: Merge Risk:
|
|
Preview build of d7d0490: |
|
I reached the same change from the Bun side ( A reproduction without a debugger. Evict # 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'
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.
8c6c963...robobun/8ba1e0ae/testffi-wait-for-tier-up It is one commit: the same call in the loop, plus |
Problem
testOptimizingTierPointerArgumentWithNonViewCellsfails 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.testFFI.cpp:2407) callshotuntil 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
Heap::completeAllJITPlans()after each call. A compile that the call started is finished and installed before the next call.testFFIfrommainand from this branch. gdb holds the JIT worker thread for 0.3 s and for 2 s at the start of each compile:mainfails with the message above, this branch passes. Without the hold, both pass all 1,509,957 checks.Background
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.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.tsfailed 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.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
testFFIofautobuild-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.JSC::FTL::compilegives the first form: only line 2414 fails.JSC::DFG::Plan::compileInThreadImplgives the second form: lines 2414 and 2415 fail.JSC_thresholdForJITAfterWarmUp,JSC_thresholdForOptimizeAfterWarmUp,JSC_thresholdForFTLOptimizeAfterWarmUpat 2000000000).The builds compared.
testFFI.cppofmainand of this branch, compiled with the flags of the prebuilt'scompile_commands.json(-O3, no LTO) and linked with the static libraries of thelinux-amd64-aotprebuilt.JSC::DFG::Plan::compileInThreadImpl:mainfails lines 2414 and 2415, this branch passes.JSC::FTL::compile:mainfails line 2414, this branch passes.main.taskset -c 0): this branch passes all.linux-amd64-debug-asan-aotprebuilt) 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.