Skip to content

Commit 56cb23a

Browse files
authored
JIT: Keep continuation alive until generic context is loaded (#121951)
There is a theoretical problem where JIT reports the continuation as dead before having restored the generic context local that the EE side is using to keep a `LoaderAllocator` alive. Insert an explicit `GT_KEEPALIVE` node after the state restore. Fix #117265
1 parent d345fb2 commit 56cb23a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/coreclr/jit/async.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,14 @@ void AsyncTransformation::RestoreFromDataOnResumption(const ContinuationLayout&
19721972

19731973
LIR::AsRange(resumeBB).InsertAtEnd(LIR::SeqTree(m_comp, store));
19741974
}
1975+
1976+
if (layout.KeepAliveOffset != UINT_MAX)
1977+
{
1978+
// Ensure that the continuation remains alive until we finished loading the generic context
1979+
GenTree* continuation = m_comp->gtNewLclvNode(m_comp->lvaAsyncContinuationArg, TYP_REF);
1980+
GenTree* keepAlive = m_comp->gtNewKeepAliveNode(continuation);
1981+
LIR::AsRange(resumeBB).InsertAtEnd(LIR::SeqTree(m_comp, keepAlive));
1982+
}
19751983
}
19761984

19771985
//------------------------------------------------------------------------

0 commit comments

Comments
 (0)