Skip to content

JIT: Fix GC hole when converting a pinned pointer back to a byref in the same register - #138281

Open
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:fix-gchole-138268
Open

EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:fix-gchole-138268

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #138268

When a non-GC local (e.g. a pinned pointer) is stored into a GC local that got the same register, codegen elides the move. In fully interruptible code the emitter learns register GC liveness only from emitted instructions (and IG boundaries), so the register wasn't reported until the next IG. In TensorPrimitives Vectorized128 on arm64 the unpin landed inside that window, so a compacting GC could move the array while the only byref to it sat in an unreported register:

mov     x0, x1
stp     xzr, xzr, [fp, #0x10]   ; unpin, x5 (dRef) not reported
mov     x1, x5

Fix: in that case start a new IG carrying codegen's current GC info (the same thing temp labels do), so x5 becomes live at the right offset with no extra instructions. The only diffs are GC info and IG boundaries.

Minimal repro (a multi-threaded GC stress, too slow for a regression test): https://gist.github.com/EgorBo/70b824e0197c2ea16edc1107b9ecaa0c

…erruptible code

Converting a pinned pointer back to a byref (ref *ptr) can be a no-op move when
both locals share a register. The emitter learns register GC liveness from emitted
instructions only, so the register was not reported until the next IG and the
pin could be released while the byref was untracked.

Fixes dotnet#138268

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b1986f27-d029-45e5-be9b-a311d8cf8033
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 25, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Avoids the code size regression: start a new IG carrying codegen's GC info
when a same-register store turns a non-GC value into a GC local.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b1986f27-d029-45e5-be9b-a311d8cf8033

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[arm64][JIT] GC tracking hole in TensorPrimitives.Vectorized128: combined unpin (stp xzr, xzr) reordered before second ref *ptr assignment

1 participant