Skip to content

Commit 3fed4b3

Browse files
github-actions[bot]noahfalktommcdon
authored
Reduce funceval abort (#108256)
Visual Studio reported that they were seeing unnecessary func-eval aborts. This was due to a lock ordering issue between CrstReadyToRunEntryPointToMethodDescMap and the coop mode transition. Flipping the ordering should fix the issue for this particular lock though it doesn't prevent any other lock from blocking func-evals. This should reduce, but not eliminate, the number of cases where func-eval abort is required. Co-authored-by: Noah Falk <[email protected]> Co-authored-by: Tom McDonald <[email protected]>
1 parent 41e6052 commit 3fed4b3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/coreclr/vm/readytoruninfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ void ReadyToRunInfo::SetMethodDescForEntryPointInNativeImage(PCODE entryPoint, M
351351
}
352352
CONTRACTL_END;
353353

354+
// We are entering coop mode here so that we don't do it later inside LookupMap while we are already holding the Crst.
355+
// Doing it in the other order can block the debugger from running func-evals. For example thread A would acquire the Crst,
356+
// then block at the coop transition inside LookupMap waiting for the debugger to resume from a break state. The debugger then
357+
// requests thread B to run a funceval, the funceval tries to load some R2R method calling in here, then it blocks because
358+
// thread A is holding the Crst.
359+
GCX_COOP();
354360
CrstHolder ch(&m_Crst);
355361

356362
if ((TADDR)m_entryPointToMethodDescMap.LookupValue(PCODEToPINSTR(entryPoint), (LPVOID)PCODEToPINSTR(entryPoint)) == (TADDR)INVALIDENTRY)
@@ -697,7 +703,7 @@ ReadyToRunInfo::ReadyToRunInfo(Module * pModule, LoaderAllocator* pLoaderAllocat
697703
m_pHeader(pHeader),
698704
m_pNativeImage(pModule != NULL ? pNativeImage: NULL), // m_pNativeImage is only set for composite image components, not the composite R2R info itself
699705
m_readyToRunCodeDisabled(FALSE),
700-
m_Crst(CrstReadyToRunEntryPointToMethodDescMap),
706+
m_Crst(CrstReadyToRunEntryPointToMethodDescMap, CRST_UNSAFE_COOPGC),
701707
m_pPersistentInlineTrackingMap(NULL),
702708
m_pNextR2RForUnrelatedCode(NULL)
703709
{

0 commit comments

Comments
 (0)