Skip to content

JIT: Keep intrinsic-only loops fully interruptible - #133884

Merged
EgorBo merged 3 commits into
mainfrom
copilot/fix-gc-deadlock-issue
Sep 15, 2026
Merged

EgorBo merged 3 commits into
mainfrom
copilot/fix-gc-deadlock-issue

Conversation

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Later optimizations can remove a loop’s only intrinsic call after interruptibility is decided, leaving a partially interruptible, safepoint-free loop that hangs GC suspension.

  • Safepoint detection: Exclude IsSpecialIntrinsic calls from IsGcSafePoint, conservatively making intrinsic-only loops fully interruptible.
  • Regression coverage: Exercise small and zero-length span copies, SequenceEqual, Fill, and Clear during GC, with a large-copy control whose helper call survives.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 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: @agocke
See info in area-owners.md if you want to be subscribed.

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GC deadlock in Span.CopyTo method JIT: Keep intrinsic-only loops fully interruptible Sep 14, 2026
Copilot AI requested a review from EgorBo September 14, 2026 15:36
@EgorBo
EgorBo marked this pull request as ready for review September 14, 2026 18:25
@EgorBo
EgorBo requested review from AndyAyersMS and a lite review from Copilot September 14, 2026 18:25
@EgorBo

EgorBo commented Sep 14, 2026

Copy link
Copy Markdown
Member

Almost no diffs, slight increase in GC info as expected, since full interruptability adds size.

@azure-pipelines

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

@EgorBo

EgorBo commented Sep 14, 2026

Copy link
Copy Markdown
Member

PTAL @AndyAyersMS @dotnet/jit-contrib

Comment thread src/coreclr/jit/compiler.hpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Narrow the intrinsic check and add regression tests for the described GC scenarios.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This JIT change prevents GC suspension deadlocks in loops whose only intrinsic call is removed during lowering.

Changes:

  • Excludes special intrinsics from GC safe-point detection.
  • Treats intrinsic-only loops as fully interruptible.
File summaries
File Summary
src/coreclr/jit/compiler.hpp Updates IsGcSafePoint; review found the condition may be broader than removable intrinsics and noted missing promised regression coverage.
Review details

Suppressed comments (1)

src/coreclr/jit/compiler.hpp:3892

  • IsSpecialIntrinsic is broader than the calls that this PR's lowering can remove: the importer also marks cases such as Thread.get_CurrentThread, Array<T>.GetEnumerator, String.FastAllocateString, and math intrinsics that may be re-materialized as user calls. The relevant unrolling in LowerCall is additionally target-gated to AMD64/ARM64, but this check applies on every target. When one of these calls survives, suppressing its safe-point flag needlessly makes loops fully interruptible and increases GC-info/codegen cost; please narrow the condition to removable intrinsics/targets or justify the broader cost.
    if (!call->IsFastTailCall() && !call->IsSpecialIntrinsic())
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/coreclr/jit/compiler.hpp
@EgorBo
EgorBo enabled auto-merge (squash) September 15, 2026 21:22
@EgorBo
EgorBo merged commit 0554cde into main Sep 15, 2026
135 of 138 checks passed
@EgorBo
EgorBo deleted the copilot/fix-gc-deadlock-issue branch September 15, 2026 21:22
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT (bug): GC deadlock — method stays partially interruptible after lowering unrolls the loop's only GC safepoint (Span.CopyTo)

4 participants