Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a6c2f78

Browse files
Merge pull request #10955 from adityamandaleeka/makeHandleStoreClass
Make a GCHandleStore class and interface for use by the VM
2 parents ed254ae + 0bb12f6 commit a6c2f78

19 files changed

+567
-520
lines changed

src/gc/gc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extern "C" GCHeapType g_gc_heap_type;
115115
extern "C" uint32_t g_max_generation;
116116
extern "C" MethodTable* g_gc_pFreeObjectMethodTable;
117117

118-
::IGCHandleTable* CreateGCHandleTable();
118+
::IGCHandleManager* CreateGCHandleManager();
119119

120120
namespace WKS {
121121
::IGCHeapInternal* CreateGCHeap();
@@ -260,8 +260,8 @@ void updateGCShadow(Object** ptr, Object* val);
260260
// The single GC heap instance, shared with the VM.
261261
extern IGCHeapInternal* g_theGCHeap;
262262

263-
// The single GC handle table instance, shared with the VM.
264-
extern IGCHandleTable* g_theGCHandleTable;
263+
// The single GC handle manager instance, shared with the VM.
264+
extern IGCHandleManager* g_theGCHandleManager;
265265

266266
#ifndef DACCESS_COMPILE
267267
inline bool IsGCInProgress(bool bConsiderGCStart = false)

src/gc/gccommon.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "gc.h"
1616

1717
IGCHeapInternal* g_theGCHeap;
18-
IGCHandleTable* g_theGCHandleTable;
18+
IGCHandleManager* g_theGCHandleManager;
1919

2020
#ifdef FEATURE_STANDALONE_GC
2121
IGCToCLR* g_theGCToCLR;
@@ -143,18 +143,18 @@ namespace SVR
143143
extern void PopulateDacVars(GcDacVars* dacVars);
144144
}
145145

146-
bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleTable** gcHandleTable, GcDacVars* gcDacVars)
146+
bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleManager** gcHandleManager, GcDacVars* gcDacVars)
147147
{
148148
LIMITED_METHOD_CONTRACT;
149149

150150
IGCHeapInternal* heap;
151151

152152
assert(gcDacVars != nullptr);
153153
assert(gcHeap != nullptr);
154-
assert(gcHandleTable != nullptr);
154+
assert(gcHandleManager != nullptr);
155155

156-
IGCHandleTable* handleTable = CreateGCHandleTable();
157-
if (handleTable == nullptr)
156+
IGCHandleManager* handleManager = CreateGCHandleManager();
157+
if (handleManager == nullptr)
158158
{
159159
return false;
160160
}
@@ -192,7 +192,7 @@ bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleTa
192192
assert(clrToGC == nullptr);
193193
#endif
194194

195-
*gcHandleTable = handleTable;
195+
*gcHandleManager = handleManager;
196196
*gcHeap = heap;
197197
return true;
198198
}

src/gc/gchandletable.cpp

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,104 +8,127 @@
88
#include "gchandletableimpl.h"
99
#include "objecthandle.h"
1010

11-
IGCHandleTable* CreateGCHandleTable()
11+
GCHandleStore* g_gcGlobalHandleStore;
12+
13+
IGCHandleManager* CreateGCHandleManager()
1214
{
13-
return new(nothrow) GCHandleTable();
15+
return new (nothrow) GCHandleManager();
1416
}
1517

16-
bool GCHandleTable::Initialize()
18+
void GCHandleStore::Uproot()
1719
{
18-
return Ref_Initialize();
20+
Ref_RemoveHandleTableBucket(&_underlyingBucket);
1921
}
2022

21-
void GCHandleTable::Shutdown()
23+
bool GCHandleStore::ContainsHandle(OBJECTHANDLE handle)
2224
{
23-
Ref_Shutdown();
25+
return _underlyingBucket.Contains(handle);
2426
}
2527

26-
void* GCHandleTable::GetGlobalHandleStore()
28+
OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type)
2729
{
28-
return (void*)g_HandleTableMap.pBuckets[0];
30+
HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()];
31+
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
2932
}
3033

