Skip to content

Commit

Permalink
deleted TS_GCSuspendPending
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed May 1, 2024
1 parent e6daa34 commit 6883eec
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 49 deletions.
2 changes: 0 additions & 2 deletions docs/design/datacontracts/Thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ enum ThreadState
TS_AbortRequested = 0x00000001, // Abort the thread
TS_GCSuspendPending = 0x00000002, // ThreadSuspend::SuspendRuntime watches this thread to leave coop mode.
TS_GCSuspendRedirected = 0x00000004, // ThreadSuspend::SuspendRuntime has redirected the thread to suspention routine.
TS_GCSuspendFlags = TS_GCSuspendPending | TS_GCSuspendRedirected, // used to track suspension progress. Only SuspendRuntime writes/resets these.
TS_DebugSuspendPending = 0x00000008, // Is the debugger suspending threads?
TS_GCOnTransitions = 0x00000010, // Force a GC on stub transitions (GCStress only)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/fcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ NOINLINE Object* FC_GCPoll(void* __me, Object* objToProtect)
INCONTRACT(FCallCheck __fCallCheck(__FILE__, __LINE__));

Thread *thread = GetThread();
if (thread->CatchAtSafePointOpportunistic()) // Does someone want this thread stopped?
if (thread->CatchAtSafePoint()) // Does someone want this thread stopped?
{
HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_CAPTURE_DEPTH_2, objToProtect);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ class HelperMethodFrame : public Frame
FORCEINLINE void Poll()
{
WRAPPER_NO_CONTRACT;
if (m_pThread->CatchAtSafePointOpportunistic())
if (m_pThread->CatchAtSafePoint())
CommonTripThread();
}
#endif // DACCESS_COMPILE
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ static void MonitorEnter(Object* obj, BYTE* pbLockTaken)

GCPROTECT_BEGININTERIOR(pbLockTaken);

if (GET_THREAD()->CatchAtSafePointOpportunistic())
if (GET_THREAD()->CatchAtSafePoint())
{
GET_THREAD()->PulseGCMode();
}
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3651,7 +3651,7 @@ NOINLINE static void JIT_MonEnter_Helper(Object* obj, BYTE* pbLockTaken, LPVOID

GCPROTECT_BEGININTERIOR(pbLockTaken);

if (GET_THREAD()->CatchAtSafePointOpportunistic())
if (GET_THREAD()->CatchAtSafePoint())
{
GET_THREAD()->PulseGCMode();
}
Expand Down Expand Up @@ -3730,7 +3730,7 @@ NOINLINE static void JIT_MonTryEnter_Helper(Object* obj, INT32 timeOut, BYTE* pb

GCPROTECT_BEGININTERIOR(pbLockTaken);

if (GET_THREAD()->CatchAtSafePointOpportunistic())
if (GET_THREAD()->CatchAtSafePoint())
{
GET_THREAD()->PulseGCMode();
}
Expand Down Expand Up @@ -3764,7 +3764,7 @@ HCIMPL3(void, JIT_MonTryEnter_Portable, Object* obj, INT32 timeOut, BYTE* pbLock

pCurThread = GetThread();

if (pCurThread->CatchAtSafePointOpportunistic())
if (pCurThread->CatchAtSafePoint())
{
goto FramedLockHelper;
}
Expand Down Expand Up @@ -3936,7 +3936,7 @@ HCIMPL_MONHELPER(JIT_MonEnterStatic_Portable, AwareLock *lock)
MONHELPER_STATE(_ASSERTE(pbLockTaken != NULL && *pbLockTaken == 0));

Thread *pCurThread = GetThread();
if (pCurThread->CatchAtSafePointOpportunistic())
if (pCurThread->CatchAtSafePoint())
{
goto FramedLockHelper;
}
Expand Down Expand Up @@ -4830,7 +4830,7 @@ HCIMPL0(VOID, JIT_PollGC)
return;

// Does someone want this thread stopped?
if (!GetThread()->CatchAtSafePointOpportunistic())
if (!GetThread()->CatchAtSafePoint())
return;

// Tailcall to the slow helper
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/object.inl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ FORCEINLINE bool Object::TryEnterObjMonitorSpinHelper()
} CONTRACTL_END;

Thread *pCurThread = GetThread();
if (pCurThread->CatchAtSafePointOpportunistic())
if (pCurThread->CatchAtSafePoint())
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/syncblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ void SyncBlockCache::CleanupSyncBlocks()
pParam->psb = NULL;

// pulse GC mode to allow GC to perform its work
if (FinalizerThread::GetFinalizerThread()->CatchAtSafePointOpportunistic())
if (FinalizerThread::GetFinalizerThread()->CatchAtSafePoint())
{
FinalizerThread::GetFinalizerThread()->PulseGCMode();
}
Expand Down
14 changes: 6 additions & 8 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7065,22 +7065,20 @@ void CommonTripThread()
CONTRACTL {
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
}
CONTRACTL_END;

Thread *thread = GetThread();
thread->HandleThreadAbort ();
thread->HandleThreadAbort();

if (thread->CatchAtSafePointOpportunistic())
{
_ASSERTE(!ThreadStore::HoldingThreadStore(thread));
_ASSERTE(!ThreadStore::HoldingThreadStore(thread));
#ifdef FEATURE_HIJACK
thread->UnhijackThread();
thread->UnhijackThread();
#endif // FEATURE_HIJACK

// Trap
thread->PulseGCMode();
}
// Trap
thread->PulseGCMode();
#else
DacNotImpl();
#endif // #ifndef DACCESS_COMPILE
Expand Down
23 changes: 13 additions & 10 deletions src/coreclr/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class Thread

public:
// If we are trying to suspend a thread, we set the appropriate pending bit to
// indicate why we want to suspend it (TS_GCSuspendPending or TS_DebugSuspendPending).
// indicate why we want to suspend it (TS_AbortRequested or TS_DebugSuspendPending).
//
// If instead the thread has blocked itself, via WaitSuspendEvent, we indicate
// this with TS_SyncSuspended. However, we need to know whether the synchronous
Expand All @@ -608,9 +608,8 @@ class Thread

TS_AbortRequested = 0x00000001, // Abort the thread

TS_GCSuspendPending = 0x00000002, // ThreadSuspend::SuspendRuntime watches this thread to leave coop mode.
// unused = 0x00000002,
TS_GCSuspendRedirected = 0x00000004, // ThreadSuspend::SuspendRuntime has redirected the thread to suspention routine.
TS_GCSuspendFlags = TS_GCSuspendPending | TS_GCSuspendRedirected, // used to track suspension progress. Only SuspendRuntime writes/resets these.

TS_DebugSuspendPending = 0x00000008, // Is the debugger suspending threads?
TS_GCOnTransitions = 0x00000010, // Force a GC on stub transitions (GCStress only)
Expand Down Expand Up @@ -671,8 +670,7 @@ class Thread
// enum is changed, we also need to update SOS to reflect this.</TODO>

// We require (and assert) that the following bits are less than 0x100.
TS_CatchAtSafePoint = (TS_AbortRequested | TS_GCSuspendPending |
TS_DebugSuspendPending | TS_GCOnTransitions),
TS_CatchAtSafePoint = (TS_AbortRequested | TS_DebugSuspendPending | TS_GCOnTransitions),
};

// Thread flags that aren't really states in themselves but rather things the thread
Expand Down Expand Up @@ -937,11 +935,18 @@ class Thread
void DoExtraWorkForFinalizer();

#ifndef DACCESS_COMPILE
DWORD CatchAtSafePointOpportunistic()
DWORD CatchAtSafePoint()
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_COOPERATIVE;
}
CONTRACTL_END;

