Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock when we request a ReJIT due to an inlined method #98400

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8241,17 +8241,32 @@ void CEEInfo::reportInliningDecision (CORINFO_METHOD_HANDLE inlinerHnd,

if (CORProfilerEnableRejit())
{
// If ReJIT is enabled, there is a chance that a race happened where the profiler
// requested a ReJIT on a method, but before the ReJIT occurred an inlining happened.
// If we end up reporting an inlining on a method with non-default IL it means the race
// happened and we need to manually request ReJIT for it since it was missed.
CodeVersionManager* pCodeVersionManager = pCallee->GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pCallee);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL())
ModuleID modId = 0;
mdMethodDef methodDef = mdMethodDefNil;
BOOL shouldCallReJIT = FALSE;

{
davmason marked this conversation as resolved.
Show resolved Hide resolved
// If ReJIT is enabled, there is a chance that a race happened where the profiler
// requested a ReJIT on a method, but before the ReJIT occurred an inlining happened.
// If we end up reporting an inlining on a method with non-default IL it means the race
// happened and we need to manually request ReJIT for it since it was missed.
CodeVersionManager* pCodeVersionManager = pCallee->GetCodeVersionManager();
CodeVersionManager::LockHolder codeVersioningLockHolder;
ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(pCallee);
if (ilVersion.GetRejitState() != ILCodeVersion::kStateActive || !ilVersion.HasDefaultIL())
{
shouldCallReJIT = TRUE;
modId = reinterpret_cast<ModuleID>(pCaller->GetModule());
methodDef = pCaller->GetMemberDef();
// Do Not call RequestReJIT inside this scope, calling RequestReJIT while holding the CodeVersionManager lock
// will cause deadlocks with other threads calling RequestReJIT since it tries to obtain the CodeVersionManager lock
}
davmason marked this conversation as resolved.
Show resolved Hide resolved
}

if (shouldCallReJIT)
{
ModuleID modId = reinterpret_cast<ModuleID>(pCaller->GetModule());
mdMethodDef methodDef = pCaller->GetMemberDef();
_ASSERTE(modId != 0);
_ASSERTE(methodDef != mdMethodDefNil);
ReJitManager::RequestReJIT(1, &modId, &methodDef, static_cast<COR_PRF_REJIT_FLAGS>(0));
}
}
Expand Down
Loading