Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AllocFast.S « amd64 « Runtime « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a1e5e5fce661dc07a96245c3a4d2f1e703fe68e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

.intel_syntax noprefix
#include <AsmOffsets.inc>         // generated by the build from AsmOffsets.cpp
#include <unixasmmacros.inc>

// Allocate non-array, non-finalizable object. If the allocation doesn't fit into the current thread's
// allocation context then automatically fallback to the slow allocation path.
//  RDI == EEType
NESTED_ENTRY RhpNewFast, _TEXT, NoHandler
        push_nonvol_reg rbx
        mov         rbx, rdi

        // rax = GetThread()
        INLINE_GETTHREAD

        //
        // rbx contains EEType pointer
        //
        mov         edx, [rbx + OFFSETOF__EEType__m_uBaseSize]

        //
        // rax: Thread pointer
        // rbx: EEType pointer
        // rdx: base size
        //

        mov         rsi, [rax + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
        add         rdx, rsi
        cmp         rdx, [rax + OFFSETOF__Thread__m_alloc_context__alloc_limit]
        ja          LOCAL_LABEL(RhpNewFast_RarePath)

        // set the new alloc pointer
        mov         [rax + OFFSETOF__Thread__m_alloc_context__alloc_ptr], rdx

        mov         rax, rsi

        // set the new object's EEType pointer
        mov         [rsi], rbx

        .cfi_remember_state
        pop_nonvol_reg rbx
        ret

        .cfi_restore_state
        .cfi_def_cfa_offset 16          // workaround cfi_restore_state bug
LOCAL_LABEL(RhpNewFast_RarePath):
        mov         rdi, rbx            // restore EEType
        xor         esi, esi
        pop_nonvol_reg rbx
        jmp         C_FUNC(RhpNewObject)

NESTED_END RhpNewFast, _TEXT



// Allocate non-array object with finalizer
//  RDI == EEType
LEAF_ENTRY RhpNewFinalizable, _TEXT
        mov         esi, GC_ALLOC_FINALIZE
        jmp         C_FUNC(RhpNewObject)
LEAF_END RhpNewFinalizable, _TEXT



// Allocate non-array object
//  RDI == EEType
//  ESI == alloc flags
NESTED_ENTRY RhpNewObject, _TEXT, NoHandler

        PUSH_COOP_PINVOKE_FRAME rcx
        END_PROLOGUE

        // RCX: transition frame

        // Preserve the EEType in RBX
        mov         rbx, rdi

        mov         edx, [rdi + OFFSETOF__EEType__m_uBaseSize]      // cbSize

        // Call the rest of the allocation helper.
        // void* RhpGcAlloc(EEType *pEEType, UInt32 uFlags, UIntNative cbSize, void * pTransitionFrame)
        call        C_FUNC(RhpGcAlloc)

        // Set the new object's EEType pointer on success.
        test        rax, rax
        jz          LOCAL_LABEL(NewOutOfMemory)
        mov         [rax + OFFSETOF__Object__m_pEEType], rbx

        // If the object is bigger than RH_LARGE_OBJECT_SIZE, we must publish it to the BGC
        mov         esi, [rbx + OFFSETOF__EEType__m_uBaseSize]
.att_syntax
        cmp         $RH_LARGE_OBJECT_SIZE, %rsi
.intel_syntax noprefix
        jb          LOCAL_LABEL(New_SkipPublish)
        mov         rdi, rax            // rdi: object
                                        // rsi: already contains object size
        call        C_FUNC(RhpPublishObject) // rax: this function returns the object that was passed-in
LOCAL_LABEL(New_SkipPublish):

        .cfi_remember_state
        POP_COOP_PINVOKE_FRAME
        ret

        .cfi_restore_state
        .cfi_def_cfa_offset 96          // workaround cfi_restore_state bug
LOCAL_LABEL(NewOutOfMemory):
        // This is the OOM failure path. We're going to tail-call to a managed helper that will throw
        // an out of memory exception that the caller of this allocator understands.

        mov         rdi, rbx            // EEType pointer
        xor         esi, esi            // Indicate that we should throw OOM.

        POP_COOP_PINVOKE_FRAME

        jmp         C_FUNC(RhExceptionHandling_FailedAllocation)
NESTED_END RhpNewObject, _TEXT


// Allocate a string.
//  RDI == EEType
//  ESI == character/element count
NESTED_ENTRY RhNewString, _TEXT, NoHandler
        // we want to limit the element count to the non-negative 32-bit int range
        cmp         rsi, 07fffffffh
        ja          LOCAL_LABEL(StringSizeOverflow)

        push_nonvol_reg rbx
        push_nonvol_reg r12
        push_register rcx       // padding

        mov         rbx, rdi    // save EEType
        mov         r12, rsi    // save element count

        // rax = GetThread()
        INLINE_GETTHREAD

        mov         rcx, rax    // rcx = Thread*

        // Compute overall allocation size (align(base size + (element size * elements), 8)).
        lea         rax, [r12 * STRING_COMPONENT_SIZE + STRING_BASE_SIZE + 7]
        and         rax, -8

        // rax == string size
        // rbx == EEType
        // rcx == Thread*
        // r12 == element count

        mov         rdx, rax
        add         rax, [rcx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
        jc          LOCAL_LABEL(RhNewString_RarePath)

        // rax == new alloc ptr
        // rbx == EEType
        // rcx == Thread*
        // rdx == string size
        // r12 == element count
        cmp         rax, [rcx + OFFSETOF__Thread__m_alloc_context__alloc_limit]
        ja          LOCAL_LABEL(RhNewString_RarePath)

        mov         [rcx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], rax

        // calc the new object pointer
        sub         rax, rdx

        mov         [rax + OFFSETOF__Object__m_pEEType], rbx
        mov         [rax + OFFSETOF__String__m_Length], r12d

        .cfi_remember_state
        pop_register rcx       // padding
        pop_nonvol_reg r12
        pop_nonvol_reg rbx
        ret

        .cfi_restore_state
        .cfi_def_cfa_offset 32  // workaround cfi_restore_state bug
LOCAL_LABEL(RhNewString_RarePath):
        mov         rdi, rbx    // restore EEType
        mov         rsi, r12    // restore element count
        // passing string size in rdx

        pop_register rcx        // padding
        pop_nonvol_reg r12
        pop_nonvol_reg rbx
        jmp C_FUNC(RhpNewArrayRare)

LOCAL_LABEL(StringSizeOverflow):
        // We get here if the size of the final string object can't be represented as an unsigned 
        // 32-bit value. We're going to tail-call to a managed helper that will throw
        // an OOM exception that the caller of this allocator understands.

        // rdi holds EEType pointer already
        xor         esi, esi            // Indicate that we should throw OOM.
        jmp         C_FUNC(RhExceptionHandling_FailedAllocation)

NESTED_END RhNewString, _TEXT


// Allocate one dimensional, zero based array (SZARRAY).
//  RDI == EEType
//  ESI == element count
NESTED_ENTRY RhpNewArray, _TEXT, NoHandler
        // we want to limit the element count to the non-negative 32-bit int range
        cmp         rsi, 07fffffffh
        ja          LOCAL_LABEL(ArraySizeOverflow)

        push_nonvol_reg rbx
        push_nonvol_reg r12
        push_register rcx       // padding

        mov         rbx, rdi    // save EEType
        mov         r12, rsi    // save element count

        // rax = GetThread()
        INLINE_GETTHREAD

        mov         rcx, rax    // rcx = Thread*

        // Compute overall allocation size (align(base size + (element size * elements), 8)).
        movzx       eax, word ptr [rbx + OFFSETOF__EEType__m_usComponentSize]
        mul         r12
        mov         edx, [rbx + OFFSETOF__EEType__m_uBaseSize]
        add         rax, rdx
        add         rax, 7
        and         rax, -8

        // rax == array size
        // rbx == EEType
        // rcx == Thread*
        // r12 == element count

        mov         rdx, rax
        add         rax, [rcx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]
        jc          LOCAL_LABEL(RhpNewArray_RarePath)

        // rax == new alloc ptr
        // rbx == EEType
        // rcx == Thread*
        // rdx == array size
        // r12 == element count
        cmp         rax, [rcx + OFFSETOF__Thread__m_alloc_context__alloc_limit]
        ja          LOCAL_LABEL(RhpNewArray_RarePath)

        mov         [rcx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], rax

        // calc the new object pointer
        sub         rax, rdx

        mov         [rax + OFFSETOF__Object__m_pEEType], rbx
        mov         [rax + OFFSETOF__Array__m_Length], r12d

        .cfi_remember_state
        pop_register rcx       // padding
        pop_nonvol_reg r12
        pop_nonvol_reg rbx
        ret

        .cfi_restore_state
        .cfi_def_cfa_offset 32  // workaround cfi_restore_state bug
LOCAL_LABEL(RhpNewArray_RarePath):
        mov         rdi, rbx    // restore EEType
        mov         rsi, r12    // restore element count
        // passing array size in rdx

        pop_register rcx        // padding
        pop_nonvol_reg r12
        pop_nonvol_reg rbx
        jmp C_FUNC(RhpNewArrayRare)

LOCAL_LABEL(ArraySizeOverflow):
        // We get here if the size of the final array object can't be represented as an unsigned 
        // 32-bit value. We're going to tail-call to a managed helper that will throw
        // an overflow exception that the caller of this allocator understands.

        // rdi holds EEType pointer already
        mov         esi, 1              // Indicate that we should throw OverflowException
        jmp         C_FUNC(RhExceptionHandling_FailedAllocation)

NESTED_END RhpNewArray, _TEXT

NESTED_ENTRY RhpNewArrayRare, _TEXT, NoHandler

        // rdi == EEType
        // rsi == element count
        // rdx == array size

        PUSH_COOP_PINVOKE_FRAME rcx
        END_PROLOGUE

        // rcx: transition frame

        // Preserve the EEType in RBX
        mov         rbx, rdi
        // Preserve the element count in R12
        mov         r12, rsi
        // Preserve the size in R13
        mov         r13, rdx

        // passing EEType in rdi
        xor         rsi, rsi        // uFlags
        // pasing size in rdx
        // pasing pTransitionFrame in rcx

        // Call the rest of the allocation helper.
        // void* RhpGcAlloc(EEType *pEEType, UInt32 uFlags, UIntNative cbSize, void * pTransitionFrame)
        call        C_FUNC(RhpGcAlloc)

        // Set the new object's EEType pointer and length on success.
        test        rax, rax
        jz          LOCAL_LABEL(ArrayOutOfMemory)
        mov         [rax + OFFSETOF__Object__m_pEEType], rbx
        mov         [rax + OFFSETOF__Array__m_Length], r12d

        // If the object is bigger than RH_LARGE_OBJECT_SIZE, we must publish it to the BGC
.att_syntax
        cmp         $RH_LARGE_OBJECT_SIZE, %r13
.intel_syntax noprefix
        jb          LOCAL_LABEL(NewArray_SkipPublish)
        mov         rdi, rax            // rcx: object
        mov         rsi, r13            // rdx: object size
        call        C_FUNC(RhpPublishObject) // rax: this function returns the object that was passed-in
LOCAL_LABEL(NewArray_SkipPublish):

        .cfi_remember_state
        POP_COOP_PINVOKE_FRAME
        ret

        .cfi_restore_state
        .cfi_def_cfa_offset 96          // workaround cfi_restore_state bug
LOCAL_LABEL(ArrayOutOfMemory):
        // This is the OOM failure path. We're going to tail-call to a managed helper that will throw
        // an out of memory exception that the caller of this allocator understands.

        mov         rdi, rbx            // EEType pointer
        xor         esi, esi            // Indicate that we should throw OOM.

        POP_COOP_PINVOKE_FRAME

        jmp         C_FUNC(RhExceptionHandling_FailedAllocation)

NESTED_END RhpNewArrayRare, _TEXT