Skip to content

fix(jsc): wake passive collector when mutator starts waiting - #775

Open
steipete wants to merge 1 commit into
oven-sh:mainfrom
steipete:fix/passive-collector-wakeup-upstream
Open

steipete wants to merge 1 commit into
oven-sh:mainfrom
steipete:fix/passive-collector-wakeup-upstream

Conversation

@steipete

@steipete steipete commented Oct 7, 2026

Copy link
Copy Markdown

A synchronous collection can stop making progress when multiple worker heaps share the GC helper pool. This showed up in a multi-worker server workload as a worker's synchronous GC stalling for tens of seconds while other heaps occupied the shared marking helpers.

SlotVisitor::drainInParallelPassively() checks mutatorWaitingBit on entry. If the collector has already donated its work and parked when the mutator subsequently enters Heap::waitForCollector(), setting that bit does not wake the collector. The mutator waits for collection to finish, while its collector waits for helpers that are busy elsewhere.

Wake the marking condition after setting the waiting bit, under the marking mutex and after releasing the thread mutex. Recheck the bit inside the passive loop and switch to active draining. The marking mutex pairs the predicate check and wait with the notification, while keeping the two mutexes unnested. This follows the current Collector ownership of marking state.

The native regression in Source/JavaScriptCore/API/tests/testGCProgress.cpp uses real Heap operations. It occupies the shared helpers, requests asynchronous collection, observes the target collector parked through ParkingLot, and only then starts the mutator's synchronous wait. The unpatched control must positively exhibit both waiters, recover after releasing helpers, and retain its roots. The fixed engine must finish before helper release and retain the same roots. Setup timeout is a distinct failure. The test runs in its own executable because its scheduler settings and helper-pool gate are process-wide.

Built and tested on Linux x86-64 against 7012d42e55da294d8996f2dece6911aa9f0b7b6b, with Bun JSC additions, the Bun event loop, FTL, and external mimalloc enabled. With the same final test source, the unpatched engine exits 1 with a positive wait-cycle witness (no timeout, roots intact). The fixed engine passes 20/20 fresh-process runs, always completing before helper release with roots intact. All 55 selected GC stress configurations also pass, covering gc-b3, gc-invocation-with-transfer, gc-should-reap-dead-watchpoints, and both splay heap-access tests. Build and run the regression with cmake --build build --target testGCProgress and build/bin/testGCProgress.

The related WebKit change #72377 removes broadcasts at marking termination, when no work remains. This fixes the later mutator-wait transition while work remains, which is still present after that change and the Collector refactor.

Notify the marking condition under its mutex after the mutator sets its
waiting bit and releases the collector thread lock. Recheck the waiting
bit inside passive draining so the collector can take over marking when
shared helper threads are busy with another heap.

Add a standalone native API regression that observes the collector parked
before starting the synchronous wait. The unpatched engine positively
exhibits the wait cycle; the fixed engine completes before helper release.
Both paths preserve the rooted object graph.

Validation: Linux x86-64 positive control, 20 fixed-engine regression runs,
55 GC stress configurations, WebKit style check, and scoped P2 review.

@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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7378a1bb-c9c5-487e-8433-eabb5bef2b5d
📥 Commits

Reviewing files that changed from the base of the PR and between 7012d42 and 68e0b5d.

📒 Files selected for processing (4)
  • Source/JavaScriptCore/API/tests/testGCProgress.cpp
  • Source/JavaScriptCore/heap/Heap.cpp
  • Source/JavaScriptCore/heap/SlotVisitor.cpp
  • Source/JavaScriptCore/shell/CMakeLists.txt

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


Walkthrough

The change updates passive GC draining to respond to a mutator-waiting state that appears during termination waits. It adds a standalone testGCProgress probe for asynchronous full collection and parking observations, then adds the executable to the JavaScriptCore shell build.

Changes

GC Progress

Layer / File(s) Summary
GC wait handling
Source/JavaScriptCore/heap/Heap.cpp, Source/JavaScriptCore/heap/SlotVisitor.cpp
Heap::waitForCollector notifies marking-condition waiters when its completion predicate remains false. Passive draining switches to drainInParallel(timeout) if the mutator-waiting bit becomes set during the termination wait.
GC progress probe and build integration
Source/JavaScriptCore/API/tests/testGCProgress.cpp, Source/JavaScriptCore/shell/CMakeLists.txt
The probe occupies shared GC helpers, starts an asynchronous full collection, records collector and mutator parking, and checks completion and root values. The shell build defines and builds the executable with platform-specific libraries and mimalloc support.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 68e0b

No confirmed issue blocks merging after normal build and test checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: waking a passive collector when the mutator starts waiting.
Description check ✅ Passed The description explains the bug, the fix, affected functions, regression test, and reported test results. It does not include a Bugzilla issue ID or the template’s “Reviewed by” line, but it is other…
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.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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

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.

1 participant