#5471)
* Trace grace subtrees on the legacy heap, and gate heap integrity in CI
The grace-subtree pass added in #5442 covers BiBOP pages only. The legacy
sweep grants a fresh (gcMark == -1) legacy object exactly the same one-cycle
grace -- codenameOneGCSweep promotes it to the current epoch instead of
freeing it -- but nothing traced its subtree, so an older object reachable
ONLY through such an object was freed while it was still referenced. That is
the same defect #5442 fixed, on the other heap. Everything above
CN1_BIBOP_MAX_OBJECT lands there (the retained large byte[] blocks and
Hashtable bucket arrays of issue 5425), as does every allocation the adaptive
survivor-heavy bypass diverts off the page heap, and every matured survivor,
whose table entry is what the sweep consults. Measured with the audit half
added below: ~65,800 untraced fresh legacy objects per cycle on a
bypass-heavy workload, with children reachable only through them.
Mirror the page walk over allObjectsInHeap. Only entries already migrated
into the table can be fresh at that point -- pending allocations are not
swept until the mark that migrates them, and migration happens with the
owning thread paused, upstream of this pass -- so the pass is exact. Cost is
one extra walk of an array the sweep already walks in full, and only fresh
entries are traced: StormAB and LoadLoop wall time and RSS are unchanged and
LargeArrayLoad still collects in 5 cycles. CN1_DISABLE_LEGACY_GRACE is the
A/B escape hatch, mirroring CN1_DISABLE_SATB.
Add the gate that would have caught both halves. Checksums are structurally
blind to this failure: when a sweep frees memory a survivor still
references, nothing diverges at the point of the bug -- the dangling
reference reads whatever object recycled the slot, so the damage surfaces
later, elsewhere, as corrupted data. That is how #5436's regression reached
a user as "non word" dictionary entries and an impossible NPE instead of as
a failing test. -DCN1_GC_VERIFY makes the invariant observable by destroying
the plausible replacement:
- POISON every reclaimed page slot and legacy block. This includes the O(1)
all-dead page reclaim, which is where nearly all page memory is actually
reclaimed and which normally drops a page without writing a single slot,
leaving every dead object with an intact-looking header -- the reason a
dangling read in this VM finds plausible data rather than crashing.
- QUARANTINE freed legacy blocks in a ring instead of returning them to the
C allocator, so a poisoned block stays mapped and recognizable.
- VERIFY after every sweep: walk each survivor through its own generated
mark function with the collector in verify mode, classifying every
reference field against the page registry, the live-extent index and the
quarantine set. A field pointing into reclaimed memory is reported with
the holder's class, the victim's class and the field's mark call site,
then aborts at the cycle that created it.
The gate holds CURRENT-EPOCH survivors to the invariant, where a dangling
field is unambiguous: the sweep either marked the object reachable (marking
traces children) or promoted it by the grace rule (tracing the subtree was
the grace pass's job). References it cannot place are skipped, so a
violation is never a false alarm. CN1_GC_VERIFY_AGING extends it to
previous-epoch survivors as a census rather than a gate.
run-gc-verify.sh runs it over nine drivers and then re-injects the #5442
defect (CN1_GC_FAULT=nograce disables the grace pass) and REQUIRES the
verifier to catch it -- a gate nobody has watched fail is not a gate, and a
build where the verification silently compiled out would otherwise report a
permanent, meaningless pass. GcHeapIntegrityIntegrationTest is the CI twin
and asserts both halves.
Two supporting pieces, both born from the same investigation:
- LegacyGrace is the legacy-path twin of GraceAudit, plus the
[GRACE-AUDIT-LEGACY] half of -DCN1_GRACE_AUDIT. Writing it exposed why
drivers in this area come back green while the defect is present: the
hazard has to be built with no mark in flight (during a mark the SATB
barriers cover the very reference move under test) and the driver has to
scrub its own native stack afterwards, because the conservative root scan
marks whatever a returned frame's leftover word still points at. Both are
documented at the driver and in the README.
- CN1_GC_TRACE_MARK names the mark pass that keeps a class alive, which is
how that retention was identified; CN1_GC_VERIFY_CENSUS reports whether a
driver's hazard set actually ages out instead of being pinned.
Validation: gauntlet GREEN in both stop modes, run-gc-verify GREEN over all
nine drivers with the fault self-test firing, GraceAudit clean under
-DCN1_GRACE_AUDIT, and the new integration test green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Sanitize the collector's env knobs in the heap-integrity gate
Both halves of the gate are decided by environment variables, and anyone
debugging the collector has exactly those exported: CN1_GC_VERIFY_SOFT
downgrades the abort the faulted half asserts on, and CN1_GC_FAULT injects the
defect the clean half asserts is absent. An inherited knob would invert a
result rather than fail loudly. Drop CN1_* from the child environment in the
integration test and unset the knobs at the top of run-gc-verify.sh, so both
start from a known state and see only what they set themselves.
Verified by running each with CN1_GC_FAULT=nograce and CN1_GC_VERIFY_SOFT=1
exported: the test passes and the script reports GC-VERIFY GREEN.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Report the mark site from the frame that actually has it
cn1GcVerifyChild read __builtin_return_address(0) itself, which resolves to
the return address in gcMarkObject -- one frame too deep, and in a different
object file from the generated mark function the label claimed it pointed
into. Anyone following a violation back to a field would have landed in the
collector rather than at the field read.
Capture the address in gcMarkObject instead, where this frame's return address
IS the instruction inside the generated mark function (or gcMarkArrayObject for
an element), and pass it down. Report it as an offset from the holder's own
mark function so the line is self-verifying without symbols and survives ASLR:
markSite= 0x102fa66c0 = markFn+36 (the field read, inside the holder's mark function)
A small positive offset means the frame is right; add it to the mark
function's symbol to reach the exact field.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Make every driver in the gate carry its weight, and fix the CI self-test on Linux
Three problems, all the same shape: a check that reports success without
having checked anything.
1. The verifier never reported whether it RAN. MtStress, MapTorture and
SbTorture exit before any sweep completes, so their "clean" results in
run-gc-verify.sh meant only that nothing was ever verified -- exactly the
hollow-gate failure the fault self-test exists to prevent, sitting inside
the same script. Count completed passes, print them at exit, and fail any
driver reporting zero. Those three now end with one collection over the
heap they built (printing nothing, so the gauntlet's byte-identical
comparison is unaffected) and contribute real coverage.
2. The CI self-test failed on Linux: the fault was injected and the workload
completed, but no dangling reference appeared, so the test declared the
gate inert. Reproduced in a linux/amd64 container -- the platform is fine
(GraceAudit detects the fault there), the app's hazard was too weak. Its
during-mark phase now follows the shape that provably breaks a missing
grace pass: refill, kick a mark, then allocate dropped fresh nodes in
sleep-separated slices so they land across the mark rather than racing
past it, then go quiet for a full cycle so the untraced children age past
the free threshold. Verified in the container: clean 0 violations / 23
passes, faulted aborts with 20 reports, three runs, no variance.
3. The integration test now also requires a nonzero pass count, so a
workload that stops driving collection fails instead of passing silently.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Add the Codename One header to the three tortures this PR touches
MapTorture, MtStress and SbTorture predate the copyright gate and carried no
header at all. The gate only inspects files a PR adds or modifies, so giving
them a trailing collection in the previous commit is what pulled them into
scope. Header text copied verbatim from LegacyGrace.java, added in this PR
and already passing.
Comment-only: scripts/check-copyright-headers.sh passes over the branch, and
the gauntlet still matches the host JVM byte for byte.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Correct the documented contract of cn1GcVerifyQuarantineFree
The comment described an earlier design in which the function handed the
evicted block back for the caller to release. It returns a boolean and frees
the displaced block itself, and the call site in codenameOneGcFree already
relies on that boolean -- so the comment was the only thing out of date, and
the one part a future caller would have read first.
State what the return value means instead: TRUE when the block was
quarantined and must NOT be freed, FALSE when the quarantine could not be
allocated and the caller should free normally.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Resolve the injected fault before the first grace pass consults it
cn1GcFaultNoGrace was initialized only by cn1GcVerifyHeap, which runs after
the sweep. The first cycle of every faulted run therefore traced grace
subtrees normally, and a workload completing a single GC cycle never had the
defect injected at all -- the self-test would have reported a gate that
"cannot fail" purely because nothing ever faulted it. Resolve the switch at
its first use in the mark instead; cn1GcFaultInit is idempotent and
GC-thread only, so the call in cn1GcVerifyHeap stays as a harmless second
one. Observable: [GC-FAULT] now prints before the first verify pass rather
than after a sweep.
Checking that turned up a matching gap in GcStress, which reported 1 verify
pass on one run and 0 on the next: its churn triggers collections, but
whether the last one reaches its sweep before the process exits is a race,
so the new vacuity check would have flaked in CI. It gets the same trailing
collection as the other drivers (prints nothing, so the gauntlet comparison
is unaffected).
Two consecutive gate runs now report identical pass counts across all nine
drivers, and the gauntlet stays byte-identical to the host JVM.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* State LegacyGrace's real allocation volume against the trigger
The hazard comment still described the driver's first shape -- 256 parents of
~800 bytes -- after it was scaled to KEEP=10000 arrays of 65 references. The
number matters rather than being decoration: the window only works while
nothing in it starts a collection, so a reader checking that property was
being handed the wrong figure by an order of magnitude.
Give the real one (about 560 bytes each, 5.6 MB total, against the 24 MB
allocation-volume trigger) and say which constants would break the window if
raised. Same for the other precondition, that no mark is in flight, since
both are equally easy to lose when editing the driver.
Comment-only; LegacyGrace still reports 120 clean verify passes with the
fault self-test firing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Add the Codename One header to GcStress
GcStress is the fourth torture in this tree without a header, and the
trailing collection added for the vacuity check pulled it into the copyright
gate's scope. Missed on the first pass because the earlier commit added
headers to the three drivers touched at that point, and GcStress was edited
after that check ran.
Audited every source file this branch touches rather than fixing one report
at a time: all eight now carry the header and
scripts/check-copyright-headers.sh passes over the full branch range.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Summary
Root cause and impact
Issue #5425 combines a large retained set of small arrays with continued temporary allocation. The fixed 24 MiB BiBOP trigger and the prior throughput classification can force collections too frequently for that shape, while the old unconditional mark belt magnifies the cost of each cycle.
The production collector now observes allocation rate and survival at runtime. It grows the trigger within bounded available-memory limits, promotes high-throughput threads automatically, and uses a bounded legacy bypass for size classes that repeatedly show high survival. Applications do not need compiler flags or collector selection; the flags in the benchmark only build QA comparison variants.
The fresh-page grace scan and overflow-only belt retain correctness without scanning the grow-only page registry or doing a second full reachable-object traversal on normal cycles.
Validation
mvn -q -B -pl ByteCodeTranslator -am testfromvmwith Java 8./run-bibop-adaptive.sh 1git diff --checkFixes #5425