From 11e9864da86bcf45f45d5bd2fdccb198aace0d03 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 11 Jul 2019 12:29:12 -0700 Subject: [PATCH 1/2] Fixes when accessing fgn_maxgen_percent 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index f107b134ca23..d4202e48e891 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -12392,6 +12392,11 @@ wait_full_gc_status gc_heap::full_gc_wait (GCEvent *event, int time_out_ms) if ((wait_result == WAIT_OBJECT_0) || (wait_result == WAIT_TIMEOUT)) { +#ifdef MULTIPLE_HEAPS + maxgen_percent = g_heaps[0]->fgn_maxgen_percent; +#else + maxgen_percent = fgn_maxgen_percent; +#endif //MULTIPLE_HEAPS if (maxgen_percent == 0) { return wait_full_gc_cancelled; @@ -36900,6 +36905,7 @@ bool GCHeap::RegisterForFullGCNotification(uint32_t gen2Percentage, } #else //MULTIPLE_HEAPS pGenGCHeap->fgn_last_alloc = dd_new_allocation (pGenGCHeap->dynamic_data_of (0)); + pGenGCHeap->fgn_maxgen_percent = gen2Percentage; #endif //MULTIPLE_HEAPS pGenGCHeap->full_gc_approach_event.Reset(); @@ -36913,9 +36919,17 @@ bool GCHeap::RegisterForFullGCNotification(uint32_t gen2Percentage, bool GCHeap::CancelFullGCNotification() { +#ifdef MULTIPLE_HEAPS + for (int hn = 0; hn < gc_heap::n_heaps; hn++) + { + gc_heap* hp = gc_heap::g_heaps [hn]; + hp->fgn_maxgen_percent = 0; + } +#else //MULTIPLE_HEAPS pGenGCHeap->fgn_maxgen_percent = 0; - pGenGCHeap->fgn_loh_percent = 0; +#endif //MULTIPLE_HEAPS + pGenGCHeap->fgn_loh_percent = 0; pGenGCHeap->full_gc_approach_event.Set(); pGenGCHeap->full_gc_end_event.Set(); From c3798cf0cefa041f417ef0d32b74c8059c8cd4b7 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 11 Jul 2019 14:09:40 -0700 Subject: [PATCH 2/2] Avoid duplicate code when getting fgn_maxgen_percent twice in full_gc_wait --- src/gc/gc.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index d4202e48e891..f49366474e5e 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -12377,13 +12377,13 @@ void gc_heap::send_full_gc_notification (int gen_num, BOOL due_to_alloc_p) wait_full_gc_status gc_heap::full_gc_wait (GCEvent *event, int time_out_ms) { - uint32_t maxgen_percent = 0; #ifdef MULTIPLE_HEAPS - maxgen_percent = g_heaps[0]->fgn_maxgen_percent; + gc_heap* hp = gc_heap::g_heaps[0]; #else - maxgen_percent = fgn_maxgen_percent; + gc_heap* hp = pGenGCHeap; #endif //MULTIPLE_HEAPS - if (maxgen_percent == 0) + + if (hp->fgn_maxgen_percent == 0) { return wait_full_gc_na; } @@ -12392,12 +12392,7 @@ wait_full_gc_status gc_heap::full_gc_wait (GCEvent *event, int time_out_ms) if ((wait_result == WAIT_OBJECT_0) || (wait_result == WAIT_TIMEOUT)) { -#ifdef MULTIPLE_HEAPS - maxgen_percent = g_heaps[0]->fgn_maxgen_percent; -#else - maxgen_percent = fgn_maxgen_percent; -#endif //MULTIPLE_HEAPS - if (maxgen_percent == 0) + if (hp->fgn_maxgen_percent == 0) { return wait_full_gc_cancelled; }