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 | |
23 | OBJECTREF AllocateValueSzArray(TypeHandle elementType, INT32 length); |
24 | // The main Array allocation routine, can do multi-dimensional |
25 | OBJECTREF AllocateArrayEx(MethodTable *pArrayMT, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap = FALSE |
26 | DEBUG_ARG(BOOL bDontSetAppDomain = FALSE)); |
27 | OBJECTREF AllocateArrayEx(TypeHandle arrayClass, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap = FALSE |
28 | DEBUG_ARG(BOOL bDontSetAppDomain = FALSE)); |
29 | // Optimized verion of above |
30 | OBJECTREF 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 |
41 | typedef HCCALL2_PTR(Object*, FastPrimitiveArrayAllocatorFuncPtr, CorElementType type, DWORD cElements); |
42 | |
43 | extern FastPrimitiveArrayAllocatorFuncPtr fastPrimitiveArrayAllocator; |
44 | |
45 | // The fast version always allocates in the normal heap |
46 | OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements); |
47 | |
48 | // The slow version is distinguished via overloading by an additional parameter |
49 | OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements, BOOL bAllocateInLargeHeap); |
50 | |
51 | |
52 | // Allocate SD array of object pointers. |
53 | typedef HCCALL2_PTR(Object*, FastObjectArrayAllocatorFuncPtr, MethodTable *pArrayMT, DWORD cElements); |
54 | |
55 | extern FastObjectArrayAllocatorFuncPtr fastObjectArrayAllocator; |
56 | |
57 | // The fast version always allocates in the normal heap |
58 | OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType); |
59 | |
60 | // The slow version is distinguished via overloading by an additional parameter |
61 | OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType, BOOL bAllocateInLargeHeap); |
62 | |
63 | |
64 | // Allocate string |
65 | typedef HCCALL1_PTR(StringObject*, FastStringAllocatorFuncPtr, DWORD cchArrayLength); |
66 | |
67 | extern FastStringAllocatorFuncPtr fastStringAllocator; |
68 | |
69 | STRINGREF AllocateString( DWORD cchStringLength ); |
70 | |
71 | // The slow version, implemented in gcscan.cpp |
72 | STRINGREF 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 |
79 | OBJECTREF AllocatePrimitiveArray(CorElementType type, DWORD cElements, BOOL bAllocateInLargeHeap = FALSE); |
80 | |
81 | // Allocate SD array of object pointers |
82 | OBJECTREF AllocateObjectArray(DWORD cElements, TypeHandle ElementType, BOOL bAllocateInLargeHeap = FALSE); |
83 | |
84 | STRINGREF SlowAllocateString( DWORD cchStringLength ); |
85 | |
86 | inline STRINGREF AllocateString( DWORD cchStringLength ) |
87 | { |
88 | WRAPPER_NO_CONTRACT; |
89 | |
90 | return SlowAllocateString( cchStringLength ); |
91 | } |
92 | |
93 | #endif |
94 | |
95 | OBJECTREF 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 | |
104 | OBJECTREF AllocateObject(MethodTable *pMT |
105 | #ifdef FEATURE_COMINTEROP |
106 | , bool fHandleCom = true |
107 | #endif |
108 | ); |
109 | |
110 | extern int StompWriteBarrierEphemeral(bool isRuntimeSuspended); |
111 | extern int StompWriteBarrierResize(bool isRuntimeSuspended, bool bReqUpperBoundsCheck); |
112 | extern int SwitchToWriteWatchBarrier(bool isRuntimeSuspended); |
113 | extern int SwitchToNonWriteWatchBarrier(bool isRuntimeSuspended); |
114 | extern void FlushWriteBarrierInstructionCache(); |
115 | |
116 | extern void ThrowOutOfMemoryDimensionsExceeded(); |
117 | |
118 | //======================================================================== |
119 | // |
120 | // WRITE BARRIER HELPERS |
121 | // |
122 | //======================================================================== |
123 | |
124 | void ErectWriteBarrier(OBJECTREF* dst, OBJECTREF ref); |
125 | void SetCardsAfterBulkCopy(Object **start, size_t len); |
126 | #endif // _GCHELPERS_H_ |
127 | |