From 7c8da2df53ca9189b42458e85b36835f3c93b240 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Wed, 17 Jan 2024 14:15:58 -0800 Subject: [PATCH 1/3] Frozen objects should be identified as Gen2 in the handle table --- src/coreclr/gc/handletable.cpp | 15 ++++++++++++++- src/coreclr/gc/handletablepriv.h | 4 ++++ src/coreclr/gc/handletablescan.cpp | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/coreclr/gc/handletable.cpp b/src/coreclr/gc/handletable.cpp index ca8b1dbaa61cb..e5248e9e03429 100644 --- a/src/coreclr/gc/handletable.cpp +++ b/src/coreclr/gc/handletable.cpp @@ -24,6 +24,19 @@ DWORD g_dwHandles = 0; #endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE +#ifndef DACCESS_COMPILE + +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif + +int WhichGeneration(_UNCHECKED_OBJECTREF obj) +{ + int generation = g_theGCHeap->WhichGeneration(obj); + return generation == INT_MAX ? max_generation : generation; +} +#endif //DACCESS_COMPILE + /**************************************************************************** * * FORWARD DECLARATIONS @@ -577,7 +590,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 = WhichGeneration(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..a635f7904f4cb 100644 --- a/src/coreclr/gc/handletablepriv.h +++ b/src/coreclr/gc/handletablepriv.h @@ -942,3 +942,7 @@ void CALLBACK BlockVerifyAgeMapForBlocks(PTR_TableSegment pSegment, uint32_t uBl PTR_TableSegment CALLBACK xxxAsyncSegmentIterator(PTR_HandleTable pTable, TableSegment *pPrevSegment, CrstHolderWithState *pCrstHolder); /*--------------------------------------------------------------------------*/ + +#ifndef DACCESS_COMPILE +int WhichGeneration(_UNCHECKED_OBJECTREF obj); +#endif //DACCESS_COMPILE diff --git a/src/coreclr/gc/handletablescan.cpp b/src/coreclr/gc/handletablescan.cpp index 171647501b4cb..86c875f873de3 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 = WhichGeneration(*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 = WhichGeneration(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 = WhichGeneration(obj); //debugging code //if (minAge > thisAge && thisAge < g_theGCHeap->GetMaxGeneration()) From 3432189d34ee295993f32245c810b32f130deb44 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Wed, 17 Jan 2024 16:35:23 -0800 Subject: [PATCH 2/3] Code review feedback --- src/coreclr/gc/env/common.h | 1 + src/coreclr/gc/handletable.cpp | 5 ----- src/coreclr/gc/handletablepriv.h | 8 ++++++++ 3 files changed, 9 insertions(+), 5 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 e5248e9e03429..4b68e03001e3a 100644 --- a/src/coreclr/gc/handletable.cpp +++ b/src/coreclr/gc/handletable.cpp @@ -25,11 +25,6 @@ DWORD g_dwHandles = 0; #endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE #ifndef DACCESS_COMPILE - -#ifndef INT_MAX -#define INT_MAX 2147483647 -#endif - int WhichGeneration(_UNCHECKED_OBJECTREF obj) { int generation = g_theGCHeap->WhichGeneration(obj); diff --git a/src/coreclr/gc/handletablepriv.h b/src/coreclr/gc/handletablepriv.h index a635f7904f4cb..d5d02587601e3 100644 --- a/src/coreclr/gc/handletablepriv.h +++ b/src/coreclr/gc/handletablepriv.h @@ -944,5 +944,13 @@ PTR_TableSegment CALLBACK xxxAsyncSegmentIterator(PTR_HandleTable pTable, TableS /*--------------------------------------------------------------------------*/ #ifndef DACCESS_COMPILE + +/* + * WhichGeneration + * + * Get the generation of an object, where a frozen object is regarded as max_generation + * + */ int WhichGeneration(_UNCHECKED_OBJECTREF obj); + #endif //DACCESS_COMPILE From 5791489908ba0ed2d878be9b4dccd17af193cbbf Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Fri, 19 Jan 2024 20:01:58 -0800 Subject: [PATCH 3/3] WhichGeneration -> GetConvertedGeneration --- src/coreclr/gc/handletable.cpp | 4 ++-- src/coreclr/gc/handletablepriv.h | 4 ++-- src/coreclr/gc/handletablescan.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/gc/handletable.cpp b/src/coreclr/gc/handletable.cpp index 4b68e03001e3a..356b0e0bdc314 100644 --- a/src/coreclr/gc/handletable.cpp +++ b/src/coreclr/gc/handletable.cpp @@ -25,7 +25,7 @@ DWORD g_dwHandles = 0; #endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE #ifndef DACCESS_COMPILE -int WhichGeneration(_UNCHECKED_OBJECTREF obj) +int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj) { int generation = g_theGCHeap->WhichGeneration(obj); return generation == INT_MAX ? max_generation : generation; @@ -585,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 = 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 d5d02587601e3..e09e89cecaaae 100644 --- a/src/coreclr/gc/handletablepriv.h +++ b/src/coreclr/gc/handletablepriv.h @@ -946,11 +946,11 @@ PTR_TableSegment CALLBACK xxxAsyncSegmentIterator(PTR_HandleTable pTable, TableS #ifndef DACCESS_COMPILE /* - * WhichGeneration + * GetConvertedGeneration * * Get the generation of an object, where a frozen object is regarded as max_generation * */ -int WhichGeneration(_UNCHECKED_OBJECTREF obj); +int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj); #endif //DACCESS_COMPILE diff --git a/src/coreclr/gc/handletablescan.cpp b/src/coreclr/gc/handletablescan.cpp index 86c875f873de3..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 = 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 = 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 = WhichGeneration(obj); + int thisAge = GetConvertedGeneration(obj); //debugging code //if (minAge > thisAge && thisAge < g_theGCHeap->GetMaxGeneration())