Skip to content

Implement getFunctionEntryPoint for runtime-async R2R compilation#7

Open
jtschuster wants to merge 1 commit intoruntime16from
UseGetFunctionEntrypoint
Open

Implement getFunctionEntryPoint for runtime-async R2R compilation#7
jtschuster wants to merge 1 commit intoruntime16from
UseGetFunctionEntrypoint

Conversation

@jtschuster
Copy link
Owner

Runtime-async methods call into AsyncHelpers (CaptureContexts, RestoreContexts, etc.) via method handles returned by getAsyncInfo. Previously, crossgen2's getFunctionEntrypoint created a delay-load import for these calls, but only updateEntryPointForTailCall (PR dotnet#56669) actually had jumpable thunk support, so when the JIT called this getFunctionEntryPoint for jmp instructions, those calls failed (see callconv3_d jit test).

This change removes the CORINFO_HELP_ASYNC_* JIT helper infrastructure and instead routes all async helper calls through getFunctionEntrypoint with standard (non-jumpable) delay-load imports.

JIT changes (async.cpp):

  • Replace gtNewHelperCallNode(CORINFO_HELP_ASYNC_*) with gtNewCallNode(CT_USER_FUNC, methHnd) for all 7 async helper call sites (CaptureContexts, RestoreContexts, CaptureContinuationContext, CaptureExecutionContext, RestoreContextsOnSuspension, RestoreExecutionContext)
  • Call getFunctionEntrypoint + setEntryPoint on each call node under FEATURE_READYTORUN so fgMorphArgs adds the R2R indirection cell arg (x11 on ARM64, found from return address on x64).

JIT changes (codegenxarch.cpp):

  • In GT_JMP epilog, call updateEntryPointForTailCall to upgrade the import to a jumpable thunk, which will cause the JIT to load rax with the indirection cell address. This is necessary for jmps targeting delayload imports because jmp has no return address for the standard x64 thunk to decode. This is similar to what was necessary for tail calls.

Crossgen2 changes (CorInfoImpl.ReadyToRun.cs):

  • Use regular DelayLoadMethodImport for calls to getFunctionEntrypoint. The JIT's GT_JMP codegen calls updateEntryPointForTailCall when needed to get a jumpable import.

NativeAOT scanner fix (ILImporter.Scanner.cs):

  • Fix incorrect method names (AsyncCaptureExecutionContext -> CaptureExecutionContext, etc.) in dependency tracking.

R2RDump fix (CoreDisTools.cs):

  • Handle ARM64 BL instructions targeting async resumption stubs, which are separate RuntimeFunctions not listed in the target method's collection. Replace Debug.Fail for now until we decide we want to move forward with this design.

Removed CORINFO_HELP_ASYNC_* helpers from corinfo.h, jithelpers.h, readytorun.h, readytorunhelpers.h, utils.cpp, ReadyToRunConstants.cs, CorInfoHelpFunc.cs, JitHelper.cs, ReadyToRunSignature.cs, and CorInfoImpl.RyuJit.cs.

Runtime-async methods call into AsyncHelpers (CaptureContexts,
RestoreContexts, etc.) via method handles returned by getAsyncInfo.
Previously, crossgen2's getFunctionEntrypoint created a jumpable
delay-load import for these calls, but only updateEntryPointForTailCall
(PR dotnet#56669) actually had jumpable thunk support, so these calls failed.

This change removes the unused CORINFO_HELP_ASYNC_* JIT helper
infrastructure and instead routes all async helper calls through
getFunctionEntrypoint with standard (non-jumpable) delay-load imports.

JIT changes (async.cpp):
- Replace gtNewHelperCallNode(CORINFO_HELP_ASYNC_*) with
 gtNewCallNode(CT_USER_FUNC, methHnd) for all 7 async helper call
 sites (CaptureContexts, RestoreContexts, CaptureContinuationContext,
 CaptureExecutionContext, RestoreContextsOnSuspension,
 RestoreExecutionContext)
- Call getFunctionEntrypoint + setEntryPoint on each call node under
 FEATURE_READYTORUN so fgMorphArgs adds the R2R indirection cell arg
 (x11 on ARM64, found from return address on x64)

JIT changes (codegenxarch.cpp):
- In GT_JMP epilog, call updateEntryPointForTailCall to upgrade the
 import to a jumpable thunk, then always load rax with the cell
 address. This is required because jmp has no return address for the
 standard thunk to decode.

Crossgen2 changes (CorInfoImpl.ReadyToRun.cs):
- Set isJumpableImportRequired to false in getFunctionEntrypoint. The
 JIT's GT_JMP codegen calls updateEntryPointForTailCall when needed.
- Remove CORINFO_HELP_ASYNC_* cases from GetHelperFtnUncached.

NativeAOT scanner fix (ILImporter.Scanner.cs):
- Fix incorrect method names (AsyncCaptureExecutionContext ->
 CaptureExecutionContext, etc.) in dependency tracking.

R2RDump fix (CoreDisTools.cs):
- Handle ARM64 BL instructions targeting async resumption stubs, which
 are separate RuntimeFunctions not listed in the target method's
 collection. Replace Debug.Fail with graceful fallthrough.

Removed CORINFO_HELP_ASYNC_* infrastructure from corinfo.h,
jithelpers.h, readytorun.h, readytorunhelpers.h, utils.cpp,
ReadyToRunConstants.cs, CorInfoHelpFunc.cs, JitHelper.cs,
ReadyToRunSignature.cs, and CorInfoImpl.RyuJit.cs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant