diff options
-rw-r--r-- | src/vm/appdomain.hpp | 3 | ||||
-rw-r--r-- | src/vm/ceemain.cpp | 4 | ||||
-rw-r--r-- | src/vm/gchandletableutilities.h | 94 | ||||
-rw-r--r-- | src/vm/gcheaputilities.cpp | 2 | ||||
-rw-r--r-- | src/vm/gcheaputilities.h | 76 | ||||
-rw-r--r-- | src/vm/threads.h | 1 |
6 files changed, 100 insertions, 80 deletions
diff --git a/src/vm/appdomain.hpp b/src/vm/appdomain.hpp index 8022334e03..343857b467 100644 --- a/src/vm/appdomain.hpp +++ b/src/vm/appdomain.hpp @@ -28,6 +28,7 @@ #include "ilstubcache.h" #include "testhookmgr.h" #include "gcheaputilities.h" +#include "gchandletableutilities.h" #include "../binder/inc/applicationcontext.hpp" #include "rejit.h" @@ -1239,7 +1240,7 @@ public: { WRAPPER_NO_CONTRACT; - IGCHandleTable *pHandleTable = GCHeapUtilities::GetGCHandleTable(); + IGCHandleTable *pHandleTable = GCHandleTableUtilities::GetGCHandleTable(); return pHandleTable->CreateHandleOfType(m_hHandleTableBucket->pTable[GetCurrentThreadHomeHeapNumber()], OBJECTREFToObject(object), type); } diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index 602ccc92bd..9c3a89f38e 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -866,7 +866,7 @@ void EEStartupHelper(COINITIEE fFlags) // Initialize remoting - if (!GCHeapUtilities::GetGCHandleTable()->Initialize()) + if (!GCHandleTableUtilities::GetGCHandleTable()->Initialize()) { IfFailGo(E_OUTOFMEMORY); } @@ -1856,7 +1856,7 @@ part2: #ifdef SHOULD_WE_CLEANUP if (!g_fFastExitProcess) { - GCHeapUtilities::GetGCHandleTable()->Shutdown(); + GCHandleTableUtilities::GetGCHandleTable()->Shutdown(); } #endif /* SHOULD_WE_CLEANUP */ diff --git a/src/vm/gchandletableutilities.h b/src/vm/gchandletableutilities.h new file mode 100644 index 0000000000..62b68e5903 --- /dev/null +++ b/src/vm/gchandletableutilities.h @@ -0,0 +1,94 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#ifndef _GCHANDLETABLEUTILITIES_H_ +#define _GCHANDLETABLEUTILITIES_H_ + +#include "gcinterface.h" + +extern "C" IGCHandleTable* g_pGCHandleTable; + +class GCHandleTableUtilities +{ +public: + // Retrieves the GC handle table. + static IGCHandleTable* GetGCHandleTable() + { + LIMITED_METHOD_CONTRACT; + + assert(g_pGCHandleTable != nullptr); + return g_pGCHandleTable; + } + +private: + // This class should never be instantiated. + GCHandleTableUtilities() = delete; +}; + +void ValidateHandleAndAppDomain(OBJECTHANDLE handle); + +// Given a handle, returns an OBJECTREF for the object it refers to. +inline OBJECTREF ObjectFromHandle(OBJECTHANDLE handle) +{ + _ASSERTE(handle); + +#ifdef _DEBUG_IMPL + ValidateHandleAndAppDomain(handle); +#endif // _DEBUG_IMPL + + // Wrap the raw OBJECTREF and return it + return UNCHECKED_OBJECTREF_TO_OBJECTREF(*PTR_UNCHECKED_OBJECTREF(handle)); +} + +#ifndef DACCESS_COMPILE + +inline OBJECTHANDLE CreateWeakHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_DEFAULT); +} + +inline OBJECTHANDLE CreateShortWeakHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_WEAK_SHORT); +} + +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); +} + +inline OBJECTHANDLE CreatePinningHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_PINNED); +} + +inline OBJECTHANDLE CreateSizedRefHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_SIZEDREF); +} + +inline OBJECTHANDLE CreateAsyncPinningHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_ASYNCPINNED); +} + +inline OBJECTHANDLE CreateRefcountedHandle(HHANDLETABLE table, OBJECTREF object) +{ + return GCHandleTableUtilities::GetGCHandleTable()->CreateHandleOfType(table, OBJECTREFToObject(object), HNDTYPE_REFCOUNTED); +} + +#endif // !DACCESS_COMPILE + +#endif // _GCHANDLETABLEUTILITIES_H_ + diff --git a/src/vm/gcheaputilities.cpp b/src/vm/gcheaputilities.cpp index 730728927a..60f08683f8 100644 --- a/src/vm/gcheaputilities.cpp +++ b/src/vm/gcheaputilities.cpp @@ -45,7 +45,7 @@ void ValidateHandleAndAppDomain(OBJECTHANDLE handle) OBJECTREF objRef = ObjectToOBJECTREF(*(Object**)handle); VALIDATEOBJECTREF(objRef); - IGCHandleTable *pHandleTable = GCHeapUtilities::GetGCHandleTable(); + IGCHandleTable *pHandleTable = GCHandleTableUtilities::GetGCHandleTable(); void* handleTable = pHandleTable->GetHandleTableForHandle(handle); DWORD context = (DWORD)pHandleTable->GetHandleTableContext(handleTable); diff --git a/src/vm/gcheaputilities.h b/src/vm/gcheaputilities.h index c6e8507d77..0680763e76 100644 --- a/src/vm/gcheaputilities.h +++ b/src/vm/gcheaputilities.h @@ -26,7 +26,6 @@ GPTR_DECL(uint32_t,g_card_table); // GC will update it when it needs to. extern "C" gc_alloc_context g_global_alloc_context; -extern "C" IGCHandleTable* g_pGCHandleTable; extern "C" uint32_t* g_card_bundle_table; extern "C" uint8_t* g_ephemeral_low; extern "C" uint8_t* g_ephemeral_high; @@ -72,15 +71,6 @@ public: return g_pGCHeap; } - // Retrieves the GC handle table. - static IGCHandleTable* GetGCHandleTable() - { - LIMITED_METHOD_CONTRACT; - - assert(g_pGCHandleTable != nullptr); - return g_pGCHandleTable; - } - // Returns true if the heap has been initialized, false otherwise. inline static bool IsGCHeapInitialized() { @@ -209,71 +199,5 @@ private: GCHeapUtilities() = delete; }; -// Handle-related utilities. - -void ValidateHandleAndAppDomain(OBJECTHANDLE handle); - -// Given a handle, returns an OBJECTREF for the object it refers to. -inline OBJECTREF ObjectFromHandle(OBJECTHANDLE handle) -{ - _ASSERTE(handle); - -#ifdef _DEBUG_IMPL - ValidateHandleAndAppDomain(handle); -#endif // _DEBUG_IMPL - - // Wrap the raw OBJECTREF and return it - 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_ diff --git a/src/vm/threads.h b/src/vm/threads.h index f34066feb3..cc0c4c1533 100644 --- a/src/vm/threads.h +++ b/src/vm/threads.h @@ -143,6 +143,7 @@ #include "mscoree.h" #include "appdomainstack.h" #include "gcheaputilities.h" +#include "gchandletableutilities.h" #include "gcinfotypes.h" #include <clrhost.h> |