return HasThreadStateOpportunistic(TS_CatchAtSafePoint);
return g_TrapReturningThreads & 1 ||
HasThreadStateOpportunistic(TS_CatchAtSafePoint);
}
#endif // DACCESS_COMPILE

Expand Down Expand Up @@ -3222,8 +3227,6 @@ class Thread
if (SuspendSucceeded)
UnhijackThread();
#endif // FEATURE_HIJACK

_ASSERTE(!HasThreadStateOpportunistic(Thread::TS_GCSuspendPending));
}

static LPVOID GetStaticFieldAddress(FieldDesc *pFD);
Expand Down
20 changes: 1 addition & 19 deletions src/coreclr/vm/threadsuspend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,6 @@ void ThreadSuspend::SuspendAllThreads()
// This thread
Thread *pCurThread = GetThreadNULLOk();


//
// Remember that we're the one suspending the EE
//
Expand All @@ -3333,8 +3332,6 @@ void ThreadSuspend::SuspendAllThreads()
//
ThreadStore::SetThreadTrapForSuspension();

_ASSERTE(!pCurThread || !pCurThread->HasThreadState(Thread::TS_GCSuspendFlags));

// Flush the store buffers on all CPUs, to ensure two things:
// - we get a reliable reading of the threads' m_fPreemptiveGCDisabled state
// - other threads see that g_TrapReturningThreads is set
Expand All @@ -3359,24 +3356,12 @@ void ThreadSuspend::SuspendAllThreads()

if (pTargetThread->m_fPreemptiveGCDisabled.LoadWithoutBarrier())
{
if (!pTargetThread->HasThreadStateOpportunistic(Thread::TS_GCSuspendPending))
{
pTargetThread->SetThreadState(Thread::TS_GCSuspendPending);
}

remaining++;
if (!observeOnly)
{
pTargetThread->Hijack();
}
}
else
{
if (pTargetThread->HasThreadStateOpportunistic(Thread::TS_GCSuspendPending))
{
pTargetThread->ResetThreadState(Thread::TS_GCSuspendPending);
}
}
}

if (!remaining)
Expand Down Expand Up @@ -3503,12 +3488,10 @@ void Thread::Hijack()
}

// the thread is suspended here, we can hijack, if it is stopped in hijackable location

if (!m_fPreemptiveGCDisabled.LoadWithoutBarrier())
{
// actually, we are done with this one
STRESS_LOG1(LF_SYNC, LL_INFO1000, " Thread %x went preemptive while suspending it is at a GC safe point\n", this);
ResetThreadState(Thread::TS_GCSuspendFlags);
ResumeThread();
return;
}
Expand Down Expand Up @@ -5662,7 +5645,6 @@ void ThreadSuspend::SuspendEE(SUSPEND_REASON reason)
while ((thread = ThreadStore::GetThreadList(thread)) != NULL)
{
thread->DisableStressHeap();
_ASSERTE(!thread->HasThreadState(Thread::TS_GCSuspendPending));
}
}
#endif
Expand Down Expand Up @@ -5717,7 +5699,7 @@ void ThreadSuspend::SuspendEE(SUSPEND_REASON reason)
LOG((LF_GCROOTS | LF_GC | LF_CORDB, LL_INFO10, "The EE is free now...\n"));

// If someone's trying to suspend *this* thread, this is a good opportunity.
if (pCurThread && pCurThread->CatchAtSafePointOpportunistic())
if (pCurThread && pCurThread->CatchAtSafePoint())
{
pCurThread->PulseGCMode(); // Go suspend myself.
}
Expand Down

0 comments on commit 6883eec

Please sign in to comment.