Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src/coreclr/gc/gchandletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ IGCHandleManager* CreateGCHandleManager()

void GCHandleStore::Uproot()
{
Ref_RemoveHandleTableBucket(&_underlyingBucket);
// 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)
{
return _underlyingBucket.Contains(handle);
// 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;
}

// this is the number of handles we allocate in a handle table before we switch to the next table.
Expand Down Expand Up @@ -129,25 +134,10 @@ 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 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;
#endif
}

void GCHandleManager::DestroyHandleStore(IGCHandleStore* store)
Expand Down Expand Up @@ -221,4 +211,3 @@ void GCHandleManager::TraceRefCountedHandles(HANDLESCANPROC callback, uintptr_t
{
::Ref_TraceRefCountHandles(callback, param1, param2);
}

89 changes: 0 additions & 89 deletions src/coreclr/gc/objecthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/gc/objecthandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading