Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/coreclr/src/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ ClrDataAccess::GetThreadData(CLRDATA_ADDRESS threadAddr, struct DacpThreadData *
threadData->pFrame = PTR_CDADDR(thread->m_pFrame);
threadData->context = PTR_CDADDR(thread->m_pDomain);
threadData->domain = PTR_CDADDR(thread->m_pDomain);
threadData->lockCount = thread->m_dwLockCount;
threadData->lockCount = (DWORD)-1;
#ifndef TARGET_UNIX
threadData->teb = TO_CDADDR(thread->m_pTEB);
#else
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/src/vm/amd64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_pFrame
#define Thread_m_pFrame OFFSETOF__Thread__m_pFrame

#ifndef CROSSGEN_COMPILE
#define OFFSETOF__Thread__m_State 0x8
ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_State
== offsetof(Thread, m_State));

#define OFFSETOF__Thread__m_dwLockCount 0x20
ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_dwLockCount
== offsetof(Thread, m_dwLockCount));

#define OFFSETOF__Thread__m_ThreadId 0x24
ASMCONSTANTS_C_ASSERT(OFFSETOF__Thread__m_ThreadId
== offsetof(Thread, m_ThreadId));

#define OFFSET__Thread__m_alloc_context__alloc_ptr 0x58
ASMCONSTANTS_C_ASSERT(OFFSET__Thread__m_alloc_context__alloc_ptr == offsetof(Thread, m_alloc_context) + offsetof(gc_alloc_context, alloc_ptr));
Expand Down
22 changes: 0 additions & 22 deletions src/coreclr/src/vm/comthreadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,11 @@ VOID NTAPI RegisterWaitForSingleObjectCallback(PVOID delegateInfo, BOOLEAN Timer
}
CONTRACTL_END;

// This thread should not have any locks held at entry point.
_ASSERTE(pThread->m_dwLockCount == 0);

GCX_COOP();

RegisterWaitForSingleObjectCallback_Args args = { ((DelegateInfo*) delegateInfo), TimerOrWaitFired };

ManagedThreadBase::ThreadPool(RegisterWaitForSingleObjectCallback_Worker, &args);

// We should have released all locks.
_ASSERTE(g_fEEShutDown || pThread->m_dwLockCount == 0 || pThread->m_fRudeAborted);
return;
}

FCIMPL5(LPVOID, ThreadPoolNative::CorRegisterWaitForSingleObject,
Expand Down Expand Up @@ -465,9 +458,6 @@ VOID QueueUserWorkItemManagedCallback(PVOID pArg)

_ASSERTE(NULL != pArg);

// This thread should not have any locks held at entry point.
_ASSERTE(GetThread()->m_dwLockCount == 0);

bool* wasNotRecalled = (bool*)pArg;

MethodDescCallSite dispatch(METHOD__TP_WAIT_CALLBACK__PERFORM_WAIT_CALLBACK);
Expand Down Expand Up @@ -661,9 +651,6 @@ void __stdcall BindIoCompletionCallbackStubEx(DWORD ErrorCode,
}
CONTRACTL_END;

// This thread should not have any locks held at entry point.
_ASSERTE(pThread->m_dwLockCount == 0);

LOG((LF_INTEROP, LL_INFO10000, "In IO_CallBackStub thread 0x%x retCode 0x%x, overlap 0x%x\n", pThread, ErrorCode, lpOverlapped));

GCX_COOP();
Expand All @@ -672,9 +659,6 @@ void __stdcall BindIoCompletionCallbackStubEx(DWORD ErrorCode,
ManagedThreadBase::ThreadPool(BindIoCompletionCallBack_Worker, &args);

LOG((LF_INTEROP, LL_INFO10000, "Leaving IO_CallBackStub thread 0x%x retCode 0x%x, overlap 0x%x\n", pThread, ErrorCode, lpOverlapped));
// We should have released all locks.
_ASSERTE(g_fEEShutDown || pThread->m_dwLockCount == 0 || pThread->m_fRudeAborted);
return;
}

void WINAPI BindIoCompletionCallbackStub(DWORD ErrorCode,
Expand Down Expand Up @@ -814,16 +798,10 @@ VOID WINAPI AppDomainTimerCallback(PVOID callbackState, BOOLEAN timerOrWaitFired
}
CONTRACTL_END;

// This thread should not have any locks held at entry point.
_ASSERTE(pThread->m_dwLockCount == 0);

GCX_COOP();

ThreadpoolMgr::TimerInfoContext* pTimerInfoContext = (ThreadpoolMgr::TimerInfoContext*)callbackState;
ManagedThreadBase::ThreadPool(AppDomainTimerCallback_Worker, pTimerInfoContext);

// We should have released all locks.
_ASSERTE(g_fEEShutDown || pThread->m_dwLockCount == 0 || pThread->m_fRudeAborted);
}

HANDLE QCALLTYPE AppDomainTimerNative::CreateAppDomainTimer(INT32 dueTime, INT32 timerId)
Expand Down
14 changes: 1 addition & 13 deletions src/coreclr/src/vm/eepolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,7 @@ EPolicyAction EEPolicy::GetFinalAction(EPolicyAction action, Thread *pThread)
defaultAction = m_DefaultAction[OPR_ThreadAbort];
break;
case eRudeAbortThread:
if (pThread && !pThread->HasLockInCurrentDomain())
{
defaultAction = m_DefaultAction[OPR_ThreadRudeAbortInNonCriticalRegion];
}
else
{
defaultAction = m_DefaultAction[OPR_ThreadRudeAbortInCriticalRegion];
}
break;
case eUnloadAppDomain:
defaultAction = m_DefaultAction[OPR_AppDomainUnload];
Expand Down Expand Up @@ -591,12 +584,7 @@ EPolicyAction EEPolicy::DetermineResourceConstraintAction(Thread *pThread)
}
CONTRACTL_END;

