Repository navigation
Fix allocation-by-class profiler cache ownership - #134390
Conversation
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
|
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. |
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
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
Resolved since last review (1)
There was a problem hiding this comment.
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
Open (2)
Resolved since last review (1)
lateralusX
left a comment
There was a problem hiding this comment.
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:
ValidateAllocationByClassCachechecks 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.
2dd6c48 to
eb2e3ea
Compare

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