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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void ProcessFinalizers()
{
// RhpWaitForFinalizerRequest() returned false and indicated that memory is low. We help
// out by initiating a garbage collection and then go back to waiting for another request.
InternalCalls.RhCollect(-1, InternalGCCollectionMode.Blocking);
InternalCalls.RhCollect(0, InternalGCCollectionMode.Blocking, lowMemoryP: true);
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/coreclr/nativeaot/Runtime/FinalizerHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ GPTR_DECL(Thread, g_pFinalizerThread);
CLREventStatic g_FinalizerEvent;
CLREventStatic g_FinalizerDoneEvent;

static HANDLE g_lowMemoryNotification = NULL;

EXTERN_C void QCALLTYPE ProcessFinalizers();

// Unmanaged front-end to the finalizer thread. We require this because at the point the GC creates the
Expand Down Expand Up @@ -76,6 +78,7 @@ bool RhInitializeFinalization()
return false;
if (!g_FinalizerDoneEvent.CreateManualEventNoThrow(false))
return false;
g_lowMemoryNotification = PalCreateLowMemoryResourceNotification();

// Create the finalizer thread itself.
if (!PalStartFinalizerThread(FinalizerStart, (void*)g_FinalizerEvent.GetOSEvent()))
Expand Down Expand Up @@ -132,17 +135,12 @@ EXTERN_C UInt32_BOOL QCALLTYPE RhpWaitForFinalizerRequest()
// two second timeout expires.
do
{
HANDLE lowMemEvent = NULL;
#if 0 // TODO: hook up low memory notification
lowMemEvent = pHeap->GetLowMemoryNotificationEvent();
HANDLE lowMemEvent = g_lowMemoryNotification;
HANDLE rgWaitHandles[] = { g_FinalizerEvent.GetOSEvent(), lowMemEvent };
uint32_t cWaitHandles = (fLastEventWasLowMemory || (lowMemEvent == NULL)) ? 1 : 2;
uint32_t uTimeout = fLastEventWasLowMemory ? 2000 : INFINITE;

uint32_t uResult = PalWaitForMultipleObjectsEx(cWaitHandles, rgWaitHandles, FALSE, uTimeout, FALSE);
#else
uint32_t uResult = PalWaitForSingleObjectEx(g_FinalizerEvent.GetOSEvent(), INFINITE, FALSE);
#endif
uint32_t uResult = PalCompatibleWaitAny(/*alertable=*/ FALSE, uTimeout, cWaitHandles, rgWaitHandles, /*allowReentrantWait=*/ FALSE);

switch (uResult)
{
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalMarkThunksAsValidCallTargets(

REDHAWK_PALIMPORT uint32_t REDHAWK_PALAPI PalCompatibleWaitAny(UInt32_BOOL alertable, uint32_t timeout, uint32_t count, HANDLE* pHandles, UInt32_BOOL allowReentrantWait);

REDHAWK_PALIMPORT HANDLE PalCreateLowMemoryResourceNotification();

REDHAWK_PALIMPORT void REDHAWK_PALAPI PalAttachThread(void* thread);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalDetachThread(void* thread);

Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,11 @@ REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalCompatibleWaitAny(UInt32_BOOL alert
return WaitForSingleObjectEx(pHandles[0], timeout, alertable);
}

REDHAWK_PALEXPORT HANDLE PalCreateLowMemoryResourceNotification()
{
return NULL;
}

#if !__has_builtin(_mm_pause)
extern "C" void _mm_pause()
// Defined for implementing PalYieldProcessor in PalRedhawk.h
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalCompatibleWaitAny(UInt32_BOOL alert
}
}

REDHAWK_PALEXPORT HANDLE PalCreateLowMemoryResourceNotification()
{
return CreateMemoryResourceNotification(LowMemoryResourceNotification);
}

REDHAWK_PALEXPORT void REDHAWK_PALAPI PalSleep(uint32_t milliseconds)
{
return Sleep(milliseconds);
Expand Down