31-
void* GCHandleTable::CreateHandleStore(void* context)
34+
OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo)
3235
{
33-
#ifndef FEATURE_REDHAWK
34-
return (void*)::Ref_CreateHandleTableBucket(ADIndex((DWORD)(uintptr_t)context));
35-
#else
36-
assert("CreateHandleStore is not implemented when FEATURE_REDHAWK is defined!");
37-
return nullptr;
38-
#endif
36+
HHANDLETABLE handletable = _underlyingBucket.pTable[heapToAffinitizeTo];
37+
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
3938
}
4039

41-
void* GCHandleTable::GetHandleContext(OBJECTHANDLE handle)
40+
OBJECTHANDLE GCHandleStore::CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo)
4241
{
43-
return (void*)((uintptr_t)::HndGetHandleTableADIndex(::HndGetHandleTable(handle)).m_dwIndex);
42+
HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()];
43+
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object), reinterpret_cast<uintptr_t>(pExtraInfo));
4444
}
4545

46-
void GCHandleTable::DestroyHandleStore(void* store)
46+
OBJECTHANDLE GCHandleStore::CreateDependentHandle(Object* primary, Object* secondary)
4747
{
48-
Ref_DestroyHandleTableBucket((HandleTableBucket*) store);
48+
HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()];
49+
OBJECTHANDLE handle = ::HndCreateHandle(handletable, HNDTYPE_DEPENDENT, ObjectToOBJECTREF(primary));
50+
::SetDependentHandleSecondary(handle, ObjectToOBJECTREF(secondary));
51+
52+
return handle;
4953
}
5054

51-
void GCHandleTable::UprootHandleStore(void* store)
55+
GCHandleStore::~GCHandleStore()
5256
{
53-
Ref_RemoveHandleTableBucket((HandleTableBucket*) store);
57+
::Ref_DestroyHandleTableBucket(&_underlyingBucket);
5458
}
5559

56-
bool GCHandleTable::ContainsHandle(void* store, OBJECTHANDLE handle)
60+
bool GCHandleManager::Initialize()
5761
{
58-
return ((HandleTableBucket*)store)->Contains(handle);
62+
return Ref_Initialize();
5963
}
6064

61-
OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* store, Object* object, int type)
65+
void GCHandleManager::Shutdown()
6266
{
63-
HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[GetCurrentThreadHomeHeapNumber()];
64-
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
67+
if (g_gcGlobalHandleStore != nullptr)
68+
{
69+
DestroyHandleStore(g_gcGlobalHandleStore);
70+
}
71+
72+
::Ref_Shutdown();
6573
}
6674

67-
OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* store, Object* object, int type, int heapToAffinitizeTo)
75+
IGCHandleStore* GCHandleManager::GetGlobalHandleStore()
6876
{
69-
HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[heapToAffinitizeTo];
70-
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
77+
return g_gcGlobalHandleStore;
7178
}
7279

73-
OBJECTHANDLE GCHandleTable::CreateGlobalHandleOfType(Object* object, int type)
80+
IGCHandleStore* GCHandleManager::CreateHandleStore(void* context)
7481
{
75-
return ::HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, ObjectToOBJECTREF(object));
82+
#ifndef FEATURE_REDHAWK
83+
GCHandleStore* store = new (nothrow) GCHandleStore();
84+
if (store == nullptr)
85+
return nullptr;
86+
87+
bool success = ::Ref_InitializeHandleTableBucket(&store->_underlyingBucket, context);
88+
if (!success)
89+
{
90+
delete store;
91+
return nullptr;
92+
}
93+
94+
return store;
95+
#else
96+
assert("CreateHandleStore is not implemented when FEATURE_REDHAWK is defined!");
97+
return nullptr;
98+
#endif
7699
}
77100

78-
OBJECTHANDLE GCHandleTable::CreateHandleWithExtraInfo(void* store, Object* object, int type, void* pExtraInfo)
101+
void GCHandleManager::DestroyHandleStore(IGCHandleStore* store)
79102
{
80-
HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[GetCurrentThreadHomeHeapNumber()];
81-
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object), reinterpret_cast<uintptr_t>(pExtraInfo));
103+
delete store;
82104
}
83105