EPolicyAction action;
if (pThread->HasLockInCurrentDomain()) {
action = GetEEPolicy()->GetActionOnFailure(FAIL_CriticalResource);
}
else
action = GetEEPolicy()->GetActionOnFailure(FAIL_NonCriticalResource);
EPolicyAction action = GetEEPolicy()->GetActionOnFailure(FAIL_CriticalResource);

AppDomain *pDomain = GetAppDomain();
// If it is default domain, we can not unload the appdomain
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/src/vm/i386/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ ASMCONSTANTS_C_ASSERT(Thread_m_pFrame == offsetof(Thread, m_pFrame))
#endif // CROSSGEN_COMPILE

#ifndef CROSSGEN_COMPILE
#define Thread_m_dwLockCount 0x14
ASMCONSTANTS_C_ASSERT(Thread_m_dwLockCount == offsetof(Thread, m_dwLockCount))

#define Thread_m_ThreadId 0x18
ASMCONSTANTS_C_ASSERT(Thread_m_ThreadId == offsetof(Thread, m_ThreadId))

#ifdef FEATURE_HIJACK
#define TS_Hijacked_ASM 0x80
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/src/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,17 +1747,12 @@ static void MonitorEnter(Object* obj, BYTE* pbLockTaken)

GCPROTECT_BEGININTERIOR(pbLockTaken);

#ifdef _DEBUG
Thread *pThread = GetThread();
DWORD lockCount = pThread->m_dwLockCount;
#endif
if (GET_THREAD()->CatchAtSafePointOpportunistic())
{
GET_THREAD()->PulseGCMode();
}
objRef->EnterObjMonitor();
_ASSERTE ((objRef->GetSyncBlock()->GetMonitor()->GetRecursionLevel() == 1 && pThread->m_dwLockCount == lockCount + 1) ||
pThread->m_dwLockCount == lockCount);

if (pbLockTaken != 0) *pbLockTaken = 1;

GCPROTECT_END();
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/src/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3807,17 +3807,12 @@ NOINLINE static void JIT_MonEnter_Helper(Object* obj, BYTE* pbLockTaken, LPVOID

GCPROTECT_BEGININTERIOR(pbLockTaken);

#ifdef _DEBUG
Thread *pThread = GetThread();
DWORD lockCount = pThread->m_dwLockCount;
#endif
if (GET_THREAD()->CatchAtSafePointOpportunistic())
{
GET_THREAD()->PulseGCMode();
}
objRef->EnterObjMonitor();
_ASSERTE ((objRef->GetSyncBlock()->GetMonitor()->GetRecursionLevel() == 1 && pThread->m_dwLockCount == lockCount + 1) ||
pThread->m_dwLockCount == lockCount);

if (pbLockTaken != 0) *pbLockTaken = 1;

GCPROTECT_END();
Expand Down
15 changes: 1 addition & 14 deletions src/coreclr/src/vm/syncblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,6 @@ AwareLock::EnterHelperResult ObjHeader::EnterObjMonitorHelperSpin(Thread* pCurTh
LONG newValue = oldValue | tid;
if (InterlockedCompareExchangeAcquire((LONG*)&m_SyncBlockValue, newValue, oldValue) == oldValue)
{
pCurThread->IncLockCount();
return AwareLock::EnterHelperResult_Entered;
}

Expand Down Expand Up @@ -2279,16 +2278,7 @@ BOOL ObjHeader::Wait(INT32 timeOut, BOOL exitContext)
if (!pSB->DoesCurrentThreadOwnMonitor())
COMPlusThrow(kSynchronizationLockException);

#ifdef _DEBUG
Thread *pThread = GetThread();
DWORD curLockCount = pThread->m_dwLockCount;
#endif

BOOL result = pSB->Wait(timeOut,exitContext);

_ASSERTE (curLockCount == pThread->m_dwLockCount);

return result;
return pSB->Wait(timeOut,exitContext);
}

void ObjHeader::Pulse()
Expand Down Expand Up @@ -2394,7 +2384,6 @@ void AwareLock::Enter()
// We get here if we successfully acquired the mutex.
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();

#if defined(_DEBUG) && defined(TRACK_SYNC)
// The best place to grab this is from the ECall frame
Expand Down Expand Up @@ -2457,7 +2446,6 @@ BOOL AwareLock::TryEnter(INT32 timeOut)
// We get here if we successfully acquired the mutex.
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();

#if defined(_DEBUG) && defined(TRACK_SYNC)
// The best place to grab this is from the ECall frame
Expand Down Expand Up @@ -2726,7 +2714,6 @@ BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)

m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();

#if defined(_DEBUG) && defined(TRACK_SYNC)
// The best place to grab this is from the ECall frame
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/src/vm/syncblk.inl
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ FORCEINLINE bool AwareLock::TryEnterHelper(Thread* pCurThread)
{
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();
return true;
}

Expand Down Expand Up @@ -526,7 +525,6 @@ FORCEINLINE AwareLock::EnterHelperResult AwareLock::TryEnterBeforeSpinLoopHelper
// Lock was acquired and the spinner was not registered
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();
return EnterHelperResult_Entered;
}

Expand Down Expand Up @@ -558,7 +556,6 @@ FORCEINLINE AwareLock::EnterHelperResult AwareLock::TryEnterInsideSpinLoopHelper
// Lock was acquired and spinner was unregistered
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();
return EnterHelperResult_Entered;
}

Expand All @@ -581,7 +578,6 @@ FORCEINLINE bool AwareLock::TryEnterAfterSpinLoopHelper(Thread *pCurThread)
// Spinner was unregistered and the lock was acquired
m_HoldingThread = pCurThread;
m_Recursion = 1;
pCurThread->IncLockCount();
return true;
}

Expand Down Expand Up @@ -609,7 +605,6 @@ FORCEINLINE AwareLock::EnterHelperResult ObjHeader::EnterObjMonitorHelper(Thread
LONG newValue = oldValue | tid;
if (InterlockedCompareExchangeAcquire((LONG*)&m_SyncBlockValue, newValue, oldValue) == oldValue)
{
pCurThread->IncLockCount();
return AwareLock::EnterHelperResult_Entered;
}

Expand Down Expand Up @@ -691,7 +686,6 @@ FORCEINLINE AwareLock::LeaveHelperAction AwareLock::LeaveHelper(Thread* pCurThre

if (--m_Recursion == 0)
{
m_HoldingThread->DecLockCount();
m_HoldingThread = NULL;

// Clear lock bit and determine whether we must signal a waiter to wake
Expand Down Expand Up @@ -734,7 +728,6 @@ FORCEINLINE AwareLock::LeaveHelperAction ObjHeader::LeaveObjMonitorHelper(Thread
{
return AwareLock::LeaveHelperAction_Yield;
}
pCurThread->DecLockCount();
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/src/vm/threadpoolrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,6 @@ void ManagedPerAppDomainTPCount::DispatchWorkItem(bool* foundWork, bool* wasNotR
}
}

// We should have released all locks.
_ASSERTE(g_fEEShutDown || pThread->m_dwLockCount == 0 || pThread->m_fRudeAborted);

*foundWork = true;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/src/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,6 @@ void DestroyThread(Thread *th)

_ASSERTE (th == GetThread());

_ASSERTE(g_fEEShutDown || th->m_dwLockCount == 0 || th->m_fRudeAborted);

GCX_PREEMP_NO_DTOR();

if (th->IsAbortRequested()) {
Expand Down Expand Up @@ -934,7 +932,6 @@ HRESULT Thread::DetachThread(BOOL fDLLThreadDetach)
#endif // FEATURE_COMINTEROP

_ASSERTE(!PreemptiveGCDisabled());
_ASSERTE(g_fEEShutDown || m_dwLockCount == 0 || m_fRudeAborted);

_ASSERTE ((m_State & Thread::TS_Detached) == 0);

Expand Down Expand Up @@ -1325,9 +1322,6 @@ Thread::Thread()
m_ulEnablePreemptiveGCCount = 0;
#endif

m_dwLockCount = 0;
m_dwBeginLockCount = 0;

#ifdef _DEBUG
dbg_m_cSuspendedThreads = 0;
dbg_m_cSuspendedThreadsWithoutOSLock = 0;
Expand Down
31 changes: 1 addition & 30 deletions src/coreclr/src/vm/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ class Thread
void EnablePreemptiveGC() { }
void DisablePreemptiveGC() { }

inline void IncLockCount() { }
inline void DecLockCount() { }

static LPVOID GetStaticFieldAddress(FieldDesc *pFD) { return NULL; }

PTR_AppDomain GetDomain() { return ::GetAppDomain(); }
Expand Down Expand Up @@ -1187,9 +1184,7 @@ class Thread
// unused = 0x00080000,
TSNC_RaiseUnloadEvent = 0x00100000, // Finalize thread is raising managed unload event which
// may call AppDomain.Unload.
TSNC_UnbalancedLocks = 0x00200000, // Do not rely on lock accounting for this thread:
// we left an app domain with a lock count different from
// when we entered it
// unused = 0x00200000,
// unused = 0x00400000,
TSNC_IgnoreUnhandledExceptions = 0x00800000, // Set for a managed thread born inside an appdomain created with the APPDOMAIN_IGNORE_UNHANDLED_EXCEPTIONS flag.
TSNC_ProcessedUnhandledException = 0x01000000,// Set on a thread on which we have done unhandled exception processing so that
Expand Down Expand Up @@ -1504,10 +1499,6 @@ class Thread
//-----------------------------------------------------------
PTR_AppDomain m_pDomain;

// Track the number of locks (critical section, spin lock, syncblock lock,
// EE Crst, GC lock) held by the current thread.
DWORD m_dwLockCount;

// Unique thread id used for thin locks - kept as small as possible, as we have limited space
// in the object header to store it.
DWORD m_ThreadId;
Expand Down Expand Up @@ -1635,12 +1626,7 @@ class Thread
// Flags for thread states that have no concurrency issues.
ThreadStateNoConcurrency m_StateNC;

inline void IncLockCount();
inline void DecLockCount();

private:
DWORD m_dwBeginLockCount; // lock count when the thread enters current domain

#ifdef _DEBUG
DWORD dbg_m_cSuspendedThreads;
// Count of suspended threads that we know are not in native code (and therefore cannot hold OS lock which prevents us calling out to host)
Expand Down Expand Up @@ -1720,21 +1706,6 @@ class Thread
DWORD m_dwHashCodeSeed;

public:

inline BOOL HasLockInCurrentDomain()
{
LIMITED_METHOD_CONTRACT;

_ASSERTE(m_dwLockCount >= m_dwBeginLockCount);

// Equivalent to (m_dwLockCount != m_dwBeginLockCount ||
// m_dwCriticalRegionCount ! m_dwBeginCriticalRegionCount),
// but without branching instructions
BOOL fHasLock = (m_dwLockCount ^ m_dwBeginLockCount);

return fHasLock;
}

inline DWORD GetNewHashCode()
{
LIMITED_METHOD_CONTRACT;
Expand Down
Loading