1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 #ifndef _LOADER_ALLOCATOR_I
7 #define _LOADER_ALLOCATOR_I
9 #include "assembly.hpp"
11 #ifndef DACCESS_COMPILE
12 inline LOADERALLOCATORREF LoaderAllocator::GetExposedObject()
14 LIMITED_METHOD_CONTRACT;
15 OBJECTREF loaderAllocatorObject = (m_hLoaderAllocatorObjectHandle != NULL) ? ObjectFromHandle(m_hLoaderAllocatorObjectHandle) : NULL;
16 return (LOADERALLOCATORREF)loaderAllocatorObject;
20 inline void GlobalLoaderAllocator::Init(BaseDomain *pDomain)
22 LoaderAllocator::Init(pDomain, m_ExecutableHeapInstance);
25 inline void AppDomainLoaderAllocator::Init(AppDomain *pAppDomain)
28 m_Id.Init(pAppDomain);
29 LoaderAllocator::Init((BaseDomain *)pAppDomain);
32 inline void LoaderAllocatorID::Init(AppDomain *pAppDomain)
34 m_type = LAT_AppDomain;
35 m_pAppDomain = pAppDomain;
38 inline void AssemblyLoaderAllocator::Init(AppDomain* pAppDomain)
41 LoaderAllocator::Init((BaseDomain *)pAppDomain);
44 inline BOOL LoaderAllocatorID::Equals(LoaderAllocatorID *pId)
46 LIMITED_METHOD_CONTRACT;
47 if (GetType() != pId->GetType())
50 return GetValue() == pId->GetValue();
53 inline void LoaderAllocatorID::Init()
55 LIMITED_METHOD_CONTRACT;
56 m_type = LAT_Assembly;
59 inline void LoaderAllocatorID::SetDomainAssembly(DomainAssembly* pAssembly)
61 LIMITED_METHOD_CONTRACT;
62 _ASSERTE(m_type == LAT_Assembly);
63 m_pDomainAssembly = pAssembly;
66 inline VOID* LoaderAllocatorID::GetValue()
68 LIMITED_METHOD_DAC_CONTRACT;
72 inline COUNT_T LoaderAllocatorID::Hash()
74 LIMITED_METHOD_DAC_CONTRACT;
75 return (COUNT_T)(SIZE_T)GetValue();
78 inline LoaderAllocatorType LoaderAllocatorID::GetType()
80 LIMITED_METHOD_DAC_CONTRACT;
84 inline DomainAssembly* LoaderAllocatorID::GetDomainAssembly()
86 LIMITED_METHOD_DAC_CONTRACT;
87 _ASSERTE(m_type == LAT_Assembly);
88 return m_pDomainAssembly;
91 inline AppDomain *LoaderAllocatorID::GetAppDomain()
93 LIMITED_METHOD_DAC_CONTRACT;
94 _ASSERTE(m_type == LAT_AppDomain);
98 inline BOOL LoaderAllocatorID::IsCollectible()
100 LIMITED_METHOD_DAC_CONTRACT;
101 return m_type == LAT_Assembly;
104 inline LoaderAllocatorID* AssemblyLoaderAllocator::Id()
106 LIMITED_METHOD_DAC_CONTRACT;
110 inline LoaderAllocatorID* GlobalLoaderAllocator::Id()
112 LIMITED_METHOD_DAC_CONTRACT;
116 inline LoaderAllocatorID* AppDomainLoaderAllocator::Id()
118 LIMITED_METHOD_DAC_CONTRACT;
123 FORCEINLINE BOOL LoaderAllocator::GetHandleValueFast(LOADERHANDLE handle, OBJECTREF *pValue)
125 LIMITED_METHOD_CONTRACT;
127 // If the slot value does have the low bit set, then it is a simple pointer to the value
128 // Otherwise, we will need a more complicated operation to get the value.
129 if ((((UINT_PTR)handle) & 1) != 0)
131 *pValue = *((OBJECTREF *)(((UINT_PTR)handle) - 1));
140 FORCEINLINE BOOL LoaderAllocator::GetHandleValueFastPhase2(LOADERHANDLE handle, OBJECTREF *pValue)
143 STATIC_CONTRACT_NOTHROW;
144 STATIC_CONTRACT_MODE_COOPERATIVE;
145 STATIC_CONTRACT_NOTHROW;
146 STATIC_CONTRACT_GC_NOTRIGGER;
151 /* This is lockless access to the handle table, be careful */
152 OBJECTREF loaderAllocatorAsObjectRef = ObjectFromHandle(m_hLoaderAllocatorObjectHandle);
154 // If the managed loader allocator has been collected, then the handles associated with it are dead as well.
155 if (loaderAllocatorAsObjectRef == NULL)
158 LOADERALLOCATORREF loaderAllocator = dac_cast<LOADERALLOCATORREF>(loaderAllocatorAsObjectRef);
159 PTRARRAYREF handleTable = loaderAllocator->GetHandleTable();
160 UINT_PTR index = (((UINT_PTR)handle) >> 1) - 1;
161 *pValue = handleTable->GetAt(index);
166 FORCEINLINE OBJECTREF LoaderAllocator::GetHandleValueFastCannotFailType2(LOADERHANDLE handle)
169 STATIC_CONTRACT_NOTHROW;
170 STATIC_CONTRACT_MODE_COOPERATIVE;
171 STATIC_CONTRACT_NOTHROW;
172 STATIC_CONTRACT_GC_NOTRIGGER;
174 /* This is lockless access to the handle table, be careful */
175 OBJECTREF loaderAllocatorAsObjectRef = ObjectFromHandle(m_hLoaderAllocatorObjectHandle);
176 LOADERALLOCATORREF loaderAllocator = dac_cast<LOADERALLOCATORREF>(loaderAllocatorAsObjectRef);
177 PTRARRAYREF handleTable = loaderAllocator->GetHandleTable();
178 UINT_PTR index = (((UINT_PTR)handle) >> 1) - 1;
180 return handleTable->GetAt(index);
182 #endif // _LOADER_ALLOCATOR_I