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

Commit 80ca680

Browse files
Move handle manipulation functions to interface.
1 parent a6c2f78 commit 80ca680

File tree

7 files changed

+49
-14
lines changed

7 files changed

+49
-14
lines changed

src/gc/gc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34222,7 +34222,7 @@ bool GCHeap::StressHeap(gc_alloc_context * context)
3422234222
if (g_pConfig->AppDomainLeaks() && str->SetAppDomainNoThrow())
3422334223
{
3422434224
#endif
34225-
StoreObjectInHandle(m_StressObjs[i], ObjectToOBJECTREF(str));
34225+
HndAssignHandle(m_StressObjs[i], ObjectToOBJECTREF(str));
3422634226
#if CHECK_APP_DOMAIN_LEAKS
3422734227
}
3422834228
#endif
@@ -34255,7 +34255,7 @@ bool GCHeap::StressHeap(gc_alloc_context * context)
3425534255
{
3425634256
// Let the string itself become garbage.
3425734257
// will be realloced next time around
34258-
StoreObjectInHandle(m_StressObjs[m_CurStressObj], 0);
34258+
HndAssignHandle(m_StressObjs[m_CurStressObj], 0);
3425934259
}
3426034260
}
3426134261
}

src/gc/gchandletable.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,18 @@ void* GCHandleManager::GetExtraInfoFromHandle(OBJECTHANDLE handle)
132132
{
133133
return (void*)::HndGetHandleExtraInfo(handle);
134134
}
135+
136+
void GCHandleManager::StoreObjectInHandle(OBJECTHANDLE handle, Object* object)
137+
{
138+
::HndAssignHandle(handle, ObjectToOBJECTREF(object));
139+
}
140+
141+
bool GCHandleManager::StoreObjectInHandleIfNull(OBJECTHANDLE handle, Object* object)
142+
{
143+
return !!::HndFirstAssignHandle(handle, ObjectToOBJECTREF(object));
144+
}
145+
146+
Object* GCHandleManager::CompareAndSwapObjectInHandle(OBJECTHANDLE handle, Object* object, Object* comparandObject)
147+
{
148+
return (Object*)::HndInterlockedCompareExchangeHandle(handle, ObjectToOBJECTREF(object), ObjectToOBJECTREF(comparandObject));
149+
}

src/gc/gchandletableimpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class GCHandleManager : public IGCHandleManager
5454
virtual void DestroyHandleOfUnknownType(OBJECTHANDLE handle);
5555

5656
virtual void* GetExtraInfoFromHandle(OBJECTHANDLE handle);
57+
58+
virtual void StoreObjectInHandle(OBJECTHANDLE handle, Object* object);
59+
60+
virtual bool StoreObjectInHandleIfNull(OBJECTHANDLE handle, Object* object);
61+
62+
virtual Object* CompareAndSwapObjectInHandle(OBJECTHANDLE handle, Object* object, Object* comparandObject);
5763
};
5864

5965
#endif // GCHANDLETABLE_H_

src/gc/gcinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ class IGCHandleManager {
444444
virtual void DestroyHandleOfUnknownType(OBJECTHANDLE handle) = 0;
445445

446446
virtual void* GetExtraInfoFromHandle(OBJECTHANDLE handle) = 0;
447+
448+
virtual void StoreObjectInHandle(OBJECTHANDLE handle, Object* object) = 0;
449+
450+
virtual bool StoreObjectInHandleIfNull(OBJECTHANDLE handle, Object* object) = 0;
451+
452+
virtual Object* CompareAndSwapObjectInHandle(OBJECTHANDLE handle, Object* object, Object* comparandObject) = 0;
447453
};
448454

449455
// IGCHeap is the interface that the VM will use when interacting with the GC.

src/gc/objecthandle.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@
2121
#include <weakreference.h>
2222
#endif // FEATURE_COMINTEROP
2323

24-
/*
25-
* Convenience macros for accessing handles. StoreFirstObjectInHandle is like
26-
* StoreObjectInHandle, except it only succeeds if transitioning from NULL to
27-
* non-NULL. In other words, if this handle is being initialized for the first
28-
* time.
29-
*/
30-
#define StoreObjectInHandle(handle, object) HndAssignHandle(handle, object)
31-
#define InterlockedCompareExchangeObjectInHandle(handle, object, oldObj) HndInterlockedCompareExchangeHandle(handle, object, oldObj)
32-
#define StoreFirstObjectInHandle(handle, object) HndFirstAssignHandle(handle, object)
33-
3424
typedef DPTR(struct HandleTableMap) PTR_HandleTableMap;
3525
typedef DPTR(struct HandleTableBucket) PTR_HandleTableBucket;
3626
typedef DPTR(PTR_HandleTableBucket) PTR_PTR_HandleTableBucket;
@@ -94,7 +84,7 @@ inline void ResetOBJECTHANDLE(OBJECTHANDLE handle)
9484
{
9585
WRAPPER_NO_CONTRACT;
9686

97-
StoreObjectInHandle(handle, NULL);
87+
HndAssignHandle(handle, NULL);
9888
}
9989

10090
#ifndef FEATURE_REDHAWK

src/vm/appdomain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4679,7 +4679,8 @@ OBJECTREF AppDomain::GetExposedObject()
46794679
obj = (APPDOMAINREF) AllocateObject(pMT);
46804680
obj->SetDomain(this);
46814681

4682-
if(StoreFirstObjectInHandle(m_ExposedObject, (OBJECTREF) obj) == FALSE) {
4682+
if (!StoreFirstObjectInHandle(m_ExposedObject, (OBJECTREF) obj))
4683+
{
46834684
obj = (APPDOMAINREF) GetRawExposedObject();
46844685
_ASSERTE(obj);
46854686
}

src/vm/gchandleutilities.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ inline OBJECTHANDLE CreateVariableHandle(IGCHandleStore* store, OBJECTREF object
169169
return store->CreateHandleWithExtraInfo(OBJECTREFToObject(object), HNDTYPE_VARIABLE, (void*)((uintptr_t)type));
170170
}
171171

172+
// Handle object manipulation convenience functions
173+
174+
inline void StoreObjectInHandle(OBJECTHANDLE handle, OBJECTREF object)
175+
{
176+
GCHandleUtilities::GetGCHandleManager()->StoreObjectInHandle(handle, OBJECTREFToObject(object));
177+
}
178+
179+
inline bool StoreFirstObjectInHandle(OBJECTHANDLE handle, OBJECTREF object)
180+
{
181+
return GCHandleUtilities::GetGCHandleManager()->StoreObjectInHandleIfNull(handle, OBJECTREFToObject(object));
182+
}
183+
184+
inline void* InterlockedCompareExchangeObjectInHandle(OBJECTHANDLE handle, OBJECTREF object, OBJECTREF comparandObject)
185+
{
186+
return GCHandleUtilities::GetGCHandleManager()->CompareAndSwapObjectInHandle(handle, OBJECTREFToObject(object), OBJECTREFToObject(comparandObject));
187+
}
188+
172189
// Handle destruction convenience functions
173190

174191
inline void DestroyHandle(OBJECTHANDLE handle)

0 commit comments

Comments
 (0)