Skip to content

Async Profiler: Emit the method's native code start address as the async-profiler V1 MethodID.#130420

Open
lateralusX wants to merge 7 commits into
dotnet:mainfrom
lateralusX:lateralusX/async-profiler-v1-native-ip-as-method-id
Open

Async Profiler: Emit the method's native code start address as the async-profiler V1 MethodID.#130420
lateralusX wants to merge 7 commits into
dotnet:mainfrom
lateralusX:lateralusX/async-profiler-v1-native-ip-as-method-id

Conversation

@lateralusX

Copy link
Copy Markdown
Member

Background

The async profiler's V1 (StateMachineAsync) path identifies each async frame by a method id. Until now AsyncStateMachineDiagnostics.ResolveMethodId emitted the state machine's MoveNext MethodDesc/MonoMethod pointer as that id.

That has two problems:

• Symbolication is fragile and divergent. A raw MethodDesc pointer is not an instruction pointer, so a trace consumer has to depend on EventPipe rundown events to do symbolication. That doesn't work cleanly cross-process/offline and doesn't match how any other frame gets symbolized (perfmap/ETW-EventPipe rundown/ProcessSymbol).
• Inconsistent with V2. The V2 (RuntimeAsync) path already reports continuation native IPs, which symbolicate like ordinary frames. V1 should behave the same so a single resolution path covers both.

Change

Introduce a runtime primitive to retrieve the native code start address of a method and use it as the V1 method id. V1 frames now symbolicate uniformly as native IPs - exactly like V2 continuation IPs and regular stack frames - removing the special MethodDesc -dereference path in consumers.

CoreCLR

• New QCall RuntimeMethodHandle_GetNativeCode returning PCODE .
• Managed RuntimeMethodHandle.GetNativeCodeInternal(IRuntimeMethodInfo) wrapper.

Mono

• New icall RuntimeMethodHandle.GetNativeCode returning gpointer.
• Managed RuntimeMethodHandle.GetNativeCodeInternal(IntPtr) wrapper.

Shared

•  AsyncStateMachineDiagnostics.ResolveMethodId now returns the native code start of MoveNext instead of MethodHandle.Value.

All output from runtime related to internal symbol to native code mappings emits all versions of the method to the same symbol, so that means a tier0 address will still resolve to the same symbol even if a tier1 version outdates it, the same for a re-jitted method.

Testing

• Existing async-profiler V1 tests pass on CoreCLR and Mono.
• Validated end-to-end with custom perfview TraceEvent async-profiler parser.

@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.

Pull request overview

This PR changes the async-profiler V1 (StateMachineAsync) “MethodId” from a managed method handle/pointer to the method’s native code start address, aligning it with how V2 (RuntimeAsync) and normal stack frames are symbolicated. It adds runtime primitives in both CoreCLR (QCall) and Mono (icall + runtime callback) to retrieve a method’s native code start and wires AsyncStateMachineDiagnostics.ResolveMethodId to use that value.

Changes:

  • CoreCLR: add RuntimeMethodHandle_GetNativeCode QCall returning PCODE, with managed wrapper in RuntimeMethodHandle.
  • Mono: add RuntimeMethodHandle.GetNativeCode icall and a new runtime callback to locate a method’s native code start.
  • Shared CoreLib: update AsyncStateMachineDiagnostics.ResolveMethodId to return native code start for MoveNext.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncStateMachineDiagnostics.cs Switch V1 method id resolution from method handle to native code start.
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs Add managed wrapper for the new CoreCLR QCall.
src/coreclr/vm/runtimehandles.h Declare new RuntimeMethodHandle_GetNativeCode QCall entrypoint.
src/coreclr/vm/runtimehandles.cpp Implement QCall logic to return native code start (including unboxing-stub handling).
src/coreclr/vm/qcallentrypoints.cpp Register the new QCall entrypoint.
src/mono/System.Private.CoreLib/src/System/RuntimeMethodHandle.cs Add managed InternalCall/wrapper for Mono native code lookup.
src/mono/mono/metadata/object-internals.h Add a new runtime callback for “method code start”.
src/mono/mono/mini/mini-runtime.c Implement and install the callback using existing JIT/AOT/interp lookup logic.
src/mono/mono/metadata/icall.c Implement ves_icall_RuntimeMethodHandle_GetNativeCode.
src/mono/mono/metadata/icall-def.h Register the new RuntimeMethodHandle icall.

Comment thread src/coreclr/vm/runtimehandles.cpp Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 17: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.

Pull request overview

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

Comment thread src/mono/mono/mini/mini-runtime.c
Comment thread src/mono/mono/metadata/icall.c
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 17:22

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/vm/runtimehandles.cpp Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 17:46

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 10, 2026 13:15

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

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

Copilot AI review requested due to automatic review settings July 10, 2026 14:22

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

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.

2 participants