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 * Wraps handle table to implement various handle types (Strong, Weak, etc.)
12 #ifndef _OBJECTHANDLE_H
13 #define _OBJECTHANDLE_H
16 * include handle manager declarations
18 #include "handletable.h"
20 typedef DPTR(struct HandleTableMap) PTR_HandleTableMap;
21 typedef DPTR(struct HandleTableBucket) PTR_HandleTableBucket;
22 typedef DPTR(PTR_HandleTableBucket) PTR_PTR_HandleTableBucket;
26 PTR_PTR_HandleTableBucket pBuckets;
27 PTR_HandleTableMap pNext;
31 extern HandleTableMap g_HandleTableMap;
33 // struct containing g_SystemInfo.dwNumberOfProcessors HHANDLETABLEs and current table index
34 // instead of just single HHANDLETABLE for on-fly balancing while adding handles on multiproc machines
36 struct HandleTableBucket
38 PTR_HHANDLETABLE pTable;
39 uint32_t HandleTableIndex;
41 bool Contains(OBJECTHANDLE handle);
46 * Type mask definitions for HNDTYPE_VARIABLE handles.
48 #define VHT_WEAK_SHORT (0x00000100) // avoid using low byte so we don't overlap normal types
49 #define VHT_WEAK_LONG (0x00000200) // avoid using low byte so we don't overlap normal types
50 #define VHT_STRONG (0x00000400) // avoid using low byte so we don't overlap normal types
51 #define VHT_PINNED (0x00000800) // avoid using low byte so we don't overlap normal types
53 #define IS_VALID_VHT_VALUE(flag) ((flag == VHT_WEAK_SHORT) || \
54 (flag == VHT_WEAK_LONG) || \
55 (flag == VHT_STRONG) || \
59 OBJECTREF GetDependentHandleSecondary(OBJECTHANDLE handle);
61 #ifndef DACCESS_COMPILE
62 void SetDependentHandleSecondary(OBJECTHANDLE handle, OBJECTREF secondary);
63 #endif // !DACCESS_COMPILE
65 #ifndef DACCESS_COMPILE
66 uint32_t GetVariableHandleType(OBJECTHANDLE handle);
67 void UpdateVariableHandleType(OBJECTHANDLE handle, uint32_t type);
68 uint32_t CompareExchangeVariableHandleType(OBJECTHANDLE handle, uint32_t oldType, uint32_t newType);
71 * Convenience prototypes for using the global handles
74 int GetCurrentThreadHomeHeapNumber();
77 * Table maintenance routines
79 bool Ref_Initialize();
81 HandleTableBucket* Ref_CreateHandleTableBucket(void* context);
82 bool Ref_InitializeHandleTableBucket(HandleTableBucket* bucket, void* context);
83 BOOL Ref_HandleAsyncPinHandles(async_pin_enum_fn callback, void* context);
84 void Ref_RelocateAsyncPinHandles(HandleTableBucket *pSource, HandleTableBucket *pTarget, void (*clearIfComplete)(Object*), void (*setHandle)(Object*, OBJECTHANDLE));
85 void Ref_RemoveHandleTableBucket(HandleTableBucket *pBucket);
86 void Ref_DestroyHandleTableBucket(HandleTableBucket *pBucket);
89 * GC-time scanning entrypoints
93 void Ref_BeginSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration);
94 void Ref_EndSynchronousGC (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration);
96 typedef void Ref_promote_func(class Object**, ScanContext*, uint32_t);
98 void Ref_TraceRefCountHandles(HANDLESCANPROC callback, uintptr_t lParam1, uintptr_t lParam2);
99 void Ref_TracePinningRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
100 void Ref_TraceNormalRoots(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
101 void Ref_UpdatePointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
102 void Ref_UpdatePinnedPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
103 DhContext *Ref_GetDependentHandleContext(ScanContext* sc);
104 bool Ref_ScanDependentHandlesForPromotion(DhContext *pDhContext);
105 void Ref_ScanDependentHandlesForClearing(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
106 void Ref_ScanDependentHandlesForRelocation(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
107 void Ref_ScanSizedRefHandles(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
108 #ifdef FEATURE_REDHAWK
109 void Ref_ScanPointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn);
112 void Ref_CheckReachable (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
113 void Ref_CheckAlive (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
114 void Ref_ScanHandlesForProfilerAndETW(uint32_t uMaxGeneration, uintptr_t lp1, handle_scan_fn fn);
115 void Ref_ScanDependentHandlesForProfilerAndETW(uint32_t uMaxGeneration, ScanContext * SC, handle_scan_fn fn);
116 void Ref_AgeHandles (uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
117 void Ref_RejuvenateHandles(uint32_t uCondemnedGeneration, uint32_t uMaxGeneration, uintptr_t lp1);
119 void Ref_VerifyHandleTable(uint32_t condemned, uint32_t maxgen, ScanContext* sc);
121 #endif // DACCESS_COMPILE
123 #endif //_OBJECTHANDLE_H