From c56ba36e9b949d561ec9f94dd530fc352b9d83a2 Mon Sep 17 00:00:00 2001 From: vsadov <8218165+VSadov@users.noreply.github.com> Date: Tue, 22 Nov 2022 21:27:21 -0800 Subject: [PATCH 1/2] Aging dependent handles --- src/coreclr/gc/handletablescan.cpp | 24 +++++++++++++++++++++++- src/coreclr/gc/objecthandle.cpp | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/handletablescan.cpp b/src/coreclr/gc/handletablescan.cpp index 276e865518b23d..f90cf7bcfb6c14 100644 --- a/src/coreclr/gc/handletablescan.cpp +++ b/src/coreclr/gc/handletablescan.cpp @@ -796,10 +796,21 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca // compute the first handle in the first clump of this block _UNCHECKED_OBJECTREF *pValue = pSegment->rgValue + (uClump * HANDLE_HANDLES_PER_CLUMP); + uint32_t uBlock = uClump / HANDLE_CLUMPS_PER_BLOCK; + uint8_t uType = pSegment->rgBlockType[uBlock]; + + _UNCHECKED_OBJECTREF* pUserDataBlock = NULL; + if (uType == HNDTYPE_DEPENDENT) + { + uint8_t uData = pSegment->rgUserData[uBlock]; + _ASSERTE(uData != BLOCK_INVALID); + pUserDataBlock = pSegment->rgValue + (uData * HANDLE_HANDLES_PER_BLOCK); + } + // loop over the clumps, scanning those that are identified by the mask do { - // compute the last handle in this clump + // compute the last handle in this clump _UNCHECKED_OBJECTREF *pLast = pValue + HANDLE_HANDLES_PER_CLUMP; // if this clump should be scanned then scan it @@ -827,6 +838,17 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca } }); #endif + if (uType == HNDTYPE_DEPENDENT) + { + size_t handleIndexInBlock = ((size_t)pValue / HANDLE_SIZE) & (HANDLE_HANDLES_PER_BLOCK - 1); + _UNCHECKED_OBJECTREF pSecondary = pUserDataBlock[handleIndexInBlock]; + if (pSecondary) + { + int secondaryAge = g_theGCHeap->WhichGeneration(pSecondary); + if (minAge > secondaryAge) + minAge = secondaryAge; + } + } } } _ASSERTE(FitsInU1(minAge)); diff --git a/src/coreclr/gc/objecthandle.cpp b/src/coreclr/gc/objecthandle.cpp index 62803851d1d198..45054e04941d8f 100644 --- a/src/coreclr/gc/objecthandle.cpp +++ b/src/coreclr/gc/objecthandle.cpp @@ -1815,6 +1815,7 @@ void Ref_AgeHandles(uint32_t condemned, uint32_t maxgen, ScanContext* sc) #ifdef FEATURE_VARIABLE_HANDLES HNDTYPE_VARIABLE, #endif + HNDTYPE_DEPENDENT, #ifdef FEATURE_REFCOUNTED_HANDLES HNDTYPE_REFCOUNTED, #endif @@ -1868,13 +1869,13 @@ void Ref_RejuvenateHandles(uint32_t condemned, uint32_t maxgen, ScanContext* sc) HNDTYPE_WEAK_SHORT, HNDTYPE_WEAK_LONG, - HNDTYPE_STRONG, HNDTYPE_PINNED, #ifdef FEATURE_VARIABLE_HANDLES HNDTYPE_VARIABLE, #endif + HNDTYPE_DEPENDENT, #ifdef FEATURE_REFCOUNTED_HANDLES HNDTYPE_REFCOUNTED, #endif From f4d735ec33a1604bcc31f975ff335417c54186ec Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Fri, 12 Jun 2026 08:42:13 -0700 Subject: [PATCH 2/2] Update src/coreclr/gc/handletablescan.cpp --- src/coreclr/gc/handletablescan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/gc/handletablescan.cpp b/src/coreclr/gc/handletablescan.cpp index f90cf7bcfb6c14..15137c85f1e2e1 100644 --- a/src/coreclr/gc/handletablescan.cpp +++ b/src/coreclr/gc/handletablescan.cpp @@ -844,7 +844,7 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca _UNCHECKED_OBJECTREF pSecondary = pUserDataBlock[handleIndexInBlock]; if (pSecondary) { - int secondaryAge = g_theGCHeap->WhichGeneration(pSecondary); + int secondaryAge = GetConvertedGeneration(pSecondary); if (minAge > secondaryAge) minAge = secondaryAge; }