|
8 | 8 | #include "gchandletableimpl.h"
|
9 | 9 | #include "objecthandle.h"
|
10 | 10 |
|
11 |
| -IGCHandleTable* CreateGCHandleTable() |
| 11 | +GCHandleStore* g_gcGlobalHandleStore; |
| 12 | + |
| 13 | +IGCHandleManager* CreateGCHandleManager() |
12 | 14 | {
|
13 |
| - return new(nothrow) GCHandleTable(); |
| 15 | + return new (nothrow) GCHandleManager(); |
14 | 16 | }
|
15 | 17 |
|
16 |
| -bool GCHandleTable::Initialize() |
| 18 | +void GCHandleStore::Uproot() |
17 | 19 | {
|
18 |
| - return Ref_Initialize(); |
| 20 | + Ref_RemoveHandleTableBucket(&_underlyingBucket); |
19 | 21 | }
|
20 | 22 |
|
21 |
| -void GCHandleTable::Shutdown() |
| 23 | +bool GCHandleStore::ContainsHandle(OBJECTHANDLE handle) |
22 | 24 | {
|
23 |
| - Ref_Shutdown(); |
| 25 | + return _underlyingBucket.Contains(handle); |
24 | 26 | }
|
25 | 27 |
|
26 |
| -void* GCHandleTable::GetGlobalHandleStore() |
| 28 | +OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type) |
27 | 29 | {
|
28 |
| - return (void*)g_HandleTableMap.pBuckets[0]; |
| 30 | + HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()]; |
| 31 | + return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object)); |
29 | 32 | }
|
30 | 33 |
|
31 |
| -void* GCHandleTable::CreateHandleStore(void* context) |
| 34 | +OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo) |
32 | 35 | {
|
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)); |
39 | 38 | }
|
40 | 39 |
|
41 |
| -void* GCHandleTable::GetHandleContext(OBJECTHANDLE handle) |
| 40 | +OBJECTHANDLE GCHandleStore::CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo) |
42 | 41 | {
|
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)); |
44 | 44 | }
|
45 | 45 |
|
46 |
| -void GCHandleTable::DestroyHandleStore(void* store) |
| 46 | +OBJECTHANDLE GCHandleStore::CreateDependentHandle(Object* primary, Object* secondary) |
47 | 47 | {
|
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; |
49 | 53 | }
|
50 | 54 |
|
51 |
| -void GCHandleTable::UprootHandleStore(void* store) |
| 55 | +GCHandleStore::~GCHandleStore() |
52 | 56 | {
|
53 |
| - Ref_RemoveHandleTableBucket((HandleTableBucket*) store); |
| 57 | + ::Ref_DestroyHandleTableBucket(&_underlyingBucket); |
54 | 58 | }
|
55 | 59 |
|
56 |
| -bool GCHandleTable::ContainsHandle(void* store, OBJECTHANDLE handle) |
| 60 | +bool GCHandleManager::Initialize() |
57 | 61 | {
|
58 |
| - return ((HandleTableBucket*)store)->Contains(handle); |
| 62 | + return Ref_Initialize(); |
59 | 63 | }
|
60 | 64 |
|
61 |
| -OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* store, Object* object, int type) |
| 65 | +void GCHandleManager::Shutdown() |
62 | 66 | {
|
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(); |
65 | 73 | }
|
66 | 74 |
|
67 |
| -OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* store, Object* object, int type, int heapToAffinitizeTo) |
| 75 | +IGCHandleStore* GCHandleManager::GetGlobalHandleStore() |
68 | 76 | {
|
69 |
| - HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[heapToAffinitizeTo]; |
70 |
| - return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object)); |
| 77 | + return g_gcGlobalHandleStore; |
71 | 78 | }
|
72 | 79 |
|
73 |
| -OBJECTHANDLE GCHandleTable::CreateGlobalHandleOfType(Object* object, int type) |
| 80 | +IGCHandleStore* GCHandleManager::CreateHandleStore(void* context) |
74 | 81 | {
|
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 |
76 | 99 | }
|
77 | 100 |
|
78 |
| -OBJECTHANDLE GCHandleTable::CreateHandleWithExtraInfo(void* store, Object* object, int type, void* pExtraInfo) |
| 101 | +void GCHandleManager::DestroyHandleStore(IGCHandleStore* store) |
79 | 102 | {
|
80 |
| - HHANDLETABLE handletable = ((HandleTableBucket*)store)->pTable[GetCurrentThreadHomeHeapNumber()]; |
81 |
| - return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object), reinterpret_cast<uintptr_t>(pExtraInfo)); |
| 103 | + delete store; |
82 | 104 | }
|
83 | 105 |
|
84 |
| -OBJECTHANDLE GCHandleTable::CreateDependentHandle(void* store, Object* primary, Object* secondary) |
| 106 | +void* GCHandleManager::GetHandleContext(OBJECTHANDLE handle) |
85 | 107 | {
|
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 | +} |
89 | 110 |
|
90 |
| - return handle; |
| 111 | +OBJECTHANDLE GCHandleManager::CreateGlobalHandleOfType(Object* object, int type) |
| 112 | +{ |
| 113 | + return ::HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, ObjectToOBJECTREF(object)); |
91 | 114 | }
|
92 | 115 |
|
93 |
| -OBJECTHANDLE GCHandleTable::CreateDuplicateHandle(OBJECTHANDLE handle) |
| 116 | +OBJECTHANDLE GCHandleManager::CreateDuplicateHandle(OBJECTHANDLE handle) |
94 | 117 | {
|
95 | 118 | return ::HndCreateHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, ::HndFetchHandle(handle));
|
96 | 119 | }
|
97 | 120 |
|
98 |
| -void GCHandleTable::DestroyHandleOfType(OBJECTHANDLE handle, int type) |
| 121 | +void GCHandleManager::DestroyHandleOfType(OBJECTHANDLE handle, int type) |
99 | 122 | {
|
100 | 123 | ::HndDestroyHandle(::HndGetHandleTable(handle), type, handle);
|
101 | 124 | }
|
102 | 125 |
|
103 |
| -void GCHandleTable::DestroyHandleOfUnknownType(OBJECTHANDLE handle) |
| 126 | +void GCHandleManager::DestroyHandleOfUnknownType(OBJECTHANDLE handle) |
104 | 127 | {
|
105 | 128 | ::HndDestroyHandleOfUnknownType(::HndGetHandleTable(handle), handle);
|
106 | 129 | }
|
107 | 130 |
|
108 |
| -void* GCHandleTable::GetExtraInfoFromHandle(OBJECTHANDLE handle) |
| 131 | +void* GCHandleManager::GetExtraInfoFromHandle(OBJECTHANDLE handle) |
109 | 132 | {
|
110 | 133 | return (void*)::HndGetHandleExtraInfo(handle);
|
111 | 134 | }
|
0 commit comments