From e17f40a186c294f977e336cab049d9026cf40c78 Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Wed, 5 Apr 2017 15:14:44 -0700 Subject: Add handle creation functionality to IGCHandleTable and make VM code use it. --- src/gc/gchandletable.cpp | 5 ++++ src/gc/gchandletableimpl.h | 2 ++ src/gc/gcinterface.h | 2 ++ src/gc/objecthandle.h | 71 ---------------------------------------------- src/vm/appdomain.hpp | 4 ++- src/vm/gcheaputilities.h | 49 ++++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 72 deletions(-) diff --git a/src/gc/gchandletable.cpp b/src/gc/gchandletable.cpp index f468bd300f..c4b16886b2 100644 --- a/src/gc/gchandletable.cpp +++ b/src/gc/gchandletable.cpp @@ -32,3 +32,8 @@ void* GCHandleTable::GetHandleTableForHandle(OBJECTHANDLE handle) { return (void*)::HndGetHandleTable(handle); } + +OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* table, Object* object, int type) +{ + return ::HndCreateHandle((HHANDLETABLE)table, type, ObjectToOBJECTREF(object)); +} diff --git a/src/gc/gchandletableimpl.h b/src/gc/gchandletableimpl.h index 11fa163df7..f98fd96109 100644 --- a/src/gc/gchandletableimpl.h +++ b/src/gc/gchandletableimpl.h @@ -17,6 +17,8 @@ public: virtual void* GetHandleTableContext(void* handleTable); virtual void* GetHandleTableForHandle(OBJECTHANDLE handle); + + virtual OBJECTHANDLE CreateHandleOfType(void* table, Object* object, int type); }; #endif // GCHANDLETABLE_H_ diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h index b5a9e0e8f9..4407fac30c 100644 --- a/src/gc/gcinterface.h +++ b/src/gc/gcinterface.h @@ -395,6 +395,8 @@ public: virtual void* GetHandleTableContext(void* handleTable) = 0; virtual void* GetHandleTableForHandle(OBJECTHANDLE handle) = 0; + + virtual OBJECTHANDLE CreateHandleOfType(void* table, Object* object, int type) = 0; }; // IGCHeap is the interface that the VM will use when interacting with the GC. diff --git a/src/gc/objecthandle.h b/src/gc/objecthandle.h index 386c5d4512..69ddb2c4ec 100644 --- a/src/gc/objecthandle.h +++ b/src/gc/objecthandle.h @@ -78,13 +78,6 @@ struct HandleTableBucket * Convenience macros and prototypes for the various handle types we define */ -inline OBJECTHANDLE CreateTypedHandle(HHANDLETABLE table, OBJECTREF object, int type) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, type, object); -} - inline void DestroyTypedHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -92,13 +85,6 @@ inline void DestroyTypedHandle(OBJECTHANDLE handle) HndDestroyHandleOfUnknownType(HndGetHandleTable(handle), handle); } -inline OBJECTHANDLE CreateHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_DEFAULT, object); -} - inline void DestroyHandle(OBJECTHANDLE handle) { CONTRACTL @@ -121,14 +107,6 @@ inline OBJECTHANDLE CreateDuplicateHandle(OBJECTHANDLE handle) { return HndCreateHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, HndFetchHandle(handle)); } - -inline OBJECTHANDLE CreateWeakHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_WEAK_DEFAULT, object); -} - inline void DestroyWeakHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -136,13 +114,6 @@ inline void DestroyWeakHandle(OBJECTHANDLE handle) HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_WEAK_DEFAULT, handle); } -inline OBJECTHANDLE CreateShortWeakHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_WEAK_SHORT, object); -} - inline void DestroyShortWeakHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -150,14 +121,6 @@ inline void DestroyShortWeakHandle(OBJECTHANDLE handle) HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_WEAK_SHORT, handle); } - -inline OBJECTHANDLE CreateLongWeakHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_WEAK_LONG, object); -} - inline void DestroyLongWeakHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -169,13 +132,6 @@ inline void DestroyLongWeakHandle(OBJECTHANDLE handle) typedef Holder,DestroyLongWeakHandle> LongWeakHandleHolder; #endif -inline OBJECTHANDLE CreateStrongHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_STRONG, object); -} - inline void DestroyStrongHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -183,13 +139,6 @@ inline void DestroyStrongHandle(OBJECTHANDLE handle) HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_STRONG, handle); } -inline OBJECTHANDLE CreatePinningHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_PINNED, object); -} - inline void DestroyPinningHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -201,13 +150,6 @@ inline void DestroyPinningHandle(OBJECTHANDLE handle) typedef Wrapper, DestroyPinningHandle, NULL> PinningHandleHolder; #endif -inline OBJECTHANDLE CreateAsyncPinningHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_ASYNCPINNED, object); -} - inline void DestroyAsyncPinningHandle(OBJECTHANDLE handle) { WRAPPER_NO_CONTRACT; @@ -219,13 +161,6 @@ inline void DestroyAsyncPinningHandle(OBJECTHANDLE handle) typedef Wrapper, DestroyAsyncPinningHandle, NULL> AsyncPinningHandleHolder; #endif -inline OBJECTHANDLE CreateSizedRefHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_SIZEDREF, object, (uintptr_t)0); -} - void DestroySizedRefHandle(OBJECTHANDLE handle); #ifndef FEATURE_REDHAWK @@ -233,12 +168,6 @@ typedef Wrapper, DestroySizedRefHandle, NU #endif #ifdef FEATURE_COMINTEROP -inline OBJECTHANDLE CreateRefcountedHandle(HHANDLETABLE table, OBJECTREF object) -{ - WRAPPER_NO_CONTRACT; - - return HndCreateHandle(table, HNDTYPE_REFCOUNTED, object); -} inline void DestroyRefcountedHandle(OBJECTHANDLE handle) { diff --git a/src/vm/appdomain.hpp b/src/vm/appdomain.hpp index d6023dd3b2..8022334e03 100644 --- a/src/vm/appdomain.hpp +++ b/src/vm/appdomain.hpp @@ -1238,7 +1238,9 @@ public: OBJECTHANDLE CreateTypedHandle(OBJECTREF object, int type) { WRAPPER_NO_CONTRACT; - return ::CreateTypedHandle(m_hHandleTableBucket->pTable[GetCurrentThreadHomeHeapNumber()], object, type); + + IGCHandleTable *pHandleTable = GCHeapUtilities::GetGCHandleTable(); + return pHandleTable->CreateHandleOfType(m_hHandleTableBucket->pTable[GetCurrentThreadHomeHeapNumber()], OBJECTREFToObject(object), type); } OBJECTHANDLE CreateHandle(OBJECTREF object) diff --git a/src/vm/gcheaputilities.h b/src/vm/gcheaputilities.h index 064165bc11..c6e8507d77 100644 --- a/src/vm/gcheaputilities.h +++ b/src/vm/gcheaputilities.h @@ -226,5 +226,54 @@ inline OBJECTREF ObjectFromHandle(OBJECTHANDLE handle) return UNCHECKED_OBJECTREF_TO_OBJECTREF(*PTR_UNCHECKED_OBJECTREF(handle)); } +#ifndef DACCESS_COMPILE + +inline OBJECTHANDLE CreateWeakHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT); +} + +inline OBJECTHANDLE CreateShortWeakHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT); +} + +inline OBJECTHANDLE CreateLongWeakHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_LONG); +} + +inline OBJECTHANDLE CreateHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_DEFAULT); +} + +inline OBJECTHANDLE CreateStrongHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_STRONG); +} + +inline OBJECTHANDLE CreatePinningHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_PINNED); +} + +inline OBJECTHANDLE CreateSizedRefHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_SIZEDREF); +} + +inline OBJECTHANDLE CreateAsyncPinningHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_ASYNCPINNED); +} + +inline OBJECTHANDLE CreateRefcountedHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHeapUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_REFCOUNTED); +} + +#endif // !DACCESS_COMPILE + #endif // _GCHEAPUTILITIES_H_ -- cgit v1.2.3