84-
OBJECTHANDLE GCHandleTable::CreateDependentHandle(void* store, Object* primary, Object* secondary)
106+
void* GCHandleManager::GetHandleContext(OBJECTHANDLE handle)
85107
{
86-
HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[GetCurrentThreadHomeHeapNumber()];
87-
OBJECTHANDLE handle = ::HndCreateHandle(handletable, HNDTYPE_DEPENDENT, ObjectToOBJECTREF(primary));
88-
::SetDependentHandleSecondary(handle, ObjectToOBJECTREF(secondary));
108+
return (void*)((uintptr_t)::HndGetHandleTableADIndex(::HndGetHandleTable(handle)).m_dwIndex);
109+
}
89110

90-
return handle;
111+
OBJECTHANDLE GCHandleManager::CreateGlobalHandleOfType(Object* object, int type)
112+
{
113+
return ::HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, ObjectToOBJECTREF(object));
91114
}
92115

93-
OBJECTHANDLE GCHandleTable::CreateDuplicateHandle(OBJECTHANDLE handle)
116+
OBJECTHANDLE GCHandleManager::CreateDuplicateHandle(OBJECTHANDLE handle)
94117
{
95118
return ::HndCreateHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, ::HndFetchHandle(handle));
96119
}
97120

98-
void GCHandleTable::DestroyHandleOfType(OBJECTHANDLE handle, int type)
121+
void GCHandleManager::DestroyHandleOfType(OBJECTHANDLE handle, int type)
99122
{
100123
::HndDestroyHandle(::HndGetHandleTable(handle), type, handle);
101124
}
102125

103-
void GCHandleTable::DestroyHandleOfUnknownType(OBJECTHANDLE handle)
126+
void GCHandleManager::DestroyHandleOfUnknownType(OBJECTHANDLE handle)
104127
{
105128
::HndDestroyHandleOfUnknownType(::HndGetHandleTable(handle), handle);
106129
}
107130

108-
void* GCHandleTable::GetExtraInfoFromHandle(OBJECTHANDLE handle)
131+
void* GCHandleManager::GetExtraInfoFromHandle(OBJECTHANDLE handle)
109132
{
110133
return (void*)::HndGetHandleExtraInfo(handle);
111134
}

src/gc/gchandletableimpl.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,44 @@
66
#define GCHANDLETABLE_H_
77

88
#include "gcinterface.h"
9+
#include "objecthandle.h"
910

10-
class GCHandleTable : public IGCHandleTable
11+
class GCHandleStore : public IGCHandleStore
1112
{
1213
public:
13-
virtual bool Initialize();
14+
virtual void Uproot();
1415

15-
virtual void Shutdown();
16+
virtual bool ContainsHandle(OBJECTHANDLE handle);
1617

17-
virtual void* GetGlobalHandleStore();
18+
virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type);
1819

19-
virtual void* CreateHandleStore(void* context);
20+
virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo);
2021

21-
virtual void* GetHandleContext(OBJECTHANDLE handle);
22+
virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo);
23+
24+
virtual OBJECTHANDLE CreateDependentHandle(Object* primary, Object* secondary);
25+
26+
virtual ~GCHandleStore();
27+
28+
HandleTableBucket _underlyingBucket;
29+
};
2230

23-
virtual void DestroyHandleStore(void* store);
31+
extern GCHandleStore* g_gcGlobalHandleStore;
2432

25-
virtual void UprootHandleStore(void* store);
33+
class GCHandleManager : public IGCHandleManager
34+
{
35+
public:
36+
virtual bool Initialize();
2637

27-
virtual bool ContainsHandle(void* store, OBJECTHANDLE handle);
38+
virtual void Shutdown();
2839

29-
virtual OBJECTHANDLE CreateHandleOfType(void* store, Object* object, int type);
40+
virtual void* GetHandleContext(OBJECTHANDLE handle);
3041

31-
virtual OBJECTHANDLE CreateHandleOfType(void* store, Object* object, int type, int heapToAffinitizeTo);
42+
virtual IGCHandleStore* GetGlobalHandleStore();
3243

33-
virtual OBJECTHANDLE CreateHandleWithExtraInfo(void* store, Object* object, int type, void* pExtraInfo);
44+
virtual IGCHandleStore* CreateHandleStore(void* context);
3445

35-
virtual OBJECTHANDLE CreateDependentHandle(void* store, Object* primary, Object* secondary);
46+
virtual void DestroyHandleStore(IGCHandleStore* store);
3647

3748
virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, int type);
3849

