Skip to content

Commit 170fdd0

Browse files
author
Koundinya Veluri
committed
Revert changes relevant to forbid-suspend-for-debugger scopes
1 parent edffc0c commit 170fdd0

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

src/coreclr/vm/appdomain.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,7 @@ class BaseDomain
11771177

11781178
// To be used when the thread may enter cooperative GC mode while holding the lock. The thread enters a
11791179
// forbid-suspend-for-debugger region along with acquiring the lock, such that it would not suspend for the debugger while
1180-
// holding the lock, as that may otherwise cause a FuncEval to deadlock when trying to acquire the lock. This holder cannot
1181-
// be used when there may be GC allocation inside its scope (see the base class for more information).
1180+
// holding the lock, as that may otherwise cause a FuncEval to deadlock when trying to acquire the lock.
11821181
class DomainCacheCrstHolderForGCCoop : private CrstAndForbidSuspendForDebuggerHolder
11831182
{
11841183
public:

src/coreclr/vm/crst.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,6 @@ friend class Crst;
395395
// This just exists to convert legacy OS Critical Section patterns over to holders.
396396
typedef DacHolder<CrstBase *, CrstBase::ReleaseLock, CrstBase::AcquireLock, 0, CompareDefault> UnsafeCrstInverseHolder;
397397

398-
// This holder acquires the lock in preemptive GC mode and puts the thread in a forbid-suspend-for-debugger region. It is
399-
// used when cooperative GC mode would be entered while the lock is held, which can normally suspend for the debugger and
400-
// cause FuncEvals to deadlock upon trying to acquire the lock. Using this holder prevents the thread from suspending for
401-
// the debugger upon GC mode switches inside the forbid region.
402-
//
403-
// However, the forbid region does not prevent the thread from waiting for a pending GC upon allocating from the GC. For
404-
// instance, some other thread may have started a GC and suspended for the debugger, then this thread allocates from the GC
405-
// and needs to perform a GC, so it waits for the other GC to complete. At that point debugger suspension cannot complete
406-
// because this thread is stuck inside the forbid region. So, this holder should not be used in cases that may allocate from
407-
// the GC.
408398
class CrstAndForbidSuspendForDebuggerHolder
409399
{
410400
private:

src/coreclr/vm/threadsuspend.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,18 +2113,9 @@ void Thread::RareDisablePreemptiveGC()
21132113
// Note IsGCInProgress is also true for say Pause (anywhere SuspendEE happens) and GCThread is the
21142114
// thread that did the Pause. While in Pause if another thread attempts Rev/Pinvoke it should get inside the following and
21152115
// block until resume
2116-
if ((
2117-
(GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2118-
(m_State & TS_DebugSuspendPending) ||
2119-
(m_State & TS_StackCrawlNeeded)
2120-
) &&
2121-
2122-
// When in a forbid-suspend-for-debugger region and the thread waits for an in-progress GC, it would become stuck in the
2123-
// forbid region until the GC is complete. In the meantime, the debugger may need to have the runtime suspend for the
2124-
// debugger first, perhaps in a GC-unsafe point. This thread would not be able to suspend for the debugger and would
2125-
// cause a deadlock during debugger suspension. When in the forbid region, allow disabling preemptive GC and bypass the
2126-
// above heuristics.
2127-
!IsInForbidSuspendForDebuggerRegion())
2116+
if ((GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2117+
((m_State & TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion()) ||
2118+
(m_State & TS_StackCrawlNeeded))
21282119
{
21292120
STRESS_LOG1(LF_SYNC, LL_INFO1000, "RareDisablePreemptiveGC: entering. Thread state = %x\n", m_State.Load());
21302121

@@ -2190,10 +2181,9 @@ void Thread::RareDisablePreemptiveGC()
21902181
// However, it is possible for the current thread to become the GC
21912182
// thread while in this loop. This happens if you use the COM+
21922183
// debugger to suspend this thread and then release it.
2193-
_ASSERTE(!IsInForbidSuspendForDebuggerRegion());
21942184
if (! ((GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2195-
(m_State & TS_DebugSuspendPending) ||
2196-
(m_State & TS_StackCrawlNeeded)) )
2185+
((m_State & TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion()) ||
2186+
(m_State & TS_StackCrawlNeeded)) )
21972187
{
21982188
break;
21992189
}

0 commit comments

Comments
 (0)