Skip to content

Report CoreCLR Write Barriers And Code-Heap Stubs In Traces - #132190

Open
brianrob wants to merge 13 commits into
dotnet:mainfrom
brianrob:brianrob-coreclr-etw-stub-reporting
Open

Report CoreCLR Write Barriers And Code-Heap Stubs In Traces#132190
brianrob wants to merge 13 commits into
dotnet:mainfrom
brianrob:brianrob-coreclr-etw-stub-reporting

Conversation

@brianrob

@brianrob brianrob commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

Improve symbol coverage for executable code generated outside normal JIT methods. This is in response to an internal customer that is capturing traces where large percentages of symbols are unresolvable and don't resolve to a module. Upon investigation, these symbols should resolve to the copied write barrier or one of several different kinds of stubs.

Coverage

Executable range Live ETW/EventPipe Capture state and rundown Live PerfMap On-demand PerfMap
Copied write barriers Existing: emitted before tracing-provider initialization. This PR: moves reporting after initialization and preserves individual names and explicit sizes. This PR: reports individual ranges through MethodUnloadVerbose, MethodDCStartVerbose, and MethodDCEndVerbose. This PR: reports individual named ranges. This PR: replays individual named ranges.
EEJitManager jump/code-fragment blocks This PR: reports blocks through MethodLoadVerbose. This PR: reports blocks through MethodUnloadVerbose, MethodDCStartVerbose, and MethodDCEndVerbose. Existing: reports blocks or individual allocations according to DOTNET_PerfMapStubGranularity. This PR: replays blocks regardless of live block/individual granularity.
Individual symbols within EEJitManager blocks Existing: no individual or block events. This PR: reports one event for the allocation block containing the stubs. Existing: no individual or block replay. This PR: replays the allocation block containing the stubs. Existing: reports individual symbols where instrumented. This PR: no change. Existing: no replay. This PR: reports the allocation block because individual symbols cannot be reconstructed.

On-demand PerfMap generation uses blocks because individual allocations cannot be reconstructed during enumeration.

All ETW/EventPipe entries use JitHelperMethod metadata.

Implementation Notes

CodeHeapIterator now snapshots each heap’s end and uses per-heap lookahead to produce bounded, non-overlapping stub ranges. Jump-stub sizes use their existing allocation metadata; other code-fragment blocks use the bounded allocation extent.

Copied write-barrier reporting derives targets from the configured JIT helper table.

This does not change stub layout, allocation size, alignment, CodeHeader adjacency, DAC contracts, or jump reachability.

Note

This pull request description was created with GitHub Copilot.

brianrob and others added 3 commits August 6, 2026 13:19
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Copilot AI lite review requested due to automatic review settings August 12, 2026 00:23

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.

Pull request overview

This PR expands runtime symbol reporting for executable code that’s generated/allocated outside normal JITted methods, so tracing consumers can attribute those code ranges in ETW/EventPipe and PerfMap outputs. It does this by emitting helper-style method events for copied write barriers and code-heap stub/code-fragment blocks, and by improving CodeHeapIterator’s ability to surface bounded stub ranges during enumeration/rundown.

Changes:

  • Add reporting/enumeration of copied write-barrier code ranges for ETW enumeration and PerfMap (including replay during method enumeration).
  • Teach CodeHeapIterator to identify stub code blocks and provide bounded sizes + kinds for logging.
  • Extend the EventPipe rundown validation test to generate VSD activity and validate helper events appear in live + rundown streams.
Show a summary per file
File Description
src/tests/tracing/eventpipe/rundownvalidation/rundownvalidation.cs Generates VSD activity and validates helper-style stub/write-barrier events appear in live + rundown method events.
src/coreclr/vm/threads.h Renames/init entrypoint and adds declarations for copied write-barrier reporting helpers.
src/coreclr/vm/threads.cpp Implements enumeration/reporting of copied write barriers to PerfMap and ETW enumeration.
src/coreclr/vm/perfmap.cpp Emits copied write barriers and stub-block ranges when generating an on-demand PerfMap.
src/coreclr/vm/eventtrace.cpp Extends helper event emission to support different enumeration event types and reports stub blocks + copied write barriers during enumeration.
src/coreclr/vm/dynamicmethod.cpp Ensures heap list entries for host code heaps carry a loader allocator pointer for filtered iteration.
src/coreclr/vm/codeman.h Adds wide-string stub-kind names, stub-kind/size accessors on CodeHeapIterator, and moves small-block threshold to a shared constant.
src/coreclr/vm/codeman.cpp Updates CodeHeapIterator to snapshot heap ends, identify stub code blocks, and report stub blocks via PerfMap + ETW helper events.
src/coreclr/vm/ceemain.cpp Calls the new tracing-data initializer during startup.
src/coreclr/inc/eventtracebase.h Updates/moves SendHelperEvent declaration to support passing enumeration options.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 0
  • Review effort level: Lite

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Copilot AI review requested due to automatic review settings August 12, 2026 01:33

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.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/coreclr/vm/codeman.cpp Outdated
@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.

