Skip to content

Fix allocation-by-class profiler cache ownership - #134390

Merged
rcj1 merged 1 commit into
dotnet:mainfrom
rcj1:fix-134241-profiler-cache
Oct 5, 2026
Merged

rcj1 merged 1 commit into
dotnet:mainfrom
rcj1:fix-134241-profiler-cache

Conversation

@rcj1

@rcj1 rcj1 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Make the reusable allocation-by-class data block instance-owned so notification profiler teardown cannot free an active profiler's heap-walk state. Fixes #134241

Make the reusable allocation-by-class data block instance-owned so notification profiler teardown cannot free an active profiler's heap-walk state. Also release the outer data block during profiler destruction.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a3b2fca2-9dfc-47f3-a74a-cb0710028843
Copilot AI lite review requested due to automatic review settings September 22, 2026 01:24
@rcj1
rcj1 requested review from hoyosjs and lateralusX September 22, 2026 01:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 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: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

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.

Copilot review overview

🟡 Changes recommended

No regression test covers concurrent GC reporting with notification-profiler failure or teardown.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR fixes a CoreCLR profiler lifetime race by making allocation-by-class scratch storage instance-owned instead of process-global.

Changes:

  • Converts the cache pointer to an instance member.
  • Initializes and cleans up each profiler’s cache independently.
  • Preserves cache reuse and heap-walk context.
File Description
src/​coreclr/​vm/​eetoprofinterfaceimpl.h Declares per-profiler cache ownership.
src/​coreclr/​vm/​eetoprofinterfaceimpl.cpp Initializes, uses, and frees the instance-owned cache.

Copilot AI review requested due to automatic review settings September 22, 2026 01:43

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.

Copilot review overview

🟡 Changes recommended

The regression test may pass while reading freed arrays, so it does not deterministically detect the original lifetime bug.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 22, 2026 02:10

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.

Copilot review overview

🟡 Changes recommended

The regression test can falsely fail on legitimate cache growth and does not deterministically exercise the freed-buffer lifetime violation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
Resolved since last review (1)

@lateralusX lateralusX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The runtime fix looks good to me. Making the cache instance-owned addresses the lifetime mismatch directly, and deleting the outer AllocByClassData block completes the cleanup.

I suggest keeping this PR focused on that fix and removing the new test and its supporting helpers/exports. I have two concerns with the current test:

  • ValidateAllocationByClassCache checks callback-buffer identity, not cache lifetime. Legitimate buffer growth can change those addresses, while allocator reuse means unchanged addresses do not prove that the storage was never freed.
  • The verification phases advance on successive GC callbacks rather than explicit attach/teardown milestones. Automatic collections can therefore advance the state early, including completing the “after teardown” check before teardown has completed.

The test does provide an indirect check for the constructor resetting the shared cache, but its additional machinery and timing assumptions make it difficult to maintain as reliable coverage. I would not add runtime test hooks solely to make this scenario deterministic.

@rcj1
rcj1 force-pushed the fix-134241-profiler-cache branch from 2dd6c48 to eb2e3ea Compare September 30, 2026 15:38

@lateralusX lateralusX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@rcj1
rcj1 merged commit 8e6821d into dotnet:main Oct 5, 2026
114 checks passed
@rcj1
rcj1 deleted the fix-134241-profiler-cache branch October 5, 2026 17:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 6, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification-profiler teardown can corrupt allocation-by-class GC reporting

3 participants