From 8deb9196ce27d08337d1c5d9c00ab20f310b37bd Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Tue, 12 Apr 2022 18:47:04 -0700 Subject: [PATCH 1/2] Report SIP survivors --- src/coreclr/gc/gc.cpp | 52 +++++++++++++++++++++++++++++++++-------- src/coreclr/gc/gcpriv.h | 5 +++- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 9a594fbc2d4721..e280ceaaa243e9 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -32150,11 +32150,7 @@ void gc_heap::walk_relocation (void* profiling_context, record_surv_fn fn) generation* condemned_gen = generation_of (i); heap_segment* current_heap_segment = heap_segment_rw (generation_start_segment (condemned_gen)); #ifdef USE_REGIONS - while (current_heap_segment && heap_segment_swept_in_plan (current_heap_segment)) - { - // TODO: Walk the heap segment and report the plugs. - current_heap_segment = heap_segment_next_rw (current_heap_segment); - } + current_heap_segment = walk_relocation_sip (current_heap_segment, profiling_context, fn); if (!current_heap_segment) continue; #endif // USE_REGIONS @@ -32187,11 +32183,7 @@ void gc_heap::walk_relocation (void* profiling_context, record_surv_fn fn) } current_heap_segment = heap_segment_next_rw (current_heap_segment); #ifdef USE_REGIONS - while (current_heap_segment && heap_segment_swept_in_plan (current_heap_segment)) - { - // TODO: Walk the heap segment and report the plugs. - current_heap_segment = heap_segment_next_rw (current_heap_segment); - } + current_heap_segment = walk_relocation_sip (current_heap_segment, profiling_context, fn); #endif // USE_REGIONS if (current_heap_segment) { @@ -32218,6 +32210,46 @@ void gc_heap::walk_relocation (void* profiling_context, record_surv_fn fn) } } +#ifdef USE_REGIONS +heap_segment* gc_heap::walk_relocation_sip (heap_segment* current_heap_segment, void* profiling_context, record_surv_fn fn) +{ + while (current_heap_segment && heap_segment_swept_in_plan (current_heap_segment)) + { + uint8_t* start = heap_segment_mem (current_heap_segment); + uint8_t* end = heap_segment_allocated (current_heap_segment); + uint8_t* obj = start; + uint8_t* plug_start = nullptr; + while (obj < end) + { + uint8_t* next_obj = obj + Align (size (obj)); + BOOL isFree = ((CObjectHeader*)obj)->IsFree(); + if (plug_start == nullptr) + { + if (!isFree) + { + plug_start = obj; + } + } + else + { + if (isFree) + { + fn (plug_start, obj, 0, profiling_context, false, false); + plug_start = nullptr; + } + } + obj = next_obj; + } + if (plug_start) + { + fn (plug_start, end, 0, profiling_context, false, false); + } + current_heap_segment = heap_segment_next_rw (current_heap_segment); + } + return current_heap_segment; +} +#endif // USE_REGIONS + void gc_heap::walk_survivors (record_surv_fn fn, void* context, walk_surv_type type) { if (type == walk_for_gc) diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index 0f042baa6018f1..8b364071286e0c 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -1647,7 +1647,10 @@ class gc_heap PER_HEAP void walk_relocation (void* profiling_context, record_surv_fn fn); - +#ifdef USE_REGIONS + PER_HEAP + heap_segment* walk_relocation_sip (heap_segment* current_heap_segment, void* profiling_context, record_surv_fn fn); +#endif // USE_REGIONS PER_HEAP void walk_relocation_in_brick (uint8_t* tree, walk_relocate_args* args); From 1ce3b374fffadc66d43e26b29ba91b6f740e0342 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Thu, 14 Apr 2022 08:23:41 -0700 Subject: [PATCH 2/2] Code review feedback --- src/coreclr/gc/gc.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index e280ceaaa243e9..64ef8a56d20e5f 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -32221,24 +32221,23 @@ heap_segment* gc_heap::walk_relocation_sip (heap_segment* current_heap_segment, uint8_t* plug_start = nullptr; while (obj < end) { - uint8_t* next_obj = obj + Align (size (obj)); - BOOL isFree = ((CObjectHeader*)obj)->IsFree(); - if (plug_start == nullptr) + if (((CObjectHeader*)obj)->IsFree()) { - if (!isFree) + if (plug_start) { - plug_start = obj; + fn (plug_start, obj, 0, profiling_context, false, false); + plug_start = nullptr; } } else { - if (isFree) + if (!plug_start) { - fn (plug_start, obj, 0, profiling_context, false, false); - plug_start = nullptr; + plug_start = obj; } } - obj = next_obj; + + obj += Align (size (obj)); } if (plug_start) {