@@ -950,6 +950,12 @@ void AsyncTransformation::LiftLIREdges(BasicBlock* block,
950950//
951951bool AsyncTransformation::ContinuationNeedsKeepAlive (AsyncLiveness& life)
952952{
953+ if (m_comp->IsTargetAbi (CORINFO_NATIVEAOT_ABI))
954+ {
955+ // Native AOT doesn't have a LoaderAllocator
956+ return false ;
957+ }
958+
953959 const unsigned GENERICS_CTXT_FROM = CORINFO_GENERICS_CTXT_FROM_METHODDESC | CORINFO_GENERICS_CTXT_FROM_METHODTABLE;
954960 if (((m_comp->info .compMethodInfo ->options & GENERICS_CTXT_FROM) != 0 ) && life.IsLive (m_comp->info .compTypeCtxtArg ))
955961 {
@@ -1504,28 +1510,20 @@ GenTreeCall* AsyncTransformation::CreateAllocContinuationCall(AsyncLiveness&
15041510 const ContinuationLayout& layout)
15051511{
15061512 GenTree* contClassHndNode = m_comp->gtNewIconEmbClsHndNode (layout.ClassHnd );
1507- // If VM requests that we report the method handle, or if we have a shared generic context method handle
1508- // that is live here, then we need to call a different helper to keep the loader alive.
1509- if (((m_comp->info .compMethodInfo ->options & CORINFO_GENERICS_CTXT_FROM_METHODDESC) != 0 ) &&
1510- life.IsLive (m_comp->info .compTypeCtxtArg ) && !m_comp->IsTargetAbi (CORINFO_NATIVEAOT_ABI))
1513+
1514+ // If we need to keep the loader alive, use a different helper.
1515+ if (ContinuationNeedsKeepAlive (life))
15111516 {
15121517 assert (layout.KeepAliveOffset != UINT_MAX);
1513- GenTree* methodHandleArg = m_comp->gtNewLclvNode (m_comp->info .compTypeCtxtArg , TYP_I_IMPL);
1518+ GenTree* handleArg = m_comp->gtNewLclvNode (m_comp->info .compTypeCtxtArg , TYP_I_IMPL);
15141519 // Offset passed to function is relative to instance data.
15151520 int keepAliveOffset = (OFFSETOF__CORINFO_Continuation__data - SIZEOF__CORINFO_Object) + layout.KeepAliveOffset ;
1516- GenTree* keepAliveOffsetNode = m_comp->gtNewIconNode (keepAliveOffset);
1517- return m_comp->gtNewHelperCallNode (CORINFO_HELP_ALLOC_CONTINUATION_METHOD, TYP_REF, prevContinuation,
1518- contClassHndNode, keepAliveOffsetNode, methodHandleArg);
1519- }
1520- else if (((m_comp->info .compMethodInfo ->options & CORINFO_GENERICS_CTXT_FROM_METHODTABLE) != 0 ) &&
1521- life.IsLive (m_comp->info .compTypeCtxtArg ) && !m_comp->IsTargetAbi (CORINFO_NATIVEAOT_ABI))
1522- {
1523- assert (layout.KeepAliveOffset != UINT_MAX);
1524- GenTree* classHandleArg = m_comp->gtNewLclvNode (m_comp->info .compTypeCtxtArg , TYP_I_IMPL);
1525- int keepAliveOffset = (OFFSETOF__CORINFO_Continuation__data - SIZEOF__CORINFO_Object) + layout.KeepAliveOffset ;
1526- GenTree* keepAliveOffsetNode = m_comp->gtNewIconNode (keepAliveOffset);
1527- return m_comp->gtNewHelperCallNode (CORINFO_HELP_ALLOC_CONTINUATION_CLASS, TYP_REF, prevContinuation,
1528- contClassHndNode, keepAliveOffsetNode, classHandleArg);
1521+ GenTree* keepAliveOffsetNode = m_comp->gtNewIconNode (keepAliveOffset);
1522+ CorInfoHelpFunc helperNum = (m_comp->info .compMethodInfo ->options & CORINFO_GENERICS_CTXT_FROM_METHODTABLE) != 0
1523+ ? CORINFO_HELP_ALLOC_CONTINUATION_CLASS
1524+ : CORINFO_HELP_ALLOC_CONTINUATION_METHOD;
1525+ return m_comp->gtNewHelperCallNode (helperNum, TYP_REF, prevContinuation, contClassHndNode, keepAliveOffsetNode,
1526+ handleArg);
15291527 }
15301528
15311529 return m_comp->gtNewHelperCallNode (CORINFO_HELP_ALLOC_CONTINUATION, TYP_REF, prevContinuation, contClassHndNode);
0 commit comments