From 50b175bcbbd5ce5a8a6586d2738a9b8db8efd334 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Sat, 17 May 2025 12:20:08 -0700 Subject: [PATCH] Report collection counts non-inclusively (#51) --- src/coreclr/gc/satori/SatoriGC.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/coreclr/gc/satori/SatoriGC.cpp b/src/coreclr/gc/satori/SatoriGC.cpp index 674b46c4b82..bc91fc3b79e 100644 --- a/src/coreclr/gc/satori/SatoriGC.cpp +++ b/src/coreclr/gc/satori/SatoriGC.cpp @@ -197,13 +197,26 @@ unsigned SatoriGC::WhichGeneration(Object* obj) int SatoriGC::CollectionCount(int generation, int get_bgc_fgc_coutn) { - //get_bgc_fgc_coutn N/A + // get_bgc_fgc_coutn - not sure what this is. thus N/A + if ((unsigned)generation > (unsigned)2) { return 0; } - return (int)m_heap->Recycler()->GetCollectionCount(generation); + int64_t count = m_heap->Recycler()->GetCollectionCount(generation); + + // in the public API GC counts are not inclusive + if (generation < 1) + { + count -= m_heap->Recycler()->GetCollectionCount(1); + } + else if (generation < 2) + { + count -= m_heap->Recycler()->GetCollectionCount(2); + } + + return (int)count; } int SatoriGC::StartNoGCRegion(uint64_t totalSize, bool lohSizeKnown, uint64_t lohSize, bool disallowFullBlockingGC) @@ -360,6 +373,8 @@ bool SatoriGC::IsGCInProgressHelper(bool bConsiderGCStart) return m_gcInProgress; } +// this is basically a GC index +// it is used in suspend events, and in GC stress. unsigned SatoriGC::GetGcCount() { if (!m_heap) @@ -367,7 +382,7 @@ unsigned SatoriGC::GetGcCount() return 0; } - return (unsigned)(int)m_heap->Recycler()->GetCollectionCount(/*gen*/ 1); + return (unsigned)(int)m_heap->Recycler()->GetCollectionCount(/*gen*/ 0); } bool SatoriGC::IsThreadUsingAllocationContextHeap(gc_alloc_context* acontext, int thread_number)