src/gc/gcinterface.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ struct segment_info
169169

170170
class Object;
171171
class IGCHeap;
172-
class IGCHandleTable;
172+
class IGCHandleManager;
173173

174174
// Initializes the garbage collector. Should only be called
175175
// once, during EE startup. Returns true if the initialization
176176
// was successful, false otherwise.
177-
bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleTable** gcHandleTable, GcDacVars* gcDacVars);
177+
bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleManager** gcHandleTable, GcDacVars* gcDacVars);
178178

179179
// The runtime needs to know whether we're using workstation or server GC
180180
// long before the GCHeap is created. This function sets the type of
@@ -402,32 +402,38 @@ typedef struct OBJECTHANDLE__* OBJECTHANDLE;
402402
typedef uintptr_t OBJECTHANDLE;
403403
#endif
404404

405-
class IGCHandleTable {
405+
class IGCHandleStore {
406406
public:
407407

408-
virtual bool Initialize() = 0;
408+
virtual void Uproot() = 0;
409409

410-
virtual void Shutdown() = 0;
410+
virtual bool ContainsHandle(OBJECTHANDLE handle) = 0;
411411

412-
virtual void* GetHandleContext(OBJECTHANDLE handle) = 0;
412+
virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type) = 0;
413+
414+
virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo) = 0;
415+
416+
virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo) = 0;
413417

414-
virtual void* GetGlobalHandleStore() = 0;
418+
virtual OBJECTHANDLE CreateDependentHandle(Object* primary, Object* secondary) = 0;
415419

416-
virtual void* CreateHandleStore(void* context) = 0;
420+
virtual ~IGCHandleStore() {};
421+
};
417422

418-
virtual void DestroyHandleStore(void* store) = 0;
423+
class IGCHandleManager {
424+
public:
419425

420-
virtual void UprootHandleStore(void* store) = 0;
426+
virtual bool Initialize() = 0;
421427

422-
virtual bool ContainsHandle(void* store, OBJECTHANDLE handle) = 0;
428+
virtual void Shutdown() = 0;
423429

424-
virtual OBJECTHANDLE CreateHandleOfType(void* store, Object* object, int type) = 0;
430+
virtual void* GetHandleContext(OBJECTHANDLE handle) = 0;
425431

426-
virtual OBJECTHANDLE CreateHandleOfType(void* store, Object* object, int type, int heapToAffinitizeTo) = 0;
432+
virtual IGCHandleStore* GetGlobalHandleStore() = 0;
427433

428-
virtual OBJECTHANDLE CreateHandleWithExtraInfo(void* store, Object* object, int type, void* pExtraInfo) = 0;
434+
virtual IGCHandleStore* CreateHandleStore(void* context) = 0;
429435

430-
virtual OBJECTHANDLE CreateDependentHandle(void* store, Object* primary, Object* secondary) = 0;
436+
virtual void DestroyHandleStore(IGCHandleStore* store) = 0;
431437

432438
virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, int type) = 0;
433439

src/gc/handletablecore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ void SegmentRelocateAsyncPinHandles (TableSegment *pSegment, HandleTable *pTarge
10031003
overlapped->m_userObject = NULL;
10041004
}
10051005
BashMTForPinnedObject(ObjectToOBJECTREF(value));
1006-
overlapped->m_pinSelf = CreateAsyncPinningHandle((HHANDLETABLE)pTargetTable,ObjectToOBJECTREF(value));
1006+
1007+
overlapped->m_pinSelf = HndCreateHandle((HHANDLETABLE)pTargetTable, HNDTYPE_ASYNCPINNED, ObjectToOBJECTREF(value));
10071008
*pValue = NULL;
10081009
}
10091010
pValue ++;

0 commit comments

Comments
 (0)