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.
4
5/*
6 * GCHELPERS.H
7 *
8 * GC Allocation and Write Barrier Helpers
9 *
10
11 *
12 */
13
14#ifndef _GCHELPERS_H_
15#define _GCHELPERS_H_
16
17//========================================================================
18//
19// ALLOCATION HELPERS
20//
21//========================================================================
22
23OBJECTREF AllocateValueSzArray(TypeHandle elementType, INT32 length);
24 // The main Array allocation routine, can do multi-dimensional
25OBJECTREF AllocateArrayEx(MethodTable *pArrayMT, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap = FALSE
26 DEBUG_ARG(BOOL bDontSetAppDomain = FALSE));
27OBJECTREF AllocateArrayEx(TypeHandle arrayClass, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap = FALSE
28 DEBUG_ARG(BOOL bDontSetAppDomain = FALSE));
29 // Optimized verion of above
30OBJECTREF FastAllocatePrimitiveArray(MethodTable* arrayType, DWORD cElements, BOOL bAllocateInLargeHeap = FALSE);
31
32
33#if defined(_TARGET_X86_)
34
35 // for x86, we generate efficient allocators for some special cases
36 // these are called via inline wrappers that call the generated allocators
37 // via function pointers.
38
39
40 // Create a SD array of primitive types
41typedef HCCALL2_PTR(Object*, FastPrimitiveArrayAllocatorFuncPtr, CorElementType type, DWORD cElements);
42
43extern FastPrimitiveArrayAllocatorFuncPtr fastPrimitiveArrayAllocator;
44
45 // The fast version always allocates in the normal heap
46OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements);
47
48 // The slow version is distinguished via overloading by an additional parameter
49OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements, BOOL bAllocateInLargeHeap);
50
51
52// Allocate SD array of object pointers.
53typedef HCCALL2_PTR(Object*, FastObjectArrayAllocatorFuncPtr, MethodTable *pArrayMT, DWORD cElements);
54
55extern FastObjectArrayAllocatorFuncPtr fastObjectArrayAllocator;
56
57 // The fast version always allocates in the normal heap
58OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType);
59
60 // The slow version is distinguished via overloading by an additional parameter
61OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType, BOOL bAllocateInLargeHeap);
62
63
64 // Allocate string
65typedef HCCALL1_PTR(StringObject*, FastStringAllocatorFuncPtr, DWORD cchArrayLength);
66
67extern FastStringAllocatorFuncPtr fastStringAllocator;
68
69STRINGREF AllocateString( DWORD cchStringLength );
70
71 // The slow version, implemented in gcscan.cpp
72STRINGREF SlowAllocateString( DWORD cchStringLength );
73
74#else
75
76// On other platforms, go to the (somewhat less efficient) implementations in gcscan.cpp
77
78 // Create a SD array of primitive types
79OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements, BOOL bAllocateInLargeHeap = FALSE);
80
81 // Allocate SD array of object pointers
82OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType, BOOL bAllocateInLargeHeap = FALSE);
83
84STRINGREF SlowAllocateString( DWORD cchStringLength );
85
86inline STRINGREF AllocateString( DWORD cchStringLength )
87{
88 WRAPPER_NO_CONTRACT;
89
90 return SlowAllocateString( cchStringLength );
91}
92
93#endif
94
95OBJECTREF DupArrayForCloning(BASEARRAYREF pRef, BOOL bAllocateInLargeHeap = FALSE);
96
97// The JIT requests the EE to specify an allocation helper to use at each new-site.
98// The EE makes this choice based on whether context boundaries may be involved,
99// whether the type is a COM object, whether it is a large object,
100// whether the object requires finalization.
101// These functions will throw OutOfMemoryException so don't need to check
102// for NULL return value from them.
103
104OBJECTREF AllocateObject(MethodTable *pMT
105#ifdef FEATURE_COMINTEROP
106 , bool fHandleCom = true
107#endif
108 );
109
110extern int StompWriteBarrierEphemeral(bool isRuntimeSuspended);
111extern int StompWriteBarrierResize(bool isRuntimeSuspended, bool bReqUpperBoundsCheck);
112extern int SwitchToWriteWatchBarrier(bool isRuntimeSuspended);
113extern int SwitchToNonWriteWatchBarrier(bool isRuntimeSuspended);
114extern void FlushWriteBarrierInstructionCache();
115
116extern void ThrowOutOfMemoryDimensionsExceeded();
117
118//========================================================================
119//
120// WRITE BARRIER HELPERS
121//
122//========================================================================
123
124void ErectWriteBarrier(OBJECTREF* dst, OBJECTREF ref);
125void SetCardsAfterBulkCopy(Object **start, size_t len);
126#endif // _GCHELPERS_H_
127