brianrob and others added 3 commits August 12, 2026 12:19
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Copilot AI review requested due to automatic review settings August 12, 2026 22:56

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Copilot AI review requested due to automatic review settings August 13, 2026 00:50

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brianrob

Copy link
Copy Markdown
Member Author

/azp run runtime

Note

This rerun request was generated by GitHub Copilot after Build Analysis identified unrelated infrastructure timeouts and known test failures.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
@brianrob

Copy link
Copy Markdown
Member Author

/ba-g Clean rerun reproduced unrelated known failures #131925 and #132030 plus a transient NuGet CDN DNS resolution failure; this PR's CoreCLR build passed locally.

Note

This Build Analysis override rationale was generated by GitHub Copilot.

@brianrob
brianrob marked this pull request as ready for review August 13, 2026 17:14
@brianrob
brianrob requested review from a team, Copilot and jkotas August 13, 2026 17:14
@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.

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.

Review details

Suppressed comments (1)

src/tests/tracing/eventpipe/rundownvalidation/rundownvalidation.cs:111

  • The test currently requires write-barrier helper events to be present and valid (ValidateHelperEvents(rundownWriteBarriers)), but copied write barriers are not necessarily enabled. In CoreCLR, write-barrier copying is gated by CLRConfig::UNSUPPORTED_UseGCWriteBarrierCopy and defaults to disabled (src/coreclr/vm/eeconfig.cpp:110 sets fIsWriteBarrierCopyEnabled = false; src/coreclr/vm/eeconfig.cpp:531 sets it based on the config switch). When the copy is disabled, ReportCopiedWriteBarriers* won’t emit any helper events, rundownWriteBarriers stays empty, and this test will fail on otherwise-correct builds.

Consider validating write-barrier helpers only when the events are actually present (or otherwise gating the expectation on a detectable condition).

                bool hasValidCoreClrHelpers =
                    !PlatformDetection.IsCoreCLR ||
                    !RuntimeFeature.IsDynamicCodeCompiled ||
                    (ValidateHelperEvents(liveStubBlocks) &&
                        ValidateHelperEvents(rundownStubBlocks) &&
                        ValidateHelperEvents(rundownWriteBarriers) &&
                        HaveMatchingStubBlocks(liveStubBlocks, rundownStubBlocks));
  • Files reviewed: 11/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@davidwrighton

Copy link
Copy Markdown
Member

LGTM, but I want @hoyosjs to review as well before signoff.

@brianrob
brianrob requested a review from hoyosjs August 14, 2026 18:49
blockWriterHolder.GetRW()->m_used = 0;
blockWriterHolder.GetRW()->m_allocated = numJumps;
if (pMD && pMD->IsLCGMethod())
blockWriterHolder.GetRW()->SetHostCodeHeap(static_cast<HostCodeHeap*>(pCodeHeap->pHeap));

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.

These LCG jump-stub blocks now receive a load event below, but LCGMethodResolver::TryDestroyCodeHeapMemory frees them without emitting an unload event.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. Fixed.

PRECONDITION(ulHelperSize != 0);
} CONTRACTL_END;

EX_TRY

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.

Now that this is folder to SendHelperEvent - I don't see any explicit trycatch and no guard for ETW_TRACING_CATEGORY_ENABLED, so the ngen keyword (not just the jit keyword) also enable these. If anything at least a comment would help to see why this is not consistent with all other methods.

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.

That being said - the GC barrier and the VSD stubs to get used regardless of jit. This now feelds more correct

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right - I didn't intentionally remove the function that's responsible for the try/catch block. I do want to keep the tracing category check out though because we're not generating any expensive strings, and we do want these to show up regardless of which keyword (JIT or NGEN) initializes them.

I've updated the PR to fix-up the API boundary between ETW::MethodLog and the rest of the VM call sites.

brianrob and others added 2 commits August 14, 2026 16:28
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8ec89d46-dd0a-4373-8c4b-9ccdabfdecc2
Copilot AI review requested due to automatic review settings August 16, 2026 20:45

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.

Review details

  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/tests/tracing/eventpipe/rundownvalidation/rundownvalidation.cs
@brianrob

Copy link
Copy Markdown
Member Author

/ba-g Current failures are unrelated known test failures: HttpListener timeout #132336 on both Windows checked legs, browser-Wasm bestfit-finalize #132107, and browser-Wasm ContextualReflection preemptive-GC assertion #131925. The affected tests and subsystems are outside this PR's ETW/stub changes.

Note

This Build Analysis override rationale was generated by GitHub Copilot.

@brianrob

Copy link
Copy Markdown
Member Author

@hoyosjs this one should be ready for review again. Thanks.

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.

5 participants