summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gc/gchandletable.cpp18
-rw-r--r--src/gc/gchandletableimpl.h6
-rw-r--r--src/gc/gcinterface.h6
-rw-r--r--src/gc/objecthandle.cpp18
-rw-r--r--src/gc/objecthandle.h73
-rw-r--r--src/gc/sample/GCSample.cpp4
-rw-r--r--src/vm/appdomain.hpp12
-rw-r--r--src/vm/gchandletableutilities.h65
-rw-r--r--src/vm/threads.cpp10
9 files changed, 109 insertions, 103 deletions
diff --git a/src/gc/gchandletable.cpp b/src/gc/gchandletable.cpp
index c4b16886b2..f8222b193a 100644
--- a/src/gc/gchandletable.cpp
+++ b/src/gc/gchandletable.cpp
@@ -37,3 +37,21 @@ OBJECTHANDLE GCHandleTable::CreateHandleOfType(void* table, Object* object, int
{
return ::HndCreateHandle((HHANDLETABLE)table, type, ObjectToOBJECTREF(object));
}
+
+OBJECTHANDLE GCHandleTable::CreateGlobalHandleOfType(Object* object, int type)
+{
+ return ::HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, ObjectToOBJECTREF(object));
+}
+
+OBJECTHANDLE GCHandleTable::CreateHandleWithExtraInfo(void* table, Object* object, int type, void* pExtraInfo)
+{
+ return ::HndCreateHandle((HHANDLETABLE)table, type, ObjectToOBJECTREF(object), reinterpret_cast<uintptr_t>(pExtraInfo));
+}
+
+OBJECTHANDLE GCHandleTable::CreateDependentHandle(void* table, Object* primary, Object* secondary)
+{
+ OBJECTHANDLE handle = ::HndCreateHandle((HHANDLETABLE)table, HNDTYPE_DEPENDENT, ObjectToOBJECTREF(primary));
+ ::SetDependentHandleSecondary(handle, ObjectToOBJECTREF(secondary));
+
+ return handle;
+} \ No newline at end of file
diff --git a/src/gc/gchandletableimpl.h b/src/gc/gchandletableimpl.h
index f98fd96109..787e0c1675 100644
--- a/src/gc/gchandletableimpl.h
+++ b/src/gc/gchandletableimpl.h
@@ -19,6 +19,12 @@ public:
virtual void* GetHandleTableForHandle(OBJECTHANDLE handle);
virtual OBJECTHANDLE CreateHandleOfType(void* table, Object* object, int type);
+
+ virtual OBJECTHANDLE CreateHandleWithExtraInfo(void* table, Object* object, int type, void* pExtraInfo);
+
+ virtual OBJECTHANDLE CreateDependentHandle(void* table, Object* primary, Object* secondary);
+
+ virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, int type);
};
#endif // GCHANDLETABLE_H_
diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h
index 4407fac30c..2fe9b3a1ef 100644
--- a/src/gc/gcinterface.h
+++ b/src/gc/gcinterface.h
@@ -397,6 +397,12 @@ public:
virtual void* GetHandleTableForHandle(OBJECTHANDLE handle) = 0;
virtual OBJECTHANDLE CreateHandleOfType(void* table, Object* object, int type) = 0;
+
+ virtual OBJECTHANDLE CreateHandleWithExtraInfo(void* table, Object* object, int type, void* pExtraInfo) = 0;
+
+ virtual OBJECTHANDLE CreateDependentHandle(void* table, Object* primary, Object* secondary) = 0;
+
+ virtual OBJECTHANDLE CreateGlobalHandleOfType(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.cpp b/src/gc/objecthandle.cpp
index 5f5ecbf556..cf749bf010 100644
--- a/src/gc/objecthandle.cpp
+++ b/src/gc/objecthandle.cpp
@@ -871,24 +871,6 @@ void Ref_EndSynchronousGC(uint32_t condemned, uint32_t maxgen)
*/
}
-
-OBJECTHANDLE CreateDependentHandle(HHANDLETABLE table, OBJECTREF primary, OBJECTREF secondary)
-{
- CONTRACTL
- {
- THROWS;
- GC_NOTRIGGER;
- MODE_COOPERATIVE;
- }
- CONTRACTL_END;
-
- OBJECTHANDLE handle = HndCreateHandle(table, HNDTYPE_DEPENDENT, primary);
-
- SetDependentHandleSecondary(handle, secondary);
-
- return handle;
-}
-
void SetDependentHandleSecondary(OBJECTHANDLE handle, OBJECTREF objref)
{
CONTRACTL
diff --git a/src/gc/objecthandle.h b/src/gc/objecthandle.h
index 69ddb2c4ec..a665bf7341 100644
--- a/src/gc/objecthandle.h
+++ b/src/gc/objecthandle.h
@@ -100,13 +100,6 @@ inline void DestroyHandle(OBJECTHANDLE handle)
HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, handle);
}
-inline OBJECTHANDLE CreateDuplicateHandle(OBJECTHANDLE handle) {
- WRAPPER_NO_CONTRACT;
-
- // Create a new STRONG handle in the same table as an existing handle.
- return HndCreateHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, HndFetchHandle(handle));
-}
-
inline void DestroyWeakHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -176,13 +169,6 @@ inline void DestroyRefcountedHandle(OBJECTHANDLE handle)
HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_REFCOUNTED, handle);
}
-inline OBJECTHANDLE CreateWinRTWeakHandle(HHANDLETABLE table, OBJECTREF object, IWeakReference* pWinRTWeakReference)
-{
- WRAPPER_NO_CONTRACT;
- _ASSERTE(pWinRTWeakReference != NULL);
- return HndCreateHandle(table, HNDTYPE_WEAK_WINRT, object, reinterpret_cast<uintptr_t>(pWinRTWeakReference));
-}
-
void DestroyWinRTWeakHandle(OBJECTHANDLE handle);
#endif // FEATURE_COMINTEROP
@@ -192,7 +178,6 @@ void DestroyWinRTWeakHandle(OBJECTHANDLE handle);
OBJECTREF GetDependentHandleSecondary(OBJECTHANDLE handle);
#ifndef DACCESS_COMPILE
-OBJECTHANDLE CreateDependentHandle(HHANDLETABLE table, OBJECTREF primary, OBJECTREF secondary);
void SetDependentHandleSecondary(OBJECTHANDLE handle, OBJECTREF secondary);
inline void DestroyDependentHandle(OBJECTHANDLE handle)
@@ -268,12 +253,6 @@ public:
int GetCurrentThreadHomeHeapNumber();
-inline OBJECTHANDLE CreateGlobalTypedHandle(OBJECTREF object, int type)
-{
- WRAPPER_NO_CONTRACT;
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, object);
-}
-
inline void DestroyGlobalTypedHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -281,14 +260,6 @@ inline void DestroyGlobalTypedHandle(OBJECTHANDLE handle)
HndDestroyHandleOfUnknownType(HndGetHandleTable(handle), handle);
}
-inline OBJECTHANDLE CreateGlobalHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
- CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_DEFAULT, object);
-}
-
inline void DestroyGlobalHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -296,13 +267,6 @@ inline void DestroyGlobalHandle(OBJECTHANDLE handle)
HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, handle);
}
-inline OBJECTHANDLE CreateGlobalWeakHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_WEAK_DEFAULT, object);
-}
-
inline void DestroyGlobalWeakHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -310,14 +274,6 @@ inline void DestroyGlobalWeakHandle(OBJECTHANDLE handle)
HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_WEAK_DEFAULT, handle);
}
-inline OBJECTHANDLE CreateGlobalShortWeakHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
- CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_WEAK_SHORT, object);
-}
-
inline void DestroyGlobalShortWeakHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -329,13 +285,6 @@ inline void DestroyGlobalShortWeakHandle(OBJECTHANDLE handle)
typedef Holder<OBJECTHANDLE,DoNothing<OBJECTHANDLE>,DestroyGlobalShortWeakHandle> GlobalShortWeakHandleHolder;
#endif
-inline OBJECTHANDLE CreateGlobalLongWeakHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_WEAK_LONG, object);
-}
-
inline void DestroyGlobalLongWeakHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -343,14 +292,6 @@ inline void DestroyGlobalLongWeakHandle(OBJECTHANDLE handle)
HndDestroyHandle(HndGetHandleTable(handle), HNDTYPE_WEAK_LONG, handle);
}
-inline OBJECTHANDLE CreateGlobalStrongHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
- CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_STRONG, object);
-}
-
inline void DestroyGlobalStrongHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -362,13 +303,6 @@ inline void DestroyGlobalStrongHandle(OBJECTHANDLE handle)
typedef Holder<OBJECTHANDLE,DoNothing<OBJECTHANDLE>,DestroyGlobalStrongHandle> GlobalStrongHandleHolder;
#endif
-inline OBJECTHANDLE CreateGlobalPinningHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_PINNED, object);
-}
-
inline void DestroyGlobalPinningHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
@@ -377,13 +311,6 @@ inline void DestroyGlobalPinningHandle(OBJECTHANDLE handle)
}
#ifdef FEATURE_COMINTEROP
-inline OBJECTHANDLE CreateGlobalRefcountedHandle(OBJECTREF object)
-{
- WRAPPER_NO_CONTRACT;
-
- return HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_REFCOUNTED, object);
-}
-
inline void DestroyGlobalRefcountedHandle(OBJECTHANDLE handle)
{
WRAPPER_NO_CONTRACT;
diff --git a/src/gc/sample/GCSample.cpp b/src/gc/sample/GCSample.cpp
index 45915c0d04..ed67e892ff 100644
--- a/src/gc/sample/GCSample.cpp
+++ b/src/gc/sample/GCSample.cpp
@@ -201,7 +201,7 @@ int __cdecl main(int argc, char* argv[])
return -1;
// Create strong handle and store the object into it
- OBJECTHANDLE oh = CreateGlobalHandle(pObj);
+ OBJECTHANDLE oh = HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_DEFAULT, pObj);
if (oh == NULL)
return -1;
@@ -224,7 +224,7 @@ int __cdecl main(int argc, char* argv[])
}
// Create weak handle that points to our object
- OBJECTHANDLE ohWeak = CreateGlobalWeakHandle(HndFetchHandle(oh));
+ OBJECTHANDLE ohWeak = HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_WEAK_DEFAULT, HndFetchHandle(oh));
if (ohWeak == NULL)
return -1;
diff --git a/src/vm/appdomain.hpp b/src/vm/appdomain.hpp
index 343857b467..1da057c9c4 100644
--- a/src/vm/appdomain.hpp
+++ b/src/vm/appdomain.hpp
@@ -1325,8 +1325,16 @@ public:
OBJECTHANDLE CreateDependentHandle(OBJECTREF primary, OBJECTREF secondary)
{
- WRAPPER_NO_CONTRACT;
- return ::CreateDependentHandle(m_hHandleTableBucket->pTable[GetCurrentThreadHomeHeapNumber()], primary, secondary);
+ CONTRACTL
+ {
+ THROWS;
+ GC_NOTRIGGER;
+ MODE_COOPERATIVE;
+ }
+ CONTRACTL_END;
+
+ IGCHandleTable *pHandleTable = GCHandleTableUtilities::GetGCHandleTable();
+ return pHandleTable->CreateDependentHandle((void*)m_hHandleTableBucket->pTable[GetCurrentThreadHomeHeapNumber()], OBJECTREFToObject(primary), OBJECTREFToObject(secondary));
}
#endif // DACCESS_COMPILE && !CROSSGEN_COMPILE
diff --git a/src/vm/gchandletableutilities.h b/src/vm/gchandletableutilities.h
index 62b68e5903..dbd8efef11 100644
--- a/src/vm/gchandletableutilities.h
+++ b/src/vm/gchandletableutilities.h
@@ -7,6 +7,10 @@
#include "gcinterface.h"
+#ifdef FEATURE_COMINTEROP
+#include <weakreference.h>
+#endif
+
extern "C" IGCHandleTable* g_pGCHandleTable;
class GCHandleTableUtilities
@@ -43,6 +47,13 @@ inline OBJECTREF ObjectFromHandle(OBJECTHANDLE handle)
#ifndef DACCESS_COMPILE
+// Handle creation convenience functions
+
+inline OBJECTHANDLE CreateHandle(HHANDLETABLE table, OBJECTREF object)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+}
+
inline OBJECTHANDLE CreateWeakHandle(HHANDLETABLE table, OBJECTREF object)
{
return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
@@ -58,11 +69,6 @@ inline OBJECTHANDLE CreateLongWeakHandle(HHANDLETABLE table, OBJECTREF object)
return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
}
-inline OBJECTHANDLE CreateHandle(HHANDLETABLE table, OBJECTREF object)
-{
- return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_DEFAULT);
-}
-
inline OBJECTHANDLE CreateStrongHandle(HHANDLETABLE table, OBJECTREF object)
{
return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_STRONG);
@@ -88,6 +94,55 @@ inline OBJECTHANDLE CreateRefcountedHandle(HHANDLETABLE table, OBJECTREF object)
return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
}
+// Global handle creation convenience functions
+
+inline OBJECTHANDLE CreateGlobalHandle(OBJECTREF object)
+{
+ CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_DEFAULT);
+}
+
+inline OBJECTHANDLE CreateGlobalWeakHandle(OBJECTREF object)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT);
+}
+
+inline OBJECTHANDLE CreateGlobalShortWeakHandle(OBJECTREF object)
+{
+ CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT);
+}
+
+inline OBJECTHANDLE CreateGlobalLongWeakHandle(OBJECTREF object)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_WEAK_LONG);
+}
+
+inline OBJECTHANDLE CreateGlobalStrongHandle(OBJECTREF object)
+{
+ CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL);
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_STRONG);
+}
+
+inline OBJECTHANDLE CreateGlobalPinningHandle(OBJECTREF object)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_PINNED);
+}
+
+inline OBJECTHANDLE CreateGlobalRefcountedHandle(OBJECTREF object)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateGlobalHandleOfType(OBJECTREFToObject(object), HNDTYPE_REFCOUNTED);
+}
+
+// Special handle creation convenience functions
+
+#ifdef FEATURE_COMINTEROP
+inline OBJECTHANDLE CreateWinRTWeakHandle(HHANDLETABLE table, OBJECTREF object, IWeakReference* pWinRTWeakReference)
+{
+ return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleWithExtraInfo(table, OBJECTREFToObject(object), HNDTYPE_WEAK_WINRT, (void*)pWinRTWeakReference);
+}
+#endif // FEATURE_COMINTEROP
+
#endif // !DACCESS_COMPILE
#endif // _GCHANDLETABLEUTILITIES_H_
diff --git a/src/vm/threads.cpp b/src/vm/threads.cpp
index da805bdd46..d1dd772d7c 100644
--- a/src/vm/threads.cpp
+++ b/src/vm/threads.cpp
@@ -5074,9 +5074,13 @@ void Thread::SafeUpdateLastThrownObject(void)
{
EX_TRY
{
- // Using CreateDuplicateHandle here ensures that the AD of the last thrown object matches the domain of
- // the current throwable.
- SetLastThrownObjectHandle(CreateDuplicateHandle(hThrowable));
+ IGCHandleTable *pHandleTable = GCHandleTableUtilities::GetGCHandleTable();
+ void* table = pHandleTable->GetHandleTableForHandle(hThrowable);
+
+ // Creating a duplicate handle here ensures that the AD of the last thrown object
+ // matches the domain of the current throwable.
+ OBJECTHANDLE duplicateHandle = pHandleTable->CreateHandleOfType(table, OBJECTREFToObject(ObjectFromHandle(hThrowable)), HNDTYPE_DEFAULT);
+ SetLastThrownObjectHandle(duplicateHandle);
}
EX_CATCH
{