From f974d59bb193371617a24e4aa9ac4f0d07aced22 Mon Sep 17 00:00:00 2001 From: "Mukund Raghav Sharma (Moko)" <68247673+mrsharm@users.noreply.github.com> Date: Mon, 1 Aug 2022 09:39:18 -0700 Subject: [PATCH] Fixed a WKS specific issue by not clobbering the heap_segment_saved_allocated (#72923) * Fixed the WKS issue by not clobbering the heap_segment_saved_allocated * Addressed feedback: --- src/coreclr/gc/gc.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index e278bba5005f3..67ff74640c7cb 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -28243,6 +28243,16 @@ void gc_heap::add_plug_in_condemned_info (generation* gen, size_t plug_size) } #endif //FEATURE_EVENT_TRACE +inline void save_allocated(heap_segment* seg) +{ +#ifndef MULTIPLE_HEAP + if (!heap_segment_saved_allocated(seg)) +#endif // !MULTIPLE_HEAP + { + heap_segment_saved_allocated (seg) = heap_segment_allocated (seg); + } +} + #ifdef _PREFAST_ #pragma warning(push) #pragma warning(disable:21000) // Suppress PREFast warning about overly large function @@ -28328,6 +28338,7 @@ void gc_heap::plan_phase (int condemned_gen_number) heap_segment* fseg = seg; do { + heap_segment_saved_allocated(seg) = 0; if (in_range_for_segment (slow, seg)) { uint8_t* start_unmarked = 0; @@ -28375,7 +28386,7 @@ void gc_heap::plan_phase (int condemned_gen_number) bgc_clear_batch_mark_array_bits ((shigh + Align (size (shigh))), heap_segment_allocated (seg)); } #endif //BACKGROUND_GC - heap_segment_saved_allocated (seg) = heap_segment_allocated (seg); + save_allocated(seg); heap_segment_allocated (seg) = shigh + Align (size (shigh)); } // test if the segment is in the range of [slow, shigh] @@ -28394,7 +28405,7 @@ void gc_heap::plan_phase (int condemned_gen_number) #endif //USE_REGIONS } #endif //BACKGROUND_GC - heap_segment_saved_allocated (seg) = heap_segment_allocated (seg); + save_allocated(seg); // shorten it to minimum heap_segment_allocated (seg) = heap_segment_mem (seg); } @@ -28428,7 +28439,7 @@ void gc_heap::plan_phase (int condemned_gen_number) bgc_clear_batch_mark_array_bits (start_unmarked, heap_segment_allocated (seg)); } #endif //BACKGROUND_GC - heap_segment_saved_allocated (seg) = heap_segment_allocated (seg); + save_allocated(seg); heap_segment_allocated (seg) = start_unmarked; seg = heap_segment_next_rw (seg); @@ -28711,7 +28722,7 @@ void gc_heap::plan_phase (int condemned_gen_number) #endif //USE_REGIONS { assert (heap_segment_allocated (seg1) == end); - heap_segment_saved_allocated (seg1) = heap_segment_allocated (seg1); + save_allocated(seg1); heap_segment_allocated (seg1) = plug_end; current_brick = update_brick_table (tree, current_brick, x, plug_end); dprintf (REGIONS_LOG, ("region %Ix-%Ix(%Ix) non SIP", @@ -31042,7 +31053,7 @@ void gc_heap::sweep_region_in_plan (heap_segment* region, #endif //_DEBUG assert (last_marked_obj_end); - heap_segment_saved_allocated (region) = heap_segment_allocated (region); + save_allocated(region); heap_segment_allocated (region) = last_marked_obj_end; heap_segment_plan_allocated (region) = heap_segment_allocated (region);