-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fixes when accessing fgn_maxgen_percent #25650
Conversation
PR #25350 changed `fgn_maxgen_percent` to be a per-heap property when `MULTIPLE_HEAPS` is set. A few uses need to be updated. * In `full_gc_wait`, must re-read `fgn_maxgen_percent` before the second test of `maxgen_percent == 0`. (Otherwise the second test is statically unreachable.) * In RegisterForFullGCNotification, must set `fgn_maxgen_percent` when `MULTIPLE_HEAPS` is not set * In CancelFullGCNotification, must set `fgn_maxgen_percent` for each heap separately when `MULTIPLE_HEAPS` is set. Fix dotnet/corefx#39374
src/gc/gc.cpp
Outdated
| if ((wait_result == WAIT_OBJECT_0) || (wait_result == WAIT_TIMEOUT)) | ||
| { | ||
| #ifdef MULTIPLE_HEAPS | ||
| maxgen_percent = g_heaps[0]->fgn_maxgen_percent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxgen_percent = g_heaps[0]->fgn_maxgen_percent; [](start = 7, length = 49)
maxgen_percent was already read at the beginning of this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see your comment from above - is it because the 1st time we read the value we observe its not set yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operation may be canceled while we're waiting, and CancelFullGCNotification works by setting fgn_maxgen_percent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh right; we still wanna return the right status so we need to re-read. makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw we could also write the code this way (like what the other places are doing) so you don't have to duplicate the code:
#ifdef MULTIPLE_HEAPS
gc_heap* hp = gc_heap::g_heaps[0];
#else
gc_heap* hp = pGenGCHeap;
#endif //MULTIPLE_HEAPS
if (hp->fgn_maxgen_percent == 0)
|
Simplified test case: using System;
using System.Threading;
namespace cs
{
class Program
{
public static int Main(string[] args)
{
Console.WriteLine($"Server gc? {System.Runtime.GCSettings.IsServerGC}");
GC.RegisterForFullGCNotification(20, 20);
Thread cancelProc = new Thread(new ThreadStart(CancelProc));
cancelProc.Start();
GCNotificationStatus result = GC.WaitForFullGCComplete(-1);
cancelProc.Join();
if (result == GCNotificationStatus.Canceled)
{
Console.WriteLine("success");
return 0;
}
else
{
Console.Error.WriteLine($"Error - WaitForFullGCComplete result not Cancelled. Instead result is: {result}");
return 1;
}
}
private static void CancelProc()
{
Thread.Sleep(500);
GC.CancelFullGCNotification();
}
}
}Tested with both server and workstation GCs. |
|
approved to merge. |
* Fixes when accessing fgn_maxgen_percent PR dotnet/coreclr#25350 changed `fgn_maxgen_percent` to be a per-heap property when `MULTIPLE_HEAPS` is set. A few uses need to be updated. * In `full_gc_wait`, must re-read `fgn_maxgen_percent` before the second test of `maxgen_percent == 0`. (Otherwise the second test is statically unreachable.) * In RegisterForFullGCNotification, must set `fgn_maxgen_percent` when `MULTIPLE_HEAPS` is not set * In CancelFullGCNotification, must set `fgn_maxgen_percent` for each heap separately when `MULTIPLE_HEAPS` is set. Fix dotnet/corefxdotnet/coreclr#39374 * Avoid duplicate code when getting fgn_maxgen_percent twice in full_gc_wait Commit migrated from dotnet/coreclr@4b5ae70
PR #25350 changed
fgn_maxgen_percentto be a per-heap property whenMULTIPLE_HEAPSis set. A few uses need to be updated.full_gc_wait, must re-readfgn_maxgen_percentbefore thesecond test of
maxgen_percent == 0.(Otherwise the second test is statically unreachable.)
fgn_maxgen_percentwhenMULTIPLE_HEAPSis not setfgn_maxgen_percentfor eachheap separately when
MULTIPLE_HEAPSis set.Fix dotnet/corefx#39374