Skip to content

Commit d1a7184

Browse files
Issue was that if a BGC thread handles a mark stack overflow, but runs into yet another mark stack overflow on another heap, we set a flag on the region, and the containing heap. However, the BGC handling the other heap may have already decided to move on, and may thus not see the flag. (#74814)
Fix is to set the flag on the heap doing the scan rather than the heap containing the object causing the mark stack stack overflow. The thread handling that heap will indeed recheck the flag and rescan if necessary. This necessitates another change because in the concurrent case, we need each BGC thread to enter mark stack overflow scanning if there was a mark stack overflow on its heap. So we need to propagate the per-heap flag to all the heaps. Fixed another issue for regions where the small_object_segments local variable in background_process_mark_overflow_internal would be set incorrectly in the non-concurrent case. It would be set to FALSE as soon as all the regions for gen 0 are processed. Co-authored-by: Peter Sollich <petersol@microsoft.com>
1 parent 65051a0 commit d1a7184

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24659,12 +24659,7 @@ void gc_heap::set_background_overflow_p (uint8_t* oo)
2465924659
heap_segment* overflow_region = get_region_info_for_address (oo);
2466024660
overflow_region->flags |= heap_segment_flags_overflow;
2466124661
dprintf (3,("setting overflow flag for region %p", heap_segment_mem (overflow_region)));
24662-
#ifdef MULTIPLE_HEAPS
24663-
gc_heap* overflow_heap = heap_segment_heap (overflow_region);
24664-
#else
24665-
gc_heap* overflow_heap = nullptr;
24666-
#endif
24667-
overflow_heap->background_overflow_p = TRUE;
24662+
background_overflow_p = TRUE;
2466824663
}
2466924664
#endif //USE_REGIONS
2467024665

@@ -25311,13 +25306,13 @@ void gc_heap::background_process_mark_overflow_internal (uint8_t* min_add, uint8
2531125306

2531225307
dprintf (2, ("h%d: SOH: ov-mo: %Id", heap_number, total_marked_objects));
2531325308
fire_overflow_event (min_add, max_add, total_marked_objects, i);
25314-
if (small_object_segments)
25309+
if (i >= soh_gen2)
2531525310
{
2531625311
concurrent_print_time_delta (concurrent_p ? "Cov SOH" : "Nov SOH");
25312+
small_object_segments = FALSE;
2531725313
}
2531825314

2531925315
total_marked_objects = 0;
25320-
small_object_segments = FALSE;
2532125316
}
2532225317
}
2532325318
}
@@ -33980,23 +33975,35 @@ void gc_heap::background_scan_dependent_handles (ScanContext *sc)
3398033975

3398133976
if (!s_fScanRequired)
3398233977
{
33983-
#ifndef USE_REGIONS
33978+
#ifdef USE_REGIONS
33979+
BOOL all_heaps_background_overflow_p = FALSE;
33980+
#else //USE_REGIONS
3398433981
uint8_t* all_heaps_max = 0;
3398533982
uint8_t* all_heaps_min = MAX_PTR;
33983+
#endif //USE_REGIONS
3398633984
int i;
3398733985
for (i = 0; i < n_heaps; i++)
3398833986
{
33987+
#ifdef USE_REGIONS
33988+
// in the regions case, compute the OR of all the per-heap flags
33989+
if (g_heaps[i]->background_overflow_p)
33990+
all_heaps_background_overflow_p = TRUE;
33991+
#else //USE_REGIONS
3398933992
if (all_heaps_max < g_heaps[i]->background_max_overflow_address)
3399033993
all_heaps_max = g_heaps[i]->background_max_overflow_address;
3399133994
if (all_heaps_min > g_heaps[i]->background_min_overflow_address)
3399233995
all_heaps_min = g_heaps[i]->background_min_overflow_address;
33996+
#endif //USE_REGIONS
3399333997
}
3399433998
for (i = 0; i < n_heaps; i++)
3399533999
{
34000+
#ifdef USE_REGIONS
34001+
g_heaps[i]->background_overflow_p = all_heaps_background_overflow_p;
34002+
#else //USE_REGIONS
3399634003
g_heaps[i]->background_max_overflow_address = all_heaps_max;
3399734004
g_heaps[i]->background_min_overflow_address = all_heaps_min;
34005+
#endif //USE_REGIONS
3399834006
}
33999-
#endif //!USE_REGIONS
3400034007
}
3400134008

3400234009
dprintf(2, ("Starting all gc thread mark stack overflow processing"));
@@ -34740,15 +34747,24 @@ void gc_heap::background_mark_phase ()
3474034747

3474134748
enable_preemptive ();
3474234749

34743-
#if defined(MULTIPLE_HEAPS) && !defined(USE_REGIONS)
34750+
#if defined(MULTIPLE_HEAPS)
3474434751
bgc_t_join.join(this, gc_join_concurrent_overflow);
3474534752
if (bgc_t_join.joined())
3474634753
{
34754+
#ifdef USE_REGIONS
34755+
BOOL all_heaps_background_overflow_p = FALSE;
34756+
#else //USE_REGIONS
3474734757
uint8_t* all_heaps_max = 0;
3474834758
uint8_t* all_heaps_min = MAX_PTR;
34759+
#endif //USE_REGIONS
3474934760
int i;
3475034761
for (i = 0; i < n_heaps; i++)
3475134762
{
34763+
#ifdef USE_REGIONS
34764+
// in the regions case, compute the OR of all the per-heap flags
34765+
if (g_heaps[i]->background_overflow_p)
34766+
all_heaps_background_overflow_p = TRUE;
34767+
#else //USE_REGIONS
3475234768
dprintf (3, ("heap %d overflow max is %Ix, min is %Ix",
3475334769
i,
3475434770
g_heaps[i]->background_max_overflow_address,
@@ -34757,17 +34773,21 @@ void gc_heap::background_mark_phase ()
3475734773
all_heaps_max = g_heaps[i]->background_max_overflow_address;
3475834774
if (all_heaps_min > g_heaps[i]->background_min_overflow_address)
3475934775
all_heaps_min = g_heaps[i]->background_min_overflow_address;
34760-
34776+
#endif //USE_REGIONS
3476134777
}
3476234778
for (i = 0; i < n_heaps; i++)
3476334779
{
34780+
#ifdef USE_REGIONS
34781+
g_heaps[i]->background_overflow_p = all_heaps_background_overflow_p;
34782+
#else //USE_REGIONS
3476434783
g_heaps[i]->background_max_overflow_address = all_heaps_max;
3476534784
g_heaps[i]->background_min_overflow_address = all_heaps_min;
34785+
#endif //USE_REGIONS
3476634786
}
3476734787
dprintf(3, ("Starting all bgc threads after updating the overflow info"));
3476834788
bgc_t_join.restart();
3476934789
}
34770-
#endif //MULTIPLE_HEAPS && !USE_REGIONS
34790+
#endif //MULTIPLE_HEAPS
3477134791

3477234792
disable_preemptive (true);
3477334793

0 commit comments

Comments
 (0)