diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 729bbca700c1e4..53fea8196fdb9c 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -598,13 +598,6 @@ enum CorInfoHelpFunc CORINFO_HELP_ALLOC_CONTINUATION_METHOD, CORINFO_HELP_ALLOC_CONTINUATION_CLASS, - CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS, - CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, - CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT, - CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT, - CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION, - CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT, - CORINFO_HELP_COUNT, }; diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index ff98e3a450d397..4ea275c055a02f 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -356,13 +356,6 @@ DYNAMICJITHELPER(CORINFO_HELP_ALLOC_CONTINUATION_METHOD, NULL, METHOD__ASYNC_HELPERS__ALLOC_CONTINUATION_METHOD) DYNAMICJITHELPER(CORINFO_HELP_ALLOC_CONTINUATION_CLASS, NULL, METHOD__ASYNC_HELPERS__ALLOC_CONTINUATION_CLASS) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS, NULL, METHOD__ASYNC_HELPERS__CAPTURE_CONTEXTS) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, NULL, METHOD__ASYNC_HELPERS__RESTORE_CONTEXTS) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT, NULL, METHOD__ASYNC_HELPERS__CAPTURE_EXECUTION_CONTEXT) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT, NULL, METHOD__ASYNC_HELPERS__RESTORE_EXECUTION_CONTEXT) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION, NULL, METHOD__ASYNC_HELPERS__RESTORE_CONTEXTS_ON_SUSPENSION) - DYNAMICJITHELPER(CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT, NULL, METHOD__ASYNC_HELPERS__CAPTURE_CONTINUATION_CONTEXT) - #undef JITHELPER #undef DYNAMICJITHELPER #undef JITHELPER diff --git a/src/coreclr/inc/readytorun.h b/src/coreclr/inc/readytorun.h index 6cef4f725df22a..3cf688dfe445b5 100644 --- a/src/coreclr/inc/readytorun.h +++ b/src/coreclr/inc/readytorun.h @@ -478,12 +478,6 @@ enum ReadyToRunHelper READYTORUN_HELPER_AllocContinuation = 0x120, READYTORUN_HELPER_AllocContinuationClass = 0x121, READYTORUN_HELPER_AllocContinuationMethod = 0x122, - READYTORUN_HELPER_AsyncCaptureContexts = 0x123, - READYTORUN_HELPER_AsyncRestoreContexts = 0x124, - READYTORUN_HELPER_AsyncCaptureExecutionContext = 0x125, - READYTORUN_HELPER_AsyncRestoreExecutionContext = 0x126, - READYTORUN_HELPER_AsyncRestoreContextsOnSuspension = 0x127, - READYTORUN_HELPER_AsyncCaptureContinuationContext = 0x128, }; #include "readytoruninstructionset.h" diff --git a/src/coreclr/inc/readytorunhelpers.h b/src/coreclr/inc/readytorunhelpers.h index f0f4a3d7c5ce7c..35ff922e413a6d 100644 --- a/src/coreclr/inc/readytorunhelpers.h +++ b/src/coreclr/inc/readytorunhelpers.h @@ -129,13 +129,6 @@ HELPER(READYTORUN_HELPER_GetCurrentManagedThreadId, CORINFO_HELP_GETCURRENTMANAG HELPER(READYTORUN_HELPER_AllocContinuation, CORINFO_HELP_ALLOC_CONTINUATION, ) HELPER(READYTORUN_HELPER_AllocContinuationClass, CORINFO_HELP_ALLOC_CONTINUATION_CLASS, ) HELPER(READYTORUN_HELPER_AllocContinuationMethod, CORINFO_HELP_ALLOC_CONTINUATION_METHOD, ) -HELPER(READYTORUN_HELPER_AsyncCaptureContexts, CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS, ) -HELPER(READYTORUN_HELPER_AsyncRestoreContexts, CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, ) -HELPER(READYTORUN_HELPER_AsyncCaptureExecutionContext, CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT, ) -HELPER(READYTORUN_HELPER_AsyncRestoreExecutionContext, CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT, ) -HELPER(READYTORUN_HELPER_AsyncRestoreContextsOnSuspension, CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION, ) -HELPER(READYTORUN_HELPER_AsyncCaptureContinuationContext, CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT, ) - HELPER(READYTORUN_HELPER_InitClass, CORINFO_HELP_INITCLASS, ) HELPER(READYTORUN_HELPER_InitInstClass, CORINFO_HELP_INITINSTCLASS, ) diff --git a/src/coreclr/jit/async.cpp b/src/coreclr/jit/async.cpp index 0ee852554a55f1..4b5f252e36d250 100644 --- a/src/coreclr/jit/async.cpp +++ b/src/coreclr/jit/async.cpp @@ -163,13 +163,24 @@ PhaseStatus Compiler::SaveAsyncContexts() // For OSR, we did this in the tier0 method. if (!opts.IsOSR()) { - GenTreeCall* captureCall = gtNewHelperCallNode(CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS, TYP_VOID); + GenTreeCall* captureCall = gtNewCallNode(CT_USER_FUNC, asyncInfo->captureContextsMethHnd, TYP_VOID); captureCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclAddrNode(lvaAsyncSynchronizationContextVar, 0))); captureCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclAddrNode(lvaAsyncExecutionContextVar, 0))); lvaGetDesc(lvaAsyncSynchronizationContextVar)->lvHasLdAddrOp = true; lvaGetDesc(lvaAsyncExecutionContextVar)->lvHasLdAddrOp = true; +#ifdef FEATURE_READYTORUN + CORINFO_CONST_LOOKUP captureEntryPoint; + info.compCompHnd->getFunctionEntryPoint(asyncInfo->captureContextsMethHnd, &captureEntryPoint); + captureCall->setEntryPoint(captureEntryPoint); +#endif + + CORINFO_CALL_INFO callInfo = {}; + callInfo.hMethod = captureCall->gtCallMethHnd; + callInfo.methodFlags = info.compCompHnd->getMethodAttribs(callInfo.hMethod); + impMarkInlineCandidate(captureCall, MAKE_METHODCONTEXT(callInfo.hMethod), false, &callInfo, compInlineContext); + Statement* captureStmt = fgNewStmtFromTree(captureCall); fgInsertStmtAtBeg(fgFirstBB, captureStmt); @@ -191,12 +202,20 @@ PhaseStatus Compiler::SaveAsyncContexts() resumed = gtNewOperNode(GT_NE, TYP_INT, continuation, null); } - GenTreeCall* restoreCall = gtNewHelperCallNode(CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, TYP_VOID); + GenTreeCall* restoreCall = gtNewCallNode(CT_USER_FUNC, asyncInfo->restoreContextsMethHnd, TYP_VOID); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncSynchronizationContextVar, TYP_REF))); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncExecutionContextVar, TYP_REF))); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(resumed)); +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP restoreEntryPoint; + info.compCompHnd->getFunctionEntryPoint(asyncInfo->restoreContextsMethHnd, &restoreEntryPoint); + restoreCall->setEntryPoint(restoreEntryPoint); + } +#endif + Statement* restoreStmt = fgNewStmtFromTree(restoreCall); fgInsertStmtAtEnd(faultBB, restoreStmt); @@ -357,12 +376,26 @@ BasicBlock* Compiler::CreateReturnBB(unsigned* mergedReturnLcl) resumed = gtNewOperNode(GT_NE, TYP_INT, continuation, null); } - GenTreeCall* restoreCall = gtNewHelperCallNode(CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, TYP_VOID); + GenTreeCall* restoreCall = gtNewCallNode(CT_USER_FUNC, asyncInfo->restoreContextsMethHnd, TYP_VOID); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncSynchronizationContextVar, TYP_REF))); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncExecutionContextVar, TYP_REF))); restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(resumed)); +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP restoreEntryPoint; + info.compCompHnd->getFunctionEntryPoint(asyncInfo->restoreContextsMethHnd, &restoreEntryPoint); + restoreCall->setEntryPoint(restoreEntryPoint); + } +#endif + + // This restore is an inline candidate (unlike the fault one) + CORINFO_CALL_INFO callInfo = {}; + callInfo.hMethod = restoreCall->gtCallMethHnd; + callInfo.methodFlags = info.compCompHnd->getMethodAttribs(callInfo.hMethod); + impMarkInlineCandidate(restoreCall, MAKE_METHODCONTEXT(callInfo.hMethod), false, &callInfo, compInlineContext); + Statement* restoreStmt = fgNewStmtFromTree(restoreCall); fgInsertStmtAtEnd(newReturnBB, restoreStmt); JITDUMP("Inserted restore statement in return block\n"); @@ -2105,11 +2138,19 @@ void AsyncTransformation::FillInDataOnSuspension(GenTreeCall* call, GenTree* contContextElementPlaceholder = m_compiler->gtNewZeroConNode(TYP_BYREF); GenTree* flagsPlaceholder = m_compiler->gtNewZeroConNode(TYP_BYREF); GenTreeCall* captureCall = - m_compiler->gtNewHelperCallNode(CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT, TYP_VOID); + m_compiler->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->captureContinuationContextMethHnd, TYP_VOID); captureCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(flagsPlaceholder)); captureCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(contContextElementPlaceholder)); +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP entryPoint; + m_compiler->info.compCompHnd->getFunctionEntryPoint(m_asyncInfo->captureContinuationContextMethHnd, &entryPoint); + captureCall->setEntryPoint(entryPoint); + } +#endif + m_compiler->compCurBB = suspendBB; m_compiler->fgMorphTree(captureCall); @@ -2149,7 +2190,15 @@ void AsyncTransformation::FillInDataOnSuspension(GenTreeCall* call, if (layout.ExecutionContextOffset != UINT_MAX) { GenTreeCall* captureExecContext = - m_compiler->gtNewHelperCallNode(CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT, TYP_REF); + m_compiler->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->captureExecutionContextMethHnd, TYP_REF); + +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP entryPoint; + m_compiler->info.compCompHnd->getFunctionEntryPoint(m_asyncInfo->captureExecutionContextMethHnd, &entryPoint); + captureExecContext->setEntryPoint(entryPoint); + } +#endif m_compiler->compCurBB = suspendBB; m_compiler->fgMorphTree(captureExecContext); @@ -2191,12 +2240,20 @@ void AsyncTransformation::RestoreContexts(BasicBlock* block, GenTreeCall* call, GenTree* execContextPlaceholder = m_compiler->gtNewNull(); GenTree* syncContextPlaceholder = m_compiler->gtNewNull(); GenTreeCall* restoreCall = - m_compiler->gtNewHelperCallNode(CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION, TYP_VOID); + m_compiler->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->restoreContextsOnSuspensionMethHnd, TYP_VOID); restoreCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(syncContextPlaceholder)); restoreCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(execContextPlaceholder)); restoreCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(resumedPlaceholder)); +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP entryPoint; + m_compiler->info.compCompHnd->getFunctionEntryPoint(m_asyncInfo->restoreContextsOnSuspensionMethHnd, &entryPoint); + restoreCall->setEntryPoint(entryPoint); + } +#endif + m_compiler->compCurBB = suspendBB; m_compiler->fgMorphTree(restoreCall); @@ -2394,9 +2451,17 @@ void AsyncTransformation::RestoreFromDataOnResumption(const ContinuationLayout& { GenTree* valuePlaceholder = m_compiler->gtNewZeroConNode(TYP_REF); GenTreeCall* restoreCall = - m_compiler->gtNewHelperCallNode(CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT, TYP_VOID); + m_compiler->gtNewCallNode(CT_USER_FUNC, m_asyncInfo->restoreExecutionContextMethHnd, TYP_VOID); restoreCall->gtArgs.PushFront(m_compiler, NewCallArg::Primitive(valuePlaceholder)); +#ifdef FEATURE_READYTORUN + { + CORINFO_CONST_LOOKUP entryPoint; + m_compiler->info.compCompHnd->getFunctionEntryPoint(m_asyncInfo->restoreExecutionContextMethHnd, &entryPoint); + restoreCall->setEntryPoint(entryPoint); + } +#endif + m_compiler->compCurBB = resumeBB; m_compiler->fgMorphTree(restoreCall); diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 72a245f594030d..f1380f35a176c0 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -1770,15 +1770,6 @@ void HelperCallProperties::init() isAllocator = true; break; - case CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS: - case CORINFO_HELP_ASYNC_RESTORE_CONTEXTS: - case CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT: - case CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT: - case CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION: - case CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT: - mutatesHeap = true; - break; - default: // The most pessimistic results are returned for these helpers. mutatesHeap = true; diff --git a/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs b/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs index a058802ce48685..42a95aae0f8000 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs @@ -363,13 +363,6 @@ public enum ReadyToRunHelper AllocContinuation = 0x120, AllocContinuationClass = 0x121, AllocContinuationMethod = 0x122, - AsyncCaptureContexts = 0x123, - AsyncRestoreContexts = 0x124, - AsyncCaptureExecutionContext = 0x125, - AsyncRestoreExecutionContext = 0x126, - AsyncRestoreContextsOnSuspension = 0x127, - AsyncCaptureContinuationContext = 0x128, - // ********************************************************************************************** // // These are not actually part of the R2R file format. We have them here because it's convenient. diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index 5d019fc86fe857..c022acbc7eb91a 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -289,13 +289,6 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_ALLOC_CONTINUATION_METHOD, CORINFO_HELP_ALLOC_CONTINUATION_CLASS, - CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS, - CORINFO_HELP_ASYNC_RESTORE_CONTEXTS, - CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT, - CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT, - CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION, - CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT, - CORINFO_HELP_COUNT, } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs index 12250e29043a6e..0204c7bf5cef0d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs @@ -342,30 +342,6 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id, methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "AllocContinuation"u8, null); break; - case ReadyToRunHelper.AsyncCaptureContexts: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "CaptureContexts"u8, null); - break; - - case ReadyToRunHelper.AsyncRestoreContexts: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "RestoreContexts"u8, null); - break; - - case ReadyToRunHelper.AsyncCaptureExecutionContext: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "CaptureExecutionContext"u8, null); - break; - - case ReadyToRunHelper.AsyncRestoreExecutionContext: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "RestoreExecutionContext"u8, null); - break; - - case ReadyToRunHelper.AsyncRestoreContextsOnSuspension: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "RestoreContextsOnSuspension"u8, null); - break; - - case ReadyToRunHelper.AsyncCaptureContinuationContext: - methodDesc = context.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "CaptureContinuationContext"u8, null); - break; - default: throw new NotImplementedException(id.ToString()); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index c16a9504099565..8d4a77e25817c6 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -466,10 +466,10 @@ private void ImportCall(ILOpcode opcode, int token) _dependencies.Add(_factory.ConstructedTypeSymbol(_compilation.TypeSystemContext.ContinuationType), asyncReason); _dependencies.Add(_compilation.GetHelperEntrypoint(ReadyToRunHelper.AllocContinuation), asyncReason); - _dependencies.Add(_compilation.GetHelperEntrypoint(ReadyToRunHelper.AsyncCaptureExecutionContext), asyncReason); - _dependencies.Add(_compilation.GetHelperEntrypoint(ReadyToRunHelper.AsyncRestoreExecutionContext), asyncReason); - _dependencies.Add(_compilation.GetHelperEntrypoint(ReadyToRunHelper.AsyncCaptureContinuationContext), asyncReason); - _dependencies.Add(_compilation.GetHelperEntrypoint(ReadyToRunHelper.AsyncRestoreContextsOnSuspension), asyncReason); + _dependencies.Add(_compilation.TypeSystemContext.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "CaptureExecutionContext"u8, null), asyncReason); + _dependencies.Add(_compilation.TypeSystemContext.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "RestoreExecutionContext"u8, null), asyncReason); + _dependencies.Add(_compilation.TypeSystemContext.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "CaptureContinuationContext"u8, null), asyncReason); + _dependencies.Add(_compilation.TypeSystemContext.GetCoreLibEntryPoint("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8, "RestoreContextsOnSuspension"u8, null), asyncReason); } // If this is the task await pattern, we're actually going to call the variant diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index cb2321dbee223f..d4acd5e8638907 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -1267,30 +1267,6 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) id = ReadyToRunHelper.AllocContinuationClass; break; - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS: - id = ReadyToRunHelper.AsyncCaptureContexts; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_CONTEXTS: - id = ReadyToRunHelper.AsyncRestoreContexts; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT: - id = ReadyToRunHelper.AsyncCaptureExecutionContext; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT: - id = ReadyToRunHelper.AsyncRestoreExecutionContext; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION: - id = ReadyToRunHelper.AsyncRestoreContextsOnSuspension; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT: - id = ReadyToRunHelper.AsyncCaptureContinuationContext; - break; - case CorInfoHelpFunc.CORINFO_HELP_INITCLASS: id = ReadyToRunHelper.InitClass; break; @@ -1323,10 +1299,54 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) return _compilation.NodeFactory.GetReadyToRunHelperCell(id); } + // CORINFO_ACCESS_ANY = 0x0000, // Normal access + // CORINFO_ACCESS_THIS = 0x0001, // Accessed via the this reference + // CORINFO_ACCESS_PREFER_SLOT_OVER_TEMPORARY_ENTRYPOINT = 0x0002, // Prefer access to a method via slot over using the temporary entrypoint + + // CORINFO_ACCESS_NONNULL = 0x0004, // Instance is guaranteed non-null + + // CORINFO_ACCESS_LDFTN = 0x0010, // Accessed via ldftn + // CORINFO_ACCESS_UNMANAGED_CALLER_MAYBE = 0x0020, // Method might be attributed with UnmanagedCallersOnlyAttribute. + + // // Field access flags + // CORINFO_ACCESS_GET = 0x0100, // Field get (ldfld) + // CORINFO_ACCESS_SET = 0x0200, // Field set (stfld) + // CORINFO_ACCESS_ADDRESS = 0x0400, // Field address (ldflda) + // CORINFO_ACCESS_INIT_ARRAY = 0x0800, // Field use for InitializeArray + // // UNUSED = 0x4000, + // CORINFO_ACCESS_INLINECHECK = 0x8000, // Return fieldFlags and fieldAccessor only. Used by JIT64 during inlining. private void getFunctionEntryPoint(CORINFO_METHOD_STRUCT_* ftn, ref CORINFO_CONST_LOOKUP pResult, CORINFO_ACCESS_FLAGS accessFlags) { + DefType asyncHelpers = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8); + var captureExecutionContextMethHnd = asyncHelpers.GetKnownMethod("CaptureExecutionContext"u8, null); + var restoreExecutionContextMethHnd = asyncHelpers.GetKnownMethod("RestoreExecutionContext"u8, null); + var captureContinuationContextMethHnd = asyncHelpers.GetKnownMethod("CaptureContinuationContext"u8, null); + var captureContextsMethHnd = asyncHelpers.GetKnownMethod("CaptureContexts"u8, null); + var restoreContextsMethHnd = asyncHelpers.GetKnownMethod("RestoreContexts"u8, null); + var restoreContextsOnSuspensionMethHnd = asyncHelpers.GetKnownMethod("RestoreContextsOnSuspension"u8, null); var method = HandleToObject(ftn); - throw new RequiresRuntimeJitException($"getFunctionEntryPoint called for {method} from {MethodBeingCompiled}"); + if (method == captureExecutionContextMethHnd + || method == restoreExecutionContextMethHnd + || method == captureContinuationContextMethHnd + || method == captureContextsMethHnd + || method == restoreContextsMethHnd + || method == restoreContextsOnSuspensionMethHnd) + { + var entrypoint = _compilation.NodeFactory.MethodEntrypoint( + new MethodWithToken( + method, + _compilation.NodeFactory.Resolver.GetModuleTokenForMethod(method, true, true), + null, + false, + MethodBeingCompiled), + false, + false, + false); + pResult = CreateConstLookupToSymbol(entrypoint); + } + else{ + throw new RequiresRuntimeJitException(method.ToString()); + } } private bool canTailCall(CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHOD_STRUCT_* declaredCalleeHnd, CORINFO_METHOD_STRUCT_* exactCalleeHnd, bool fIsTailPrefix) diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs index 5bfa19a560ca21..2547a936f57f0b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs @@ -2043,25 +2043,6 @@ private void ParseHelper(StringBuilder builder) builder.Append("ALLOC_CONTINUATION_CLASS"); break; - case ReadyToRunHelper.AsyncCaptureContexts: - builder.Append("ASYNC_CAPTURE_CONTEXTS"); - break; - case ReadyToRunHelper.AsyncRestoreContexts: - builder.Append("ASYNC_RESTORE_CONTEXTS"); - break; - case ReadyToRunHelper.AsyncCaptureExecutionContext: - builder.Append("ASYNC_CAPTURE_EXECUTION_CONTEXT"); - break; - case ReadyToRunHelper.AsyncRestoreExecutionContext: - builder.Append("ASYNC_RESTORE_EXECUTION_CONTEXT"); - break; - case ReadyToRunHelper.AsyncRestoreContextsOnSuspension: - builder.Append("ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION"); - break; - case ReadyToRunHelper.AsyncCaptureContinuationContext: - builder.Append("ASYNC_CAPTURE_CONTINUATION_CONTEXT"); - break; - case ReadyToRunHelper.InitClass: builder.Append("INIT_CLASS"); break; diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 32b83695ea0d64..b69e48d86c22ee 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -765,30 +765,6 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum) id = ReadyToRunHelper.AllocContinuation; break; - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_CONTEXTS: - id = ReadyToRunHelper.AsyncCaptureContexts; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_CONTEXTS: - id = ReadyToRunHelper.AsyncRestoreContexts; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_EXECUTION_CONTEXT: - id = ReadyToRunHelper.AsyncCaptureExecutionContext; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_EXECUTION_CONTEXT: - id = ReadyToRunHelper.AsyncRestoreExecutionContext; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_RESTORE_CONTEXTS_ON_SUSPENSION: - id = ReadyToRunHelper.AsyncRestoreContextsOnSuspension; - break; - - case CorInfoHelpFunc.CORINFO_HELP_ASYNC_CAPTURE_CONTINUATION_CONTEXT: - id = ReadyToRunHelper.AsyncCaptureContinuationContext; - break; - case CorInfoHelpFunc.CORINFO_HELP_GETSYNCFROMCLASSHANDLE: return _compilation.NodeFactory.MethodEntrypoint(_compilation.NodeFactory.TypeSystemContext.GetCoreLibEntryPoint("System"u8, "Type"u8, "GetTypeFromMethodTable"u8, null)); case CorInfoHelpFunc.CORINFO_HELP_GETCLASSFROMMETHODPARAM: