Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Issue was that if a BGC thread handles a mark stack overflow, but run…
…s 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.

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.
  • Loading branch information
PeterSolMS committed Aug 25, 2022
commit a9eb0d08c038575dd258e3a3ccd3cae52423d029
46 changes: 33 additions & 13 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24659,12 +24659,7 @@ void gc_heap::set_background_overflow_p (uint8_t* oo)
heap_segment* overflow_region = get_region_info_for_address (oo);
overflow_region->flags |= heap_segment_flags_overflow;
dprintf (3,("setting overflow flag for region %p", heap_segment_mem (overflow_region)));
#ifdef MULTIPLE_HEAPS
gc_heap* overflow_heap = heap_segment_heap (overflow_region);
#else
gc_heap* overflow_heap = nullptr;
#endif
overflow_heap->background_overflow_p = TRUE;
background_overflow_p = TRUE;
}
#endif //USE_REGIONS

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

dprintf (2, ("h%d: SOH: ov-mo: %Id", heap_number, total_marked_objects));
fire_overflow_event (min_add, max_add, total_marked_objects, i);
if (small_object_segments)
if (i >= soh_gen2)
{
concurrent_print_time_delta (concurrent_p ? "Cov SOH" : "Nov SOH");
small_object_segments = FALSE;
}

total_marked_objects = 0;
small_object_segments = FALSE;
}
}
}
Expand Down Expand Up @@ -33980,23 +33975,35 @@ void gc_heap::background_scan_dependent_handles (ScanContext *sc)

if (!s_fScanRequired)
{
#ifndef USE_REGIONS
#ifdef USE_REGIONS
BOOL all_heaps_background_overflow_p = FALSE;
#else //USE_REGIONS
uint8_t* all_heaps_max = 0;
uint8_t* all_heaps_min = MAX_PTR;
#endif //USE_REGIONS
int i;
for (i = 0; i < n_heaps; i++)
{
#ifdef USE_REGIONS
// in the regions case, compute the OR of all the per-heap flags
if (g_heaps[i]->background_overflow_p)
all_heaps_background_overflow_p = TRUE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any perf impact of setting this across all heaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the perf impact is to do some work balancing between all Server BGC threads processing OF. for heaps that didn't actually have any OF it would quickly filter by its regions' OF flag.

#else //USE_REGIONS
if (all_heaps_max < g_heaps[i]->background_max_overflow_address)
all_heaps_max = g_heaps[i]->background_max_overflow_address;
if (all_heaps_min > g_heaps[i]->background_min_overflow_address)
all_heaps_min = g_heaps[i]->background_min_overflow_address;
#endif //USE_REGIONS
}
for (i = 0; i < n_heaps; i++)
{
#ifdef USE_REGIONS
g_heaps[i]->background_overflow_p = all_heaps_background_overflow_p;
#else //USE_REGIONS
g_heaps[i]->background_max_overflow_address = all_heaps_max;
g_heaps[i]->background_min_overflow_address = all_heaps_min;
#endif //USE_REGIONS
}
#endif //!USE_REGIONS
}

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

enable_preemptive ();

#if defined(MULTIPLE_HEAPS) && !defined(USE_REGIONS)
#if defined(MULTIPLE_HEAPS)
bgc_t_join.join(this, gc_join_concurrent_overflow);
if (bgc_t_join.joined())
{
#ifdef USE_REGIONS
BOOL all_heaps_background_overflow_p = FALSE;
#else //USE_REGIONS
uint8_t* all_heaps_max = 0;
uint8_t* all_heaps_min = MAX_PTR;
#endif //USE_REGIONS
int i;
for (i = 0; i < n_heaps; i++)
{
#ifdef USE_REGIONS
// in the regions case, compute the OR of all the per-heap flags
if (g_heaps[i]->background_overflow_p)
all_heaps_background_overflow_p = TRUE;
#else //USE_REGIONS
dprintf (3, ("heap %d overflow max is %Ix, min is %Ix",
i,
g_heaps[i]->background_max_overflow_address,
Expand All @@ -34757,17 +34773,21 @@ void gc_heap::background_mark_phase ()
all_heaps_max = g_heaps[i]->background_max_overflow_address;
if (all_heaps_min > g_heaps[i]->background_min_overflow_address)
all_heaps_min = g_heaps[i]->background_min_overflow_address;

#endif //USE_REGIONS
}
for (i = 0; i < n_heaps; i++)
{
#ifdef USE_REGIONS
g_heaps[i]->background_overflow_p = all_heaps_background_overflow_p;
#else //USE_REGIONS
g_heaps[i]->background_max_overflow_address = all_heaps_max;
g_heaps[i]->background_min_overflow_address = all_heaps_min;
#endif //USE_REGIONS
}
dprintf(3, ("Starting all bgc threads after updating the overflow info"));
bgc_t_join.restart();
}
#endif //MULTIPLE_HEAPS && !USE_REGIONS
#endif //MULTIPLE_HEAPS

disable_preemptive (true);

Expand Down