quick_entrypoints_arm64.S revision ae6ba1fd36ef6cd6520354fa874cf9cc2fc5877b
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_arm64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21
22.macro INCREASE_FRAME frame_adjustment
23    sub sp, sp, #(\frame_adjustment)
24    .cfi_adjust_cfa_offset (\frame_adjustment)
25.endm
26
27.macro DECREASE_FRAME frame_adjustment
28    add sp, sp, #(\frame_adjustment)
29    .cfi_adjust_cfa_offset -(\frame_adjustment)
30.endm
31
32.macro SAVE_REG reg, offset
33    str \reg, [sp, #(\offset)]
34    .cfi_rel_offset \reg, (\offset)
35.endm
36
37.macro RESTORE_REG reg, offset
38    ldr \reg, [sp, #(\offset)]
39    .cfi_restore \reg
40.endm
41
42.macro SAVE_TWO_REGS reg1, reg2, offset
43    stp \reg1, \reg2, [sp, #(\offset)]
44    .cfi_rel_offset \reg1, (\offset)
45    .cfi_rel_offset \reg2, (\offset) + 8
46.endm
47
48.macro RESTORE_TWO_REGS reg1, reg2, offset
49    ldp \reg1, \reg2, [sp, #(\offset)]
50    .cfi_restore \reg1
51    .cfi_restore \reg2
52.endm
53
54.macro SAVE_TWO_REGS_INCREASE_FRAME reg1, reg2, frame_adjustment
55    stp \reg1, \reg2, [sp, #-(\frame_adjustment)]!
56    .cfi_adjust_cfa_offset (\frame_adjustment)
57    .cfi_rel_offset \reg1, 0
58    .cfi_rel_offset \reg2, 8
59.endm
60
61.macro RESTORE_TWO_REGS_DECREASE_FRAME reg1, reg2, frame_adjustment
62    ldp \reg1, \reg2, [sp], #(\frame_adjustment)
63    .cfi_restore \reg1
64    .cfi_restore \reg2
65    .cfi_adjust_cfa_offset -(\frame_adjustment)
66.endm
67
68    /*
69     * Macro that sets up the callee save frame to conform with
70     * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
71     */
72.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
73    // art::Runtime** xIP0 = &art::Runtime::instance_
74    adrp xIP0, :got:_ZN3art7Runtime9instance_E
75    ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
76
77    // Our registers aren't intermixed - just spill in order.
78    ldr xIP0, [xIP0]  // art::Runtime* xIP0 = art::Runtime::instance_;
79
80    // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves];
81    ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
82
83    INCREASE_FRAME 176
84
85    // Ugly compile-time check, but we only have the preprocessor.
86#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176)
87#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected."
88#endif
89
90    // Stack alignment filler [sp, #8].
91    // FP callee-saves.
92    stp d8, d9,   [sp, #16]
93    stp d10, d11, [sp, #32]
94    stp d12, d13, [sp, #48]
95    stp d14, d15, [sp, #64]
96
97    // GP callee-saves
98    SAVE_TWO_REGS x19, x20, 80
99    SAVE_TWO_REGS x21, x22, 96
100    SAVE_TWO_REGS x23, x24, 112
101    SAVE_TWO_REGS x25, x26, 128
102    SAVE_TWO_REGS x27, x28, 144
103    SAVE_TWO_REGS x29, xLR, 160
104
105    // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves].
106    str xIP0, [sp]
107    // Place sp in Thread::Current()->top_quick_frame.
108    mov xIP0, sp
109    str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
110.endm
111
112    /*
113     * Macro that sets up the callee save frame to conform with
114     * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
115     */
116.macro SETUP_SAVE_REFS_ONLY_FRAME
117    // art::Runtime** xIP0 = &art::Runtime::instance_
118    adrp xIP0, :got:_ZN3art7Runtime9instance_E
119    ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
120
121    // Our registers aren't intermixed - just spill in order.
122    ldr xIP0, [xIP0]  // art::Runtime* xIP0 = art::Runtime::instance_;
123
124    // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly];
125    ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
126
127    INCREASE_FRAME 96
128
129    // Ugly compile-time check, but we only have the preprocessor.
130#if (FRAME_SIZE_SAVE_REFS_ONLY != 96)
131#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected."
132#endif
133
134    // GP callee-saves.
135    // x20 paired with ArtMethod* - see below.
136    SAVE_TWO_REGS x21, x22, 16
137    SAVE_TWO_REGS x23, x24, 32
138    SAVE_TWO_REGS x25, x26, 48
139    SAVE_TWO_REGS x27, x28, 64
140    SAVE_TWO_REGS x29, xLR, 80
141
142    // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly].
143    stp xIP0, x20, [sp]
144    .cfi_rel_offset x20, 8
145
146    // Place sp in Thread::Current()->top_quick_frame.
147    mov xIP0, sp
148    str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
149.endm
150
151// TODO: Probably no need to restore registers preserved by aapcs64.
152.macro RESTORE_SAVE_REFS_ONLY_FRAME
153    // Callee-saves.
154    RESTORE_REG x20, 8
155    RESTORE_TWO_REGS x21, x22, 16
156    RESTORE_TWO_REGS x23, x24, 32
157    RESTORE_TWO_REGS x25, x26, 48
158    RESTORE_TWO_REGS x27, x28, 64
159    RESTORE_TWO_REGS x29, xLR, 80
160
161    DECREASE_FRAME 96
162.endm
163
164.macro POP_SAVE_REFS_ONLY_FRAME
165    DECREASE_FRAME 96
166.endm
167
168.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
169    RESTORE_SAVE_REFS_ONLY_FRAME
170    ret
171.endm
172
173
174.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
175    INCREASE_FRAME 224
176
177    // Ugly compile-time check, but we only have the preprocessor.
178#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224)
179#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected."
180#endif
181
182    // Stack alignment filler [sp, #8].
183    // FP args.
184    stp d0, d1, [sp, #16]
185    stp d2, d3, [sp, #32]
186    stp d4, d5, [sp, #48]
187    stp d6, d7, [sp, #64]
188
189    // Core args.
190    SAVE_TWO_REGS x1, x2, 80
191    SAVE_TWO_REGS x3, x4, 96
192    SAVE_TWO_REGS x5, x6, 112
193
194    // x7, Callee-saves.
195    SAVE_TWO_REGS x7, x20, 128
196    SAVE_TWO_REGS x21, x22, 144
197    SAVE_TWO_REGS x23, x24, 160
198    SAVE_TWO_REGS x25, x26, 176
199    SAVE_TWO_REGS x27, x28, 192
200
201    // x29(callee-save) and LR.
202    SAVE_TWO_REGS x29, xLR, 208
203
204.endm
205
206    /*
207     * Macro that sets up the callee save frame to conform with
208     * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
209     *
210     * TODO This is probably too conservative - saving FP & LR.
211     */
212.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
213    // art::Runtime** xIP0 = &art::Runtime::instance_
214    adrp xIP0, :got:_ZN3art7Runtime9instance_E
215    ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
216
217    // Our registers aren't intermixed - just spill in order.
218    ldr xIP0, [xIP0]  // art::Runtime* xIP0 = art::Runtime::instance_;
219
220    // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs];
221    ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
222
223    SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
224
225    str xIP0, [sp]    // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs].
226    // Place sp in Thread::Current()->top_quick_frame.
227    mov xIP0, sp
228    str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
229.endm
230
231.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
232    SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
233    str x0, [sp, #0]  // Store ArtMethod* to bottom of stack.
234    // Place sp in Thread::Current()->top_quick_frame.
235    mov xIP0, sp
236    str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
237.endm
238
239// TODO: Probably no need to restore registers preserved by aapcs64.
240.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
241    // FP args.
242    ldp d0, d1, [sp, #16]
243    ldp d2, d3, [sp, #32]
244    ldp d4, d5, [sp, #48]
245    ldp d6, d7, [sp, #64]
246
247    // Core args.
248    RESTORE_TWO_REGS x1, x2, 80
249    RESTORE_TWO_REGS x3, x4, 96
250    RESTORE_TWO_REGS x5, x6, 112
251
252    // x7, Callee-saves.
253    RESTORE_TWO_REGS x7, x20, 128
254    RESTORE_TWO_REGS x21, x22, 144
255    RESTORE_TWO_REGS x23, x24, 160
256    RESTORE_TWO_REGS x25, x26, 176
257    RESTORE_TWO_REGS x27, x28, 192
258
259    // x29(callee-save) and LR.
260    RESTORE_TWO_REGS x29, xLR, 208
261
262    DECREASE_FRAME 224
263.endm
264
265    /*
266     * Macro that sets up the callee save frame to conform with
267     * Runtime::CreateCalleeSaveMethod(kSaveEverything)
268     */
269.macro SETUP_SAVE_EVERYTHING_FRAME
270    INCREASE_FRAME 512
271
272    // Ugly compile-time check, but we only have the preprocessor.
273#if (FRAME_SIZE_SAVE_EVERYTHING != 512)
274#error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected."
275#endif
276
277    // Save FP registers.
278    // For better performance, store d0 and d31 separately, so that all STPs are 16-byte aligned.
279    str d0,       [sp, #8]
280    stp d1, d2,   [sp, #16]
281    stp d3, d4,   [sp, #32]
282    stp d5, d6,   [sp, #48]
283    stp d7, d8,   [sp, #64]
284    stp d9, d10,  [sp, #80]
285    stp d11, d12, [sp, #96]
286    stp d13, d14, [sp, #112]
287    stp d15, d16, [sp, #128]
288    stp d17, d18, [sp, #144]
289    stp d19, d20, [sp, #160]
290    stp d21, d22, [sp, #176]
291    stp d23, d24, [sp, #192]
292    stp d25, d26, [sp, #208]
293    stp d27, d28, [sp, #224]
294    stp d29, d30, [sp, #240]
295    str d31,      [sp, #256]
296
297    // Save core registers.
298    SAVE_REG            x0, 264
299    SAVE_TWO_REGS  x1,  x2, 272
300    SAVE_TWO_REGS  x3,  x4, 288
301    SAVE_TWO_REGS  x5,  x6, 304
302    SAVE_TWO_REGS  x7,  x8, 320
303    SAVE_TWO_REGS  x9, x10, 336
304    SAVE_TWO_REGS x11, x12, 352
305    SAVE_TWO_REGS x13, x14, 368
306    SAVE_TWO_REGS x15, x16, 384
307    SAVE_TWO_REGS x17, x18, 400
308    SAVE_TWO_REGS x19, x20, 416
309    SAVE_TWO_REGS x21, x22, 432
310    SAVE_TWO_REGS x23, x24, 448
311    SAVE_TWO_REGS x25, x26, 464
312    SAVE_TWO_REGS x27, x28, 480
313    SAVE_TWO_REGS x29, xLR, 496
314
315    // art::Runtime** xIP0 = &art::Runtime::instance_
316    adrp xIP0, :got:_ZN3art7Runtime9instance_E
317    ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
318
319    ldr xIP0, [xIP0]  // art::Runtime* xIP0 = art::Runtime::instance_;
320
321    // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything];
322    ldr xIP0, [xIP0, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET]
323
324    // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything].
325    str xIP0, [sp]
326    // Place sp in Thread::Current()->top_quick_frame.
327    mov xIP0, sp
328    str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
329.endm
330
331.macro RESTORE_SAVE_EVERYTHING_FRAME
332    // Restore FP registers.
333    // For better performance, load d0 and d31 separately, so that all LDPs are 16-byte aligned.
334    ldr d0,       [sp, #8]
335    ldp d1, d2,   [sp, #16]
336    ldp d3, d4,   [sp, #32]
337    ldp d5, d6,   [sp, #48]
338    ldp d7, d8,   [sp, #64]
339    ldp d9, d10,  [sp, #80]
340    ldp d11, d12, [sp, #96]
341    ldp d13, d14, [sp, #112]
342    ldp d15, d16, [sp, #128]
343    ldp d17, d18, [sp, #144]
344    ldp d19, d20, [sp, #160]
345    ldp d21, d22, [sp, #176]
346    ldp d23, d24, [sp, #192]
347    ldp d25, d26, [sp, #208]
348    ldp d27, d28, [sp, #224]
349    ldp d29, d30, [sp, #240]
350    ldr d31,      [sp, #256]
351
352    // Restore core registers.
353    RESTORE_REG            x0, 264
354    RESTORE_TWO_REGS  x1,  x2, 272
355    RESTORE_TWO_REGS  x3,  x4, 288
356    RESTORE_TWO_REGS  x5,  x6, 304
357    RESTORE_TWO_REGS  x7,  x8, 320
358    RESTORE_TWO_REGS  x9, x10, 336
359    RESTORE_TWO_REGS x11, x12, 352
360    RESTORE_TWO_REGS x13, x14, 368
361    RESTORE_TWO_REGS x15, x16, 384
362    RESTORE_TWO_REGS x17, x18, 400
363    RESTORE_TWO_REGS x19, x20, 416
364    RESTORE_TWO_REGS x21, x22, 432
365    RESTORE_TWO_REGS x23, x24, 448
366    RESTORE_TWO_REGS x25, x26, 464
367    RESTORE_TWO_REGS x27, x28, 480
368    RESTORE_TWO_REGS x29, xLR, 496
369
370    DECREASE_FRAME 512
371.endm
372
373.macro RETURN_IF_RESULT_IS_ZERO
374    cbnz x0, 1f                // result non-zero branch over
375    ret                        // return
3761:
377.endm
378
379.macro RETURN_IF_RESULT_IS_NON_ZERO
380    cbz x0, 1f                 // result zero branch over
381    ret                        // return
3821:
383.endm
384
385    /*
386     * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
387     * exception is Thread::Current()->exception_
388     */
389.macro DELIVER_PENDING_EXCEPTION
390    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
391    mov x0, xSELF
392
393    // Point of no return.
394    b artDeliverPendingExceptionFromCode  // artDeliverPendingExceptionFromCode(Thread*)
395    brk 0  // Unreached
396.endm
397
398.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
399    ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET]   // Get exception field.
400    cbnz \reg, 1f
401    ret
4021:
403    DELIVER_PENDING_EXCEPTION
404.endm
405
406.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
407    RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
408.endm
409
410// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
411.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
412    RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
413.endm
414
415.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
416    cbnz w0, 1f                // result non-zero branch over
417    ret                        // return
4181:
419    DELIVER_PENDING_EXCEPTION
420.endm
421
422.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
423    .extern \cxx_name
424ENTRY \c_name
425    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
426    mov x0, xSELF                     // pass Thread::Current
427    b   \cxx_name                     // \cxx_name(Thread*)
428END \c_name
429.endm
430
431.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
432    .extern \cxx_name
433ENTRY \c_name
434    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
435    mov x1, xSELF                     // pass Thread::Current.
436    b   \cxx_name                     // \cxx_name(arg, Thread*).
437    brk 0
438END \c_name
439.endm
440
441.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
442    .extern \cxx_name
443ENTRY \c_name
444    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
445    mov x2, xSELF                     // pass Thread::Current
446    b   \cxx_name                     // \cxx_name(arg1, arg2, Thread*)
447    brk 0
448END \c_name
449.endm
450
451    /*
452     * Called by managed code, saves callee saves and then calls artThrowException
453     * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
454     */
455ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
456
457    /*
458     * Called by managed code to create and deliver a NullPointerException.
459     */
460NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
461
462    /*
463     * Call installed by a signal handler to create and deliver a NullPointerException.
464     */
465ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
466
467    /*
468     * Called by managed code to create and deliver an ArithmeticException.
469     */
470NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
471
472    /*
473     * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
474     * index, arg2 holds limit.
475     */
476TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
477
478    /*
479     * Called by managed code to create and deliver a StringIndexOutOfBoundsException
480     * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
481     */
482TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
483
484    /*
485     * Called by managed code to create and deliver a StackOverflowError.
486     */
487NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
488
489    /*
490     * Called by managed code to create and deliver a NoSuchMethodError.
491     */
492ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
493
494    /*
495     * All generated callsites for interface invokes and invocation slow paths will load arguments
496     * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
497     * the method_idx.  This wrapper will save arg1-arg3, and call the appropriate C helper.
498     * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
499     *
500     * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting
501     * of the target Method* in x0 and method->code_ in x1.
502     *
503     * If unsuccessful, the helper will return null/????. There will be a pending exception in the
504     * thread and we branch to another stub to deliver it.
505     *
506     * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
507     * pointing back to the original caller.
508     *
509     * Adapted from ARM32 code.
510     *
511     * Clobbers xIP0.
512     */
513.macro INVOKE_TRAMPOLINE_BODY cxx_name
514    .extern \cxx_name
515    SETUP_SAVE_REFS_AND_ARGS_FRAME        // save callee saves in case allocation triggers GC
516    // Helper signature is always
517    // (method_idx, *this_object, *caller_method, *self, sp)
518
519    mov    x2, xSELF                      // pass Thread::Current
520    mov    x3, sp
521    bl     \cxx_name                      // (method_idx, this, Thread*, SP)
522    mov    xIP0, x1                       // save Method*->code_
523    RESTORE_SAVE_REFS_AND_ARGS_FRAME
524    cbz    x0, 1f                         // did we find the target? if not go to exception delivery
525    br     xIP0                           // tail call to target
5261:
527    DELIVER_PENDING_EXCEPTION
528.endm
529.macro INVOKE_TRAMPOLINE c_name, cxx_name
530ENTRY \c_name
531    INVOKE_TRAMPOLINE_BODY \cxx_name
532END \c_name
533.endm
534
535INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
536
537INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
538INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
539INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
540INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
541
542
543.macro INVOKE_STUB_CREATE_FRAME
544
545SAVE_SIZE=15*8   // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
546SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
547
548
549    mov x9, sp                             // Save stack pointer.
550    .cfi_register sp,x9
551
552    add x10, x2, # SAVE_SIZE_AND_METHOD    // calculate size of frame.
553    sub x10, sp, x10                       // Calculate SP position - saves + ArtMethod* + args
554    and x10, x10, # ~0xf                   // Enforce 16 byte stack alignment.
555    mov sp, x10                            // Set new SP.
556
557    sub x10, x9, #SAVE_SIZE                // Calculate new FP (later). Done here as we must move SP
558    .cfi_def_cfa_register x10              // before this.
559    .cfi_adjust_cfa_offset SAVE_SIZE
560
561    str x28, [x10, #112]
562    .cfi_rel_offset x28, 112
563
564    stp x26, x27, [x10, #96]
565    .cfi_rel_offset x26, 96
566    .cfi_rel_offset x27, 104
567
568    stp x24, x25, [x10, #80]
569    .cfi_rel_offset x24, 80
570    .cfi_rel_offset x25, 88
571
572    stp x22, x23, [x10, #64]
573    .cfi_rel_offset x22, 64
574    .cfi_rel_offset x23, 72
575
576    stp x20, x21, [x10, #48]
577    .cfi_rel_offset x20, 48
578    .cfi_rel_offset x21, 56
579
580    stp x9, x19, [x10, #32]                // Save old stack pointer and x19.
581    .cfi_rel_offset sp, 32
582    .cfi_rel_offset x19, 40
583
584    stp x4, x5, [x10, #16]                 // Save result and shorty addresses.
585    .cfi_rel_offset x4, 16
586    .cfi_rel_offset x5, 24
587
588    stp xFP, xLR, [x10]                    // Store LR & FP.
589    .cfi_rel_offset x29, 0
590    .cfi_rel_offset x30, 8
591
592    mov xFP, x10                           // Use xFP now, as it's callee-saved.
593    .cfi_def_cfa_register x29
594    mov xSELF, x3                          // Move thread pointer into SELF register.
595
596    // Copy arguments into stack frame.
597    // Use simple copy routine for now.
598    // 4 bytes per slot.
599    // X1 - source address
600    // W2 - args length
601    // X9 - destination address.
602    // W10 - temporary
603    add x9, sp, #8                         // Destination address is bottom of stack + null.
604
605    // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
606    // does not have unique-id variables.
6071:
608    cmp w2, #0
609    beq 2f
610    sub w2, w2, #4      // Need 65536 bytes of range.
611    ldr w10, [x1, x2]
612    str w10, [x9, x2]
613
614    b 1b
615
6162:
617    // Store null into ArtMethod* at bottom of frame.
618    str xzr, [sp]
619.endm
620
621.macro INVOKE_STUB_CALL_AND_RETURN
622
623    // load method-> METHOD_QUICK_CODE_OFFSET
624    ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
625    // Branch to method.
626    blr x9
627
628    // Restore return value address and shorty address.
629    ldp x4,x5, [xFP, #16]
630    .cfi_restore x4
631    .cfi_restore x5
632
633    ldr x28, [xFP, #112]
634    .cfi_restore x28
635
636    ldp x26, x27, [xFP, #96]
637    .cfi_restore x26
638    .cfi_restore x27
639
640    ldp x24, x25, [xFP, #80]
641    .cfi_restore x24
642    .cfi_restore x25
643
644    ldp x22, x23, [xFP, #64]
645    .cfi_restore x22
646    .cfi_restore x23
647
648    ldp x20, x21, [xFP, #48]
649    .cfi_restore x20
650    .cfi_restore x21
651
652    // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
653    ldrb w10, [x5]
654
655    // Check the return type and store the correct register into the jvalue in memory.
656    // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
657
658    // Don't set anything for a void type.
659    cmp w10, #'V'
660    beq 3f
661
662    // Is it a double?
663    cmp w10, #'D'
664    bne 1f
665    str d0, [x4]
666    b 3f
667
6681:  // Is it a float?
669    cmp w10, #'F'
670    bne 2f
671    str s0, [x4]
672    b 3f
673
6742:  // Just store x0. Doesn't matter if it is 64 or 32 bits.
675    str x0, [x4]
676
6773:  // Finish up.
678    ldp x2, x19, [xFP, #32]   // Restore stack pointer and x19.
679    .cfi_restore x19
680    mov sp, x2
681    .cfi_restore sp
682
683    ldp xFP, xLR, [xFP]    // Restore old frame pointer and link register.
684    .cfi_restore x29
685    .cfi_restore x30
686
687    ret
688
689.endm
690
691
692/*
693 *  extern"C" void art_quick_invoke_stub(ArtMethod *method,   x0
694 *                                       uint32_t  *args,     x1
695 *                                       uint32_t argsize,    w2
696 *                                       Thread *self,        x3
697 *                                       JValue *result,      x4
698 *                                       char   *shorty);     x5
699 *  +----------------------+
700 *  |                      |
701 *  |  C/C++ frame         |
702 *  |       LR''           |
703 *  |       FP''           | <- SP'
704 *  +----------------------+
705 *  +----------------------+
706 *  |        x28           | <- TODO: Remove callee-saves.
707 *  |         :            |
708 *  |        x19           |
709 *  |        SP'           |
710 *  |        X5            |
711 *  |        X4            |        Saved registers
712 *  |        LR'           |
713 *  |        FP'           | <- FP
714 *  +----------------------+
715 *  | uint32_t out[n-1]    |
716 *  |    :      :          |        Outs
717 *  | uint32_t out[0]      |
718 *  | ArtMethod*           | <- SP  value=null
719 *  +----------------------+
720 *
721 * Outgoing registers:
722 *  x0    - Method*
723 *  x1-x7 - integer parameters.
724 *  d0-d7 - Floating point parameters.
725 *  xSELF = self
726 *  SP = & of ArtMethod*
727 *  x1 = "this" pointer.
728 *
729 */
730ENTRY art_quick_invoke_stub
731    // Spill registers as per AACPS64 calling convention.
732    INVOKE_STUB_CREATE_FRAME
733
734    // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
735    // Parse the passed shorty to determine which register to load.
736    // Load addresses for routines that load WXSD registers.
737    adr  x11, .LstoreW2
738    adr  x12, .LstoreX2
739    adr  x13, .LstoreS0
740    adr  x14, .LstoreD0
741
742    // Initialize routine offsets to 0 for integers and floats.
743    // x8 for integers, x15 for floating point.
744    mov x8, #0
745    mov x15, #0
746
747    add x10, x5, #1         // Load shorty address, plus one to skip return value.
748    ldr w1, [x9],#4         // Load "this" parameter, and increment arg pointer.
749
750    // Loop to fill registers.
751.LfillRegisters:
752    ldrb w17, [x10], #1       // Load next character in signature, and increment.
753    cbz w17, .LcallFunction   // Exit at end of signature. Shorty 0 terminated.
754
755    cmp  w17, #'F' // is this a float?
756    bne .LisDouble
757
758    cmp x15, # 8*12         // Skip this load if all registers full.
759    beq .Ladvance4
760
761    add x17, x13, x15       // Calculate subroutine to jump to.
762    br  x17
763
764.LisDouble:
765    cmp w17, #'D'           // is this a double?
766    bne .LisLong
767
768    cmp x15, # 8*12         // Skip this load if all registers full.
769    beq .Ladvance8
770
771    add x17, x14, x15       // Calculate subroutine to jump to.
772    br x17
773
774.LisLong:
775    cmp w17, #'J'           // is this a long?
776    bne .LisOther
777
778    cmp x8, # 6*12          // Skip this load if all registers full.
779    beq .Ladvance8
780
781    add x17, x12, x8        // Calculate subroutine to jump to.
782    br x17
783
784.LisOther:                  // Everything else takes one vReg.
785    cmp x8, # 6*12          // Skip this load if all registers full.
786    beq .Ladvance4
787
788    add x17, x11, x8        // Calculate subroutine to jump to.
789    br x17
790
791.Ladvance4:
792    add x9, x9, #4
793    b .LfillRegisters
794
795.Ladvance8:
796    add x9, x9, #8
797    b .LfillRegisters
798
799// Macro for loading a parameter into a register.
800//  counter - the register with offset into these tables
801//  size - the size of the register - 4 or 8 bytes.
802//  register - the name of the register to be loaded.
803.macro LOADREG counter size register return
804    ldr \register , [x9], #\size
805    add \counter, \counter, 12
806    b \return
807.endm
808
809// Store ints.
810.LstoreW2:
811    LOADREG x8 4 w2 .LfillRegisters
812    LOADREG x8 4 w3 .LfillRegisters
813    LOADREG x8 4 w4 .LfillRegisters
814    LOADREG x8 4 w5 .LfillRegisters
815    LOADREG x8 4 w6 .LfillRegisters
816    LOADREG x8 4 w7 .LfillRegisters
817
818// Store longs.
819.LstoreX2:
820    LOADREG x8 8 x2 .LfillRegisters
821    LOADREG x8 8 x3 .LfillRegisters
822    LOADREG x8 8 x4 .LfillRegisters
823    LOADREG x8 8 x5 .LfillRegisters
824    LOADREG x8 8 x6 .LfillRegisters
825    LOADREG x8 8 x7 .LfillRegisters
826
827// Store singles.
828.LstoreS0:
829    LOADREG x15 4 s0 .LfillRegisters
830    LOADREG x15 4 s1 .LfillRegisters
831    LOADREG x15 4 s2 .LfillRegisters
832    LOADREG x15 4 s3 .LfillRegisters
833    LOADREG x15 4 s4 .LfillRegisters
834    LOADREG x15 4 s5 .LfillRegisters
835    LOADREG x15 4 s6 .LfillRegisters
836    LOADREG x15 4 s7 .LfillRegisters
837
838// Store doubles.
839.LstoreD0:
840    LOADREG x15 8 d0 .LfillRegisters
841    LOADREG x15 8 d1 .LfillRegisters
842    LOADREG x15 8 d2 .LfillRegisters
843    LOADREG x15 8 d3 .LfillRegisters
844    LOADREG x15 8 d4 .LfillRegisters
845    LOADREG x15 8 d5 .LfillRegisters
846    LOADREG x15 8 d6 .LfillRegisters
847    LOADREG x15 8 d7 .LfillRegisters
848
849
850.LcallFunction:
851
852    INVOKE_STUB_CALL_AND_RETURN
853
854END art_quick_invoke_stub
855
856/*  extern"C"
857 *     void art_quick_invoke_static_stub(ArtMethod *method,   x0
858 *                                       uint32_t  *args,     x1
859 *                                       uint32_t argsize,    w2
860 *                                       Thread *self,        x3
861 *                                       JValue *result,      x4
862 *                                       char   *shorty);     x5
863 */
864ENTRY art_quick_invoke_static_stub
865    // Spill registers as per AACPS64 calling convention.
866    INVOKE_STUB_CREATE_FRAME
867
868    // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
869    // Parse the passed shorty to determine which register to load.
870    // Load addresses for routines that load WXSD registers.
871    adr  x11, .LstoreW1_2
872    adr  x12, .LstoreX1_2
873    adr  x13, .LstoreS0_2
874    adr  x14, .LstoreD0_2
875
876    // Initialize routine offsets to 0 for integers and floats.
877    // x8 for integers, x15 for floating point.
878    mov x8, #0
879    mov x15, #0
880
881    add x10, x5, #1     // Load shorty address, plus one to skip return value.
882
883    // Loop to fill registers.
884.LfillRegisters2:
885    ldrb w17, [x10], #1         // Load next character in signature, and increment.
886    cbz w17, .LcallFunction2    // Exit at end of signature. Shorty 0 terminated.
887
888    cmp  w17, #'F'          // is this a float?
889    bne .LisDouble2
890
891    cmp x15, # 8*12         // Skip this load if all registers full.
892    beq .Ladvance4_2
893
894    add x17, x13, x15       // Calculate subroutine to jump to.
895    br  x17
896
897.LisDouble2:
898    cmp w17, #'D'           // is this a double?
899    bne .LisLong2
900
901    cmp x15, # 8*12         // Skip this load if all registers full.
902    beq .Ladvance8_2
903
904    add x17, x14, x15       // Calculate subroutine to jump to.
905    br x17
906
907.LisLong2:
908    cmp w17, #'J'           // is this a long?
909    bne .LisOther2
910
911    cmp x8, # 7*12          // Skip this load if all registers full.
912    beq .Ladvance8_2
913
914    add x17, x12, x8        // Calculate subroutine to jump to.
915    br x17
916
917.LisOther2:                 // Everything else takes one vReg.
918    cmp x8, # 7*12          // Skip this load if all registers full.
919    beq .Ladvance4_2
920
921    add x17, x11, x8        // Calculate subroutine to jump to.
922    br x17
923
924.Ladvance4_2:
925    add x9, x9, #4
926    b .LfillRegisters2
927
928.Ladvance8_2:
929    add x9, x9, #8
930    b .LfillRegisters2
931
932// Store ints.
933.LstoreW1_2:
934    LOADREG x8 4 w1 .LfillRegisters2
935    LOADREG x8 4 w2 .LfillRegisters2
936    LOADREG x8 4 w3 .LfillRegisters2
937    LOADREG x8 4 w4 .LfillRegisters2
938    LOADREG x8 4 w5 .LfillRegisters2
939    LOADREG x8 4 w6 .LfillRegisters2
940    LOADREG x8 4 w7 .LfillRegisters2
941
942// Store longs.
943.LstoreX1_2:
944    LOADREG x8 8 x1 .LfillRegisters2
945    LOADREG x8 8 x2 .LfillRegisters2
946    LOADREG x8 8 x3 .LfillRegisters2
947    LOADREG x8 8 x4 .LfillRegisters2
948    LOADREG x8 8 x5 .LfillRegisters2
949    LOADREG x8 8 x6 .LfillRegisters2
950    LOADREG x8 8 x7 .LfillRegisters2
951
952// Store singles.
953.LstoreS0_2:
954    LOADREG x15 4 s0 .LfillRegisters2
955    LOADREG x15 4 s1 .LfillRegisters2
956    LOADREG x15 4 s2 .LfillRegisters2
957    LOADREG x15 4 s3 .LfillRegisters2
958    LOADREG x15 4 s4 .LfillRegisters2
959    LOADREG x15 4 s5 .LfillRegisters2
960    LOADREG x15 4 s6 .LfillRegisters2
961    LOADREG x15 4 s7 .LfillRegisters2
962
963// Store doubles.
964.LstoreD0_2:
965    LOADREG x15 8 d0 .LfillRegisters2
966    LOADREG x15 8 d1 .LfillRegisters2
967    LOADREG x15 8 d2 .LfillRegisters2
968    LOADREG x15 8 d3 .LfillRegisters2
969    LOADREG x15 8 d4 .LfillRegisters2
970    LOADREG x15 8 d5 .LfillRegisters2
971    LOADREG x15 8 d6 .LfillRegisters2
972    LOADREG x15 8 d7 .LfillRegisters2
973
974
975.LcallFunction2:
976
977    INVOKE_STUB_CALL_AND_RETURN
978
979END art_quick_invoke_static_stub
980
981
982
983/*  extern"C" void art_quick_osr_stub(void** stack,                x0
984 *                                    size_t stack_size_in_bytes,  x1
985 *                                    const uin8_t* native_pc,     x2
986 *                                    JValue *result,              x3
987 *                                    char   *shorty,              x4
988 *                                    Thread *self)                x5
989 */
990ENTRY art_quick_osr_stub
991SAVE_SIZE=15*8   // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
992    mov x9, sp                             // Save stack pointer.
993    .cfi_register sp,x9
994
995    sub x10, sp, # SAVE_SIZE
996    and x10, x10, # ~0xf                   // Enforce 16 byte stack alignment.
997    mov sp, x10                            // Set new SP.
998
999    str x28, [sp, #112]
1000    stp x26, x27, [sp, #96]
1001    stp x24, x25, [sp, #80]
1002    stp x22, x23, [sp, #64]
1003    stp x20, x21, [sp, #48]
1004    stp x9, x19, [sp, #32]                // Save old stack pointer and x19.
1005    stp x3, x4, [sp, #16]                 // Save result and shorty addresses.
1006    stp xFP, xLR, [sp]                    // Store LR & FP.
1007    mov xSELF, x5                         // Move thread pointer into SELF register.
1008
1009    sub sp, sp, #16
1010    str xzr, [sp]                         // Store null for ArtMethod* slot
1011    // Branch to stub.
1012    bl .Losr_entry
1013    add sp, sp, #16
1014
1015    // Restore return value address and shorty address.
1016    ldp x3,x4, [sp, #16]
1017    ldr x28, [sp, #112]
1018    ldp x26, x27, [sp, #96]
1019    ldp x24, x25, [sp, #80]
1020    ldp x22, x23, [sp, #64]
1021    ldp x20, x21, [sp, #48]
1022
1023    // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1024    ldrb w10, [x4]
1025
1026    // Check the return type and store the correct register into the jvalue in memory.
1027
1028    // Don't set anything for a void type.
1029    cmp w10, #'V'
1030    beq .Losr_exit
1031
1032    // Is it a double?
1033    cmp w10, #'D'
1034    bne .Lno_double
1035    str d0, [x3]
1036    b .Losr_exit
1037
1038.Lno_double:  // Is it a float?
1039    cmp w10, #'F'
1040    bne .Lno_float
1041    str s0, [x3]
1042    b .Losr_exit
1043
1044.Lno_float:  // Just store x0. Doesn't matter if it is 64 or 32 bits.
1045    str x0, [x3]
1046
1047.Losr_exit:  // Finish up.
1048    ldp x2, x19, [sp, #32]   // Restore stack pointer and x19.
1049    ldp xFP, xLR, [sp]    // Restore old frame pointer and link register.
1050    mov sp, x2
1051    ret
1052
1053.Losr_entry:
1054    // Update stack pointer for the callee
1055    sub sp, sp, x1
1056
1057    // Update link register slot expected by the callee.
1058    sub w1, w1, #8
1059    str lr, [sp, x1]
1060
1061    // Copy arguments into stack frame.
1062    // Use simple copy routine for now.
1063    // 4 bytes per slot.
1064    // X0 - source address
1065    // W1 - args length
1066    // SP - destination address.
1067    // W10 - temporary
1068.Losr_loop_entry:
1069    cmp w1, #0
1070    beq .Losr_loop_exit
1071    sub w1, w1, #4
1072    ldr w10, [x0, x1]
1073    str w10, [sp, x1]
1074    b .Losr_loop_entry
1075
1076.Losr_loop_exit:
1077    // Branch to the OSR entry point.
1078    br x2
1079
1080END art_quick_osr_stub
1081
1082    /*
1083     * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1084     */
1085
1086ENTRY art_quick_do_long_jump
1087    // Load FPRs
1088    ldp d0, d1, [x1], #16
1089    ldp d2, d3, [x1], #16
1090    ldp d4, d5, [x1], #16
1091    ldp d6, d7, [x1], #16
1092    ldp d8, d9, [x1], #16
1093    ldp d10, d11, [x1], #16
1094    ldp d12, d13, [x1], #16
1095    ldp d14, d15, [x1], #16
1096    ldp d16, d17, [x1], #16
1097    ldp d18, d19, [x1], #16
1098    ldp d20, d21, [x1], #16
1099    ldp d22, d23, [x1], #16
1100    ldp d24, d25, [x1], #16
1101    ldp d26, d27, [x1], #16
1102    ldp d28, d29, [x1], #16
1103    ldp d30, d31, [x1]
1104
1105    // Load GPRs
1106    // TODO: lots of those are smashed, could optimize.
1107    add x0, x0, #30*8
1108    ldp x30, x1, [x0], #-16          // LR & SP
1109    ldp x28, x29, [x0], #-16
1110    ldp x26, x27, [x0], #-16
1111    ldp x24, x25, [x0], #-16
1112    ldp x22, x23, [x0], #-16
1113    ldp x20, x21, [x0], #-16
1114    ldp x18, x19, [x0], #-16
1115    ldp x16, x17, [x0], #-16
1116    ldp x14, x15, [x0], #-16
1117    ldp x12, x13, [x0], #-16
1118    ldp x10, x11, [x0], #-16
1119    ldp x8, x9, [x0], #-16
1120    ldp x6, x7, [x0], #-16
1121    ldp x4, x5, [x0], #-16
1122    ldp x2, x3, [x0], #-16
1123    mov sp, x1
1124
1125    // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1126    ldr x1, [x0, #33*8]
1127    // And the value of x0.
1128    ldr x0, [x0]
1129
1130    br  x1
1131END art_quick_do_long_jump
1132
1133    /*
1134     * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1135     * possibly null object to lock.
1136     *
1137     * Derived from arm32 code.
1138     */
1139    .extern artLockObjectFromCode
1140ENTRY art_quick_lock_object
1141    cbz    w0, .Lslow_lock
1142    add    x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET  // exclusive load/store has no immediate anymore
1143.Lretry_lock:
1144    ldr    w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1145    ldxr   w1, [x4]
1146    mov    x3, x1
1147    and    w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED  // zero the gc bits
1148    cbnz   w3, .Lnot_unlocked         // already thin locked
1149    // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1150    orr    x2, x1, x2                 // x2 holds thread id with count of 0 with preserved read barrier bits
1151    stxr   w3, w2, [x4]
1152    cbnz   w3, .Llock_stxr_fail       // store failed, retry
1153    dmb    ishld                      // full (LoadLoad|LoadStore) memory barrier
1154    ret
1155.Lnot_unlocked:  // x1: original lock word
1156    lsr    w3, w1, LOCK_WORD_STATE_SHIFT
1157    cbnz   w3, .Lslow_lock            // if either of the top two bits are set, go slow path
1158    eor    w2, w1, w2                 // lock_word.ThreadId() ^ self->ThreadId()
1159    uxth   w2, w2                     // zero top 16 bits
1160    cbnz   w2, .Lslow_lock            // lock word and self thread id's match -> recursive lock
1161                                      // else contention, go to slow path
1162    mov    x3, x1                     // copy the lock word to check count overflow.
1163    and    w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED  // zero the gc bits.
1164    add    w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE  // increment count in lock word placing in w2 to check overflow
1165    lsr    w3, w2, #LOCK_WORD_GC_STATE_SHIFT     // if the first gc state bit is set, we overflowed.
1166    cbnz   w3, .Lslow_lock            // if we overflow the count go slow path
1167    add    w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE  // increment count for real
1168    stxr   w3, w2, [x4]
1169    cbnz   w3, .Llock_stxr_fail       // store failed, retry
1170    ret
1171.Llock_stxr_fail:
1172    b      .Lretry_lock               // retry
1173.Lslow_lock:
1174    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case we block
1175    mov    x1, xSELF                  // pass Thread::Current
1176    bl     artLockObjectFromCode      // (Object* obj, Thread*)
1177    RESTORE_SAVE_REFS_ONLY_FRAME
1178    RETURN_IF_W0_IS_ZERO_OR_DELIVER
1179END art_quick_lock_object
1180
1181ENTRY art_quick_lock_object_no_inline
1182    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case we block
1183    mov    x1, xSELF                  // pass Thread::Current
1184    bl     artLockObjectFromCode      // (Object* obj, Thread*)
1185    RESTORE_SAVE_REFS_ONLY_FRAME
1186    RETURN_IF_W0_IS_ZERO_OR_DELIVER
1187END art_quick_lock_object_no_inline
1188
1189    /*
1190     * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1191     * x0 holds the possibly null object to lock.
1192     *
1193     * Derived from arm32 code.
1194     */
1195    .extern artUnlockObjectFromCode
1196ENTRY art_quick_unlock_object
1197    cbz    x0, .Lslow_unlock
1198    add    x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET  // exclusive load/store has no immediate anymore
1199.Lretry_unlock:
1200#ifndef USE_READ_BARRIER
1201    ldr    w1, [x4]
1202#else
1203    ldxr   w1, [x4]                   // Need to use atomic instructions for read barrier
1204#endif
1205    lsr    w2, w1, LOCK_WORD_STATE_SHIFT
1206    cbnz   w2, .Lslow_unlock          // if either of the top two bits are set, go slow path
1207    ldr    w2, [xSELF, #THREAD_ID_OFFSET]
1208    mov    x3, x1                     // copy lock word to check thread id equality
1209    and    w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED  // zero the gc bits
1210    eor    w3, w3, w2                 // lock_word.ThreadId() ^ self->ThreadId()
1211    uxth   w3, w3                     // zero top 16 bits
1212    cbnz   w3, .Lslow_unlock          // do lock word and self thread id's match?
1213    mov    x3, x1                     // copy lock word to detect transition to unlocked
1214    and    w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED  // zero the gc bits
1215    cmp    w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
1216    bpl    .Lrecursive_thin_unlock
1217    // transition to unlocked
1218    mov    x3, x1
1219    and    w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED  // w3: zero except for the preserved read barrier bits
1220    dmb    ish                        // full (LoadStore|StoreStore) memory barrier
1221#ifndef USE_READ_BARRIER
1222    str    w3, [x4]
1223#else
1224    stxr   w2, w3, [x4]               // Need to use atomic instructions for read barrier
1225    cbnz   w2, .Lunlock_stxr_fail     // store failed, retry
1226#endif
1227    ret
1228.Lrecursive_thin_unlock:  // w1: original lock word
1229    sub    w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE  // decrement count
1230#ifndef USE_READ_BARRIER
1231    str    w1, [x4]
1232#else
1233    stxr   w2, w1, [x4]               // Need to use atomic instructions for read barrier
1234    cbnz   w2, .Lunlock_stxr_fail     // store failed, retry
1235#endif
1236    ret
1237.Lunlock_stxr_fail:
1238    b      .Lretry_unlock               // retry
1239.Lslow_unlock:
1240    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case exception allocation triggers GC
1241    mov    x1, xSELF                  // pass Thread::Current
1242    bl     artUnlockObjectFromCode    // (Object* obj, Thread*)
1243    RESTORE_SAVE_REFS_ONLY_FRAME
1244    RETURN_IF_W0_IS_ZERO_OR_DELIVER
1245END art_quick_unlock_object
1246
1247ENTRY art_quick_unlock_object_no_inline
1248    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case exception allocation triggers GC
1249    mov    x1, xSELF                  // pass Thread::Current
1250    bl     artUnlockObjectFromCode    // (Object* obj, Thread*)
1251    RESTORE_SAVE_REFS_ONLY_FRAME
1252    RETURN_IF_W0_IS_ZERO_OR_DELIVER
1253END art_quick_unlock_object_no_inline
1254
1255    /*
1256     * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1257     * artThrowClassCastException.
1258     */
1259    .extern artThrowClassCastException
1260ENTRY art_quick_check_cast
1261    // Store arguments and link register
1262    // Stack needs to be 16B aligned on calls.
1263    SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1264    SAVE_REG xLR, 24
1265
1266    // Call runtime code
1267    bl artIsAssignableFromCode
1268
1269    // Check for exception
1270    cbz x0, .Lthrow_class_cast_exception
1271
1272    // Restore and return
1273    .cfi_remember_state
1274    RESTORE_REG xLR, 24
1275    RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
1276    ret
1277    .cfi_restore_state                // Reset unwind info so following code unwinds.
1278
1279.Lthrow_class_cast_exception:
1280    // Restore
1281    RESTORE_REG xLR, 24
1282    RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
1283
1284    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
1285    mov x2, xSELF                     // pass Thread::Current
1286    b artThrowClassCastException      // (Class*, Class*, Thread*)
1287    brk 0                             // We should not return here...
1288END art_quick_check_cast
1289
1290// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1291.macro POP_REG_NE xReg, offset, xExclude
1292    .ifnc \xReg, \xExclude
1293        ldr \xReg, [sp, #\offset]     // restore xReg
1294        .cfi_restore \xReg
1295    .endif
1296.endm
1297
1298// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1299// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1300.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1301    .ifc \xReg1, \xExclude
1302        ldr \xReg2, [sp, #(\offset + 8)]        // restore xReg2
1303    .else
1304        .ifc \xReg2, \xExclude
1305            ldr \xReg1, [sp, #\offset]          // restore xReg1
1306        .else
1307            ldp \xReg1, \xReg2, [sp, #\offset]  // restore xReg1 and xReg2
1308        .endif
1309    .endif
1310    .cfi_restore \xReg1
1311    .cfi_restore \xReg2
1312.endm
1313
1314    /*
1315     * Macro to insert read barrier, only used in art_quick_aput_obj.
1316     * xDest, wDest and xObj are registers, offset is a defined literal such as
1317     * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1318     * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1319     * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1320     */
1321.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
1322#ifdef USE_READ_BARRIER
1323#ifdef USE_BAKER_READ_BARRIER
1324    ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1325    tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1326    // False dependency to avoid needing load/load fence.
1327    add \xObj, \xObj, \xTemp, lsr #32
1328    ldr \wDest, [\xObj, #\offset]   // Heap reference = 32b. This also zero-extends to \xDest.
1329    UNPOISON_HEAP_REF \wDest
1330    b .Lrb_exit\number
1331#endif
1332.Lrb_slowpath\number:
1333    // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
1334    SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1335    SAVE_TWO_REGS x2, x3, 16
1336    SAVE_TWO_REGS x4, xLR, 32
1337
1338    // mov x0, \xRef                // pass ref in x0 (no-op for now since parameter ref is unused)
1339    .ifnc \xObj, x1
1340        mov x1, \xObj               // pass xObj
1341    .endif
1342    mov w2, #\offset                // pass offset
1343    bl artReadBarrierSlow           // artReadBarrierSlow(ref, xObj, offset)
1344    // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1345    .ifnc \wDest, w0
1346        mov \wDest, w0              // save return value in wDest
1347    .endif
1348
1349    // Conditionally restore saved registers
1350    POP_REG_NE x0, 0, \xDest
1351    POP_REG_NE x1, 8, \xDest
1352    POP_REG_NE x2, 16, \xDest
1353    POP_REG_NE x3, 24, \xDest
1354    POP_REG_NE x4, 32, \xDest
1355    RESTORE_REG xLR, 40
1356    DECREASE_FRAME 48
1357.Lrb_exit\number:
1358#else
1359    ldr \wDest, [\xObj, #\offset]   // Heap reference = 32b. This also zero-extends to \xDest.
1360    UNPOISON_HEAP_REF \wDest
1361#endif  // USE_READ_BARRIER
1362.endm
1363
1364    /*
1365     * Entry from managed code for array put operations of objects where the value being stored
1366     * needs to be checked for compatibility.
1367     * x0 = array, x1 = index, x2 = value
1368     *
1369     * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1370     * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1371     * using index-zero-extension in load/stores.
1372     *
1373     * Temporaries: x3, x4
1374     * TODO: x4 OK? ip seems wrong here.
1375     */
1376ENTRY art_quick_aput_obj_with_null_and_bound_check
1377    tst x0, x0
1378    bne art_quick_aput_obj_with_bound_check
1379    b art_quick_throw_null_pointer_exception
1380END art_quick_aput_obj_with_null_and_bound_check
1381
1382ENTRY art_quick_aput_obj_with_bound_check
1383    ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
1384    cmp w3, w1
1385    bhi art_quick_aput_obj
1386    mov x0, x1
1387    mov x1, x3
1388    b art_quick_throw_array_bounds
1389END art_quick_aput_obj_with_bound_check
1390
1391#ifdef USE_READ_BARRIER
1392    .extern artReadBarrierSlow
1393#endif
1394ENTRY art_quick_aput_obj
1395    cbz x2, .Ldo_aput_null
1396    READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0  // Heap reference = 32b
1397                                                                    // This also zero-extends to x3
1398    READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1399    // This also zero-extends to x3
1400    READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2  // Heap reference = 32b
1401                                                                    // This also zero-extends to x4
1402    cmp w3, w4  // value's type == array's component type - trivial assignability
1403    bne .Lcheck_assignability
1404.Ldo_aput:
1405    add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
1406                                                         // "Compress" = do nothing
1407    POISON_HEAP_REF w2
1408    str w2, [x3, x1, lsl #2]                             // Heap reference = 32b
1409    ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1410    lsr x0, x0, #7
1411    strb w3, [x3, x0]
1412    ret
1413.Ldo_aput_null:
1414    add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
1415                                                         // "Compress" = do nothing
1416    str w2, [x3, x1, lsl #2]                             // Heap reference = 32b
1417    ret
1418.Lcheck_assignability:
1419    // Store arguments and link register
1420    SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1421    SAVE_TWO_REGS x2, xLR, 16
1422
1423    // Call runtime code
1424    mov x0, x3              // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1425    mov x1, x4              // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1426    bl artIsAssignableFromCode
1427
1428    // Check for exception
1429    cbz x0, .Lthrow_array_store_exception
1430
1431    // Restore
1432    .cfi_remember_state
1433    RESTORE_TWO_REGS x2, xLR, 16
1434    RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
1435
1436    add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
1437                                                          // "Compress" = do nothing
1438    POISON_HEAP_REF w2
1439    str w2, [x3, x1, lsl #2]                              // Heap reference = 32b
1440    ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1441    lsr x0, x0, #7
1442    strb w3, [x3, x0]
1443    ret
1444    .cfi_restore_state            // Reset unwind info so following code unwinds.
1445.Lthrow_array_store_exception:
1446    RESTORE_TWO_REGS x2, xLR, 16
1447    RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
1448
1449    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
1450    mov x1, x2                    // Pass value.
1451    mov x2, xSELF                 // Pass Thread::Current.
1452    b artThrowArrayStoreException // (Object*, Object*, Thread*).
1453    brk 0                         // Unreached.
1454END art_quick_aput_obj
1455
1456// Macro to facilitate adding new allocation entrypoints.
1457.macro ONE_ARG_DOWNCALL name, entrypoint, return
1458    .extern \entrypoint
1459ENTRY \name
1460    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1461    mov    x1, xSELF                  // pass Thread::Current
1462    bl     \entrypoint                // (uint32_t type_idx, Method* method, Thread*)
1463    RESTORE_SAVE_REFS_ONLY_FRAME
1464    \return
1465END \name
1466.endm
1467
1468// Macro to facilitate adding new allocation entrypoints.
1469.macro TWO_ARG_DOWNCALL name, entrypoint, return
1470    .extern \entrypoint
1471ENTRY \name
1472    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1473    mov    x2, xSELF                  // pass Thread::Current
1474    bl     \entrypoint                // (uint32_t type_idx, Method* method, Thread*)
1475    RESTORE_SAVE_REFS_ONLY_FRAME
1476    \return
1477END \name
1478.endm
1479
1480// Macro to facilitate adding new allocation entrypoints.
1481.macro THREE_ARG_DOWNCALL name, entrypoint, return
1482    .extern \entrypoint
1483ENTRY \name
1484    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1485    mov    x3, xSELF                  // pass Thread::Current
1486    bl     \entrypoint
1487    RESTORE_SAVE_REFS_ONLY_FRAME
1488    \return
1489END \name
1490.endm
1491
1492// Macro to facilitate adding new allocation entrypoints.
1493.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1494    .extern \entrypoint
1495ENTRY \name
1496    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1497    mov    x4, xSELF                  // pass Thread::Current
1498    bl     \entrypoint                //
1499    RESTORE_SAVE_REFS_ONLY_FRAME
1500    \return
1501    DELIVER_PENDING_EXCEPTION
1502END \name
1503.endm
1504
1505// Macros taking opportunity of code similarities for downcalls with referrer.
1506.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1507    .extern \entrypoint
1508ENTRY \name
1509    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1510    ldr    x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
1511    mov    x2, xSELF                  // pass Thread::Current
1512    bl     \entrypoint                // (uint32_t type_idx, Method* method, Thread*, SP)
1513    RESTORE_SAVE_REFS_ONLY_FRAME
1514    \return
1515END \name
1516.endm
1517
1518.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1519    .extern \entrypoint
1520ENTRY \name
1521    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1522    ldr    x2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
1523    mov    x3, xSELF                  // pass Thread::Current
1524    bl     \entrypoint
1525    RESTORE_SAVE_REFS_ONLY_FRAME
1526    \return
1527END \name
1528.endm
1529
1530.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1531    .extern \entrypoint
1532ENTRY \name
1533    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1534    ldr    x3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
1535    mov    x4, xSELF                  // pass Thread::Current
1536    bl     \entrypoint
1537    RESTORE_SAVE_REFS_ONLY_FRAME
1538    \return
1539END \name
1540.endm
1541
1542.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1543    cbz w0, 1f                 // result zero branch over
1544    ret                        // return
15451:
1546    DELIVER_PENDING_EXCEPTION
1547.endm
1548
1549    /*
1550     * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1551     * failure.
1552     */
1553TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1554
1555    /*
1556     * Entry from managed code when uninitialized static storage, this stub will run the class
1557     * initializer and deliver the exception on error. On success the static storage base is
1558     * returned.
1559     */
1560ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1561
1562ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1563ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1564
1565ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1566ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1567ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1568ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1569ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1570ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1571ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1572
1573TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1574TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1575TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1576TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1577TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1578TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1579TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1580
1581TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1582TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1583TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1584TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1585
1586THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1587THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1588THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1589THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1590THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1591
1592// This is separated out as the argument order is different.
1593    .extern artSet64StaticFromCode
1594ENTRY art_quick_set64_static
1595    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1596    ldr    x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
1597                                      // x2 contains the parameter
1598    mov    x3, xSELF                  // pass Thread::Current
1599    bl     artSet64StaticFromCode
1600    RESTORE_SAVE_REFS_ONLY_FRAME
1601    RETURN_IF_W0_IS_ZERO_OR_DELIVER
1602END art_quick_set64_static
1603
1604    /*
1605     * Entry from managed code to resolve a string, this stub will
1606     * check the dex cache for a matching string (the fast path), and if not found,
1607     * it will allocate a String and deliver an exception on error.
1608     * On success the String is returned. R0 holds the string index.
1609     */
1610
1611ENTRY art_quick_resolve_string
1612    ldr   x1, [sp]                                               // load referrer
1613    ldr   w2, [x1, #ART_METHOD_DECLARING_CLASS_OFFSET]           // load declaring class
1614    ldr   x1, [x2, #DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET]    // load string dex cache
1615    ubfx  x2, x0, #0, #STRING_DEX_CACHE_HASH_BITS                // get masked string index into x2
1616    ldr   x2, [x1, x2, lsl #STRING_DEX_CACHE_ELEMENT_SIZE_SHIFT]  // load dex cache pair into x2
1617    cmp   x0, x2, lsr #32                                         // compare against upper 32 bits
1618    bne   .Lart_quick_resolve_string_slow_path
1619    ubfx  x0, x2, #0, #32                                        // extract lower 32 bits into x0
1620#ifdef USE_READ_BARRIER
1621    // Most common case: GC is not marking.
1622    ldr    w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1623    cbnz   x3, .Lart_quick_resolve_string_marking
1624#endif
1625    ret
1626
1627// Slow path case, the index did not match.
1628.Lart_quick_resolve_string_slow_path:
1629    SETUP_SAVE_REFS_ONLY_FRAME                      // save callee saves in case of GC
1630    mov   x1, xSELF                                 // pass Thread::Current
1631    bl    artResolveStringFromCode                  // (int32_t string_idx, Thread* self)
1632    RESTORE_SAVE_REFS_ONLY_FRAME
1633    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1634
1635// GC is marking case, need to check the mark bit.
1636.Lart_quick_resolve_string_marking:
1637    ldr   x3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1638    tbnz  x3, #LOCK_WORD_MARK_BIT_SHIFT, .Lart_quick_resolve_string_no_rb
1639    // Save LR so that we can return, also x1 for alignment purposes.
1640    SAVE_TWO_REGS_INCREASE_FRAME x1, xLR, 16        // Save x1, LR.
1641    bl     artReadBarrierMark                       // Get the marked string back.
1642    RESTORE_TWO_REGS_DECREASE_FRAME x1, xLR, 16     // Restore registers.
1643.Lart_quick_resolve_string_no_rb:
1644    ret
1645
1646END art_quick_resolve_string
1647
1648// Generate the allocation entrypoints for each allocator.
1649GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_REGION_TLAB_ALLOCATORS
1650// Comment out allocators that have arm64 specific asm.
1651// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) implemented in asm
1652// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1653// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1654GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1655// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) implemented in asm
1656// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
1657GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1658GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB)
1659GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1660GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1661GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1662GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
1663
1664// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1665ENTRY art_quick_alloc_object_rosalloc
1666    // Fast path rosalloc allocation.
1667    // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1668    // x2-x7: free.
1669    ldr    x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64]    // Load dex cache resolved types array
1670                                                              // Load the class (x2)
1671    ldr    w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1672    cbz    x2, .Lart_quick_alloc_object_rosalloc_slow_path    // Check null class
1673    ldr    x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]  // Check if the thread local
1674                                                              // allocation stack has room.
1675                                                              // ldp won't work due to large offset.
1676    ldr    x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1677    cmp    x3, x4
1678    bhs    .Lart_quick_alloc_object_rosalloc_slow_path
1679    ldr    w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET]  // Load the object size (x3)
1680    cmp    x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE        // Check if the size is for a thread
1681                                                              // local allocation. Also does the
1682                                                              // finalizable and initialization
1683                                                              // checks.
1684    bhs    .Lart_quick_alloc_object_rosalloc_slow_path
1685                                                              // Compute the rosalloc bracket index
1686                                                              // from the size. Since the size is
1687                                                              // already aligned we can combine the
1688                                                              // two shifts together.
1689    add    x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1690                                                              // Subtract pointer size since ther
1691                                                              // are no runs for 0 byte allocations
1692                                                              // and the size is already aligned.
1693    ldr    x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
1694                                                              // Load the free list head (x3). This
1695                                                              // will be the return val.
1696    ldr    x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1697    cbz    x3, .Lart_quick_alloc_object_rosalloc_slow_path
1698    // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1699    ldr    x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET]               // Load the next pointer of the head
1700                                                              // and update the list head with the
1701                                                              // next pointer.
1702    str    x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1703                                                              // Store the class pointer in the
1704                                                              // header. This also overwrites the
1705                                                              // next pointer. The offsets are
1706                                                              // asserted to match.
1707#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1708#error "Class pointer needs to overwrite next pointer."
1709#endif
1710    POISON_HEAP_REF w2
1711    str    w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
1712                                                              // Fence. This is "ish" not "ishst" so
1713                                                              // that it also ensures ordering of
1714                                                              // the object size load with respect
1715                                                              // to later accesses to the class
1716                                                              // object. Alternatively we could use
1717                                                              // "ishst" if we use load-acquire for
1718                                                              // the class status load.
1719                                                              // Needs to be done before pushing on
1720                                                              // allocation since Heap::VisitObjects
1721                                                              // relies on seeing the class pointer.
1722                                                              // b/28790624
1723    dmb    ish
1724                                                              // Push the new object onto the thread
1725                                                              // local allocation stack and
1726                                                              // increment the thread local
1727                                                              // allocation stack top.
1728    ldr    x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1729    str    w3, [x1], #COMPRESSED_REFERENCE_SIZE               // (Increment x1 as a side effect.)
1730    str    x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1731                                                              // Decrement the size of the free list
1732    ldr    w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1733    sub    x1, x1, #1
1734                                                              // TODO: consider combining this store
1735                                                              // and the list head store above using
1736                                                              // strd.
1737    str    w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1738
1739    mov    x0, x3                                             // Set the return value and return.
1740    ret
1741.Lart_quick_alloc_object_rosalloc_slow_path:
1742    SETUP_SAVE_REFS_ONLY_FRAME             // save callee saves in case of GC
1743    mov    x2, xSELF                       // pass Thread::Current
1744    bl     artAllocObjectFromCodeRosAlloc  // (uint32_t type_idx, Method* method, Thread*)
1745    RESTORE_SAVE_REFS_ONLY_FRAME
1746    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1747END art_quick_alloc_object_rosalloc
1748
1749
1750// The common fast path code for art_quick_alloc_array_region_tlab.
1751.macro ALLOC_ARRAY_TLAB_FAST_PATH slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1752    // Check null class
1753    cbz    \wClass, \slowPathLabel
1754    ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED \slowPathLabel, \xClass, \wClass, \xCount, \wCount, \xTemp0, \wTemp0, \xTemp1, \wTemp1, \xTemp2, \wTemp2
1755.endm
1756
1757// The common fast path code for art_quick_alloc_array_region_tlab.
1758.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1759    // Array classes are never finalizable or uninitialized, no need to check.
1760    ldr    \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1761    UNPOISON_HEAP_REF \wTemp0
1762    ldr    \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1763    lsr    \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1764                                                              // bits.
1765                                                              // xCount is holding a 32 bit value,
1766                                                              // it can not overflow.
1767    lsl    \xTemp1, \xCount, \xTemp0                          // Calculate data size
1768    // Add array data offset and alignment.
1769    add    \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1770#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1771#error Long array data offset must be 4 greater than int array data offset.
1772#endif
1773
1774    add    \xTemp0, \xTemp0, #1                               // Add 4 to the length only if the
1775                                                              // component size shift is 3
1776                                                              // (for 64 bit alignment).
1777    and    \xTemp0, \xTemp0, #4
1778    add    \xTemp1, \xTemp1, \xTemp0
1779    and    \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask
1780                                                              // (addr + 7) & ~7. The mask must
1781                                                              // be 64 bits to keep high bits in
1782                                                              // case of overflow.
1783    // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1784    // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1785    // 32 bit int. Since the max shift for arrays is 3, it can not become a negative 64 bit int.
1786    cmp    \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD               // Possibly a large object, go slow
1787    bhs    \slowPathLabel                                     // path.
1788
1789    ldr    \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET]         // Check tlab for space, note that
1790                                                              // we use (end - begin) to handle
1791                                                              // negative size arrays. It is
1792                                                              // assumed that a negative size will
1793                                                              // always be greater unsigned than
1794                                                              // region size.
1795    ldr    \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1796    sub    \xTemp2, \xTemp2, \xTemp0
1797    cmp    \xTemp1, \xTemp2
1798    bhi    \slowPathLabel
1799    // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1800                                                              // Move old thread_local_pos to x0
1801                                                              // for the return value.
1802    mov    x0, \xTemp0
1803    add    \xTemp0, \xTemp0, \xTemp1
1804    str    \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET]         // Store new thread_local_pos.
1805    ldr    \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]     // Increment thread_local_objects.
1806    add    \xTemp0, \xTemp0, #1
1807    str    \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1808    POISON_HEAP_REF \wClass
1809    str    \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET]         // Store the class pointer.
1810    str    \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]         // Store the array length.
1811                                                              // Fence.
1812    dmb    ishst
1813    ret
1814.endm
1815
1816// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1817//
1818// x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current
1819// x3-x7: free.
1820// Need to preserve x0 and x1 to the slow path.
1821.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1822    cbz    x2, \slowPathLabel                                 // Check null class
1823    ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED \slowPathLabel
1824.endm
1825
1826// TODO: delete ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since it is the same as
1827// ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED.
1828.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel
1829    ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED \slowPathLabel
1830.endm
1831
1832.macro ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED slowPathLabel
1833    ldr    x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1834    ldr    x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
1835    ldr    w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET]  // Load the object size (x7).
1836    add    x6, x4, x7                                         // Add object size to tlab pos.
1837    cmp    x6, x5                                             // Check if it fits, overflow works
1838                                                              // since the tlab pos and end are 32
1839                                                              // bit values.
1840    bhi    \slowPathLabel
1841    // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1842    mov    x0, x4
1843    str    x6, [xSELF, #THREAD_LOCAL_POS_OFFSET]              // Store new thread_local_pos.
1844    ldr    x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]          // Increment thread_local_objects.
1845    add    x5, x5, #1
1846    str    x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1847    POISON_HEAP_REF w2
1848    str    w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET]              // Store the class pointer.
1849                                                              // Fence. This is "ish" not "ishst" so
1850                                                              // that the code after this allocation
1851                                                              // site will see the right values in
1852                                                              // the fields of the class.
1853                                                              // Alternatively we could use "ishst"
1854                                                              // if we use load-acquire for the
1855                                                              // object size load.)
1856    dmb    ish
1857    ret
1858.endm
1859
1860// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1861ENTRY art_quick_alloc_object_tlab
1862    // Fast path tlab allocation.
1863    // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1864    // x2-x7: free.
1865#if defined(USE_READ_BARRIER)
1866    mvn    x0, xzr                                            // Read barrier not supported here.
1867    ret                                                       // Return -1.
1868#endif
1869    ldr    x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64]    // Load dex cache resolved types array
1870                                                              // Load the class (x2)
1871    ldr    w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1872    ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1873.Lart_quick_alloc_object_tlab_slow_path:
1874    SETUP_SAVE_REFS_ONLY_FRAME           // Save callee saves in case of GC.
1875    mov    x2, xSELF                     // Pass Thread::Current.
1876    bl     artAllocObjectFromCodeTLAB    // (uint32_t type_idx, Method* method, Thread*)
1877    RESTORE_SAVE_REFS_ONLY_FRAME
1878    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1879END art_quick_alloc_object_tlab
1880
1881// The common code for art_quick_alloc_object_*region_tlab
1882.macro GENERATE_ALLOC_OBJECT_REGION_TLAB name, entrypoint, fast_path, is_resolved, read_barrier
1883ENTRY \name
1884    // Fast path region tlab allocation.
1885    // x0: type_idx/resolved class/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1886    // If is_resolved is 1 then x0 is the resolved type, otherwise it is the index.
1887    // x2-x7: free.
1888#if !defined(USE_READ_BARRIER)
1889    mvn    x0, xzr                                            // Read barrier must be enabled here.
1890    ret                                                       // Return -1.
1891#endif
1892.if \is_resolved
1893    mov    x2, x0 // class is actually stored in x0 already
1894.else
1895    ldr    x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64]    // Load dex cache resolved types array
1896                                                              // Load the class (x2)
1897    ldr    w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1898    // If the class is null, go slow path. The check is required to read the lock word.
1899    cbz    w2, .Lslow_path\name
1900.endif
1901.if \read_barrier
1902    // Most common case: GC is not marking.
1903    ldr    w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1904    cbnz   x3, .Lmarking\name
1905.endif
1906.Ldo_allocation\name:
1907    \fast_path .Lslow_path\name
1908.Lmarking\name:
1909.if \read_barrier
1910    // GC is marking, check the lock word of the class for the mark bit.
1911    // Class is not null, check mark bit in lock word.
1912    ldr    w3, [x2, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1913    // If the bit is not zero, do the allocation.
1914    tbnz    w3, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
1915                                                              // The read barrier slow path. Mark
1916                                                              // the class.
1917    SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32                   // Save registers (x0, x1, lr).
1918    SAVE_REG xLR, 24                                          // Align sp by 16 bytes.
1919    mov    x0, x2                                             // Pass the class as the first param.
1920    bl     artReadBarrierMark
1921    mov    x2, x0                                             // Get the (marked) class back.
1922    RESTORE_REG xLR, 24
1923    RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32                // Restore registers.
1924    b      .Ldo_allocation\name
1925.endif
1926.Lslow_path\name:
1927    SETUP_SAVE_REFS_ONLY_FRAME                 // Save callee saves in case of GC.
1928    mov    x2, xSELF                           // Pass Thread::Current.
1929    bl     \entrypoint                         // (uint32_t type_idx, Method* method, Thread*)
1930    RESTORE_SAVE_REFS_ONLY_FRAME
1931    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1932END \name
1933.endm
1934
1935// Use ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since the null check is already done in GENERATE_ALLOC_OBJECT_TLAB.
1936GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_region_tlab, artAllocObjectFromCodeRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 0, 1
1937// No read barrier for the resolved or initialized cases since the caller is responsible for the
1938// read barrier due to the to-space invariant.
1939GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 1, 0
1940GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED, 1, 0
1941
1942// TODO: We could use this macro for the normal tlab allocator too.
1943
1944// The common code for art_quick_alloc_array_*region_tlab
1945.macro GENERATE_ALLOC_ARRAY_REGION_TLAB name, entrypoint, fast_path, is_resolved
1946ENTRY \name
1947    // Fast path array allocation for region tlab allocation.
1948    // x0: uint32_t type_idx
1949    // x1: int32_t component_count
1950    // x2: ArtMethod* method
1951    // x3-x7: free.
1952#if !defined(USE_READ_BARRIER)
1953    mvn    x0, xzr                                            // Read barrier must be enabled here.
1954    ret                                                       // Return -1.
1955#endif
1956.if \is_resolved
1957    mov    x3, x0
1958    // If already resolved, class is stored in x0
1959.else
1960    ldr    x3, [x2, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64]    // Load dex cache resolved types array
1961                                                              // Load the class (x2)
1962    ldr    w3, [x3, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1963.endif
1964    // Most common case: GC is not marking.
1965    ldr    w4, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1966    cbnz   x4, .Lmarking\name
1967.Ldo_allocation\name:
1968    \fast_path .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1969.Lmarking\name:
1970    // GC is marking, check the lock word of the class for the mark bit.
1971    // If the class is null, go slow path. The check is required to read the lock word.
1972    cbz    w3, .Lslow_path\name
1973    // Class is not null, check mark bit in lock word.
1974    ldr    w4, [x3, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1975    // If the bit is not zero, do the allocation.
1976    tbnz   w4, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
1977                                                              // The read barrier slow path. Mark
1978                                                              // the class.
1979    stp    x0, x1, [sp, #-32]!                                // Save registers (x0, x1, x2, lr).
1980    stp    x2, xLR, [sp, #16]
1981    mov    x0, x3                                             // Pass the class as the first param.
1982    bl     artReadBarrierMark
1983    mov    x3, x0                                             // Get the (marked) class back.
1984    ldp    x2, xLR, [sp, #16]
1985    ldp    x0, x1, [sp], #32                                  // Restore registers.
1986    b      .Ldo_allocation\name
1987.Lslow_path\name:
1988    // x0: uint32_t type_idx / mirror::Class* klass (if resolved)
1989    // x1: int32_t component_count
1990    // x2: ArtMethod* method
1991    // x3: Thread* self
1992    SETUP_SAVE_REFS_ONLY_FRAME        // save callee saves in case of GC
1993    mov    x3, xSELF                  // pass Thread::Current
1994    bl     \entrypoint
1995    RESTORE_SAVE_REFS_ONLY_FRAME
1996    RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1997END \name
1998.endm
1999
2000GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_region_tlab, artAllocArrayFromCodeRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH, 0
2001// TODO: art_quick_alloc_array_resolved_region_tlab seems to not get called. Investigate compiler.
2002GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED, 1
2003
2004    /*
2005     * Called by managed code when the thread has been asked to suspend.
2006     */
2007    .extern artTestSuspendFromCode
2008ENTRY art_quick_test_suspend
2009    SETUP_SAVE_EVERYTHING_FRAME               // save callee saves for stack crawl
2010    mov    x0, xSELF
2011    bl     artTestSuspendFromCode             // (Thread*)
2012    RESTORE_SAVE_EVERYTHING_FRAME
2013    ret
2014END art_quick_test_suspend
2015
2016ENTRY art_quick_implicit_suspend
2017    mov    x0, xSELF
2018    SETUP_SAVE_REFS_ONLY_FRAME                // save callee saves for stack crawl
2019    bl     artTestSuspendFromCode             // (Thread*)
2020    RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
2021END art_quick_implicit_suspend
2022
2023     /*
2024     * Called by managed code that is attempting to call a method on a proxy class. On entry
2025     * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2026     * method agrees with a ref and args callee save frame.
2027     */
2028     .extern artQuickProxyInvokeHandler
2029ENTRY art_quick_proxy_invoke_handler
2030    SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
2031    mov     x2, xSELF                   // pass Thread::Current
2032    mov     x3, sp                      // pass SP
2033    bl      artQuickProxyInvokeHandler  // (Method* proxy method, receiver, Thread*, SP)
2034    ldr     x2, [xSELF, THREAD_EXCEPTION_OFFSET]
2035    cbnz    x2, .Lexception_in_proxy    // success if no exception is pending
2036    RESTORE_SAVE_REFS_AND_ARGS_FRAME    // Restore frame
2037    fmov    d0, x0                      // Store result in d0 in case it was float or double
2038    ret                                 // return on success
2039.Lexception_in_proxy:
2040    RESTORE_SAVE_REFS_AND_ARGS_FRAME
2041    DELIVER_PENDING_EXCEPTION
2042END art_quick_proxy_invoke_handler
2043
2044    /*
2045     * Called to resolve an imt conflict.
2046     * x0 is the conflict ArtMethod.
2047     * xIP1 is a hidden argument that holds the target interface method's dex method index.
2048     *
2049     * Note that this stub writes to xIP0, xIP1, and x0.
2050     */
2051    .extern artInvokeInterfaceTrampoline
2052ENTRY art_quick_imt_conflict_trampoline
2053    ldr xIP0, [sp, #0]  // Load referrer
2054    ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64]   // Load dex cache methods array
2055    ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT]  // Load interface method
2056    ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64]  // Load ImtConflictTable
2057    ldr x0, [xIP1]  // Load first entry in ImtConflictTable.
2058.Limt_table_iterate:
2059    cmp x0, xIP0
2060    // Branch if found. Benchmarks have shown doing a branch here is better.
2061    beq .Limt_table_found
2062    // If the entry is null, the interface method is not in the ImtConflictTable.
2063    cbz x0, .Lconflict_trampoline
2064    // Iterate over the entries of the ImtConflictTable.
2065    ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2066    b .Limt_table_iterate
2067.Limt_table_found:
2068    // We successfully hit an entry in the table. Load the target method
2069    // and jump to it.
2070    ldr x0, [xIP1, #__SIZEOF_POINTER__]
2071    ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2072    br xIP0
2073.Lconflict_trampoline:
2074    // Call the runtime stub to populate the ImtConflictTable and jump to the
2075    // resolved method.
2076    INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
2077END art_quick_imt_conflict_trampoline
2078
2079ENTRY art_quick_resolution_trampoline
2080    SETUP_SAVE_REFS_AND_ARGS_FRAME
2081    mov x2, xSELF
2082    mov x3, sp
2083    bl artQuickResolutionTrampoline  // (called, receiver, Thread*, SP)
2084    cbz x0, 1f
2085    mov xIP0, x0            // Remember returned code pointer in xIP0.
2086    ldr x0, [sp, #0]        // artQuickResolutionTrampoline puts called method in *SP.
2087    RESTORE_SAVE_REFS_AND_ARGS_FRAME
2088    br xIP0
20891:
2090    RESTORE_SAVE_REFS_AND_ARGS_FRAME
2091    DELIVER_PENDING_EXCEPTION
2092END art_quick_resolution_trampoline
2093
2094/*
2095 * Generic JNI frame layout:
2096 *
2097 * #-------------------#
2098 * |                   |
2099 * | caller method...  |
2100 * #-------------------#    <--- SP on entry
2101 * | Return X30/LR     |
2102 * | X29/FP            |    callee save
2103 * | X28               |    callee save
2104 * | X27               |    callee save
2105 * | X26               |    callee save
2106 * | X25               |    callee save
2107 * | X24               |    callee save
2108 * | X23               |    callee save
2109 * | X22               |    callee save
2110 * | X21               |    callee save
2111 * | X20               |    callee save
2112 * | X19               |    callee save
2113 * | X7                |    arg7
2114 * | X6                |    arg6
2115 * | X5                |    arg5
2116 * | X4                |    arg4
2117 * | X3                |    arg3
2118 * | X2                |    arg2
2119 * | X1                |    arg1
2120 * | D7                |    float arg 8
2121 * | D6                |    float arg 7
2122 * | D5                |    float arg 6
2123 * | D4                |    float arg 5
2124 * | D3                |    float arg 4
2125 * | D2                |    float arg 3
2126 * | D1                |    float arg 2
2127 * | D0                |    float arg 1
2128 * | Method*           | <- X0
2129 * #-------------------#
2130 * | local ref cookie  | // 4B
2131 * | handle scope size | // 4B
2132 * #-------------------#
2133 * | JNI Call Stack    |
2134 * #-------------------#    <--- SP on native call
2135 * |                   |
2136 * | Stack for Regs    |    The trampoline assembly will pop these values
2137 * |                   |    into registers for native call
2138 * #-------------------#
2139 * | Native code ptr   |
2140 * #-------------------#
2141 * | Free scratch      |
2142 * #-------------------#
2143 * | Ptr to (1)        |    <--- SP
2144 * #-------------------#
2145 */
2146    /*
2147     * Called to do a generic JNI down-call
2148     */
2149ENTRY art_quick_generic_jni_trampoline
2150    SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
2151
2152    // Save SP , so we can have static CFI info.
2153    mov x28, sp
2154    .cfi_def_cfa_register x28
2155
2156    // This looks the same, but is different: this will be updated to point to the bottom
2157    // of the frame when the handle scope is inserted.
2158    mov xFP, sp
2159
2160    mov xIP0, #5120
2161    sub sp, sp, xIP0
2162
2163    // prepare for artQuickGenericJniTrampoline call
2164    // (Thread*,  SP)
2165    //    x0      x1   <= C calling convention
2166    //   xSELF    xFP  <= where they are
2167
2168    mov x0, xSELF   // Thread*
2169    mov x1, xFP
2170    bl artQuickGenericJniTrampoline  // (Thread*, sp)
2171
2172    // The C call will have registered the complete save-frame on success.
2173    // The result of the call is:
2174    // x0: pointer to native code, 0 on error.
2175    // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
2176
2177    // Check for error = 0.
2178    cbz x0, .Lexception_in_native
2179
2180    // Release part of the alloca.
2181    mov sp, x1
2182
2183    // Save the code pointer
2184    mov xIP0, x0
2185
2186    // Load parameters from frame into registers.
2187    // TODO Check with artQuickGenericJniTrampoline.
2188    //      Also, check again APPCS64 - the stack arguments are interleaved.
2189    ldp x0, x1, [sp]
2190    ldp x2, x3, [sp, #16]
2191    ldp x4, x5, [sp, #32]
2192    ldp x6, x7, [sp, #48]
2193
2194    ldp d0, d1, [sp, #64]
2195    ldp d2, d3, [sp, #80]
2196    ldp d4, d5, [sp, #96]
2197    ldp d6, d7, [sp, #112]
2198
2199    add sp, sp, #128
2200
2201    blr xIP0        // native call.
2202
2203    // result sign extension is handled in C code
2204    // prepare for artQuickGenericJniEndTrampoline call
2205    // (Thread*, result, result_f)
2206    //    x0       x1       x2        <= C calling convention
2207    mov x1, x0      // Result (from saved).
2208    mov x0, xSELF   // Thread register.
2209    fmov x2, d0     // d0 will contain floating point result, but needs to go into x2
2210
2211    bl artQuickGenericJniEndTrampoline
2212
2213    // Pending exceptions possible.
2214    ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
2215    cbnz x2, .Lexception_in_native
2216
2217    // Tear down the alloca.
2218    mov sp, x28
2219    .cfi_def_cfa_register sp
2220
2221    // Tear down the callee-save frame.
2222    RESTORE_SAVE_REFS_AND_ARGS_FRAME
2223
2224    // store into fpr, for when it's a fpr return...
2225    fmov d0, x0
2226    ret
2227
2228.Lexception_in_native:
2229    // Move to x1 then sp to please assembler.
2230    ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
2231    mov sp, x1
2232    .cfi_def_cfa_register sp
2233    # This will create a new save-all frame, required by the runtime.
2234    DELIVER_PENDING_EXCEPTION
2235END art_quick_generic_jni_trampoline
2236
2237/*
2238 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2239 * of a quick call:
2240 * x0 = method being called/to bridge to.
2241 * x1..x7, d0..d7 = arguments to that method.
2242 */
2243ENTRY art_quick_to_interpreter_bridge
2244    SETUP_SAVE_REFS_AND_ARGS_FRAME         // Set up frame and save arguments.
2245
2246    //  x0 will contain mirror::ArtMethod* method.
2247    mov x1, xSELF                          // How to get Thread::Current() ???
2248    mov x2, sp
2249
2250    // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2251    //                                      mirror::ArtMethod** sp)
2252    bl   artQuickToInterpreterBridge
2253
2254    RESTORE_SAVE_REFS_AND_ARGS_FRAME       // TODO: no need to restore arguments in this case.
2255
2256    fmov d0, x0
2257
2258    RETURN_OR_DELIVER_PENDING_EXCEPTION
2259END art_quick_to_interpreter_bridge
2260
2261
2262//
2263// Instrumentation-related stubs
2264//
2265    .extern artInstrumentationMethodEntryFromCode
2266ENTRY art_quick_instrumentation_entry
2267    SETUP_SAVE_REFS_AND_ARGS_FRAME
2268
2269    mov   x20, x0             // Preserve method reference in a callee-save.
2270
2271    mov   x2, xSELF
2272    mov   x3, xLR
2273    bl    artInstrumentationMethodEntryFromCode  // (Method*, Object*, Thread*, LR)
2274
2275    mov   xIP0, x0            // x0 = result of call.
2276    mov   x0, x20             // Reload method reference.
2277
2278    RESTORE_SAVE_REFS_AND_ARGS_FRAME  // Note: will restore xSELF
2279    adr   xLR, art_quick_instrumentation_exit
2280    br    xIP0                // Tail-call method with lr set to art_quick_instrumentation_exit.
2281END art_quick_instrumentation_entry
2282
2283    .extern artInstrumentationMethodExitFromCode
2284ENTRY art_quick_instrumentation_exit
2285    mov   xLR, #0             // Clobber LR for later checks.
2286
2287    SETUP_SAVE_REFS_ONLY_FRAME
2288
2289    // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
2290    // we would need to fully restore it. As there are a lot of callee-save registers, it seems
2291    // easier to have an extra small stack area.
2292
2293    str x0, [sp, #-16]!       // Save integer result.
2294    .cfi_adjust_cfa_offset 16
2295    str d0,  [sp, #8]         // Save floating-point result.
2296
2297    add   x1, sp, #16         // Pass SP.
2298    mov   x2, x0              // Pass integer result.
2299    fmov  x3, d0              // Pass floating-point result.
2300    mov   x0, xSELF           // Pass Thread.
2301    bl   artInstrumentationMethodExitFromCode    // (Thread*, SP, gpr_res, fpr_res)
2302
2303    mov   xIP0, x0            // Return address from instrumentation call.
2304    mov   xLR, x1             // r1 is holding link register if we're to bounce to deoptimize
2305
2306    ldr   d0, [sp, #8]        // Restore floating-point result.
2307    ldr   x0, [sp], #16       // Restore integer result, and drop stack area.
2308    .cfi_adjust_cfa_offset 16
2309
2310    POP_SAVE_REFS_ONLY_FRAME
2311
2312    br    xIP0                // Tail-call out.
2313END art_quick_instrumentation_exit
2314
2315    /*
2316     * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2317     * will long jump to the upcall with a special exception of -1.
2318     */
2319    .extern artDeoptimize
2320ENTRY art_quick_deoptimize
2321    SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
2322    mov    x0, xSELF          // Pass thread.
2323    bl     artDeoptimize      // artDeoptimize(Thread*)
2324    brk 0
2325END art_quick_deoptimize
2326
2327    /*
2328     * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2329     * will long jump to the upcall with a special exception of -1.
2330     */
2331    .extern artDeoptimizeFromCompiledCode
2332ENTRY art_quick_deoptimize_from_compiled_code
2333    SETUP_SAVE_EVERYTHING_FRAME
2334    mov    x0, xSELF                      // Pass thread.
2335    bl     artDeoptimizeFromCompiledCode  // artDeoptimizeFromCompiledCode(Thread*)
2336    brk 0
2337END art_quick_deoptimize_from_compiled_code
2338
2339
2340    /*
2341     * String's indexOf.
2342     *
2343     * TODO: Not very optimized.
2344     * On entry:
2345     *    x0:   string object (known non-null)
2346     *    w1:   char to match (known <= 0xFFFF)
2347     *    w2:   Starting offset in string data
2348     */
2349ENTRY art_quick_indexof
2350    ldr   w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
2351    add   x0, x0, #MIRROR_STRING_VALUE_OFFSET
2352
2353    /* Clamp start to [0..count] */
2354    cmp   w2, #0
2355    csel  w2, wzr, w2, lt
2356    cmp   w2, w3
2357    csel  w2, w3, w2, gt
2358
2359    /* Save a copy to compute result */
2360    mov   x5, x0
2361
2362    /* Build pointer to start of data to compare and pre-bias */
2363    add   x0, x0, x2, lsl #1
2364    sub   x0, x0, #2
2365
2366    /* Compute iteration count */
2367    sub   w2, w3, w2
2368
2369    /*
2370     * At this point we have:
2371     *  x0: start of the data to test
2372     *  w1: char to compare
2373     *  w2: iteration count
2374     *  x5: original start of string data
2375     */
2376
2377    subs  w2, w2, #4
2378    b.lt  .Lindexof_remainder
2379
2380.Lindexof_loop4:
2381    ldrh  w6, [x0, #2]!
2382    ldrh  w7, [x0, #2]!
2383    ldrh  wIP0, [x0, #2]!
2384    ldrh  wIP1, [x0, #2]!
2385    cmp   w6, w1
2386    b.eq  .Lmatch_0
2387    cmp   w7, w1
2388    b.eq  .Lmatch_1
2389    cmp   wIP0, w1
2390    b.eq  .Lmatch_2
2391    cmp   wIP1, w1
2392    b.eq  .Lmatch_3
2393    subs  w2, w2, #4
2394    b.ge  .Lindexof_loop4
2395
2396.Lindexof_remainder:
2397    adds  w2, w2, #4
2398    b.eq  .Lindexof_nomatch
2399
2400.Lindexof_loop1:
2401    ldrh  w6, [x0, #2]!
2402    cmp   w6, w1
2403    b.eq  .Lmatch_3
2404    subs  w2, w2, #1
2405    b.ne  .Lindexof_loop1
2406
2407.Lindexof_nomatch:
2408    mov   x0, #-1
2409    ret
2410
2411.Lmatch_0:
2412    sub   x0, x0, #6
2413    sub   x0, x0, x5
2414    asr   x0, x0, #1
2415    ret
2416.Lmatch_1:
2417    sub   x0, x0, #4
2418    sub   x0, x0, x5
2419    asr   x0, x0, #1
2420    ret
2421.Lmatch_2:
2422    sub   x0, x0, #2
2423    sub   x0, x0, x5
2424    asr   x0, x0, #1
2425    ret
2426.Lmatch_3:
2427    sub   x0, x0, x5
2428    asr   x0, x0, #1
2429    ret
2430END art_quick_indexof
2431
2432    /*
2433     * Create a function `name` calling the ReadBarrier::Mark routine,
2434     * getting its argument and returning its result through W register
2435     * `wreg` (corresponding to X register `xreg`), saving and restoring
2436     * all caller-save registers.
2437     *
2438     * If `wreg` is different from `w0`, the generated function follows a
2439     * non-standard runtime calling convention:
2440     * - register `wreg` is used to pass the (sole) argument of this
2441     *   function (instead of W0);
2442     * - register `wreg` is used to return the result of this function
2443     *   (instead of W0);
2444     * - W0 is treated like a normal (non-argument) caller-save register;
2445     * - everything else is the same as in the standard runtime calling
2446     *   convention (e.g. standard callee-save registers are preserved).
2447     */
2448.macro READ_BARRIER_MARK_REG name, wreg, xreg
2449ENTRY \name
2450    // Reference is null, no work to do at all.
2451    cbz \wreg, .Lret_rb_\name
2452    /*
2453     * Allocate 46 stack slots * 8 = 368 bytes:
2454     * - 20 slots for core registers X0-X19
2455     * - 24 slots for floating-point registers D0-D7 and D16-D31
2456     * -  1 slot for return address register XLR
2457     * -  1 padding slot for 16-byte stack alignment
2458     */
2459    // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2460    ldr   wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2461    tbz   wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lslow_path_rb_\name
2462    ret
2463.Lslow_path_rb_\name:
2464    // Save all potentially live caller-save core registers.
2465    SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 368
2466    SAVE_TWO_REGS  x2,  x3, 16
2467    SAVE_TWO_REGS  x4,  x5, 32
2468    SAVE_TWO_REGS  x6,  x7, 48
2469    SAVE_TWO_REGS  x8,  x9, 64
2470    SAVE_TWO_REGS x10, x11, 80
2471    SAVE_TWO_REGS x12, x13, 96
2472    SAVE_TWO_REGS x14, x15, 112
2473    SAVE_TWO_REGS x16, x17, 128
2474    SAVE_TWO_REGS x18, x19, 144
2475    // Save all potentially live caller-save floating-point registers.
2476    stp   d0, d1,   [sp, #160]
2477    stp   d2, d3,   [sp, #176]
2478    stp   d4, d5,   [sp, #192]
2479    stp   d6, d7,   [sp, #208]
2480    stp   d16, d17, [sp, #224]
2481    stp   d18, d19, [sp, #240]
2482    stp   d20, d21, [sp, #256]
2483    stp   d22, d23, [sp, #272]
2484    stp   d24, d25, [sp, #288]
2485    stp   d26, d27, [sp, #304]
2486    stp   d28, d29, [sp, #320]
2487    stp   d30, d31, [sp, #336]
2488    // Save return address.
2489    // (sp + #352 is a padding slot)
2490    SAVE_REG xLR, 360
2491
2492    .ifnc \wreg, w0
2493      mov   w0, \wreg                   // Pass arg1 - obj from `wreg`
2494    .endif
2495    bl    artReadBarrierMark            // artReadBarrierMark(obj)
2496    .ifnc \wreg, w0
2497      mov   \wreg, w0                   // Return result into `wreg`
2498    .endif
2499
2500    // Restore core regs, except `xreg`, as `wreg` is used to return the
2501    // result of this function (simply remove it from the stack instead).
2502    POP_REGS_NE x0, x1,   0,   \xreg
2503    POP_REGS_NE x2, x3,   16,  \xreg
2504    POP_REGS_NE x4, x5,   32,  \xreg
2505    POP_REGS_NE x6, x7,   48,  \xreg
2506    POP_REGS_NE x8, x9,   64,  \xreg
2507    POP_REGS_NE x10, x11, 80,  \xreg
2508    POP_REGS_NE x12, x13, 96,  \xreg
2509    POP_REGS_NE x14, x15, 112, \xreg
2510    POP_REGS_NE x16, x17, 128, \xreg
2511    POP_REGS_NE x18, x19, 144, \xreg
2512    // Restore floating-point registers.
2513    ldp   d0, d1,   [sp, #160]
2514    ldp   d2, d3,   [sp, #176]
2515    ldp   d4, d5,   [sp, #192]
2516    ldp   d6, d7,   [sp, #208]
2517    ldp   d16, d17, [sp, #224]
2518    ldp   d18, d19, [sp, #240]
2519    ldp   d20, d21, [sp, #256]
2520    ldp   d22, d23, [sp, #272]
2521    ldp   d24, d25, [sp, #288]
2522    ldp   d26, d27, [sp, #304]
2523    ldp   d28, d29, [sp, #320]
2524    ldp   d30, d31, [sp, #336]
2525    // Restore return address and remove padding.
2526    RESTORE_REG xLR, 360
2527    DECREASE_FRAME 368
2528.Lret_rb_\name:
2529    ret
2530END \name
2531.endm
2532
2533READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0,  x0
2534READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1,  x1
2535READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2,  x2
2536READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3,  x3
2537READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4,  x4
2538READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5,  x5
2539READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6,  x6
2540READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7,  x7
2541READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8,  x8
2542READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9,  x9
2543READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2544READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2545READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2546READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2547READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2548READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
2549// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
2550READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2551READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2552READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2553READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2554READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2555READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2556READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2557READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2558READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2559READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2560READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2561READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2562READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29
2563