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.
5 #ifndef __GCENV_OBJECT_H__
6 #define __GCENV_OBJECT_H__
8 //-------------------------------------------------------------------------------------------------
10 // Low-level types describing GC object layouts.
13 // Bits stolen from the sync block index that the GC/HandleTable knows about (currently these are at the same
14 // positions as the mainline runtime but we can change this below when it becomes apparent how Redhawk will
15 // handle sync blocks).
16 #define BIT_SBLK_GC_RESERVE 0x20000000
17 #define BIT_SBLK_FINALIZER_RUN 0x40000000
19 // The sync block index header (small structure that immediately precedes every object in the GC heap). Only
20 // the GC uses this so far, and only to store a couple of bits of information.
27 uint32_t m_uSyncBlockValue;
30 uint32_t GetBits() { return m_uSyncBlockValue; }
31 void SetBit(uint32_t uBit) { Interlocked::Or(&m_uSyncBlockValue, uBit); }
32 void ClrBit(uint32_t uBit) { Interlocked::And(&m_uSyncBlockValue, ~uBit); }
33 void SetGCBit() { m_uSyncBlockValue |= BIT_SBLK_GC_RESERVE; }
34 void ClrGCBit() { m_uSyncBlockValue &= ~BIT_SBLK_GC_RESERVE; }
37 static_assert(sizeof(ObjHeader) == sizeof(uintptr_t), "this assumption is made by the VM!");
39 #define MTFlag_ContainsPointers 0x0100
40 #define MTFlag_HasCriticalFinalizer 0x0800
41 #define MTFlag_HasFinalizer 0x0010
42 #define MTFlag_IsArray 0x0008
43 #define MTFlag_Collectible 0x1000
44 #define MTFlag_HasComponentSize 0x8000
49 uint16_t m_componentSize;
53 MethodTable * m_pRelatedType;
56 void InitializeFreeObject()
58 m_baseSize = 3 * sizeof(void *);
60 m_flags = MTFlag_HasComponentSize | MTFlag_IsArray;
63 uint32_t GetBaseSize()
68 uint16_t RawGetComponentSize()
70 return m_componentSize;
75 return (m_flags & MTFlag_Collectible) != 0;
78 bool ContainsPointers()
80 return (m_flags & MTFlag_ContainsPointers) != 0;
83 bool ContainsPointersOrCollectible()
85 return ContainsPointers() || Collectible();
88 bool HasComponentSize()
90 // Note that we can't just check m_componentSize != 0 here. The VM
91 // may still construct a method table that does not have a component
92 // size, according to this method, but still has a number in the low
93 // 16 bits of the method table flags parameter.
95 // The solution here is to do what the VM does and check the
96 // HasComponentSize flag so that we're on the same page.
97 return (m_flags & MTFlag_HasComponentSize) != 0;
102 return (m_flags & MTFlag_HasFinalizer) != 0;
105 bool HasCriticalFinalizer()
107 return (m_flags & MTFlag_HasCriticalFinalizer) != 0;
112 return (m_flags & MTFlag_IsArray) != 0;
115 MethodTable * GetParent()
117 _ASSERTE(!IsArray());
118 return m_pRelatedType;
126 uint8_t* GetLoaderAllocatorObjectForGC()
128 // [LOCALGC TODO] this is not correct
135 MethodTable * m_pMethTab;
138 ObjHeader * GetHeader()
140 return ((ObjHeader *)this) - 1;
143 MethodTable * RawGetMethodTable() const
148 MethodTable * GetGCSafeMethodTable() const
150 return (MethodTable *)((uintptr_t)m_pMethTab & ~3);
153 void RawSetMethodTable(MethodTable * pMT)
158 #define MIN_OBJECT_SIZE (2*sizeof(uint8_t*) + sizeof(ObjHeader))
160 class ArrayBase : public Object
165 uint32_t GetNumComponents()
170 static size_t GetOffsetOfNumComponents()
172 return offsetof(ArrayBase, m_dwLength);
176 #endif // __GCENV_OBJECT_H__