From acea06f1f54cb8a739ca493ead595d37c8611806 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Sat, 20 Jan 2024 15:25:14 -0800 Subject: [PATCH] Frozen objects should be identified as Gen2 in the handle table (#97109) --- src/coreclr/gc/env/common.h | 1 + src/coreclr/gc/handletable.cpp | 10 +++++++++- src/coreclr/gc/handletablepriv.h | 12 ++++++++++++ src/coreclr/gc/handletablescan.cpp | 6 +++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/coreclr/gc/env/common.h b/src/coreclr/gc/env/common.h index 02e142a23a602..78562ef0438b4 100644 --- a/src/coreclr/gc/env/common.h +++ b/src/coreclr/gc/env/common.h @@ -21,6 +21,7 @@ #include #include #include +#include #include diff --git a/src/coreclr/gc/handletable.cpp b/src/coreclr/gc/handletable.cpp index ca8b1dbaa61cb..356b0e0bdc314 100644 --- a/src/coreclr/gc/handletable.cpp +++ b/src/coreclr/gc/handletable.cpp @@ -24,6 +24,14 @@ DWORD g_dwHandles = 0; #endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE +#ifndef DACCESS_COMPILE +int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj) +{ + int generation = g_theGCHeap->WhichGeneration(obj); + return generation == INT_MAX ? max_generation : generation; +} +#endif //DACCESS_COMPILE + /**************************************************************************** * * FORWARD DECLARATIONS @@ -577,7 +585,7 @@ void HndWriteBarrierWorker(OBJECTHANDLE handle, _UNCHECKED_OBJECTREF value) if (*pClumpAge != 0) // Perf optimization: if clumpAge is 0, nothing more to do { // find out generation - int generation = g_theGCHeap->WhichGeneration(value); + int generation = GetConvertedGeneration(value); uint32_t uType = HandleFetchType(handle); #ifdef FEATURE_ASYNC_PINNED_HANDLES diff --git a/src/coreclr/gc/handletablepriv.h b/src/coreclr/gc/handletablepriv.h index 086ef2e018b6f..e09e89cecaaae 100644 --- a/src/coreclr/gc/handletablepriv.h +++ b/src/coreclr/gc/handletablepriv.h @@ -942,3 +942,15 @@ void CALLBACK BlockVerifyAgeMapForBlocks(PTR_TableSegment pSegment, uint32_t uBl PTR_TableSegment CALLBACK xxxAsyncSegmentIterator(PTR_HandleTable pTable, TableSegment *pPrevSegment, CrstHolderWithState *pCrstHolder); /*--------------------------------------------------------------------------*/ + +#ifndef DACCESS_COMPILE + +/* + * GetConvertedGeneration + * + * Get the generation of an object, where a frozen object is regarded as max_generation + * + */ +int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj); + +#endif //DACCESS_COMPILE diff --git a/src/coreclr/gc/handletablescan.cpp b/src/coreclr/gc/handletablescan.cpp index 171647501b4cb..7c0692ad5b8ff 100644 --- a/src/coreclr/gc/handletablescan.cpp +++ b/src/coreclr/gc/handletablescan.cpp @@ -811,7 +811,7 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca { if (!HndIsNullOrDestroyedHandle(*pValue)) { - int thisAge = g_theGCHeap->WhichGeneration(*pValue); + int thisAge = GetConvertedGeneration(*pValue); if (minAge > thisAge) minAge = thisAge; @@ -820,7 +820,7 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca [](Object*, Object* to, void* ctx) { int* minAge = reinterpret_cast(ctx); - int generation = g_theGCHeap->WhichGeneration(to); + int generation = GetConvertedGeneration(to); if (*minAge > generation) { *minAge = generation; @@ -903,7 +903,7 @@ static void VerifyObjectAndAge(_UNCHECKED_OBJECTREF from, _UNCHECKED_OBJECTREF o { VerifyObject(from, obj); - int thisAge = g_theGCHeap->WhichGeneration(obj); + int thisAge = GetConvertedGeneration(obj); //debugging code //if (minAge > thisAge && thisAge < g_theGCHeap->GetMaxGeneration())