From 691b94baa25c10d224d26676aff141f052c88873 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 13:56:47 +0000 Subject: [PATCH 1/3] Dead-code cleanup: HandleTableMap multi-bucket scaffolding (Tier A + B.1) Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/gc/gchandletable.cpp | 36 ++++++------- src/coreclr/gc/objecthandle.cpp | 89 -------------------------------- src/coreclr/gc/objecthandle.h | 1 - 3 files changed, 16 insertions(+), 110 deletions(-) diff --git a/src/coreclr/gc/gchandletable.cpp b/src/coreclr/gc/gchandletable.cpp index d503aca269b6cd..7d08c326be28af 100644 --- a/src/coreclr/gc/gchandletable.cpp +++ b/src/coreclr/gc/gchandletable.cpp @@ -17,12 +17,21 @@ IGCHandleManager* CreateGCHandleManager() void GCHandleStore::Uproot() { - Ref_RemoveHandleTableBucket(&_underlyingBucket); + // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 + // (April 2019) when non-default AppDomains were retired. The vtable slot is + // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with + // external standalone GC implementations. + assert(!"Uproot is not in use; no callers since dotnet/coreclr#23588"); } bool GCHandleStore::ContainsHandle(OBJECTHANDLE handle) { - return _underlyingBucket.Contains(handle); + // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 + // (April 2019) when non-default AppDomains were retired. The vtable slot is + // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with + // external standalone GC implementations. + assert(!"ContainsHandle is not in use; no callers since dotnet/coreclr#23588"); + return false; } // this is the number of handles we allocate in a handle table before we switch to the next table. @@ -129,25 +138,12 @@ IGCHandleStore* GCHandleManager::GetGlobalHandleStore() IGCHandleStore* GCHandleManager::CreateHandleStore() { -#ifndef FEATURE_NATIVEAOT - GCHandleStore* store = new (nothrow) GCHandleStore(); - if (store == nullptr) - { - return nullptr; - } - - bool success = ::Ref_InitializeHandleTableBucket(&store->_underlyingBucket); - if (!success) - { - delete store; - return nullptr; - } - - return store; -#else - assert(!"CreateHandleStore is not implemented when FEATURE_NATIVEAOT is defined!"); + // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 + // (April 2019) when non-default AppDomains were retired. The vtable slot is + // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with + // external standalone GC implementations. + assert(!"CreateHandleStore is not in use; no callers since dotnet/coreclr#23588"); return nullptr; -#endif } void GCHandleManager::DestroyHandleStore(IGCHandleStore* store) diff --git a/src/coreclr/gc/objecthandle.cpp b/src/coreclr/gc/objecthandle.cpp index af7805107e5909..62803851d1d198 100644 --- a/src/coreclr/gc/objecthandle.cpp +++ b/src/coreclr/gc/objecthandle.cpp @@ -744,95 +744,6 @@ void Ref_Shutdown() } } -bool Ref_InitializeHandleTableBucket(HandleTableBucket* bucket) -{ - CONTRACTL - { - NOTHROW; - WRAPPER(GC_TRIGGERS); - INJECT_FAULT(return false); - } - CONTRACTL_END; - - HandleTableBucket *result = bucket; - HandleTableMap *walk = &g_HandleTableMap; - - HandleTableMap *last = NULL; - uint32_t offset = 0; - - result->pTable = NULL; - - // create handle table set for the bucket - int n_slots = getNumberOfSlots(); - - HandleTableBucketHolder bucketHolder(result, n_slots); - - result->pTable = new (nothrow) HHANDLETABLE[n_slots]; - if (!result->pTable) - { - return false; - } - - ZeroMemory(result->pTable, n_slots * sizeof(HHANDLETABLE)); - - for (int uCPUindex=0; uCPUindex < n_slots; uCPUindex++) { - result->pTable[uCPUindex] = HndCreateHandleTable(s_rgTypeFlags, ARRAY_SIZE(s_rgTypeFlags)); - if (!result->pTable[uCPUindex]) - return false; - } - - for (;;) { - // Do we have free slot - while (walk) { - for (uint32_t i = 0; i < INITIAL_HANDLE_TABLE_ARRAY_SIZE; i ++) { - if (walk->pBuckets[i] == 0) { - for (int uCPUindex=0; uCPUindex < n_slots; uCPUindex++) - HndSetHandleTableIndex(result->pTable[uCPUindex], i+offset); - - result->HandleTableIndex = i+offset; - if (Interlocked::CompareExchangePointer(&walk->pBuckets[i], result, NULL) == 0) { - // Get a free slot. - bucketHolder.SuppressRelease(); - return true; - } - } - } - last = walk; - offset = walk->dwMaxIndex; - walk = walk->pNext; - } - - // No free slot. - // Let's create a new node - HandleTableMap *newMap = new (nothrow) HandleTableMap; - if (!newMap) - { - return false; - } - - newMap->pBuckets = new (nothrow) HandleTableBucket * [ INITIAL_HANDLE_TABLE_ARRAY_SIZE ]; - if (!newMap->pBuckets) - { - delete newMap; - return false; - } - - newMap->dwMaxIndex = last->dwMaxIndex + INITIAL_HANDLE_TABLE_ARRAY_SIZE; - newMap->pNext = NULL; - ZeroMemory(newMap->pBuckets, - INITIAL_HANDLE_TABLE_ARRAY_SIZE * sizeof (HandleTableBucket *)); - - if (Interlocked::CompareExchangePointer(&last->pNext, newMap, NULL) != NULL) - { - // This thread loses. - delete [] newMap->pBuckets; - delete newMap; - } - walk = last->pNext; - offset = last->dwMaxIndex; - } -} - void Ref_RemoveHandleTableBucket(HandleTableBucket *pBucket) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/gc/objecthandle.h b/src/coreclr/gc/objecthandle.h index 27875c4cf5720b..414b24ebd3272d 100644 --- a/src/coreclr/gc/objecthandle.h +++ b/src/coreclr/gc/objecthandle.h @@ -81,7 +81,6 @@ int getNumberOfSlots(); */ bool Ref_Initialize(); void Ref_Shutdown(); -bool Ref_InitializeHandleTableBucket(HandleTableBucket* bucket); void Ref_RemoveHandleTableBucket(HandleTableBucket *pBucket); void Ref_DestroyHandleTableBucket(HandleTableBucket *pBucket); From 8fe7f2a4cb135c29338a5174a5cf88e3ead2a176 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 18:44:04 +0000 Subject: [PATCH 2/3] Reduce verbosity of dead-path comments in gchandletable Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/gc/gchandletable.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/coreclr/gc/gchandletable.cpp b/src/coreclr/gc/gchandletable.cpp index 7d08c326be28af..1329f2fc6273f7 100644 --- a/src/coreclr/gc/gchandletable.cpp +++ b/src/coreclr/gc/gchandletable.cpp @@ -17,20 +17,16 @@ IGCHandleManager* CreateGCHandleManager() void GCHandleStore::Uproot() { - // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 - // (April 2019) when non-default AppDomains were retired. The vtable slot is - // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with - // external standalone GC implementations. - assert(!"Uproot is not in use; no callers since dotnet/coreclr#23588"); + // Dead path. The vtable slot is preserved for GC_INTERFACE_MAJOR_VERSION 5 + // ABI compatibility with external standalone GC implementations. + assert(!"Uproot is not in use"); } bool GCHandleStore::ContainsHandle(OBJECTHANDLE handle) { - // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 - // (April 2019) when non-default AppDomains were retired. The vtable slot is - // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with - // external standalone GC implementations. - assert(!"ContainsHandle is not in use; no callers since dotnet/coreclr#23588"); + // Dead path. The vtable slot is preserved for GC_INTERFACE_MAJOR_VERSION 5 + // ABI compatibility with external standalone GC implementations. + assert(!"ContainsHandle is not in use"); return false; } @@ -217,4 +213,3 @@ void GCHandleManager::TraceRefCountedHandles(HANDLESCANPROC callback, uintptr_t { ::Ref_TraceRefCountHandles(callback, param1, param2); } - From 03b551b547aa4f9a0cb0daac9ba7b09d0b89daaa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 20:06:05 +0000 Subject: [PATCH 3/3] Align CreateHandleStore dead-path assert message Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/gc/gchandletable.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/coreclr/gc/gchandletable.cpp b/src/coreclr/gc/gchandletable.cpp index 1329f2fc6273f7..e70b38ebb6c339 100644 --- a/src/coreclr/gc/gchandletable.cpp +++ b/src/coreclr/gc/gchandletable.cpp @@ -134,11 +134,9 @@ IGCHandleStore* GCHandleManager::GetGlobalHandleStore() IGCHandleStore* GCHandleManager::CreateHandleStore() { - // Dead path. The last caller in CoreCLR was removed by dotnet/coreclr#23588 - // (April 2019) when non-default AppDomains were retired. The vtable slot is - // preserved for GC_INTERFACE_MAJOR_VERSION 5 ABI compatibility with - // external standalone GC implementations. - assert(!"CreateHandleStore is not in use; no callers since dotnet/coreclr#23588"); + // Dead path. The vtable slot is preserved for GC_INTERFACE_MAJOR_VERSION 5 + // ABI compatibility with external standalone GC implementations. + assert(!"CreateHandleStore is not in use"); return nullptr; }