Skip to content

Rescan a Deque whose items move during an incremental cycle (#424) - #443

Merged
dimensionscape merged 4 commits into
mainfrom
fix/incremental-deque-moves
Nov 13, 2026
Merged

dimensionscape merged 4 commits into
mainfrom
fix/incremental-deque-moves

Conversation

@dimensionscape

@dimensionscape dimensionscape commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes the intermittent "Incremental GC omitted reachable object" in the gc stress test's incremental runs (#424), and a second gap of the same kind. The commits were first written on the cppia-bugs-1106 branch and are picked from there onto current main.

  • The cause of Incremental GC verifier finds a reachable object left unmarked in gc_stress #424. An incremental cycle scans an array of more than 256 items in chunks, which can run in any order. The runtime's Deque (sys.thread.Deque) moves its items itself: a pop compacts the queue once the consumed part dominates, and a push at the front makes room by moving every item up. Either could carry items no chunk had reached into chunks already scanned, so the cycle left them unmarked. Both moves now open a mutation scope, as Array's own moves do, so the queue is scanned again. IncrementalGcDequeMoves stops a cycle partway through a 32,768-item queue and makes each move. Without the scopes the verifier aborts on every run, on a node the report shows held by a Deque. It is added to the incremental regressions in test.yml.
  • A thread object's arrays. A slice could find a new ThreadImpl on the creating thread's stack while its first array was being allocated, and the cycle could end at a later allocation in the initialiser list, before the constructor's barrier ran. The arrays are now made in a mutation scope in the constructor body, before the thread starts. The stress verifier caught this one on Windows. There is no deterministic test for it.
  • The verifier's report. It printed only the object it found unmarked. It now records how its own walk first reached each allocation and prints that chain back to a root, with each holder's type and whether this cycle marked it.

Reproduced here as in #424 (bin/Stress 3 8 1337, built with HXCPP_GC_INCREMENTAL, HXCPP_GC_INCREMENTAL_VERIFY, HXCPP_GC_BIG_BLOCKS and HXCPP_M64, MSVC x64): main failed 2 of 150 runs with the omitted object, and this branch 0 of 750, the last 600 four at a time. At main's rate, 750 clean runs would happen by chance about once in 20,000.

Fixes #424.

dimensionscape and others added 4 commits November 13, 2026 00:03
The verifier printed only the object it found unmarked, which says
nothing about where the cycle lost it. It now records how its own walk
first reached each allocation, and prints that chain back to a root,
with each holder's type and whether this cycle marked it.
An incremental cycle scans an array of more than 256 items in chunks,
which can run in any order. The runtime's Deque moves its items itself:
a pop compacts the queue once the consumed part dominates, and a push at
the front opens room by moving every item up. Either could carry items no
chunk had reached into chunks already scanned, so the cycle left them
unmarked, and the gc stress test's verifier aborted about once in 75
runs (libhxcpp #424). Both moves now open a mutation scope, as Array's
own moves do, so the queue is scanned again.

IncrementalGcDequeMoves stops a cycle partway through a 32768-item queue
and makes each move; without the scopes the verifier aborts every run.
An incremental slice could find a new ThreadImpl on the creating thread's
stack while its first array was being allocated, and the cycle could end at
a later allocation in the initialiser list, before the constructor's barrier
ran. The arrays stored in between were left unscanned and freed. The gc
stress verifier caught it on Windows.
@dimensionscape
dimensionscape merged commit f053b22 into main Nov 13, 2026
37 checks passed
@dimensionscape
dimensionscape deleted the fix/incremental-deque-moves branch November 13, 2026 14:02
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.

Incremental GC verifier finds a reachable object left unmarked in gc_stress

1 participant