Skip to content

Commit

Permalink
Delete some dead code in finalizer loop (#104287)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jul 2, 2024
1 parent 745b776 commit 7b1c0f3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 68 deletions.
9 changes: 0 additions & 9 deletions src/coreclr/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4122,15 +4122,6 @@ AppDomain::RaiseAssemblyResolveEvent(
RETURN pAssembly;
} // AppDomain::RaiseAssemblyResolveEvent

enum WorkType
{
WT_UnloadDomain = 0x1,
WT_ThreadAbort = 0x2,
WT_FinalizerThread = 0x4
};

static Volatile<DWORD> s_WorkType = 0;

void SystemDomain::ProcessDelayedUnloadLoaderAllocators()
{
CONTRACTL
Expand Down
52 changes: 7 additions & 45 deletions src/coreclr/vm/finalizerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
// Setting the event here, instead of at the bottom of the loop, could
// cause us to skip draining the Q, if the request is made as soon as
// the app starts running.
SignalFinalizationDone(TRUE);
SignalFinalizationDone();
#endif //0

WaitForFinalizerEvent (hEventFinalizer);
Expand Down Expand Up @@ -410,7 +410,7 @@ VOID FinalizerThread::FinalizerThreadWorker(void *args)
// race in that another thread starting a drain, as we leave a drain, may
// consider itself satisfied by the drain that just completed. This is
// acceptable.
SignalFinalizationDone(TRUE);
SignalFinalizationDone();
}

if (s_InitializedFinalizerThreadForPlatform)
Expand Down Expand Up @@ -538,19 +538,15 @@ void FinalizerThread::FinalizerThreadCreate()
}
}

void FinalizerThread::SignalFinalizationDone(BOOL fFinalizer)
void FinalizerThread::SignalFinalizationDone()
{
WRAPPER_NO_CONTRACT;

if (fFinalizer)
{
InterlockedAnd((LONG*)&g_FinalizerWaiterStatus, ~FWS_WaitInterrupt);
}
hEventFinalizerDone->Set();
}

// Wait for the finalizer thread to complete one pass.
void FinalizerThread::FinalizerThreadWait(DWORD timeout)
void FinalizerThread::FinalizerThreadWait()
{
ASSERT(hEventFinalizerDone->IsValid());
ASSERT(hEventFinalizer->IsValid());
Expand All @@ -569,44 +565,10 @@ void FinalizerThread::FinalizerThreadWait(DWORD timeout)
g_pRCWCleanupList->CleanupWrappersInCurrentCtxThread();
#endif // FEATURE_COMINTEROP

ULONGLONG startTime = CLRGetTickCount64();
ULONGLONG endTime;
if (timeout == INFINITE)
{
endTime = MAXULONGLONG;
}
else
{
endTime = timeout + startTime;
}

while (TRUE)
{
hEventFinalizerDone->Reset();
EnableFinalization();
hEventFinalizerDone->Reset();

//----------------------------------------------------
// Do appropriate wait and pump messages if necessary
//----------------------------------------------------
EnableFinalization();

DWORD status = hEventFinalizerDone->Wait(timeout,TRUE);
if (status != WAIT_TIMEOUT && !(g_FinalizerWaiterStatus & FWS_WaitInterrupt))
{
return;
}
// recalculate timeout
if (timeout != INFINITE)
{
ULONGLONG curTime = CLRGetTickCount64();
if (curTime >= endTime)
{
return;
}
else
{
timeout = (DWORD)(endTime - curTime);
}
}
}
hEventFinalizerDone->Wait(INFINITE,TRUE);
}
}
7 changes: 2 additions & 5 deletions src/coreclr/vm/finalizerthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ class FinalizerThread
}
}

static void FinalizerThreadWait(DWORD timeout = INFINITE);
static void FinalizerThreadWait();

// We wake up a wait for finaliation for two reasons:
// if fFinalizer=TRUE, we have finished finalization.
// if fFinalizer=FALSE, the timeout for finalization is changed, and AD unload helper thread is notified.
static void SignalFinalizationDone(BOOL fFinalizer);
static void SignalFinalizationDone();

static VOID FinalizerThreadWorker(void *args);
static DWORD WINAPI FinalizerThreadStart(void *args);
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ GVAL_IMPL(SIZE_T, g_runtimeVirtualSize);

bool g_fManagedAttach = false;

DWORD g_FinalizerWaiterStatus = 0;

//
// Do we own the lifetime of the process, ie. is it an EXE?
//
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/vm/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,6 @@ inline bool IsAtProcessExit()
#endif
}

enum FWStatus
{
FWS_WaitInterrupt = 0x00000001,
};

EXTERN DWORD g_FinalizerWaiterStatus;

#if defined(TARGET_UNIX) && defined(FEATURE_EVENT_TRACE)
extern Volatile<BOOL> g_TriggerHeapDump;
#endif // TARGET_UNIX
Expand Down

0 comments on commit 7b1c0f3

Please sign in to comment.