From e8ef453f9b1fa8c9ce3b15eb9266308cffac2be6 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 17 Oct 2025 14:48:38 -0700 Subject: [PATCH 1/3] Implement getAsyncInfo in ILCompiler --- .../tools/Common/JitInterface/CorInfoImpl.cs | 28 ++++++++++++++++++- .../tools/Common/JitInterface/CorInfoTypes.cs | 16 +++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index ab43b57640a4a5..af5ac763cc4cb6 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3358,7 +3358,33 @@ private void getEEInfo(ref CORINFO_EE_INFO pEEInfoOut) private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut) { - throw new NotImplementedException(); + DefType continuation = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "Continuation"u8); + pAsyncInfoOut.continuationClsHnd = ObjectToHandle(continuation); + // 'Next' field + pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetField("Next"u8)); + // 'Resume' field + pAsyncInfoOut.continuationResumeFldHnd = ObjectToHandle(continuation.GetField("Resume"u8)); + // 'State' field + pAsyncInfoOut.continuationStateFldHnd = ObjectToHandle(continuation.GetField("State"u8)); + // 'Flags' field + pAsyncInfoOut.continuationFlagsFldHnd = ObjectToHandle(continuation.GetField("Flags"u8)); + // 'Data' field + pAsyncInfoOut.continuationDataFldHnd = ObjectToHandle(continuation.GetField("Data"u8)); + // 'GCData' field + pAsyncInfoOut.continuationGCDataFldHnd = ObjectToHandle(continuation.GetField("Data"u8)); + // Whether or not the continuation needs to be allocated through the + // helper that also takes a method handle + pAsyncInfoOut.continuationsNeedMethodHandle = false; + DefType asyncHelpers = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8); + DefType executionContext = MethodBeingCompiled.Context.SystemModule.GetType("System.Threading"u8, "ExecutionContext"u8); + DefType @void = MethodBeingCompiled.Context.GetWellKnownType(WellKnownType.Void); + // Method handle for AsyncHelpers.CaptureExecutionContext + pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureExecutionContext"u8, null)); + // Method handle for AsyncHelpers.RestoreExecutionContext + pAsyncInfoOut.restoreExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("RestoreExecutionContext"u8, null)); + pAsyncInfoOut.captureContinuationContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureContinuationContext"u8, null)); + pAsyncInfoOut.captureContextsMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureContexts"u8, null)); + pAsyncInfoOut.restoreContextsMethHnd = ObjectToHandle(asyncHelpers.GetMethod("RestoreContexts"u8, null)); } private mdToken getMethodDefFromMethod(CORINFO_METHOD_STRUCT_* hMethod) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index f2688c585b0e52..d8dd7e9685e460 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -878,10 +878,26 @@ public unsafe struct CORINFO_ASYNC_INFO public CORINFO_CLASS_STRUCT_* continuationClsHnd; // 'Next' field public CORINFO_FIELD_STRUCT_* continuationNextFldHnd; + // 'Resume' field + public CORINFO_FIELD_STRUCT_* continuationResumeFldHnd; + // 'State' field + public CORINFO_FIELD_STRUCT_* continuationStateFldHnd; + // 'Flags' field + public CORINFO_FIELD_STRUCT_* continuationFlagsFldHnd; // 'Data' field public CORINFO_FIELD_STRUCT_* continuationDataFldHnd; // 'GCData' field public CORINFO_FIELD_STRUCT_* continuationGCDataFldHnd; + // Whether or not the continuation needs to be allocated through the + // helper that also takes a method handle + public bool continuationsNeedMethodHandle; // byte? + // Method handle for AsyncHelpers.CaptureExecutionContext + public CORINFO_METHOD_STRUCT_* captureExecutionContextMethHnd; + // Method handle for AsyncHelpers.RestoreExecutionContext + public CORINFO_METHOD_STRUCT_* restoreExecutionContextMethHnd; + public CORINFO_METHOD_STRUCT_* captureContinuationContextMethHnd; + public CORINFO_METHOD_STRUCT_* captureContextsMethHnd; + public CORINFO_METHOD_STRUCT_* restoreContextsMethHnd; } // Flags passed from JIT to runtime. From 0cf52dcbf140897696341e9b9313e6177c8d15a0 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 17 Oct 2025 15:52:04 -0700 Subject: [PATCH 2/3] Update src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index af5ac763cc4cb6..3df47ba887b672 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3371,7 +3371,7 @@ private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut) // 'Data' field pAsyncInfoOut.continuationDataFldHnd = ObjectToHandle(continuation.GetField("Data"u8)); // 'GCData' field - pAsyncInfoOut.continuationGCDataFldHnd = ObjectToHandle(continuation.GetField("Data"u8)); + pAsyncInfoOut.continuationGCDataFldHnd = ObjectToHandle(continuation.GetField("GCData"u8)); // Whether or not the continuation needs to be allocated through the // helper that also takes a method handle pAsyncInfoOut.continuationsNeedMethodHandle = false; From a728fdb7cf03690d5615d0ae5c620a0a57dbdc22 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 19 Oct 2025 12:29:04 -0700 Subject: [PATCH 3/3] Use new CORINFO_ASYNC_INFO, PR Feedback --- .../tools/Common/JitInterface/CorInfoImpl.cs | 38 ++++++------------- .../tools/Common/JitInterface/CorInfoTypes.cs | 7 ---- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index e212d1bd9cf689..4e574ed7641083 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3358,33 +3358,19 @@ private void getEEInfo(ref CORINFO_EE_INFO pEEInfoOut) private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut) { - DefType continuation = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "Continuation"u8); + DefType continuation = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices"u8, "Continuation"u8); pAsyncInfoOut.continuationClsHnd = ObjectToHandle(continuation); - // 'Next' field - pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetField("Next"u8)); - // 'Resume' field - pAsyncInfoOut.continuationResumeFldHnd = ObjectToHandle(continuation.GetField("Resume"u8)); - // 'State' field - pAsyncInfoOut.continuationStateFldHnd = ObjectToHandle(continuation.GetField("State"u8)); - // 'Flags' field - pAsyncInfoOut.continuationFlagsFldHnd = ObjectToHandle(continuation.GetField("Flags"u8)); - // 'Data' field - pAsyncInfoOut.continuationDataFldHnd = ObjectToHandle(continuation.GetField("Data"u8)); - // 'GCData' field - pAsyncInfoOut.continuationGCDataFldHnd = ObjectToHandle(continuation.GetField("GCData"u8)); - // Whether or not the continuation needs to be allocated through the - // helper that also takes a method handle - pAsyncInfoOut.continuationsNeedMethodHandle = false; - DefType asyncHelpers = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8); - DefType executionContext = MethodBeingCompiled.Context.SystemModule.GetType("System.Threading"u8, "ExecutionContext"u8); - DefType @void = MethodBeingCompiled.Context.GetWellKnownType(WellKnownType.Void); - // Method handle for AsyncHelpers.CaptureExecutionContext - pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureExecutionContext"u8, null)); - // Method handle for AsyncHelpers.RestoreExecutionContext - pAsyncInfoOut.restoreExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("RestoreExecutionContext"u8, null)); - pAsyncInfoOut.captureContinuationContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureContinuationContext"u8, null)); - pAsyncInfoOut.captureContextsMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureContexts"u8, null)); - pAsyncInfoOut.restoreContextsMethHnd = ObjectToHandle(asyncHelpers.GetMethod("RestoreContexts"u8, null)); + pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetKnownField("Next"u8)); + pAsyncInfoOut.continuationResumeFldHnd = ObjectToHandle(continuation.GetKnownField("Resume"u8)); + pAsyncInfoOut.continuationStateFldHnd = ObjectToHandle(continuation.GetKnownField("State"u8)); + pAsyncInfoOut.continuationFlagsFldHnd = ObjectToHandle(continuation.GetKnownField("Flags"u8)); + DefType asyncHelpers = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8); + DefType executionContext = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Threading"u8, "ExecutionContext"u8); + pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("CaptureExecutionContext"u8, null)); + pAsyncInfoOut.restoreExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("RestoreExecutionContext"u8, null)); + pAsyncInfoOut.captureContinuationContextMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("CaptureContinuationContext"u8, null)); + pAsyncInfoOut.captureContextsMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("CaptureContexts"u8, null)); + pAsyncInfoOut.restoreContextsMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("RestoreContexts"u8, null)); } private CORINFO_CLASS_STRUCT_* getContinuationType(nuint dataSize, ref bool objRefs, nuint objRefsSize) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index d8dd7e9685e460..ff37fc2f9bc60b 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -884,13 +884,6 @@ public unsafe struct CORINFO_ASYNC_INFO public CORINFO_FIELD_STRUCT_* continuationStateFldHnd; // 'Flags' field public CORINFO_FIELD_STRUCT_* continuationFlagsFldHnd; - // 'Data' field - public CORINFO_FIELD_STRUCT_* continuationDataFldHnd; - // 'GCData' field - public CORINFO_FIELD_STRUCT_* continuationGCDataFldHnd; - // Whether or not the continuation needs to be allocated through the - // helper that also takes a method handle - public bool continuationsNeedMethodHandle; // byte? // Method handle for AsyncHelpers.CaptureExecutionContext public CORINFO_METHOD_STRUCT_* captureExecutionContextMethHnd; // Method handle for AsyncHelpers.RestoreExecutionContext