Skip to content

Fix VALIDATE_MARKING in the Julia GC integration - #6525

Open
fingolfin wants to merge 1 commit into
masterfrom
validate-marking
Open

Fix VALIDATE_MARKING in the Julia GC integration#6525
fingolfin wants to merge 1 commit into
masterfrom
validate-marking

Conversation

@fingolfin

@fingolfin fingolfin commented Aug 26, 2026

Copy link
Copy Markdown
Member

The VALIDATE_MARKING check in JMark required the type of a marked object to be a live pool allocation, tested via jl_gc_internal_obj_base_ptr. Since GAP.jl became precompilable, its foreign types are restored from a package image and live in image memory, so the first collection aborted (the same held for types of wrapped Julia objects, which mostly live in the system image, and for the corresponding check in MarkJuliaObjSafe, which silently skipped marking). Now type objects carrying Julia's in_image header bit are accepted as valid.

Verified: without the fix, using GAP (precompiled, Julia 1.12) aborts in the first collection, reproducing oscar-system/GAP.jl#1364; with it, testinstall (standalone, Julia GC) and the GAP.jl test suite pass with VALIDATE_MARKING enabled.

The CI job guarding against regressions follows in the stacked PR #6526.

AI disclosure: diagnosis, patch and testing by Claude Code, reviewed by a human.

🤖 Generated with Claude Code

The VALIDATE_MARKING check in JMark (and the corresponding check in
MarkJuliaObjSafe) requires the type of a marked object to be a live
pool allocation, tested via jl_gc_internal_obj_base_ptr. Since GAP.jl
became precompilable, its foreign types (GapObj, SmallBag, LargeBag)
are restored from a package image via jl_reinit_foreign_type; they
live in image memory, jl_gc_internal_obj_base_ptr returns NULL for
them, and the first collection aborts. The same holds for the types
of arbitrary Julia objects wrapped by JuliaInterface, which mostly
live in the system image.

Accept type objects with the in_image header bit as valid.

This was investigated and fixed with the assistance of Claude Code
(diagnosis, patch and testing by the AI, reviewed by a human).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@fingolfin fingolfin changed the title julia_gc: accept image types in mark validation Fix VALIDATE_MARKING in the Julia GC integration Aug 26, 2026
@fingolfin fingolfin added release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes kind: bug Issues describing general bugs, and PRs fixing them topic: julia Julia GC integration and related matters topic: kernel labels Aug 26, 2026
@fingolfin
fingolfin marked this pull request as ready for review August 26, 2026 21:05
@fingolfin
fingolfin requested a review from lgoettgens August 26, 2026 21:06
fingolfin added a commit to oscar-system/GAP.jl that referenced this pull request Aug 28, 2026
A GAP object held only in a C stack frame of a Julia task must survive
collections that run while the task is suspended (parked in a Julia
call, or busy on another thread). This went wrong when the task stack
rescan optimization in GAP's julia_gc.c skipped old tasks, the cause of
long-elusive crashes; see #1032, #1224 and gap-system/gap#6525.

The tests hold a canary object solely via a wrapper bag in a GAP kernel
argument temporary and detect premature collection through per-canary
finalizers, covering automatic and explicit incremental collections
and, in a subprocess with two Julia threads and two GC mark threads, a
never-switching task on a second thread. Only automatic collections
exercise the historically buggy path, so the driver churns allocations
rather than calling GC.gc.

Fixes #996.

AI disclosure: tests developed with the assistance of Claude Code.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.16 kind: bug Issues describing general bugs, and PRs fixing them release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: julia Julia GC integration and related matters topic: kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant