Skip to content

Commit

Permalink
Avoiding suspending BeefPerf thread
Browse files Browse the repository at this point in the history
  • Loading branch information
bfiete committed Dec 24, 2019
1 parent f1e2148 commit aa7cff4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 28 additions & 7 deletions BeefRT/dbg/gc.cpp
Expand Up @@ -216,6 +216,16 @@ BFGC::ThreadInfo::~ThreadInfo()
BfpThread_Release(mThreadHandle);
}

bool BFGC::ThreadInfo::WantsSuspend()
{
#ifndef BP_DISABLED
BfpThreadId threadId = BpManager::Get()->mThreadId;
return threadId != (BfpThreadId)mThreadId;
#else
return true;
#endif
}

//////////////////////////////////////////////////////////////////////////

#ifdef BF_GC_LOG_ENABLED
Expand Down Expand Up @@ -1371,7 +1381,7 @@ bool BFGC::ScanThreads()
continue;
}

BP_ZONE("ThreadCollect");
BP_ZONE_F("ThreadCollect %d", thread->mThreadId);
//Beefy::DebugTimeGuard suspendTimeGuard(10, "ThreadSuspend");

DWORD result = 0;
Expand Down Expand Up @@ -1405,16 +1415,24 @@ bool BFGC::ScanThreads()

BFLOG2(GCLog::EVENT_SCAN_THREAD, (intptr)thread, (intptr)thread->mThreadId);

for (auto obj : thread->mStackMarkableObjects)
//
{
MarkMembers(obj);
BP_ZONE("StackMarkableObjects");
for (auto obj : thread->mStackMarkableObjects)
{
MarkMembers(obj);
}
}

intptr regVals[64];
intptr stackPtr = 0;
BfpThreadResult threadResult;
int regValCount = 64;
BfpThread_GetIntRegisters(thread->mThreadHandle, &stackPtr, regVals, &regValCount, &threadResult);
///
{
BP_ZONE("BfpThread_GetIntRegisters");
BfpThread_GetIntRegisters(thread->mThreadHandle, &stackPtr, regVals, &regValCount, &threadResult);
}
BF_ASSERT(threadResult == BfpThreadResult_Ok);

void** threadLoadAddressMap = (void**)((_TEB*)thread->mTEB)->ThreadLocalStorage;
Expand All @@ -1432,7 +1450,10 @@ bool BFGC::ScanThreads()
int length = thread->mStackStart - stackPtr;

AdjustStackPtr(stackPtr, length);
ConservativeScan((void*)stackPtr, length);
{
BP_ZONE("ConservativeScan stack");
ConservativeScan((void*)stackPtr, length);
}
mQueueMarkObjects = false;

if (mDoStackDeepMark)
Expand Down Expand Up @@ -2260,7 +2281,7 @@ void BFGC::SuspendThreads()
auto curThreadId = GetCurrentThreadId();
for (auto thread : mThreadList)
{
if ((thread->mThreadId != curThreadId) && (thread->mRunning))
if ((thread->mThreadId != curThreadId) && (thread->mRunning) && (thread->WantsSuspend()))
{
// We must lock this before suspending so we can access mStackMarkableObjects
// Otherwise we could deadlock
Expand All @@ -2279,7 +2300,7 @@ void BFGC::ResumeThreads()
auto curThreadId = GetCurrentThreadId();
for (auto thread : mThreadList)
{
if ((thread->mThreadId != curThreadId) && (thread->mRunning))
if ((thread->mThreadId != curThreadId) && (thread->mRunning) && (thread->WantsSuspend()))
{
// Previously locked in SuspendThreads
thread->mCritSect.Unlock();
Expand Down
2 changes: 2 additions & 0 deletions BeefRT/dbg/gc.h
Expand Up @@ -186,6 +186,8 @@ class BFGC
}

~ThreadInfo();

bool WantsSuspend();
};

struct RawLeakInfo
Expand Down

0 comments on commit aa7cff4

Please sign in to comment.