Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a84e95d

Browse files
committed
remove locking in SetupGcCoverage
1 parent 47007b0 commit a84e95d

File tree

2 files changed

+12
-60
lines changed

2 files changed

+12
-60
lines changed

src/vm/gccover.cpp

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -144,69 +144,15 @@ void SetupGcCoverage(MethodDesc* pMD, BYTE* methodStartPtr) {
144144
}
145145
#endif
146146

147+
// We may have lost out to another thread instrumenting this method.
148+
// If so, we'll also lose the publishing race. So just return.
147149
if (pMD->m_GcCover)
148-
return;
149-
150-
//
151-
// In the gcstress=4 case, we can easily piggy-back onto the JITLock because we
152-
// have a JIT operation that needs to take that lock already. But in the case of
153-
// gcstress=8, we cannot do this because the code already exists, and if gccoverage
154-
// were not in the picture, we're happy to race to do the prestub work because all
155-
// threads end up with the same answer and don't leak any resources in the process.
156-
//
157-
// However, with gccoverage, we need to exclude all other threads from mucking with
158-
// the code while we fill in the breakpoints and make our shadow copy of the code.
159-
//
160150
{
161-
BaseDomain* pDomain = pMD->GetDomain();
162-
// Enter the global lock which protects the list of all functions being JITd
163-
JitListLock::LockHolder pJitLock(pDomain->GetJitLock());
164-
165-
166-
// It is possible that another thread stepped in before we entered the global lock for the first time.
167-
if (pMD->m_GcCover)
168-
{
169-
// We came in to jit but someone beat us so return the jitted method!
170-
return;
171-
}
172-
else
173-
{
174-
const char *description = "jit lock (gc cover)";
175-
#ifdef _DEBUG
176-
description = pMD->m_pszDebugMethodName;
177-
#endif
178-
ReleaseHolder<JitListLockEntry> pEntry(JitListLockEntry::Find(pJitLock, pMD->GetInitialCodeVersion(), description));
179-
180-
// We have an entry now, we can release the global lock
181-
pJitLock.Release();
182-
183-
// Take the entry lock
184-
{
185-
JitListLockEntry::LockHolder pEntryLock(pEntry, FALSE);
186-
187-
if (pEntryLock.DeadlockAwareAcquire())
188-
{
189-
// we have the lock...
190-
}
191-
else
192-
{
193-
// Note that at this point we don't have the lock, but that's OK because the
194-
// thread which does have the lock is blocked waiting for us.
195-
}
196-
197-
if (pMD->m_GcCover)
198-
{
199-
return;
200-
}
201-
202-
PCODE codeStart = (PCODE) methodStartPtr;
203-
204-
SetupAndSprinkleBreakpointsForJittedMethod(pMD,
205-
codeStart
206-
);
207-
}
208-
}
151+
return;
209152
}
153+
154+
PCODE codeStart = (PCODE) methodStartPtr;
155+
SetupAndSprinkleBreakpointsForJittedMethod(pMD, codeStart);
210156
}
211157

212158
#ifdef FEATURE_PREJIT

src/vm/prestub.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,12 @@ PCODE MethodDesc::JitCompileCodeLocked(PrepareCodeConfig* pConfig, JitListLockEn
893893
// instrumentation data always matches the published code.
894894
CrstHolder gcCoverLock(&m_GCCoverCrst);
895895

896+
// Make sure no other thread has stepped in before us.
897+
if ((pOtherCode = pConfig->IsJitCancellationRequested()))
898+
{
899+
return pOtherCode;
900+
}
901+
896902
SetupGcCoverage(this, (BYTE*)pCode);
897903

898904
// This thread should always win the publishing race

0 commit comments

Comments
 (0)