Skip to content

Fixup CodeFragmentHeap block allocation reporting#127298

Open
hoyosjs wants to merge 2 commits intodotnet:mainfrom
hoyosjs:juhoyosa/report-trimmed-jit-size
Open

Fixup CodeFragmentHeap block allocation reporting#127298
hoyosjs wants to merge 2 commits intodotnet:mainfrom
hoyosjs:juhoyosa/report-trimmed-jit-size

Conversation

@hoyosjs
Copy link
Copy Markdown
Member

@hoyosjs hoyosjs commented Apr 22, 2026

#122274 fixed up some cases where block allocations produced code, but try to do a read of uncommitted memory. This change just makes it such that block records have the right size for range identification.

After this the settings provide the following expectations:

   DOTNET_PerfMapEnabled
     0 (default)  Disabled
     1            Perfmap text file + jitdump
     2            Jitdump only
     3            Perfmap text file only

   DOTNET_PerfMapShowOptimizationTiers
     0                 No tier info in symbol names
     1 (default)  Show optimization tiers in symbol names

   DOTNET_PerfMapStubGranularity
     Controls how stubs are reported. Bit 0 controls naming,
     bit 1 controls individual allocation site reporting.

     0 (default)  Grouped names, block-level only
                  Name format: "stub Type<Owner>"
                  Block stubs: perfmap yes, jitdump yes (no disassembly)
                  IndividualWithinBlock: not reported

     1            Unique names, block-level only
                  Name format: "stub<N> Type<Owner>"
                  Block stubs: perfmap yes, jitdump yes (no disassembly)
                  IndividualWithinBlock: not reported

     2            Grouped names, individual alloc sites
                  Name format: "stub Type<Owner>"
                  Block stubs: not reported
                  IndividualWithinBlock: perfmap yes, jitdump yes

     3            Unique names, individual alloc sites
                  Name format: "stub<N> Type<Owner>"
                  Block stubs: not reported
                  IndividualWithinBlock: perfmap yes, jitdump yes

     Individual stubs (e.g. write barriers) are always reported
     with full disassembly regardless of granularity setting.

Copilot AI review requested due to automatic review settings April 22, 2026 21:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes malformed Linux jitdump JIT_CODE_LOAD records emitted for block-level stub allocations when DOTNET_PerfMapStubGranularity is 0 or 1, by avoiding emitting jitdump records that would require unreadable/uninitialized code bytes. This preserves perfmap text output while preventing jitdump parser corruption.

Changes:

  • Remove the reportCodeBlock flag from PAL_PerfJitDump_LogMethod and always write code_size bytes when a jitdump record is emitted.
  • Skip emitting jitdump records for block-level stub allocations (still emit perfmap text entries).
  • Adjust CodeFragmentHeap stub-block reporting timing for newly allocated blocks.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/vm/perfmap.cpp Stops emitting jitdump entries for block stub allocations; updates jitdump logging call sites for methods/stubs to new signature.
src/coreclr/vm/codeman.cpp Moves ReportStubBlock call to after size bookkeeping for new fragment blocks.
src/coreclr/pal/src/misc/perfjitdump.cpp Simplifies jitdump record emission: removes reportCodeBlock and always appends code_size bytes.
src/coreclr/pal/inc/pal.h Updates the PAL API signature for PAL_PerfJitDump_LogMethod.

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

@noahfalk
Copy link
Copy Markdown
Member

fyi @tommcdon who worked on the previous iteration of fixing this

@hoyosjs hoyosjs marked this pull request as draft April 22, 2026 21:51
@hoyosjs hoyosjs added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 22, 2026
@hoyosjs
Copy link
Copy Markdown
Member Author

hoyosjs commented Apr 22, 2026

I got a bit more context about the intention of the settings from David. There's a few more bugs lurking here. Going to try to get one more round of fixes.

@davidwrighton
Copy link
Copy Markdown
Member

Yeah, the intention is to actually report these regions, so they can be visible in a Perf trace. I'm not sure not emitting a jitdump record is the right thing here.

@hoyosjs hoyosjs force-pushed the juhoyosa/report-trimmed-jit-size branch from 6e441b5 to 6ba8003 Compare April 22, 2026 22:27
@hoyosjs hoyosjs changed the title Fixup CodeFragmentHeap allocation perfmap reporting Fixup CodeFragmentHeap block allocation reporting Apr 22, 2026
Copilot AI review requested due to automatic review settings April 22, 2026 23:19
@hoyosjs hoyosjs marked this pull request as ready for review April 22, 2026 23:19
@hoyosjs hoyosjs removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts CoreCLR perfmap/jitdump stub reporting so stub-block entries better reflect the committed/usable ranges and unique stub names are generated safely under concurrency, aligning with the stub granularity expectations described in the PR.

Changes:

  • Make stub unique-name generation use an atomic increment instead of a plain ++.
  • Move ReportStubBlock to after block splitting so the reported size matches the portion retained/used.
  • Update the s_StubsMapped member intent/comment to reflect its role as a naming counter.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/vm/perfmap.h Changes stub-name counter declaration/comment.
src/coreclr/vm/perfmap.cpp Switches unique stub naming to InterlockedIncrement.
src/coreclr/vm/codeman.cpp Reports stub-block allocation after adjusting dwSize to avoid over-reporting the range.

Comment thread src/coreclr/vm/perfmap.h Outdated
Comment thread src/coreclr/vm/perfmap.cpp
dwSize -= dwRemaining;
}

ReportStubBlock(pMem, dwSize, m_kind);
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.

Could we end up double reporting blocks if we don't call AllocCodeFragmentBlock?

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 can end up grabbing it from the best fit path - that but since that got aligned down and returned during the if block right above this, that would cound as a separate block and should be reported separately

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.

6 participants