blob: 09fc2c2c8a3cc82e5ef86dc65e5f134e9d4005b5 [file] [log] [blame]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001/*
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
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010022.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
Vladimir Marko215076b2016-09-07 18:05:55 +010032.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
Roland Levillain97c46462017-05-11 14:04:03 +010042.macro SAVE_REG_INCREASE_FRAME reg, frame_adjustment
43 str \reg, [sp, #-(\frame_adjustment)]!
44 .cfi_adjust_cfa_offset (\frame_adjustment)
45 .cfi_rel_offset \reg, 0
46.endm
47
48.macro RESTORE_REG_DECREASE_FRAME reg, frame_adjustment
49 ldr \reg, [sp], #(\frame_adjustment)
50 .cfi_restore \reg
51 .cfi_adjust_cfa_offset -(\frame_adjustment)
52.endm
53
Vladimir Marko215076b2016-09-07 18:05:55 +010054.macro SAVE_TWO_REGS reg1, reg2, offset
55 stp \reg1, \reg2, [sp, #(\offset)]
56 .cfi_rel_offset \reg1, (\offset)
57 .cfi_rel_offset \reg2, (\offset) + 8
58.endm
59
60.macro RESTORE_TWO_REGS reg1, reg2, offset
61 ldp \reg1, \reg2, [sp, #(\offset)]
62 .cfi_restore \reg1
63 .cfi_restore \reg2
64.endm
65
66.macro SAVE_TWO_REGS_INCREASE_FRAME reg1, reg2, frame_adjustment
67 stp \reg1, \reg2, [sp, #-(\frame_adjustment)]!
68 .cfi_adjust_cfa_offset (\frame_adjustment)
69 .cfi_rel_offset \reg1, 0
70 .cfi_rel_offset \reg2, 8
71.endm
72
73.macro RESTORE_TWO_REGS_DECREASE_FRAME reg1, reg2, frame_adjustment
74 ldp \reg1, \reg2, [sp], #(\frame_adjustment)
75 .cfi_restore \reg1
76 .cfi_restore \reg2
77 .cfi_adjust_cfa_offset -(\frame_adjustment)
78.endm
79
Stuart Monteithb95a5342014-03-12 13:32:32 +000080 /*
81 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010082 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Stuart Monteithb95a5342014-03-12 13:32:32 +000083 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010084.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
85 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +080086 adrp xIP0, :got:_ZN3art7Runtime9instance_E
87 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000088
89 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010090 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +000091
Vladimir Markofd36f1f2016-08-03 18:49:58 +010092 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves];
93 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070094
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010095 INCREASE_FRAME 176
Andreas Gampe5c1e4352014-04-21 19:28:24 -070096
97 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010098#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176)
99#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700100#endif
101
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100102 // Stack alignment filler [sp, #8].
103 // FP callee-saves.
104 stp d8, d9, [sp, #16]
105 stp d10, d11, [sp, #32]
106 stp d12, d13, [sp, #48]
107 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700108
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100109 // GP callee-saves
Vladimir Marko215076b2016-09-07 18:05:55 +0100110 SAVE_TWO_REGS x19, x20, 80
111 SAVE_TWO_REGS x21, x22, 96
112 SAVE_TWO_REGS x23, x24, 112
113 SAVE_TWO_REGS x25, x26, 128
114 SAVE_TWO_REGS x27, x28, 144
115 SAVE_TWO_REGS x29, xLR, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700116
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100117 // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100118 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700119 // Place sp in Thread::Current()->top_quick_frame.
120 mov xIP0, sp
121 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000122.endm
123
Zheng Xub551fdc2014-07-25 11:49:42 +0800124 /*
125 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100126 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
Zheng Xub551fdc2014-07-25 11:49:42 +0800127 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100128.macro SETUP_SAVE_REFS_ONLY_FRAME
129 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800130 adrp xIP0, :got:_ZN3art7Runtime9instance_E
131 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
132
133 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100134 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Zheng Xub551fdc2014-07-25 11:49:42 +0800135
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100136 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly];
137 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800138
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100139 INCREASE_FRAME 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800140
141 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100142#if (FRAME_SIZE_SAVE_REFS_ONLY != 96)
143#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected."
Zheng Xub551fdc2014-07-25 11:49:42 +0800144#endif
145
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100146 // GP callee-saves.
147 // x20 paired with ArtMethod* - see below.
Vladimir Marko215076b2016-09-07 18:05:55 +0100148 SAVE_TWO_REGS x21, x22, 16
149 SAVE_TWO_REGS x23, x24, 32
150 SAVE_TWO_REGS x25, x26, 48
151 SAVE_TWO_REGS x27, x28, 64
152 SAVE_TWO_REGS x29, xLR, 80
Zheng Xub551fdc2014-07-25 11:49:42 +0800153
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100154 // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly].
Roland Levillain97c46462017-05-11 14:04:03 +0100155 // Note: We could avoid saving X20 in the case of Baker read
156 // barriers, as it is overwritten by REFRESH_MARKING_REGISTER
157 // later; but it's not worth handling this special case.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100158 stp xIP0, x20, [sp]
159 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800160
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700161 // Place sp in Thread::Current()->top_quick_frame.
162 mov xIP0, sp
163 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800164.endm
165
166// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100167.macro RESTORE_SAVE_REFS_ONLY_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100168 // Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100169 // Note: Likewise, we could avoid restoring X20 in the case of Baker
170 // read barriers, as it is overwritten by REFRESH_MARKING_REGISTER
171 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100172 RESTORE_REG x20, 8
173 RESTORE_TWO_REGS x21, x22, 16
174 RESTORE_TWO_REGS x23, x24, 32
175 RESTORE_TWO_REGS x25, x26, 48
176 RESTORE_TWO_REGS x27, x28, 64
177 RESTORE_TWO_REGS x29, xLR, 80
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700178
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100179 DECREASE_FRAME 96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000180.endm
181
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100182.macro POP_SAVE_REFS_ONLY_FRAME
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100183 DECREASE_FRAME 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700184.endm
185
Stuart Monteithb95a5342014-03-12 13:32:32 +0000186
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100187.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100188 INCREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000189
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700190 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100191#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224)
192#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700193#endif
194
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100195 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800196 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100197 stp d0, d1, [sp, #16]
198 stp d2, d3, [sp, #32]
199 stp d4, d5, [sp, #48]
200 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000201
Zheng Xu69a50302015-04-14 20:04:41 +0800202 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100203 SAVE_TWO_REGS x1, x2, 80
204 SAVE_TWO_REGS x3, x4, 96
205 SAVE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700206
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100207 // x7, Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100208 // Note: We could avoid saving X20 in the case of Baker read
209 // barriers, as it is overwritten by REFRESH_MARKING_REGISTER
210 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100211 SAVE_TWO_REGS x7, x20, 128
212 SAVE_TWO_REGS x21, x22, 144
213 SAVE_TWO_REGS x23, x24, 160
214 SAVE_TWO_REGS x25, x26, 176
215 SAVE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700216
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100217 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100218 SAVE_TWO_REGS x29, xLR, 208
Andreas Gampe03906cf2014-04-07 12:08:28 -0700219
Stuart Monteithb95a5342014-03-12 13:32:32 +0000220.endm
221
222 /*
223 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100224 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000225 *
226 * TODO This is probably too conservative - saving FP & LR.
227 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100228.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
229 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800230 adrp xIP0, :got:_ZN3art7Runtime9instance_E
231 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000232
233 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100234 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000235
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100236 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs];
237 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000238
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100239 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000240
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100241 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs].
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700242 // Place sp in Thread::Current()->top_quick_frame.
243 mov xIP0, sp
244 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
245.endm
246
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100247.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
248 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700249 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
250 // Place sp in Thread::Current()->top_quick_frame.
251 mov xIP0, sp
252 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000253.endm
254
Zheng Xub551fdc2014-07-25 11:49:42 +0800255// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100256.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800257 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100258 ldp d0, d1, [sp, #16]
259 ldp d2, d3, [sp, #32]
260 ldp d4, d5, [sp, #48]
261 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000262
Zheng Xu69a50302015-04-14 20:04:41 +0800263 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100264 RESTORE_TWO_REGS x1, x2, 80
265 RESTORE_TWO_REGS x3, x4, 96
266 RESTORE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700267
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100268 // x7, Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100269 // Note: Likewise, we could avoid restoring X20 in the case of Baker
270 // read barriers, as it is overwritten by REFRESH_MARKING_REGISTER
271 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100272 RESTORE_TWO_REGS x7, x20, 128
273 RESTORE_TWO_REGS x21, x22, 144
274 RESTORE_TWO_REGS x23, x24, 160
275 RESTORE_TWO_REGS x25, x26, 176
276 RESTORE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700277
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100278 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100279 RESTORE_TWO_REGS x29, xLR, 208
Stuart Monteithb95a5342014-03-12 13:32:32 +0000280
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100281 DECREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000282.endm
283
Vladimir Marko952dbb12016-07-28 12:01:51 +0100284 /*
285 * Macro that sets up the callee save frame to conform with
286 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000287 * when the SP has already been decremented by FRAME_SIZE_SAVE_EVERYTHING
288 * and saving registers x29 and LR is handled elsewhere.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100289 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700290.macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Marko952dbb12016-07-28 12:01:51 +0100291 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100292#if (FRAME_SIZE_SAVE_EVERYTHING != 512)
293#error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100294#endif
295
296 // Save FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100297 // For better performance, store d0 and d31 separately, so that all STPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100298 str d0, [sp, #8]
299 stp d1, d2, [sp, #16]
300 stp d3, d4, [sp, #32]
301 stp d5, d6, [sp, #48]
302 stp d7, d8, [sp, #64]
303 stp d9, d10, [sp, #80]
304 stp d11, d12, [sp, #96]
305 stp d13, d14, [sp, #112]
306 stp d15, d16, [sp, #128]
307 stp d17, d18, [sp, #144]
308 stp d19, d20, [sp, #160]
309 stp d21, d22, [sp, #176]
310 stp d23, d24, [sp, #192]
311 stp d25, d26, [sp, #208]
312 stp d27, d28, [sp, #224]
313 stp d29, d30, [sp, #240]
314 str d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100315
316 // Save core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +0100317 SAVE_REG x0, 264
318 SAVE_TWO_REGS x1, x2, 272
319 SAVE_TWO_REGS x3, x4, 288
320 SAVE_TWO_REGS x5, x6, 304
321 SAVE_TWO_REGS x7, x8, 320
322 SAVE_TWO_REGS x9, x10, 336
323 SAVE_TWO_REGS x11, x12, 352
324 SAVE_TWO_REGS x13, x14, 368
325 SAVE_TWO_REGS x15, x16, 384
326 SAVE_TWO_REGS x17, x18, 400
327 SAVE_TWO_REGS x19, x20, 416
328 SAVE_TWO_REGS x21, x22, 432
329 SAVE_TWO_REGS x23, x24, 448
330 SAVE_TWO_REGS x25, x26, 464
331 SAVE_TWO_REGS x27, x28, 480
Vladimir Marko952dbb12016-07-28 12:01:51 +0100332
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100333 // art::Runtime** xIP0 = &art::Runtime::instance_
Vladimir Marko952dbb12016-07-28 12:01:51 +0100334 adrp xIP0, :got:_ZN3art7Runtime9instance_E
335 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
336
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100337 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Vladimir Marko952dbb12016-07-28 12:01:51 +0100338
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100339 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything];
Mingyao Yang0a87a652017-04-12 13:43:15 -0700340 ldr xIP0, [xIP0, \runtime_method_offset]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100341
342 // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything].
343 str xIP0, [sp]
344 // Place sp in Thread::Current()->top_quick_frame.
345 mov xIP0, sp
346 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
347.endm
348
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000349 /*
350 * Macro that sets up the callee save frame to conform with
351 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
352 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700353.macro SETUP_SAVE_EVERYTHING_FRAME runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000354 INCREASE_FRAME 512
355 SAVE_TWO_REGS x29, xLR, 496
Mingyao Yang0a87a652017-04-12 13:43:15 -0700356 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR \runtime_method_offset
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000357.endm
358
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100359.macro RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
Vladimir Marko952dbb12016-07-28 12:01:51 +0100360 // Restore FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100361 // For better performance, load d0 and d31 separately, so that all LDPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100362 ldr d0, [sp, #8]
363 ldp d1, d2, [sp, #16]
364 ldp d3, d4, [sp, #32]
365 ldp d5, d6, [sp, #48]
366 ldp d7, d8, [sp, #64]
367 ldp d9, d10, [sp, #80]
368 ldp d11, d12, [sp, #96]
369 ldp d13, d14, [sp, #112]
370 ldp d15, d16, [sp, #128]
371 ldp d17, d18, [sp, #144]
372 ldp d19, d20, [sp, #160]
373 ldp d21, d22, [sp, #176]
374 ldp d23, d24, [sp, #192]
375 ldp d25, d26, [sp, #208]
376 ldp d27, d28, [sp, #224]
377 ldp d29, d30, [sp, #240]
378 ldr d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100379
Roland Levillain97c46462017-05-11 14:04:03 +0100380 // Restore core registers, except x0.
Vladimir Marko215076b2016-09-07 18:05:55 +0100381 RESTORE_TWO_REGS x1, x2, 272
382 RESTORE_TWO_REGS x3, x4, 288
383 RESTORE_TWO_REGS x5, x6, 304
384 RESTORE_TWO_REGS x7, x8, 320
385 RESTORE_TWO_REGS x9, x10, 336
386 RESTORE_TWO_REGS x11, x12, 352
387 RESTORE_TWO_REGS x13, x14, 368
388 RESTORE_TWO_REGS x15, x16, 384
389 RESTORE_TWO_REGS x17, x18, 400
390 RESTORE_TWO_REGS x19, x20, 416
391 RESTORE_TWO_REGS x21, x22, 432
392 RESTORE_TWO_REGS x23, x24, 448
393 RESTORE_TWO_REGS x25, x26, 464
394 RESTORE_TWO_REGS x27, x28, 480
395 RESTORE_TWO_REGS x29, xLR, 496
Vladimir Marko952dbb12016-07-28 12:01:51 +0100396
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100397 DECREASE_FRAME 512
Vladimir Marko952dbb12016-07-28 12:01:51 +0100398.endm
399
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100400.macro RESTORE_SAVE_EVERYTHING_FRAME
Mingyao Yang0a87a652017-04-12 13:43:15 -0700401 RESTORE_REG x0, 264
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100402 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
403.endm
404
Roland Levillain97c46462017-05-11 14:04:03 +0100405// Macro to refresh the Marking Register (W20).
406//
407// This macro must be called at the end of functions implementing
408// entrypoints that possibly (directly or indirectly) perform a
409// suspend check (before they return).
410.macro REFRESH_MARKING_REGISTER
411#if defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
412 ldr wMR, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
413#endif
414.endm
415
Stuart Monteithb95a5342014-03-12 13:32:32 +0000416.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700417 cbnz x0, 1f // result non-zero branch over
418 ret // return
4191:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000420.endm
421
422.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700423 cbz x0, 1f // result zero branch over
424 ret // return
4251:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000426.endm
427
428 /*
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100429 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
430 * exception is Thread::Current()->exception_ when the runtime method frame is ready.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000431 */
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100432.macro DELIVER_PENDING_EXCEPTION_FRAME_READY
Stuart Monteithb95a5342014-03-12 13:32:32 +0000433 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000434
435 // Point of no return.
Vladimir Marko908eb222016-09-14 10:29:18 +0100436 bl artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000437 brk 0 // Unreached
438.endm
439
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100440 /*
441 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
442 * exception is Thread::Current()->exception_.
443 */
444.macro DELIVER_PENDING_EXCEPTION
445 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
446 DELIVER_PENDING_EXCEPTION_FRAME_READY
447.endm
448
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700449.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
450 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
451 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000452 ret
4531:
454 DELIVER_PENDING_EXCEPTION
455.endm
456
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700457.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800458 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700459.endm
460
461// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
462.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
463 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
464.endm
465
466.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
467 cbnz w0, 1f // result non-zero branch over
468 ret // return
4691:
470 DELIVER_PENDING_EXCEPTION
471.endm
472
Stuart Monteithb95a5342014-03-12 13:32:32 +0000473.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
474 .extern \cxx_name
475ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100476 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800477 mov x0, xSELF // pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100478 bl \cxx_name // \cxx_name(Thread*)
Vladimir Marko804b03f2016-09-14 16:26:36 +0100479 brk 0
480END \c_name
481.endm
482
483.macro NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
484 .extern \cxx_name
485ENTRY \c_name
486 SETUP_SAVE_EVERYTHING_FRAME // save all registers as basis for long jump context
487 mov x0, xSELF // pass Thread::Current
488 bl \cxx_name // \cxx_name(Thread*)
489 brk 0
Stuart Monteithb95a5342014-03-12 13:32:32 +0000490END \c_name
491.endm
492
493.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
494 .extern \cxx_name
495ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100496 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800497 mov x1, xSELF // pass Thread::Current.
Vladimir Marko908eb222016-09-14 10:29:18 +0100498 bl \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000499 brk 0
500END \c_name
501.endm
502
Vladimir Marko804b03f2016-09-14 16:26:36 +0100503.macro TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000504 .extern \cxx_name
505ENTRY \c_name
Vladimir Marko804b03f2016-09-14 16:26:36 +0100506 SETUP_SAVE_EVERYTHING_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800507 mov x2, xSELF // pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100508 bl \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000509 brk 0
510END \c_name
511.endm
512
513 /*
514 * Called by managed code, saves callee saves and then calls artThrowException
515 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
516 */
517ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
518
519 /*
520 * Called by managed code to create and deliver a NullPointerException.
521 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100522NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000523
524 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100525 * Call installed by a signal handler to create and deliver a NullPointerException.
526 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000527 .extern art_quick_throw_null_pointer_exception_from_signal
528ENTRY art_quick_throw_null_pointer_exception_from_signal
529 // The fault handler pushes the gc map address, i.e. "return address", to stack
530 // and passes the fault address in LR. So we need to set up the CFI info accordingly.
531 .cfi_def_cfa_offset __SIZEOF_POINTER__
532 .cfi_rel_offset lr, 0
533 // Save all registers as basis for long jump context.
534 INCREASE_FRAME (FRAME_SIZE_SAVE_EVERYTHING - __SIZEOF_POINTER__)
535 SAVE_REG x29, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__) // LR already saved.
536 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
537 mov x0, lr // pass the fault address stored in LR by the fault handler.
538 mov x1, xSELF // pass Thread::Current.
Vladimir Marko908eb222016-09-14 10:29:18 +0100539 bl artThrowNullPointerExceptionFromSignal // (arg, Thread*).
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000540 brk 0
541END art_quick_throw_null_pointer_exception_from_signal
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100542
543 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000544 * Called by managed code to create and deliver an ArithmeticException.
545 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100546NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_div_zero, artThrowDivZeroFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000547
548 /*
549 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
550 * index, arg2 holds limit.
551 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100552TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000553
554 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100555 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
556 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
557 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100558TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_string_bounds, artThrowStringBoundsFromCode
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100559
560 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000561 * Called by managed code to create and deliver a StackOverflowError.
562 */
563NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
564
565 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000566 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700567 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100568 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700569 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000570 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700571 * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting
Stuart Monteithb95a5342014-03-12 13:32:32 +0000572 * of the target Method* in x0 and method->code_ in x1.
573 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700574 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000575 * thread and we branch to another stub to deliver it.
576 *
577 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
578 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700579 *
580 * Adapted from ARM32 code.
581 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800582 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000583 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700584.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000585 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100586 SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700587 // Helper signature is always
588 // (method_idx, *this_object, *caller_method, *self, sp)
589
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100590 mov x2, xSELF // pass Thread::Current
591 mov x3, sp
592 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800593 mov xIP0, x1 // save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100594 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +0100595 REFRESH_MARKING_REGISTER
Andreas Gampe51f76352014-05-21 08:28:48 -0700596 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800597 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07005981:
599 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700600.endm
601.macro INVOKE_TRAMPOLINE c_name, cxx_name
602ENTRY \c_name
603 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000604END \c_name
605.endm
606
Stuart Monteithb95a5342014-03-12 13:32:32 +0000607INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
608
609INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
610INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
611INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
612INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
613
Andreas Gampe03906cf2014-04-07 12:08:28 -0700614
615.macro INVOKE_STUB_CREATE_FRAME
616
Zheng Xu69a50302015-04-14 20:04:41 +0800617SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700618SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
Andreas Gampecf4035a2014-05-28 22:43:01 -0700619
Andreas Gampe03906cf2014-04-07 12:08:28 -0700620
Zheng Xu48241e72014-05-23 11:52:42 +0800621 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700622 .cfi_register sp,x9
623
Zheng Xu48241e72014-05-23 11:52:42 +0800624 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700625 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
Zheng Xu48241e72014-05-23 11:52:42 +0800626 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
627 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700628
Zheng Xu48241e72014-05-23 11:52:42 +0800629 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
630 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700631 .cfi_adjust_cfa_offset SAVE_SIZE
632
Nicolas Geoffray48088462014-12-12 10:29:38 +0000633 str x28, [x10, #112]
634 .cfi_rel_offset x28, 112
635
636 stp x26, x27, [x10, #96]
637 .cfi_rel_offset x26, 96
638 .cfi_rel_offset x27, 104
639
640 stp x24, x25, [x10, #80]
641 .cfi_rel_offset x24, 80
642 .cfi_rel_offset x25, 88
643
644 stp x22, x23, [x10, #64]
645 .cfi_rel_offset x22, 64
646 .cfi_rel_offset x23, 72
647
648 stp x20, x21, [x10, #48]
649 .cfi_rel_offset x20, 48
650 .cfi_rel_offset x21, 56
651
Zheng Xu69a50302015-04-14 20:04:41 +0800652 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700653 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700654 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700655
Zheng Xu48241e72014-05-23 11:52:42 +0800656 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700657 .cfi_rel_offset x4, 16
658 .cfi_rel_offset x5, 24
659
Zheng Xu48241e72014-05-23 11:52:42 +0800660 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700661 .cfi_rel_offset x29, 0
662 .cfi_rel_offset x30, 8
663
Zheng Xu48241e72014-05-23 11:52:42 +0800664 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700665 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800666 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700667
668 // Copy arguments into stack frame.
669 // Use simple copy routine for now.
670 // 4 bytes per slot.
671 // X1 - source address
672 // W2 - args length
673 // X9 - destination address.
674 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700675 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700676
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700677 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
678 // does not have unique-id variables.
6791:
Andreas Gampe03906cf2014-04-07 12:08:28 -0700680 cmp w2, #0
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700681 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700682 sub w2, w2, #4 // Need 65536 bytes of range.
683 ldr w10, [x1, x2]
684 str w10, [x9, x2]
685
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700686 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700687
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006882:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700689 // Store null into ArtMethod* at bottom of frame.
690 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700691.endm
692
693.macro INVOKE_STUB_CALL_AND_RETURN
694
Roland Levillain97c46462017-05-11 14:04:03 +0100695 REFRESH_MARKING_REGISTER
696
Andreas Gampe03906cf2014-04-07 12:08:28 -0700697 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700698 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700699 // Branch to method.
700 blr x9
701
702 // Restore return value address and shorty address.
Roland Levillain97c46462017-05-11 14:04:03 +0100703 ldp x4, x5, [xFP, #16]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700704 .cfi_restore x4
705 .cfi_restore x5
706
Nicolas Geoffray48088462014-12-12 10:29:38 +0000707 ldr x28, [xFP, #112]
708 .cfi_restore x28
709
710 ldp x26, x27, [xFP, #96]
711 .cfi_restore x26
712 .cfi_restore x27
713
714 ldp x24, x25, [xFP, #80]
715 .cfi_restore x24
716 .cfi_restore x25
717
718 ldp x22, x23, [xFP, #64]
719 .cfi_restore x22
720 .cfi_restore x23
721
722 ldp x20, x21, [xFP, #48]
723 .cfi_restore x20
724 .cfi_restore x21
725
Andreas Gampe03906cf2014-04-07 12:08:28 -0700726 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
727 ldrb w10, [x5]
728
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700729 // Check the return type and store the correct register into the jvalue in memory.
730 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
731
Andreas Gampe03906cf2014-04-07 12:08:28 -0700732 // Don't set anything for a void type.
733 cmp w10, #'V'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700734 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700735
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700736 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700737 cmp w10, #'D'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700738 bne 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700739 str d0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700740 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700741
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07007421: // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700743 cmp w10, #'F'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700744 bne 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700745 str s0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700746 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700747
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07007482: // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700749 str x0, [x4]
750
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07007513: // Finish up.
Zheng Xu69a50302015-04-14 20:04:41 +0800752 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700753 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700754 mov sp, x2
755 .cfi_restore sp
756
Andreas Gamped58342c2014-06-05 14:18:08 -0700757 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700758 .cfi_restore x29
759 .cfi_restore x30
760
761 ret
762
763.endm
764
765
Stuart Monteithb95a5342014-03-12 13:32:32 +0000766/*
767 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
768 * uint32_t *args, x1
769 * uint32_t argsize, w2
770 * Thread *self, x3
771 * JValue *result, x4
772 * char *shorty); x5
773 * +----------------------+
774 * | |
775 * | C/C++ frame |
776 * | LR'' |
777 * | FP'' | <- SP'
778 * +----------------------+
779 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800780 * | x28 | <- TODO: Remove callee-saves.
781 * | : |
782 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000783 * | SP' |
784 * | X5 |
785 * | X4 | Saved registers
786 * | LR' |
787 * | FP' | <- FP
788 * +----------------------+
789 * | uint32_t out[n-1] |
790 * | : : | Outs
791 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700792 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000793 * +----------------------+
794 *
795 * Outgoing registers:
796 * x0 - Method*
797 * x1-x7 - integer parameters.
798 * d0-d7 - Floating point parameters.
799 * xSELF = self
800 * SP = & of ArtMethod*
801 * x1 = "this" pointer.
802 *
803 */
804ENTRY art_quick_invoke_stub
805 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700806 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000807
808 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
809 // Parse the passed shorty to determine which register to load.
810 // Load addresses for routines that load WXSD registers.
811 adr x11, .LstoreW2
812 adr x12, .LstoreX2
813 adr x13, .LstoreS0
814 adr x14, .LstoreD0
815
816 // Initialize routine offsets to 0 for integers and floats.
817 // x8 for integers, x15 for floating point.
818 mov x8, #0
819 mov x15, #0
820
821 add x10, x5, #1 // Load shorty address, plus one to skip return value.
822 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
823
824 // Loop to fill registers.
825.LfillRegisters:
826 ldrb w17, [x10], #1 // Load next character in signature, and increment.
827 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
828
829 cmp w17, #'F' // is this a float?
830 bne .LisDouble
831
832 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700833 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000834
835 add x17, x13, x15 // Calculate subroutine to jump to.
836 br x17
837
838.LisDouble:
839 cmp w17, #'D' // is this a double?
840 bne .LisLong
841
842 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700843 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000844
845 add x17, x14, x15 // Calculate subroutine to jump to.
846 br x17
847
848.LisLong:
849 cmp w17, #'J' // is this a long?
850 bne .LisOther
851
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700852 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700853 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000854
855 add x17, x12, x8 // Calculate subroutine to jump to.
856 br x17
857
Stuart Monteithb95a5342014-03-12 13:32:32 +0000858.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700859 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700860 beq .Ladvance4
861
Stuart Monteithb95a5342014-03-12 13:32:32 +0000862 add x17, x11, x8 // Calculate subroutine to jump to.
863 br x17
864
Andreas Gampe03906cf2014-04-07 12:08:28 -0700865.Ladvance4:
866 add x9, x9, #4
867 b .LfillRegisters
868
869.Ladvance8:
870 add x9, x9, #8
871 b .LfillRegisters
872
Stuart Monteithb95a5342014-03-12 13:32:32 +0000873// Macro for loading a parameter into a register.
874// counter - the register with offset into these tables
875// size - the size of the register - 4 or 8 bytes.
876// register - the name of the register to be loaded.
877.macro LOADREG counter size register return
878 ldr \register , [x9], #\size
879 add \counter, \counter, 12
880 b \return
881.endm
882
883// Store ints.
884.LstoreW2:
885 LOADREG x8 4 w2 .LfillRegisters
886 LOADREG x8 4 w3 .LfillRegisters
887 LOADREG x8 4 w4 .LfillRegisters
888 LOADREG x8 4 w5 .LfillRegisters
889 LOADREG x8 4 w6 .LfillRegisters
890 LOADREG x8 4 w7 .LfillRegisters
891
892// Store longs.
893.LstoreX2:
894 LOADREG x8 8 x2 .LfillRegisters
895 LOADREG x8 8 x3 .LfillRegisters
896 LOADREG x8 8 x4 .LfillRegisters
897 LOADREG x8 8 x5 .LfillRegisters
898 LOADREG x8 8 x6 .LfillRegisters
899 LOADREG x8 8 x7 .LfillRegisters
900
901// Store singles.
902.LstoreS0:
903 LOADREG x15 4 s0 .LfillRegisters
904 LOADREG x15 4 s1 .LfillRegisters
905 LOADREG x15 4 s2 .LfillRegisters
906 LOADREG x15 4 s3 .LfillRegisters
907 LOADREG x15 4 s4 .LfillRegisters
908 LOADREG x15 4 s5 .LfillRegisters
909 LOADREG x15 4 s6 .LfillRegisters
910 LOADREG x15 4 s7 .LfillRegisters
911
912// Store doubles.
913.LstoreD0:
914 LOADREG x15 8 d0 .LfillRegisters
915 LOADREG x15 8 d1 .LfillRegisters
916 LOADREG x15 8 d2 .LfillRegisters
917 LOADREG x15 8 d3 .LfillRegisters
918 LOADREG x15 8 d4 .LfillRegisters
919 LOADREG x15 8 d5 .LfillRegisters
920 LOADREG x15 8 d6 .LfillRegisters
921 LOADREG x15 8 d7 .LfillRegisters
922
923
924.LcallFunction:
925
Andreas Gampe03906cf2014-04-07 12:08:28 -0700926 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000927
Stuart Monteithb95a5342014-03-12 13:32:32 +0000928END art_quick_invoke_stub
929
930/* extern"C"
931 * void art_quick_invoke_static_stub(ArtMethod *method, x0
932 * uint32_t *args, x1
933 * uint32_t argsize, w2
934 * Thread *self, x3
935 * JValue *result, x4
936 * char *shorty); x5
937 */
938ENTRY art_quick_invoke_static_stub
939 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700940 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000941
942 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
943 // Parse the passed shorty to determine which register to load.
944 // Load addresses for routines that load WXSD registers.
945 adr x11, .LstoreW1_2
946 adr x12, .LstoreX1_2
947 adr x13, .LstoreS0_2
948 adr x14, .LstoreD0_2
949
950 // Initialize routine offsets to 0 for integers and floats.
951 // x8 for integers, x15 for floating point.
952 mov x8, #0
953 mov x15, #0
954
955 add x10, x5, #1 // Load shorty address, plus one to skip return value.
956
957 // Loop to fill registers.
958.LfillRegisters2:
959 ldrb w17, [x10], #1 // Load next character in signature, and increment.
960 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
961
962 cmp w17, #'F' // is this a float?
963 bne .LisDouble2
964
965 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700966 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000967
968 add x17, x13, x15 // Calculate subroutine to jump to.
969 br x17
970
971.LisDouble2:
972 cmp w17, #'D' // is this a double?
973 bne .LisLong2
974
975 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700976 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000977
978 add x17, x14, x15 // Calculate subroutine to jump to.
979 br x17
980
981.LisLong2:
982 cmp w17, #'J' // is this a long?
983 bne .LisOther2
984
985 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700986 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000987
988 add x17, x12, x8 // Calculate subroutine to jump to.
989 br x17
990
Stuart Monteithb95a5342014-03-12 13:32:32 +0000991.LisOther2: // Everything else takes one vReg.
992 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700993 beq .Ladvance4_2
994
Stuart Monteithb95a5342014-03-12 13:32:32 +0000995 add x17, x11, x8 // Calculate subroutine to jump to.
996 br x17
997
Andreas Gampe03906cf2014-04-07 12:08:28 -0700998.Ladvance4_2:
999 add x9, x9, #4
1000 b .LfillRegisters2
1001
1002.Ladvance8_2:
1003 add x9, x9, #8
1004 b .LfillRegisters2
1005
Stuart Monteithb95a5342014-03-12 13:32:32 +00001006// Store ints.
1007.LstoreW1_2:
1008 LOADREG x8 4 w1 .LfillRegisters2
1009 LOADREG x8 4 w2 .LfillRegisters2
1010 LOADREG x8 4 w3 .LfillRegisters2
1011 LOADREG x8 4 w4 .LfillRegisters2
1012 LOADREG x8 4 w5 .LfillRegisters2
1013 LOADREG x8 4 w6 .LfillRegisters2
1014 LOADREG x8 4 w7 .LfillRegisters2
1015
1016// Store longs.
1017.LstoreX1_2:
1018 LOADREG x8 8 x1 .LfillRegisters2
1019 LOADREG x8 8 x2 .LfillRegisters2
1020 LOADREG x8 8 x3 .LfillRegisters2
1021 LOADREG x8 8 x4 .LfillRegisters2
1022 LOADREG x8 8 x5 .LfillRegisters2
1023 LOADREG x8 8 x6 .LfillRegisters2
1024 LOADREG x8 8 x7 .LfillRegisters2
1025
1026// Store singles.
1027.LstoreS0_2:
1028 LOADREG x15 4 s0 .LfillRegisters2
1029 LOADREG x15 4 s1 .LfillRegisters2
1030 LOADREG x15 4 s2 .LfillRegisters2
1031 LOADREG x15 4 s3 .LfillRegisters2
1032 LOADREG x15 4 s4 .LfillRegisters2
1033 LOADREG x15 4 s5 .LfillRegisters2
1034 LOADREG x15 4 s6 .LfillRegisters2
1035 LOADREG x15 4 s7 .LfillRegisters2
1036
1037// Store doubles.
1038.LstoreD0_2:
1039 LOADREG x15 8 d0 .LfillRegisters2
1040 LOADREG x15 8 d1 .LfillRegisters2
1041 LOADREG x15 8 d2 .LfillRegisters2
1042 LOADREG x15 8 d3 .LfillRegisters2
1043 LOADREG x15 8 d4 .LfillRegisters2
1044 LOADREG x15 8 d5 .LfillRegisters2
1045 LOADREG x15 8 d6 .LfillRegisters2
1046 LOADREG x15 8 d7 .LfillRegisters2
1047
1048
1049.LcallFunction2:
1050
Andreas Gampe03906cf2014-04-07 12:08:28 -07001051 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +00001052
Stuart Monteithb95a5342014-03-12 13:32:32 +00001053END art_quick_invoke_static_stub
1054
Andreas Gampe03906cf2014-04-07 12:08:28 -07001055
Stuart Monteithb95a5342014-03-12 13:32:32 +00001056
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001057/* extern"C" void art_quick_osr_stub(void** stack, x0
1058 * size_t stack_size_in_bytes, x1
1059 * const uin8_t* native_pc, x2
1060 * JValue *result, x3
1061 * char *shorty, x4
1062 * Thread *self) x5
1063 */
1064ENTRY art_quick_osr_stub
Vladimir Markoa26f4162018-03-02 13:53:53 +00001065SAVE_SIZE=14*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, FP, LR saved.
1066 SAVE_TWO_REGS_INCREASE_FRAME x3, x4, SAVE_SIZE
1067 SAVE_TWO_REGS x19, x20, 16
1068 SAVE_TWO_REGS x21, x22, 32
1069 SAVE_TWO_REGS x23, x24, 48
1070 SAVE_TWO_REGS x25, x26, 64
1071 SAVE_TWO_REGS x27, x28, 80
1072 SAVE_TWO_REGS xFP, xLR, 96
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001073
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001074 mov xSELF, x5 // Move thread pointer into SELF register.
Roland Levillain97c46462017-05-11 14:04:03 +01001075 REFRESH_MARKING_REGISTER
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001076
Vladimir Markoa26f4162018-03-02 13:53:53 +00001077 INCREASE_FRAME 16
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001078 str xzr, [sp] // Store null for ArtMethod* slot
1079 // Branch to stub.
1080 bl .Losr_entry
Vladimir Markoa26f4162018-03-02 13:53:53 +00001081 .cfi_remember_state
1082 DECREASE_FRAME 16
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001083
Vladimir Markoa26f4162018-03-02 13:53:53 +00001084 // Restore saved registers including value address and shorty address.
1085 RESTORE_TWO_REGS x19, x20, 16
1086 RESTORE_TWO_REGS x21, x22, 32
1087 RESTORE_TWO_REGS x23, x24, 48
1088 RESTORE_TWO_REGS x25, x26, 64
1089 RESTORE_TWO_REGS x27, x28, 80
1090 RESTORE_TWO_REGS xFP, xLR, 96
1091 RESTORE_TWO_REGS_DECREASE_FRAME x3, x4, SAVE_SIZE
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001092
1093 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1094 ldrb w10, [x4]
1095
1096 // Check the return type and store the correct register into the jvalue in memory.
1097
1098 // Don't set anything for a void type.
1099 cmp w10, #'V'
1100 beq .Losr_exit
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001101 // Is it a double?
1102 cmp w10, #'D'
Vladimir Markoa26f4162018-03-02 13:53:53 +00001103 beq .Losr_return_double
1104 // Is it a float?
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001105 cmp w10, #'F'
Vladimir Markoa26f4162018-03-02 13:53:53 +00001106 beq .Losr_return_float
1107 // Just store x0. Doesn't matter if it is 64 or 32 bits.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001108 str x0, [x3]
Vladimir Markoa26f4162018-03-02 13:53:53 +00001109.Losr_exit:
1110 ret
1111.Losr_return_double:
1112 str d0, [x3]
1113 ret
1114.Losr_return_float:
1115 str s0, [x3]
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001116 ret
1117
1118.Losr_entry:
Vladimir Markoa26f4162018-03-02 13:53:53 +00001119 .cfi_restore_state // Reset unwind info so following code unwinds.
1120 .cfi_def_cfa_offset (SAVE_SIZE+16) // workaround for clang bug: 31975598
1121
1122 mov x9, sp // Save stack pointer.
1123 .cfi_def_cfa_register x9
1124
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001125 // Update stack pointer for the callee
1126 sub sp, sp, x1
1127
1128 // Update link register slot expected by the callee.
1129 sub w1, w1, #8
1130 str lr, [sp, x1]
1131
1132 // Copy arguments into stack frame.
1133 // Use simple copy routine for now.
1134 // 4 bytes per slot.
1135 // X0 - source address
1136 // W1 - args length
1137 // SP - destination address.
1138 // W10 - temporary
1139.Losr_loop_entry:
Vladimir Markoa26f4162018-03-02 13:53:53 +00001140 cbz w1, .Losr_loop_exit
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001141 sub w1, w1, #4
1142 ldr w10, [x0, x1]
1143 str w10, [sp, x1]
1144 b .Losr_loop_entry
1145
1146.Losr_loop_exit:
1147 // Branch to the OSR entry point.
1148 br x2
1149
1150END art_quick_osr_stub
1151
Stuart Monteithb95a5342014-03-12 13:32:32 +00001152 /*
1153 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1154 */
1155
1156ENTRY art_quick_do_long_jump
1157 // Load FPRs
1158 ldp d0, d1, [x1], #16
1159 ldp d2, d3, [x1], #16
1160 ldp d4, d5, [x1], #16
1161 ldp d6, d7, [x1], #16
1162 ldp d8, d9, [x1], #16
1163 ldp d10, d11, [x1], #16
1164 ldp d12, d13, [x1], #16
1165 ldp d14, d15, [x1], #16
1166 ldp d16, d17, [x1], #16
1167 ldp d18, d19, [x1], #16
1168 ldp d20, d21, [x1], #16
1169 ldp d22, d23, [x1], #16
1170 ldp d24, d25, [x1], #16
1171 ldp d26, d27, [x1], #16
1172 ldp d28, d29, [x1], #16
1173 ldp d30, d31, [x1]
1174
1175 // Load GPRs
1176 // TODO: lots of those are smashed, could optimize.
1177 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001178 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001179 ldp x28, x29, [x0], #-16
1180 ldp x26, x27, [x0], #-16
1181 ldp x24, x25, [x0], #-16
1182 ldp x22, x23, [x0], #-16
1183 ldp x20, x21, [x0], #-16
Roland Levillain97c46462017-05-11 14:04:03 +01001184 ldp x18, x19, [x0], #-16 // X18 & xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +00001185 ldp x16, x17, [x0], #-16
1186 ldp x14, x15, [x0], #-16
1187 ldp x12, x13, [x0], #-16
1188 ldp x10, x11, [x0], #-16
1189 ldp x8, x9, [x0], #-16
1190 ldp x6, x7, [x0], #-16
1191 ldp x4, x5, [x0], #-16
1192 ldp x2, x3, [x0], #-16
1193 mov sp, x1
1194
Roland Levillain97c46462017-05-11 14:04:03 +01001195 REFRESH_MARKING_REGISTER
1196
Andreas Gampe639bdd12015-06-03 11:22:45 -07001197 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1198 ldr x1, [x0, #33*8]
1199 // And the value of x0.
1200 ldr x0, [x0]
1201
1202 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001203END art_quick_do_long_jump
1204
Andreas Gampef4e910b2014-04-29 16:55:52 -07001205 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001206 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1207 * possibly null object to lock.
1208 *
1209 * Derived from arm32 code.
1210 */
1211 .extern artLockObjectFromCode
1212ENTRY art_quick_lock_object
1213 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001214 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001215.Lretry_lock:
1216 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
Hans Boehm67eda382017-01-17 15:03:38 -08001217 ldaxr w1, [x4] // acquire needed only in most common case
1218 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001219 cbnz w3, .Lnot_unlocked // already thin locked
1220 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1221 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001222 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001223 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001224 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001225.Lnot_unlocked: // x1: original lock word
1226 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001227 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1228 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1229 uxth w2, w2 // zero top 16 bits
1230 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1231 // else contention, go to slow path
Hans Boehm67eda382017-01-17 15:03:38 -08001232 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001233 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001234 lsr w3, w2, #LOCK_WORD_GC_STATE_SHIFT // if the first gc state bit is set, we overflowed.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001235 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1236 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1237 stxr w3, w2, [x4]
1238 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001239 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001240.Llock_stxr_fail:
1241 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001242.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001243 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001244 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001245 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001246 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001247 REFRESH_MARKING_REGISTER
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001248 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1249END art_quick_lock_object
1250
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001251ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001252 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001253 mov x1, xSELF // pass Thread::Current
1254 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001255 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001256 REFRESH_MARKING_REGISTER
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001257 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1258END art_quick_lock_object_no_inline
1259
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001260 /*
1261 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1262 * x0 holds the possibly null object to lock.
1263 *
1264 * Derived from arm32 code.
1265 */
1266 .extern artUnlockObjectFromCode
1267ENTRY art_quick_unlock_object
1268 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001269 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1270.Lretry_unlock:
1271#ifndef USE_READ_BARRIER
1272 ldr w1, [x4]
1273#else
1274 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1275#endif
1276 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001277 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1278 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hans Boehm67eda382017-01-17 15:03:38 -08001279 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001280 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001281 uxth w3, w3 // zero top 16 bits
1282 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hans Boehm67eda382017-01-17 15:03:38 -08001283 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001284 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001285 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001286 // transition to unlocked
Hans Boehm67eda382017-01-17 15:03:38 -08001287 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED // w3: zero except for the preserved read barrier bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001288#ifndef USE_READ_BARRIER
Hans Boehm67eda382017-01-17 15:03:38 -08001289 stlr w3, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001290#else
Hans Boehm67eda382017-01-17 15:03:38 -08001291 stlxr w2, w3, [x4] // Need to use atomic instructions for read barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001292 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1293#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001294 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001295.Lrecursive_thin_unlock: // w1: original lock word
1296 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1297#ifndef USE_READ_BARRIER
1298 str w1, [x4]
1299#else
1300 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1301 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1302#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001303 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001304.Lunlock_stxr_fail:
Hans Boehm67eda382017-01-17 15:03:38 -08001305 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001306.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001307 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001308 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001309 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001310 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001311 REFRESH_MARKING_REGISTER
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001312 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1313END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001314
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001315ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001316 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001317 mov x1, xSELF // pass Thread::Current
1318 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001319 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001320 REFRESH_MARKING_REGISTER
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001321 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1322END art_quick_unlock_object_no_inline
1323
Andreas Gampe525cde22014-04-22 15:44:50 -07001324 /*
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001325 * Entry from managed code that calls artInstanceOfFromCode and on failure calls
1326 * artThrowClassCastExceptionForObject.
Andreas Gampe525cde22014-04-22 15:44:50 -07001327 */
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001328 .extern artInstanceOfFromCode
1329 .extern artThrowClassCastExceptionForObject
1330ENTRY art_quick_check_instance_of
Andreas Gampe525cde22014-04-22 15:44:50 -07001331 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001332 // Stack needs to be 16B aligned on calls.
Vladimir Marko215076b2016-09-07 18:05:55 +01001333 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1334 SAVE_REG xLR, 24
Andreas Gampe525cde22014-04-22 15:44:50 -07001335
1336 // Call runtime code
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001337 bl artInstanceOfFromCode
Andreas Gampe525cde22014-04-22 15:44:50 -07001338
Vladimir Markobf92b3f2018-01-17 18:11:30 +00001339 // Restore LR.
1340 RESTORE_REG xLR, 24
1341
Andreas Gampe525cde22014-04-22 15:44:50 -07001342 // Check for exception
1343 cbz x0, .Lthrow_class_cast_exception
1344
1345 // Restore and return
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001346 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001347 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001348 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001349 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001350 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampe6b90d422015-06-26 19:49:24 -07001351
Andreas Gampe525cde22014-04-22 15:44:50 -07001352.Lthrow_class_cast_exception:
1353 // Restore
Vladimir Marko215076b2016-09-07 18:05:55 +01001354 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001355
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001356 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001357 mov x2, xSELF // pass Thread::Current
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001358 bl artThrowClassCastExceptionForObject // (Object*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001359 brk 0 // We should not return here...
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001360END art_quick_check_instance_of
Andreas Gampe525cde22014-04-22 15:44:50 -07001361
Man Cao1aee9002015-07-14 22:31:42 -07001362// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1363.macro POP_REG_NE xReg, offset, xExclude
1364 .ifnc \xReg, \xExclude
1365 ldr \xReg, [sp, #\offset] // restore xReg
1366 .cfi_restore \xReg
1367 .endif
1368.endm
1369
Roland Levillain4359e612016-07-20 11:32:19 +01001370// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1371// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1372.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1373 .ifc \xReg1, \xExclude
1374 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1375 .else
1376 .ifc \xReg2, \xExclude
1377 ldr \xReg1, [sp, #\offset] // restore xReg1
1378 .else
1379 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1380 .endif
1381 .endif
1382 .cfi_restore \xReg1
1383 .cfi_restore \xReg2
1384.endm
1385
Man Cao1aee9002015-07-14 22:31:42 -07001386 /*
1387 * Macro to insert read barrier, only used in art_quick_aput_obj.
1388 * xDest, wDest and xObj are registers, offset is a defined literal such as
1389 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1390 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1391 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1392 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001393.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001394#ifdef USE_READ_BARRIER
Roland Levillain97c46462017-05-11 14:04:03 +01001395# ifdef USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001396 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1397 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1398 // False dependency to avoid needing load/load fence.
1399 add \xObj, \xObj, \xTemp, lsr #32
1400 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1401 UNPOISON_HEAP_REF \wDest
1402 b .Lrb_exit\number
Roland Levillain97c46462017-05-11 14:04:03 +01001403# endif // USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001404.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001405 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
Vladimir Marko215076b2016-09-07 18:05:55 +01001406 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1407 SAVE_TWO_REGS x2, x3, 16
1408 SAVE_TWO_REGS x4, xLR, 32
Man Cao1aee9002015-07-14 22:31:42 -07001409
Man Cao63069212015-08-21 15:51:39 -07001410 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001411 .ifnc \xObj, x1
1412 mov x1, \xObj // pass xObj
1413 .endif
1414 mov w2, #\offset // pass offset
1415 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1416 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1417 .ifnc \wDest, w0
1418 mov \wDest, w0 // save return value in wDest
1419 .endif
1420
1421 // Conditionally restore saved registers
1422 POP_REG_NE x0, 0, \xDest
1423 POP_REG_NE x1, 8, \xDest
1424 POP_REG_NE x2, 16, \xDest
1425 POP_REG_NE x3, 24, \xDest
1426 POP_REG_NE x4, 32, \xDest
Vladimir Marko215076b2016-09-07 18:05:55 +01001427 RESTORE_REG xLR, 40
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001428 DECREASE_FRAME 48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001429.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001430#else
1431 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1432 UNPOISON_HEAP_REF \wDest
1433#endif // USE_READ_BARRIER
1434.endm
1435
Man Cao1aee9002015-07-14 22:31:42 -07001436#ifdef USE_READ_BARRIER
1437 .extern artReadBarrierSlow
1438#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001439ENTRY art_quick_aput_obj
1440 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001441 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1442 // This also zero-extends to x3
1443 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1444 // This also zero-extends to x3
1445 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1446 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001447 cmp w3, w4 // value's type == array's component type - trivial assignability
1448 bne .Lcheck_assignability
1449.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001450 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001451 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001452 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001453 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1454 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001455 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001456 strb w3, [x3, x0]
1457 ret
1458.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001459 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001460 // "Compress" = do nothing
1461 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1462 ret
1463.Lcheck_assignability:
1464 // Store arguments and link register
Vladimir Marko215076b2016-09-07 18:05:55 +01001465 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1466 SAVE_TWO_REGS x2, xLR, 16
Andreas Gampef4e910b2014-04-29 16:55:52 -07001467
1468 // Call runtime code
1469 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1470 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1471 bl artIsAssignableFromCode
1472
1473 // Check for exception
1474 cbz x0, .Lthrow_array_store_exception
1475
1476 // Restore
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001477 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001478 RESTORE_TWO_REGS x2, xLR, 16
1479 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001480
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001481 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001482 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001483 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001484 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1485 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001486 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001487 strb w3, [x3, x0]
1488 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001489 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001490 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampef4e910b2014-04-29 16:55:52 -07001491.Lthrow_array_store_exception:
Vladimir Marko215076b2016-09-07 18:05:55 +01001492 RESTORE_TWO_REGS x2, xLR, 16
1493 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001494
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001495 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko908eb222016-09-14 10:29:18 +01001496 mov x1, x2 // Pass value.
1497 mov x2, xSELF // Pass Thread::Current.
1498 bl artThrowArrayStoreException // (Object*, Object*, Thread*).
1499 brk 0 // Unreached.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001500END art_quick_aput_obj
1501
Stuart Monteithb95a5342014-03-12 13:32:32 +00001502// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001503.macro ONE_ARG_DOWNCALL name, entrypoint, return
1504 .extern \entrypoint
1505ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001506 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001507 mov x1, xSELF // pass Thread::Current
1508 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001509 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001510 REFRESH_MARKING_REGISTER
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001511 \return
1512END \name
1513.endm
1514
1515// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001516.macro TWO_ARG_DOWNCALL name, entrypoint, return
1517 .extern \entrypoint
1518ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001519 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001520 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001521 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001522 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001523 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001524 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001525END \name
1526.endm
1527
Jeff Hao848f70a2014-01-15 13:49:50 -08001528// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001529.macro THREE_ARG_DOWNCALL name, entrypoint, return
1530 .extern \entrypoint
1531ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001532 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001533 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001534 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001535 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001536 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001537 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001538END \name
1539.endm
1540
Jeff Hao848f70a2014-01-15 13:49:50 -08001541// Macro to facilitate adding new allocation entrypoints.
1542.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1543 .extern \entrypoint
1544ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001545 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001546 mov x4, xSELF // pass Thread::Current
1547 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001548 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001549 REFRESH_MARKING_REGISTER
Jeff Hao848f70a2014-01-15 13:49:50 -08001550 \return
Jeff Hao848f70a2014-01-15 13:49:50 -08001551END \name
1552.endm
1553
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001554// Macros taking opportunity of code similarities for downcalls.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001555.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1556 .extern \entrypoint
1557ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001558 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001559 mov x1, xSELF // pass Thread::Current
1560 bl \entrypoint // (uint32_t type_idx, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001561 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001562 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001563 \return
1564END \name
1565.endm
1566
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001567.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1568 .extern \entrypoint
1569ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001570 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001571 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001572 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001573 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001574 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001575 \return
1576END \name
1577.endm
1578
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001579.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1580 .extern \entrypoint
1581ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001582 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001583 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001584 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001585 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001586 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001587 \return
1588END \name
1589.endm
1590
Vladimir Markoea4c1262017-02-06 19:59:33 +00001591// Macro for string and type resolution and initialization.
Mingyao Yang0a87a652017-04-12 13:43:15 -07001592.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL name, entrypoint, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Markoea4c1262017-02-06 19:59:33 +00001593 .extern \entrypoint
1594ENTRY \name
Mingyao Yang0a87a652017-04-12 13:43:15 -07001595 SETUP_SAVE_EVERYTHING_FRAME \runtime_method_offset // save everything for stack crawl
Vladimir Markoea4c1262017-02-06 19:59:33 +00001596 mov x1, xSELF // pass Thread::Current
1597 bl \entrypoint // (int32_t index, Thread* self)
1598 cbz w0, 1f // If result is null, deliver the OOME.
1599 .cfi_remember_state
1600 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
Roland Levillain97c46462017-05-11 14:04:03 +01001601 REFRESH_MARKING_REGISTER
Vladimir Markoea4c1262017-02-06 19:59:33 +00001602 ret // return
1603 .cfi_restore_state
1604 .cfi_def_cfa_offset FRAME_SIZE_SAVE_EVERYTHING // workaround for clang bug: 31975598
16051:
1606 DELIVER_PENDING_EXCEPTION_FRAME_READY
1607END \name
1608.endm
1609
Mingyao Yang0a87a652017-04-12 13:43:15 -07001610.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT name, entrypoint
1611 ONE_ARG_SAVE_EVERYTHING_DOWNCALL \name, \entrypoint, RUNTIME_SAVE_EVERYTHING_FOR_CLINIT_METHOD_OFFSET
1612.endm
1613
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001614.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1615 cbz w0, 1f // result zero branch over
1616 ret // return
16171:
1618 DELIVER_PENDING_EXCEPTION
1619.endm
1620
Matteo Franchindfd891a2014-04-30 12:17:17 +01001621 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001622 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1623 * failure.
1624 */
1625TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1626
1627 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001628 * Entry from managed code when uninitialized static storage, this stub will run the class
1629 * initializer and deliver the exception on error. On success the static storage base is
1630 * returned.
1631 */
Mingyao Yang0a87a652017-04-12 13:43:15 -07001632ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_static_storage, artInitializeStaticStorageFromCode
1633ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_type, artInitializeTypeFromCode
Vladimir Markoea4c1262017-02-06 19:59:33 +00001634ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode
1635ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_string, artResolveStringFromCode
Matteo Franchindfd891a2014-04-30 12:17:17 +01001636
Roland Levillain809f5b12018-01-04 14:05:59 +00001637// Note: Functions `art{Get,Set}<Kind>{Static,Instance}FromCompiledCode` are
1638// defined with a macro in runtime/entrypoints/quick/quick_field_entrypoints.cc.
Roland Levillain97c46462017-05-11 14:04:03 +01001639
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001640ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1641ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1642ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1643ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1644ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1645ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1646ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001647
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001648TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1649TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1650TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1651TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1652TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1653TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1654TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001655
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001656TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1657TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1658TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1659TWO_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1660TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001661
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001662THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1663THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1664THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1665THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1666THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001667
Stuart Monteithb95a5342014-03-12 13:32:32 +00001668// Generate the allocation entrypoints for each allocator.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001669GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
Mathieu Chartier8261d022016-08-08 09:41:04 -07001670// Comment out allocators that have arm64 specific asm.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001671// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1672// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1673GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001674// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001675// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
1676// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
1677// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
1678// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001679GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1680GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1681GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001682
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001683// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
1684// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
1685GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
1686// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
1687// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_tlab, TLAB)
1688// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_tlab, TLAB)
1689// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_tlab, TLAB)
1690// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_tlab, TLAB)
1691GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_tlab, TLAB)
1692GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_tlab, TLAB)
1693GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_tlab, TLAB)
1694
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001695// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1696// If isInitialized=0 the compiler can only assume it's been at least resolved.
1697.macro ART_QUICK_ALLOC_OBJECT_ROSALLOC c_name, cxx_name, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001698ENTRY \c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001699 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001700 // x0: type, xSELF(x19): Thread::Current
1701 // x1-x7: free.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001702 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1703 // allocation stack has room.
1704 // ldp won't work due to large offset.
1705 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1706 cmp x3, x4
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001707 bhs .Lslow_path\c_name
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001708 ldr w3, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3)
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001709 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001710 // local allocation. Also does the
1711 // finalizable and initialization
1712 // checks.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001713 // When isInitialized == 0, then the class is potentially not yet initialized.
1714 // If the class is not yet initialized, the object size will be very large to force the branch
1715 // below to be taken.
1716 //
1717 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001718 bhs .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001719 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001720 // from the size. Since the size is
1721 // already aligned we can combine the
1722 // two shifts together.
1723 add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1724 // Subtract pointer size since ther
1725 // are no runs for 0 byte allocations
1726 // and the size is already aligned.
1727 ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001728 // Load the free list head (x3). This
1729 // will be the return val.
1730 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001731 cbz x3, .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001732 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1733 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1734 // and update the list head with the
1735 // next pointer.
1736 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1737 // Store the class pointer in the
1738 // header. This also overwrites the
1739 // next pointer. The offsets are
1740 // asserted to match.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001741
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001742#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1743#error "Class pointer needs to overwrite next pointer."
1744#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001745 POISON_HEAP_REF w0
1746 str w0, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001747 // Push the new object onto the thread
1748 // local allocation stack and
1749 // increment the thread local
1750 // allocation stack top.
1751 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1752 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1753 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1754 // Decrement the size of the free list
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001755
1756 // After this "STR" the object is published to the thread local allocation stack,
1757 // and it will be observable from a runtime internal (eg. Heap::VisitObjects) point of view.
1758 // It is not yet visible to the running (user) compiled code until after the return.
1759 //
1760 // To avoid the memory barrier prior to the "STR", a trick is employed, by differentiating
1761 // the state of the allocation stack slot. It can be a pointer to one of:
1762 // 0) Null entry, because the stack was bumped but the new pointer wasn't written yet.
1763 // (The stack initial state is "null" pointers).
1764 // 1) A partially valid object, with an invalid class pointer to the next free rosalloc slot.
1765 // 2) A fully valid object, with a valid class pointer pointing to a real class.
1766 // Other states are not allowed.
1767 //
1768 // An object that is invalid only temporarily, and will eventually become valid.
1769 // The internal runtime code simply checks if the object is not null or is partial and then
1770 // ignores it.
1771 //
1772 // (Note: The actual check is done by seeing if a non-null object has a class pointer pointing
1773 // to ClassClass, and that the ClassClass's class pointer is self-cyclic. A rosalloc free slot
1774 // "next" pointer is not-cyclic.)
1775 //
1776 // See also b/28790624 for a listing of CLs dealing with this race.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001777 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1778 sub x1, x1, #1
1779 // TODO: consider combining this store
1780 // and the list head store above using
1781 // strd.
1782 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001783
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001784 mov x0, x3 // Set the return value and return.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001785.if \isInitialized == 0
1786 // This barrier is only necessary when the allocation also requires
1787 // a class initialization check.
1788 //
1789 // If the class is already observably initialized, then new-instance allocations are protected
1790 // from publishing by the compiler which inserts its own StoreStore barrier.
1791 dmb ish
1792 // Use a "dmb ish" fence here because if there are later loads of statics (e.g. class size),
1793 // they should happen-after the implicit initialization check.
1794 //
1795 // TODO: Remove this dmb for class initialization checks (b/36692143) by introducing
1796 // a new observably-initialized class state.
1797.endif
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001798 ret
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001799.Lslow_path\c_name:
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001800 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1801 mov x1, xSELF // pass Thread::Current
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001802 bl \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001803 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001804 REFRESH_MARKING_REGISTER
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001805 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001806END \c_name
1807.endm
1808
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001809ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_resolved_rosalloc, artAllocObjectFromCodeResolvedRosAlloc, /* isInitialized */ 0
1810ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_initialized_rosalloc, artAllocObjectFromCodeInitializedRosAlloc, /* isInitialized */ 1
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001811
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001812// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1813// If isInitialized=0 the compiler can only assume it's been at least resolved.
1814.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001815 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1816 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
1817 ldr w7, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7).
1818 add x6, x4, x7 // Add object size to tlab pos.
1819 cmp x6, x5 // Check if it fits, overflow works
1820 // since the tlab pos and end are 32
1821 // bit values.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001822
1823 // When isInitialized == 0, then the class is potentially not yet initialized.
1824 // If the class is not yet initialized, the object size will be very large to force the branch
1825 // below to be taken.
1826 //
1827 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001828 bhi \slowPathLabel
1829 str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1830 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1831 add x5, x5, #1
1832 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1833 POISON_HEAP_REF w0
1834 str w0, [x4, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1835 // Fence. This is "ish" not "ishst" so
1836 // that the code after this allocation
1837 // site will see the right values in
1838 // the fields of the class.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001839 mov x0, x4
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001840.if \isInitialized == 0
1841 // This barrier is only necessary when the allocation also requires
1842 // a class initialization check.
1843 //
1844 // If the class is already observably initialized, then new-instance allocations are protected
1845 // from publishing by the compiler which inserts its own StoreStore barrier.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001846 dmb ish
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001847 // Use a "dmb ish" fence here because if there are later loads of statics (e.g. class size),
1848 // they should happen-after the implicit initialization check.
1849 //
1850 // TODO: Remove this dmb for class initialization checks (b/36692143) by introducing
1851 // a new observably-initialized class state.
1852.endif
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001853 ret
1854.endm
1855
1856// The common code for art_quick_alloc_object_*region_tlab
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001857.macro GENERATE_ALLOC_OBJECT_RESOLVED_TLAB name, entrypoint, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001858ENTRY \name
1859 // Fast path region tlab allocation.
1860 // x0: type, xSELF(x19): Thread::Current
1861 // x1-x7: free.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001862 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED .Lslow_path\name, \isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001863.Lslow_path\name:
1864 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
1865 mov x1, xSELF // Pass Thread::Current.
1866 bl \entrypoint // (mirror::Class*, Thread*)
1867 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001868 REFRESH_MARKING_REGISTER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001869 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1870END \name
1871.endm
1872
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001873GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, /* isInitialized */ 0
1874GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, /* isInitialized */ 1
1875GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_tlab, artAllocObjectFromCodeResolvedTLAB, /* isInitialized */ 0
1876GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_tlab, artAllocObjectFromCodeInitializedTLAB, /* isInitialized */ 1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001877
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001878.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
Roland Levillain97c46462017-05-11 14:04:03 +01001879 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignment mask
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001880 // (addr + 7) & ~7. The mask must
1881 // be 64 bits to keep high bits in
1882 // case of overflow.
1883 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1884 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1885 // 32 bit int. Since the max shift for arrays is 3, it can not become a negative 64 bit int.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001886 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1887 bhs \slowPathLabel // path.
1888
1889 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1890 // we use (end - begin) to handle
1891 // negative size arrays. It is
1892 // assumed that a negative size will
1893 // always be greater unsigned than
1894 // region size.
1895 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1896 sub \xTemp2, \xTemp2, \xTemp0
1897 cmp \xTemp1, \xTemp2
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001898
1899 // The array class is always initialized here. Unlike new-instance,
1900 // this does not act as a double test.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001901 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001902 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1903 // Move old thread_local_pos to x0
1904 // for the return value.
1905 mov x0, \xTemp0
1906 add \xTemp0, \xTemp0, \xTemp1
1907 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1908 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1909 add \xTemp0, \xTemp0, #1
1910 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1911 POISON_HEAP_REF \wClass
1912 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1913 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1914 // Fence.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001915// new-array is special. The class is loaded and immediately goes to the Initialized state
1916// before it is published. Therefore the only fence needed is for the publication of the object.
1917// See ClassLinker::CreateArrayClass() for more details.
1918
1919// For publication of the new array, we don't need a 'dmb ishst' here.
1920// The compiler generates 'dmb ishst' for all new-array insts.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001921 ret
1922.endm
1923
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001924.macro GENERATE_ALLOC_ARRAY_TLAB name, entrypoint, size_setup
Mathieu Chartier8261d022016-08-08 09:41:04 -07001925ENTRY \name
1926 // Fast path array allocation for region tlab allocation.
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001927 // x0: mirror::Class* type
Mathieu Chartier8261d022016-08-08 09:41:04 -07001928 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001929 // x2-x7: free.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001930 mov x3, x0
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001931 \size_setup x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1932 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
Mathieu Chartier8261d022016-08-08 09:41:04 -07001933.Lslow_path\name:
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001934 // x0: mirror::Class* klass
Mathieu Chartier8261d022016-08-08 09:41:04 -07001935 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001936 // x2: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001937 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001938 mov x2, xSELF // pass Thread::Current
Mathieu Chartier8261d022016-08-08 09:41:04 -07001939 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001940 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001941 REFRESH_MARKING_REGISTER
Mathieu Chartier8261d022016-08-08 09:41:04 -07001942 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1943END \name
1944.endm
1945
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001946.macro COMPUTE_ARRAY_SIZE_UNKNOWN xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1947 // Array classes are never finalizable or uninitialized, no need to check.
1948 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1949 UNPOISON_HEAP_REF \wTemp0
1950 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1951 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1952 // bits.
1953 // xCount is holding a 32 bit value,
1954 // it can not overflow.
1955 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1956 // Add array data offset and alignment.
1957 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1958#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1959#error Long array data offset must be 4 greater than int array data offset.
1960#endif
1961
1962 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1963 // component size shift is 3
1964 // (for 64 bit alignment).
1965 and \xTemp0, \xTemp0, #4
1966 add \xTemp1, \xTemp1, \xTemp0
1967.endm
1968
1969.macro COMPUTE_ARRAY_SIZE_8 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1970 // Add array data offset and alignment.
1971 add \xTemp1, \xCount, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1972.endm
1973
1974.macro COMPUTE_ARRAY_SIZE_16 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1975 lsl \xTemp1, \xCount, #1
1976 // Add array data offset and alignment.
1977 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1978.endm
1979
1980.macro COMPUTE_ARRAY_SIZE_32 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1981 lsl \xTemp1, \xCount, #2
1982 // Add array data offset and alignment.
1983 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1984.endm
1985
1986.macro COMPUTE_ARRAY_SIZE_64 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1987 lsl \xTemp1, \xCount, #3
1988 // Add array data offset and alignment.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001989 add \xTemp1, \xTemp1, #(MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001990.endm
1991
Roland Levillain97c46462017-05-11 14:04:03 +01001992// TODO(ngeoffray): art_quick_alloc_array_resolved_region_tlab is not used for arm64, remove
1993// the entrypoint once all backends have been updated to use the size variants.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001994GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1995GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_8
1996GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_16
1997GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_32
1998GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_64
1999GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
2000GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_8
2001GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_16
2002GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_32
2003GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_64
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08002004
Zheng Xu48241e72014-05-23 11:52:42 +08002005 /*
Zheng Xu69a50302015-04-14 20:04:41 +08002006 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08002007 */
2008 .extern artTestSuspendFromCode
2009ENTRY art_quick_test_suspend
Mingyao Yang0a87a652017-04-12 13:43:15 -07002010 SETUP_SAVE_EVERYTHING_FRAME RUNTIME_SAVE_EVERYTHING_FOR_SUSPEND_CHECK_METHOD_OFFSET // save callee saves for stack crawl
Zheng Xu48241e72014-05-23 11:52:42 +08002011 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002012 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002013 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002014 REFRESH_MARKING_REGISTER
Vladimir Marko952dbb12016-07-28 12:01:51 +01002015 ret
Zheng Xu48241e72014-05-23 11:52:42 +08002016END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00002017
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002018ENTRY art_quick_implicit_suspend
2019 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002020 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002021 bl artTestSuspendFromCode // (Thread*)
Roland Levillain97c46462017-05-11 14:04:03 +01002022 RESTORE_SAVE_REFS_ONLY_FRAME
2023 REFRESH_MARKING_REGISTER
2024 ret
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002025END art_quick_implicit_suspend
2026
Andreas Gampee62a07e2014-03-26 14:53:21 -07002027 /*
2028 * Called by managed code that is attempting to call a method on a proxy class. On entry
2029 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2030 * method agrees with a ref and args callee save frame.
2031 */
2032 .extern artQuickProxyInvokeHandler
2033ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002034 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07002035 mov x2, xSELF // pass Thread::Current
2036 mov x3, sp // pass SP
2037 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002038 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07002039 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002040 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Roland Levillain97c46462017-05-11 14:04:03 +01002041 REFRESH_MARKING_REGISTER
Andreas Gamped1e91672014-06-02 22:50:05 -07002042 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07002043 ret // return on success
2044.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002045 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07002046 DELIVER_PENDING_EXCEPTION
2047END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00002048
Andreas Gampe51f76352014-05-21 08:28:48 -07002049 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002050 * Called to resolve an imt conflict.
2051 * x0 is the conflict ArtMethod.
2052 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2053 *
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002054 * Note that this stub writes to xIP0, xIP1, x13-x15, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002055 */
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002056 .extern artLookupResolvedMethod
Andreas Gampe51f76352014-05-21 08:28:48 -07002057ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002058 ldr xIP0, [sp, #0] // Load referrer
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002059 // Load the declaring class (without read barrier) and access flags (for obsolete method check).
2060 // The obsolete flag is set with suspended threads, so we do not need an acquire operation here.
2061#if ART_METHOD_ACCESS_FLAGS_OFFSET != ART_METHOD_DECLARING_CLASS_OFFSET + 4
2062#error "Expecting declaring class and access flags to be consecutive for LDP."
2063#endif
2064 ldp wIP0, w15, [xIP0, #ART_METHOD_DECLARING_CLASS_OFFSET]
2065 // If the method is obsolete, just go through the dex cache miss slow path.
2066 tbnz x15, #ACC_OBSOLETE_METHOD_SHIFT, .Limt_conflict_trampoline_dex_cache_miss
2067 ldr wIP0, [xIP0, #MIRROR_CLASS_DEX_CACHE_OFFSET] // Load the DexCache (without read barrier).
2068 UNPOISON_HEAP_REF wIP0
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002069 ubfx x15, xIP1, #0, #METHOD_DEX_CACHE_HASH_BITS // Calculate DexCache method slot index.
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002070 ldr xIP0, [xIP0, #MIRROR_DEX_CACHE_RESOLVED_METHODS_OFFSET] // Load the resolved methods.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002071 add xIP0, xIP0, x15, lsl #(POINTER_SIZE_SHIFT + 1) // Load DexCache method slot address.
2072
2073 // Relaxed atomic load x14:x15 from the dex cache slot.
2074.Limt_conflict_trampoline_retry_load:
2075 ldxp x14, x15, [xIP0]
2076 stxp w13, x14, x15, [xIP0]
2077 cbnz w13, .Limt_conflict_trampoline_retry_load
2078
2079 cmp x15, xIP1 // Compare method index to see if we had a DexCache method hit.
2080 bne .Limt_conflict_trampoline_dex_cache_miss
2081.Limt_conflict_trampoline_have_interface_method:
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002082 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2083 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2084.Limt_table_iterate:
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002085 cmp x0, x14
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002086 // Branch if found. Benchmarks have shown doing a branch here is better.
2087 beq .Limt_table_found
2088 // If the entry is null, the interface method is not in the ImtConflictTable.
2089 cbz x0, .Lconflict_trampoline
2090 // Iterate over the entries of the ImtConflictTable.
2091 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2092 b .Limt_table_iterate
2093.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002094 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002095 // and jump to it.
2096 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2097 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2098 br xIP0
2099.Lconflict_trampoline:
2100 // Call the runtime stub to populate the ImtConflictTable and jump to the
2101 // resolved method.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002102 mov x0, x14 // Load interface method
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002103 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002104.Limt_conflict_trampoline_dex_cache_miss:
2105 // We're not creating a proper runtime method frame here,
2106 // artLookupResolvedMethod() is not allowed to walk the stack.
2107
2108 // Save GPR args and return address, allocate space for FPR args, align stack.
2109 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2110 SAVE_TWO_REGS x2, x3, 16
2111 SAVE_TWO_REGS x4, x5, 32
2112 SAVE_TWO_REGS x6, x7, 48
2113 SAVE_REG xLR, (8 * 8 + 8 * 8 + 8)
2114
2115 // Save FPR args.
2116 stp d0, d1, [sp, #64]
2117 stp d2, d3, [sp, #80]
2118 stp d4, d5, [sp, #96]
2119 stp d6, d7, [sp, #112]
2120
2121 mov x0, xIP1 // Pass method index.
2122 ldr x1, [sp, #(8 * 8 + 8 * 8 + 8 + 8)] // Pass referrer.
2123 bl artLookupResolvedMethod // (uint32_t method_index, ArtMethod* referrer)
2124 mov x14, x0 // Move the interface method to x14 where the loop above expects it.
2125
2126 // Restore FPR args.
2127 ldp d0, d1, [sp, #64]
2128 ldp d2, d3, [sp, #80]
2129 ldp d4, d5, [sp, #96]
2130 ldp d6, d7, [sp, #112]
2131
2132 // Restore GPR args and return address.
2133 RESTORE_REG xLR, (8 * 8 + 8 * 8 + 8)
2134 RESTORE_TWO_REGS x2, x3, 16
2135 RESTORE_TWO_REGS x4, x5, 32
2136 RESTORE_TWO_REGS x6, x7, 48
2137 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2138
2139 // If the method wasn't resolved, skip the lookup and go to artInvokeInterfaceTrampoline().
2140 cbz x14, .Lconflict_trampoline
2141 b .Limt_conflict_trampoline_have_interface_method
Andreas Gampe51f76352014-05-21 08:28:48 -07002142END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002143
2144ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002145 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002146 mov x2, xSELF
2147 mov x3, sp
2148 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002149 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002150 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002151 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002152 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002153 REFRESH_MARKING_REGISTER
Zheng Xub551fdc2014-07-25 11:49:42 +08002154 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000021551:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002156 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002157 DELIVER_PENDING_EXCEPTION
2158END art_quick_resolution_trampoline
2159
2160/*
2161 * Generic JNI frame layout:
2162 *
2163 * #-------------------#
2164 * | |
2165 * | caller method... |
2166 * #-------------------# <--- SP on entry
2167 * | Return X30/LR |
2168 * | X29/FP | callee save
2169 * | X28 | callee save
2170 * | X27 | callee save
2171 * | X26 | callee save
2172 * | X25 | callee save
2173 * | X24 | callee save
2174 * | X23 | callee save
2175 * | X22 | callee save
2176 * | X21 | callee save
2177 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002178 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002179 * | X7 | arg7
2180 * | X6 | arg6
2181 * | X5 | arg5
2182 * | X4 | arg4
2183 * | X3 | arg3
2184 * | X2 | arg2
2185 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002186 * | D7 | float arg 8
2187 * | D6 | float arg 7
2188 * | D5 | float arg 6
2189 * | D4 | float arg 5
2190 * | D3 | float arg 4
2191 * | D2 | float arg 3
2192 * | D1 | float arg 2
2193 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002194 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002195 * #-------------------#
2196 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002197 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002198 * #-------------------#
2199 * | JNI Call Stack |
2200 * #-------------------# <--- SP on native call
2201 * | |
2202 * | Stack for Regs | The trampoline assembly will pop these values
2203 * | | into registers for native call
2204 * #-------------------#
2205 * | Native code ptr |
2206 * #-------------------#
2207 * | Free scratch |
2208 * #-------------------#
2209 * | Ptr to (1) | <--- SP
2210 * #-------------------#
2211 */
2212 /*
2213 * Called to do a generic JNI down-call
2214 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002215ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002216 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002217
2218 // Save SP , so we can have static CFI info.
2219 mov x28, sp
2220 .cfi_def_cfa_register x28
2221
2222 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002223 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002224 mov xFP, sp
2225
Zheng Xub551fdc2014-07-25 11:49:42 +08002226 mov xIP0, #5120
2227 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002228
2229 // prepare for artQuickGenericJniTrampoline call
2230 // (Thread*, SP)
2231 // x0 x1 <= C calling convention
2232 // xSELF xFP <= where they are
2233
2234 mov x0, xSELF // Thread*
2235 mov x1, xFP
2236 bl artQuickGenericJniTrampoline // (Thread*, sp)
2237
Andreas Gampec200a4a2014-06-16 18:39:09 -07002238 // The C call will have registered the complete save-frame on success.
2239 // The result of the call is:
2240 // x0: pointer to native code, 0 on error.
2241 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002242
Andreas Gampec200a4a2014-06-16 18:39:09 -07002243 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002244 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002245
Andreas Gampec200a4a2014-06-16 18:39:09 -07002246 // Release part of the alloca.
2247 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002248
Andreas Gampec200a4a2014-06-16 18:39:09 -07002249 // Save the code pointer
2250 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002251
2252 // Load parameters from frame into registers.
2253 // TODO Check with artQuickGenericJniTrampoline.
2254 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002255 ldp x0, x1, [sp]
2256 ldp x2, x3, [sp, #16]
2257 ldp x4, x5, [sp, #32]
2258 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002259
Andreas Gampec200a4a2014-06-16 18:39:09 -07002260 ldp d0, d1, [sp, #64]
2261 ldp d2, d3, [sp, #80]
2262 ldp d4, d5, [sp, #96]
2263 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002264
Andreas Gampec200a4a2014-06-16 18:39:09 -07002265 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002266
Zheng Xub551fdc2014-07-25 11:49:42 +08002267 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002268
2269 // result sign extension is handled in C code
2270 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002271 // (Thread*, result, result_f)
2272 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002273 mov x1, x0 // Result (from saved).
2274 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002275 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002276
2277 bl artQuickGenericJniEndTrampoline
2278
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002279 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002280 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002281 cbnz x2, .Lexception_in_native
2282
Stuart Monteithb95a5342014-03-12 13:32:32 +00002283 // Tear down the alloca.
2284 mov sp, x28
2285 .cfi_def_cfa_register sp
2286
Stuart Monteithb95a5342014-03-12 13:32:32 +00002287 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002288 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002289 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002290
2291 // store into fpr, for when it's a fpr return...
2292 fmov d0, x0
2293 ret
2294
Stuart Monteithb95a5342014-03-12 13:32:32 +00002295.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002296 // Move to x1 then sp to please assembler.
2297 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Vladimir Marko2196c652017-11-30 16:16:07 +00002298 add sp, x1, #-1 // Remove the GenericJNI tag.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002299 .cfi_def_cfa_register sp
2300 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002301 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002302END art_quick_generic_jni_trampoline
2303
2304/*
2305 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2306 * of a quick call:
2307 * x0 = method being called/to bridge to.
2308 * x1..x7, d0..d7 = arguments to that method.
2309 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002310ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002311 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002312
2313 // x0 will contain mirror::ArtMethod* method.
2314 mov x1, xSELF // How to get Thread::Current() ???
2315 mov x2, sp
2316
2317 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2318 // mirror::ArtMethod** sp)
2319 bl artQuickToInterpreterBridge
2320
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002321 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Roland Levillain97c46462017-05-11 14:04:03 +01002322 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002323
2324 fmov d0, x0
2325
2326 RETURN_OR_DELIVER_PENDING_EXCEPTION
2327END art_quick_to_interpreter_bridge
2328
Alex Lightdb01a092017-04-03 15:39:55 -07002329/*
2330 * Called to attempt to execute an obsolete method.
2331 */
2332ONE_ARG_RUNTIME_EXCEPTION art_invoke_obsolete_method_stub, artInvokeObsoleteMethod
2333
Andreas Gamped58342c2014-06-05 14:18:08 -07002334
2335//
2336// Instrumentation-related stubs
2337//
2338 .extern artInstrumentationMethodEntryFromCode
2339ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002340 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002341
Zheng Xub551fdc2014-07-25 11:49:42 +08002342 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002343
2344 mov x2, xSELF
Alex Lightb7edcda2017-04-27 13:20:31 -07002345 mov x3, sp // Pass SP
2346 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, SP)
Andreas Gamped58342c2014-06-05 14:18:08 -07002347
Zheng Xub551fdc2014-07-25 11:49:42 +08002348 mov xIP0, x0 // x0 = result of call.
2349 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002350
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002351 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Roland Levillain97c46462017-05-11 14:04:03 +01002352 REFRESH_MARKING_REGISTER
Alex Lightb7edcda2017-04-27 13:20:31 -07002353 cbz xIP0, 1f // Deliver the pending exception if method is null.
Andreas Gamped58342c2014-06-05 14:18:08 -07002354 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002355 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Alex Lightb7edcda2017-04-27 13:20:31 -07002356
23571:
2358 DELIVER_PENDING_EXCEPTION
Andreas Gamped58342c2014-06-05 14:18:08 -07002359END art_quick_instrumentation_entry
2360
2361 .extern artInstrumentationMethodExitFromCode
2362ENTRY art_quick_instrumentation_exit
2363 mov xLR, #0 // Clobber LR for later checks.
Mingyao Yang2ee17902017-08-30 11:37:08 -07002364 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002365
Mingyao Yang2ee17902017-08-30 11:37:08 -07002366 add x3, sp, #8 // Pass floating-point result pointer, in kSaveEverything frame.
2367 add x2, sp, #264 // Pass integer result pointer, in kSaveEverything frame.
2368 mov x1, sp // Pass SP.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002369 mov x0, xSELF // Pass Thread.
Alex Lightb7edcda2017-04-27 13:20:31 -07002370 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res*, fpr_res*)
Andreas Gamped58342c2014-06-05 14:18:08 -07002371
Mingyao Yang2ee17902017-08-30 11:37:08 -07002372 cbz x0, .Ldo_deliver_instrumentation_exception
2373 // Handle error
2374 cbnz x1, .Ldeoptimize
2375 // Normal return.
2376 str x0, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2377 // Set return pc.
2378 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002379 REFRESH_MARKING_REGISTER
Mingyao Yang2ee17902017-08-30 11:37:08 -07002380 br lr
2381.Ldo_deliver_instrumentation_exception:
2382 DELIVER_PENDING_EXCEPTION_FRAME_READY
2383.Ldeoptimize:
2384 str x1, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2385 // Set return pc.
2386 RESTORE_SAVE_EVERYTHING_FRAME
2387 // Jump to art_quick_deoptimize.
2388 b art_quick_deoptimize
Andreas Gamped58342c2014-06-05 14:18:08 -07002389END art_quick_instrumentation_exit
2390
2391 /*
2392 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2393 * will long jump to the upcall with a special exception of -1.
2394 */
2395 .extern artDeoptimize
2396ENTRY art_quick_deoptimize
Mingyao Yang2ee17902017-08-30 11:37:08 -07002397 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002398 mov x0, xSELF // Pass thread.
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002399 bl artDeoptimize // (Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002400 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002401END art_quick_deoptimize
2402
Sebastien Hertz07474662015-08-25 15:12:33 +00002403 /*
2404 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2405 * will long jump to the upcall with a special exception of -1.
2406 */
2407 .extern artDeoptimizeFromCompiledCode
2408ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002409 SETUP_SAVE_EVERYTHING_FRAME
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002410 mov x1, xSELF // Pass thread.
2411 bl artDeoptimizeFromCompiledCode // (DeoptimizationKind, Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002412 brk 0
2413END art_quick_deoptimize_from_compiled_code
2414
Andreas Gamped58342c2014-06-05 14:18:08 -07002415
Serban Constantinescu169489b2014-06-11 16:43:35 +01002416 /*
2417 * String's indexOf.
2418 *
2419 * TODO: Not very optimized.
2420 * On entry:
2421 * x0: string object (known non-null)
2422 * w1: char to match (known <= 0xFFFF)
2423 * w2: Starting offset in string data
2424 */
2425ENTRY art_quick_indexof
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002426#if (STRING_COMPRESSION_FEATURE)
2427 ldr w4, [x0, #MIRROR_STRING_COUNT_OFFSET]
2428#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002429 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002430#endif
Jeff Hao848f70a2014-01-15 13:49:50 -08002431 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
jessicahandojo05765752016-09-09 19:01:32 -07002432#if (STRING_COMPRESSION_FEATURE)
2433 /* w4 holds count (with flag) and w3 holds actual length */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002434 lsr w3, w4, #1
jessicahandojo05765752016-09-09 19:01:32 -07002435#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002436 /* Clamp start to [0..count] */
2437 cmp w2, #0
2438 csel w2, wzr, w2, lt
2439 cmp w2, w3
2440 csel w2, w3, w2, gt
2441
Serban Constantinescu169489b2014-06-11 16:43:35 +01002442 /* Save a copy to compute result */
2443 mov x5, x0
2444
jessicahandojo05765752016-09-09 19:01:32 -07002445#if (STRING_COMPRESSION_FEATURE)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002446 tbz w4, #0, .Lstring_indexof_compressed
jessicahandojo05765752016-09-09 19:01:32 -07002447#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002448 /* Build pointer to start of data to compare and pre-bias */
2449 add x0, x0, x2, lsl #1
2450 sub x0, x0, #2
Serban Constantinescu169489b2014-06-11 16:43:35 +01002451 /* Compute iteration count */
2452 sub w2, w3, w2
2453
2454 /*
2455 * At this point we have:
2456 * x0: start of the data to test
2457 * w1: char to compare
2458 * w2: iteration count
2459 * x5: original start of string data
2460 */
2461
2462 subs w2, w2, #4
2463 b.lt .Lindexof_remainder
2464
2465.Lindexof_loop4:
2466 ldrh w6, [x0, #2]!
2467 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002468 ldrh wIP0, [x0, #2]!
2469 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002470 cmp w6, w1
2471 b.eq .Lmatch_0
2472 cmp w7, w1
2473 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002474 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002475 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002476 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002477 b.eq .Lmatch_3
2478 subs w2, w2, #4
2479 b.ge .Lindexof_loop4
2480
2481.Lindexof_remainder:
2482 adds w2, w2, #4
2483 b.eq .Lindexof_nomatch
2484
2485.Lindexof_loop1:
2486 ldrh w6, [x0, #2]!
2487 cmp w6, w1
2488 b.eq .Lmatch_3
2489 subs w2, w2, #1
2490 b.ne .Lindexof_loop1
2491
2492.Lindexof_nomatch:
2493 mov x0, #-1
2494 ret
2495
2496.Lmatch_0:
2497 sub x0, x0, #6
2498 sub x0, x0, x5
2499 asr x0, x0, #1
2500 ret
2501.Lmatch_1:
2502 sub x0, x0, #4
2503 sub x0, x0, x5
2504 asr x0, x0, #1
2505 ret
2506.Lmatch_2:
2507 sub x0, x0, #2
2508 sub x0, x0, x5
2509 asr x0, x0, #1
2510 ret
2511.Lmatch_3:
2512 sub x0, x0, x5
2513 asr x0, x0, #1
2514 ret
jessicahandojo05765752016-09-09 19:01:32 -07002515#if (STRING_COMPRESSION_FEATURE)
2516 /*
2517 * Comparing compressed string character-per-character with
2518 * input character
2519 */
2520.Lstring_indexof_compressed:
2521 add x0, x0, x2
2522 sub x0, x0, #1
2523 sub w2, w3, w2
2524.Lstring_indexof_compressed_loop:
2525 subs w2, w2, #1
2526 b.lt .Lindexof_nomatch
2527 ldrb w6, [x0, #1]!
2528 cmp w6, w1
2529 b.eq .Lstring_indexof_compressed_matched
2530 b .Lstring_indexof_compressed_loop
2531.Lstring_indexof_compressed_matched:
2532 sub x0, x0, x5
2533 ret
2534#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002535END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002536
2537 /*
2538 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002539 * getting its argument and returning its result through W register
2540 * `wreg` (corresponding to X register `xreg`), saving and restoring
2541 * all caller-save registers.
2542 *
2543 * If `wreg` is different from `w0`, the generated function follows a
2544 * non-standard runtime calling convention:
2545 * - register `wreg` is used to pass the (sole) argument of this
2546 * function (instead of W0);
2547 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002548 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002549 * - W0 is treated like a normal (non-argument) caller-save register;
2550 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002551 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002552 */
Roland Levillain4359e612016-07-20 11:32:19 +01002553.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002554ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002555 // Reference is null, no work to do at all.
2556 cbz \wreg, .Lret_rb_\name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002557 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2558 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002559 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lnot_marked_rb_\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002560.Lret_rb_\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002561 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002562.Lnot_marked_rb_\name:
2563 // Check if the top two bits are one, if this is the case it is a forwarding address.
Vladimir Markob9d01112017-03-31 10:55:41 +01002564 tst wIP0, wIP0, lsl #1
2565 bmi .Lret_forwarding_address\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002566.Lslow_rb_\name:
Vladimir Markoea4c1262017-02-06 19:59:33 +00002567 /*
2568 * Allocate 44 stack slots * 8 = 352 bytes:
2569 * - 20 slots for core registers X0-15, X17-X19, LR
2570 * - 24 slots for floating-point registers D0-D7 and D16-D31
2571 */
2572 // We must not clobber IP1 since code emitted for HLoadClass and HLoadString
2573 // relies on IP1 being preserved.
Roland Levillain4359e612016-07-20 11:32:19 +01002574 // Save all potentially live caller-save core registers.
Vladimir Markoea4c1262017-02-06 19:59:33 +00002575 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
Vladimir Marko215076b2016-09-07 18:05:55 +01002576 SAVE_TWO_REGS x2, x3, 16
2577 SAVE_TWO_REGS x4, x5, 32
2578 SAVE_TWO_REGS x6, x7, 48
2579 SAVE_TWO_REGS x8, x9, 64
2580 SAVE_TWO_REGS x10, x11, 80
2581 SAVE_TWO_REGS x12, x13, 96
2582 SAVE_TWO_REGS x14, x15, 112
Vladimir Markoea4c1262017-02-06 19:59:33 +00002583 SAVE_TWO_REGS x17, x18, 128 // Skip x16, i.e. IP0.
2584 SAVE_TWO_REGS x19, xLR, 144 // Save also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002585 // Save all potentially live caller-save floating-point registers.
2586 stp d0, d1, [sp, #160]
2587 stp d2, d3, [sp, #176]
2588 stp d4, d5, [sp, #192]
2589 stp d6, d7, [sp, #208]
2590 stp d16, d17, [sp, #224]
2591 stp d18, d19, [sp, #240]
2592 stp d20, d21, [sp, #256]
2593 stp d22, d23, [sp, #272]
2594 stp d24, d25, [sp, #288]
2595 stp d26, d27, [sp, #304]
2596 stp d28, d29, [sp, #320]
2597 stp d30, d31, [sp, #336]
Roland Levillain4359e612016-07-20 11:32:19 +01002598
2599 .ifnc \wreg, w0
2600 mov w0, \wreg // Pass arg1 - obj from `wreg`
2601 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002602 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002603 .ifnc \wreg, w0
2604 mov \wreg, w0 // Return result into `wreg`
2605 .endif
2606
2607 // Restore core regs, except `xreg`, as `wreg` is used to return the
2608 // result of this function (simply remove it from the stack instead).
2609 POP_REGS_NE x0, x1, 0, \xreg
2610 POP_REGS_NE x2, x3, 16, \xreg
2611 POP_REGS_NE x4, x5, 32, \xreg
2612 POP_REGS_NE x6, x7, 48, \xreg
2613 POP_REGS_NE x8, x9, 64, \xreg
2614 POP_REGS_NE x10, x11, 80, \xreg
2615 POP_REGS_NE x12, x13, 96, \xreg
2616 POP_REGS_NE x14, x15, 112, \xreg
Vladimir Markoea4c1262017-02-06 19:59:33 +00002617 POP_REGS_NE x17, x18, 128, \xreg
2618 POP_REGS_NE x19, xLR, 144, \xreg // Restore also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002619 // Restore floating-point registers.
2620 ldp d0, d1, [sp, #160]
2621 ldp d2, d3, [sp, #176]
2622 ldp d4, d5, [sp, #192]
2623 ldp d6, d7, [sp, #208]
2624 ldp d16, d17, [sp, #224]
2625 ldp d18, d19, [sp, #240]
2626 ldp d20, d21, [sp, #256]
2627 ldp d22, d23, [sp, #272]
2628 ldp d24, d25, [sp, #288]
2629 ldp d26, d27, [sp, #304]
2630 ldp d28, d29, [sp, #320]
2631 ldp d30, d31, [sp, #336]
Vladimir Markoea4c1262017-02-06 19:59:33 +00002632 // Remove frame and return.
2633 DECREASE_FRAME 352
Roland Levillain02b75802016-07-13 11:54:35 +01002634 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002635.Lret_forwarding_address\name:
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002636 // Shift left by the forwarding address shift. This clears out the state bits since they are
2637 // in the top 2 bits of the lock word.
Vladimir Markob9d01112017-03-31 10:55:41 +01002638 lsl \wreg, wIP0, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002639 ret
Roland Levillain02b75802016-07-13 11:54:35 +01002640END \name
2641.endm
2642
Roland Levillain4359e612016-07-20 11:32:19 +01002643READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2644READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2645READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2646READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2647READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2648READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2649READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2650READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2651READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2652READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2653READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2654READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2655READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2656READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2657READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2658READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
Mathieu Chartier36c22712016-08-12 13:19:44 -07002659// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
Roland Levillain4359e612016-07-20 11:32:19 +01002660READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2661READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2662READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2663READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2664READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2665READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2666READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2667READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2668READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2669READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2670READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2671READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2672READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29
Orion Hodsonac141392017-01-13 11:53:47 +00002673
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002674
2675.macro SELECT_X_OR_W_FOR_MACRO macro_to_use, x, w, xreg
2676 .if \xreg
2677 \macro_to_use \x
2678 .else
2679 \macro_to_use \w
2680 .endif
2681.endm
2682
2683.macro FOR_REGISTERS macro_for_register, macro_for_reserved_register, xreg
2684 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x0, w0, \xreg
2685 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x1, w1, \xreg
2686 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x2, w2, \xreg
2687 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x3, w3, \xreg
2688 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x4, w4, \xreg
2689 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x5, w5, \xreg
2690 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x6, w6, \xreg
2691 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x7, w7, \xreg
2692 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x8, w8, \xreg
2693 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x9, w9, \xreg
2694 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x10, w10, \xreg
2695 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x11, w11, \xreg
2696 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x12, w12, \xreg
2697 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x13, w13, \xreg
2698 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x14, w14, \xreg
2699 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x15, w15, \xreg
2700 \macro_for_reserved_register // IP0 is reserved
2701 \macro_for_reserved_register // IP1 is reserved
2702 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x18, w18, \xreg
2703 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x19, w19, \xreg
2704 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x20, w20, \xreg
2705 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x21, w21, \xreg
2706 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x22, w22, \xreg
2707 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x23, w23, \xreg
2708 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x24, w24, \xreg
2709 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x25, w25, \xreg
2710 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x26, w26, \xreg
2711 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x27, w27, \xreg
2712 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x28, w28, \xreg
2713 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x29, w29, \xreg
2714 \macro_for_reserved_register // lr is reserved
2715 \macro_for_reserved_register // sp is reserved
2716.endm
2717
2718.macro FOR_XREGISTERS macro_for_register, macro_for_reserved_register
2719 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 1
2720.endm
2721
2722.macro FOR_WREGISTERS macro_for_register, macro_for_reserved_register
2723 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 0
2724.endm
2725
2726.macro BRK0_BRK0
2727 brk 0
2728 brk 0
2729.endm
2730
2731#if BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET != BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
2732#error "Array and field introspection code sharing requires same LDR offset."
2733#endif
2734.macro INTROSPECTION_ARRAY_LOAD index_reg
2735 ldr wIP0, [xIP0, \index_reg, lsl #2]
2736 b art_quick_read_barrier_mark_introspection
2737.endm
2738
2739.macro MOV_WIP0_TO_WREG_AND_BL_LR reg
2740 mov \reg, wIP0
2741 br lr // Do not use RET as we do not enter the entrypoint with "BL".
2742.endm
2743
2744.macro READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH ldr_offset
2745 /*
2746 * Allocate 44 stack slots * 8 = 352 bytes:
2747 * - 19 slots for core registers X0-15, X18-X19, LR
2748 * - 1 slot padding
2749 * - 24 slots for floating-point registers D0-D7 and D16-D31
2750 */
2751 // Save all potentially live caller-save core registers.
2752 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
2753 SAVE_TWO_REGS x2, x3, 16
2754 SAVE_TWO_REGS x4, x5, 32
2755 SAVE_TWO_REGS x6, x7, 48
2756 SAVE_TWO_REGS x8, x9, 64
2757 SAVE_TWO_REGS x10, x11, 80
2758 SAVE_TWO_REGS x12, x13, 96
2759 SAVE_TWO_REGS x14, x15, 112
2760 SAVE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2761 SAVE_REG xLR, 144 // Save return address, skip padding at 152.
2762 // Save all potentially live caller-save floating-point registers.
2763 stp d0, d1, [sp, #160]
2764 stp d2, d3, [sp, #176]
2765 stp d4, d5, [sp, #192]
2766 stp d6, d7, [sp, #208]
2767 stp d16, d17, [sp, #224]
2768 stp d18, d19, [sp, #240]
2769 stp d20, d21, [sp, #256]
2770 stp d22, d23, [sp, #272]
2771 stp d24, d25, [sp, #288]
2772 stp d26, d27, [sp, #304]
2773 stp d28, d29, [sp, #320]
2774 stp d30, d31, [sp, #336]
2775
2776 mov x0, xIP0
2777 bl artReadBarrierMark // artReadBarrierMark(obj)
2778 mov xIP0, x0
2779
2780 // Restore core regs, except x0 and x1 as the return register switch case
2781 // address calculation is smoother with an extra register.
2782 RESTORE_TWO_REGS x2, x3, 16
2783 RESTORE_TWO_REGS x4, x5, 32
2784 RESTORE_TWO_REGS x6, x7, 48
2785 RESTORE_TWO_REGS x8, x9, 64
2786 RESTORE_TWO_REGS x10, x11, 80
2787 RESTORE_TWO_REGS x12, x13, 96
2788 RESTORE_TWO_REGS x14, x15, 112
2789 RESTORE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2790 RESTORE_REG xLR, 144 // Restore return address.
Nicolas Geoffray7015e762017-07-02 21:37:02 +01002791 // Restore caller-save floating-point registers.
2792 ldp d0, d1, [sp, #160]
2793 ldp d2, d3, [sp, #176]
2794 ldp d4, d5, [sp, #192]
2795 ldp d6, d7, [sp, #208]
2796 ldp d16, d17, [sp, #224]
2797 ldp d18, d19, [sp, #240]
2798 ldp d20, d21, [sp, #256]
2799 ldp d22, d23, [sp, #272]
2800 ldp d24, d25, [sp, #288]
2801 ldp d26, d27, [sp, #304]
2802 ldp d28, d29, [sp, #320]
2803 ldp d30, d31, [sp, #336]
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002804
2805 ldr x0, [lr, #\ldr_offset] // Load the instruction.
2806 adr xIP1, .Lmark_introspection_return_switch
2807 bfi xIP1, x0, #3, #5 // Calculate switch case address.
2808 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 352
2809 br xIP1
2810.endm
2811
2812 /*
2813 * Use introspection to load a reference from the same address as the LDR
2814 * instruction in generated code would load (unless loaded by the thunk,
2815 * see below), call ReadBarrier::Mark() with that reference if needed
2816 * and return it in the same register as the LDR instruction would load.
2817 *
2818 * The entrypoint is called through a thunk that differs across load kinds.
2819 * For field and array loads the LDR instruction in generated code follows
2820 * the branch to the thunk, i.e. the LDR is at [LR, #-4], and the thunk
2821 * knows the holder and performs the gray bit check, returning to the LDR
2822 * instruction if the object is not gray, so this entrypoint no longer
2823 * needs to know anything about the holder. For GC root loads, the LDR
2824 * instruction in generated code precedes the branch to the thunk (i.e.
2825 * the LDR is at [LR, #-8]) and the thunk does not do the gray bit check.
2826 *
2827 * For field accesses and array loads with a constant index the thunk loads
2828 * the reference into IP0 using introspection and calls the main entrypoint,
Vladimir Markod1ef8732017-04-18 13:55:13 +01002829 * art_quick_read_barrier_mark_introspection. With heap poisoning enabled,
2830 * the passed reference is poisoned.
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002831 *
2832 * For array accesses with non-constant index, the thunk inserts the bits
2833 * 16-21 of the LDR instruction to the entrypoint address, effectively
2834 * calculating a switch case label based on the index register (bits 16-20)
2835 * and adding an extra offset (bit 21 is set) to differentiate from the
2836 * main entrypoint, then moves the base register to IP0 and jumps to the
2837 * switch case. Therefore we need to align the main entrypoint to 512 bytes,
2838 * accounting for a 256-byte offset followed by 32 array entrypoints
2839 * starting at art_quick_read_barrier_mark_introspection_arrays, each
2840 * containing an LDR (register) and a branch to the main entrypoint.
2841 *
2842 * For GC root accesses we cannot use the main entrypoint because of the
2843 * different offset where the LDR instruction in generated code is located.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002844 * (And even with heap poisoning enabled, GC roots are not poisoned.)
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002845 * To re-use the same entrypoint pointer in generated code, we make sure
2846 * that the gc root entrypoint (a copy of the entrypoint with a different
2847 * offset for introspection loads) is located at a known offset (768 bytes,
2848 * or BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET) from the main
2849 * entrypoint and the GC root thunk adjusts the entrypoint pointer, moves
2850 * the root register to IP0 and jumps to the customized entrypoint,
2851 * art_quick_read_barrier_mark_introspection_gc_roots. The thunk also
2852 * performs all the fast-path checks, so we need just the slow path.
2853 *
2854 * The code structure is
2855 * art_quick_read_barrier_mark_introspection:
2856 * Up to 256 bytes for the main entrypoint code.
2857 * Padding to 256 bytes if needed.
2858 * art_quick_read_barrier_mark_introspection_arrays:
2859 * Exactly 256 bytes for array load switch cases (32x2 instructions).
2860 * .Lmark_introspection_return_switch:
2861 * Exactly 256 bytes for return switch cases (32x2 instructions).
2862 * art_quick_read_barrier_mark_introspection_gc_roots:
2863 * GC root entrypoint code.
2864 */
2865 .balign 512
2866ENTRY art_quick_read_barrier_mark_introspection
2867 // At this point, IP0 contains the reference, IP1 can be freely used.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002868 // For heap poisoning, the reference is poisoned, so unpoison it first.
2869 UNPOISON_HEAP_REF wIP0
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002870 // If reference is null, just return it in the right register.
2871 cbz wIP0, .Lmark_introspection_return
2872 // Use wIP1 as temp and check the mark bit of the reference.
2873 ldr wIP1, [xIP0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2874 tbz wIP1, #LOCK_WORD_MARK_BIT_SHIFT, .Lmark_introspection_unmarked
2875.Lmark_introspection_return:
2876 // Without an extra register for the return switch case address calculation,
2877 // we exploit the high word of the xIP0 to temporarily store the ref_reg*8,
2878 // so the return switch below must move wIP0 instead of xIP0 to the register.
2879 ldr wIP1, [lr, #BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET] // Load the instruction.
2880 bfi xIP0, xIP1, #(32 + 3), #5 // Extract ref_reg*8 to high word in xIP0.
2881 adr xIP1, .Lmark_introspection_return_switch
2882 bfxil xIP1, xIP0, #32, #8 // Calculate return switch case address.
2883 br xIP1
2884.Lmark_introspection_unmarked:
2885 // Check if the top two bits are one, if this is the case it is a forwarding address.
2886 tst wIP1, wIP1, lsl #1
2887 bmi .Lmark_introspection_forwarding_address
2888 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET
2889
2890.Lmark_introspection_forwarding_address:
2891 // Shift left by the forwarding address shift. This clears out the state bits since they are
2892 // in the top 2 bits of the lock word.
2893 lsl wIP0, wIP1, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
2894 b .Lmark_introspection_return
2895
2896 // We're very close to the alloted 256B for the entrypoint code before the
2897 // array switch cases. Should we go a little bit over the limit, we can
2898 // move some code after the array switch cases and return switch cases.
2899 .balign 256
2900 .hidden art_quick_read_barrier_mark_introspection_arrays
2901 .global art_quick_read_barrier_mark_introspection_arrays
2902art_quick_read_barrier_mark_introspection_arrays:
2903 FOR_XREGISTERS INTROSPECTION_ARRAY_LOAD, BRK0_BRK0
2904.Lmark_introspection_return_switch:
2905 FOR_WREGISTERS MOV_WIP0_TO_WREG_AND_BL_LR, BRK0_BRK0
2906 .hidden art_quick_read_barrier_mark_introspection_gc_roots
2907 .global art_quick_read_barrier_mark_introspection_gc_roots
2908art_quick_read_barrier_mark_introspection_gc_roots:
2909 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET
2910END art_quick_read_barrier_mark_introspection
2911
Orion Hodsonac141392017-01-13 11:53:47 +00002912.extern artInvokePolymorphic
2913ENTRY art_quick_invoke_polymorphic
2914 SETUP_SAVE_REFS_AND_ARGS_FRAME // Save callee saves in case allocation triggers GC.
2915 mov x2, xSELF
2916 mov x3, sp
2917 INCREASE_FRAME 16 // Reserve space for JValue result.
2918 str xzr, [sp, #0] // Initialize result to zero.
2919 mov x0, sp // Set r0 to point to result.
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002920 bl artInvokePolymorphic // artInvokePolymorphic(result, receiver, thread, save_area)
Orion Hodsonac141392017-01-13 11:53:47 +00002921 uxtb w0, w0 // Result is the return type descriptor as a char.
2922 sub w0, w0, 'A' // Convert to zero based index.
2923 cmp w0, 'Z' - 'A'
2924 bhi .Lcleanup_and_return // Clean-up if out-of-bounds.
2925 adrp x1, .Lhandler_table // Compute address of handler table.
2926 add x1, x1, :lo12:.Lhandler_table
2927 ldrb w0, [x1, w0, uxtw] // Lookup handler offset in handler table.
2928 adr x1, .Lstart_of_handlers
2929 add x0, x1, w0, sxtb #2 // Convert relative offset to absolute address.
2930 br x0 // Branch to handler.
2931
2932.Lstart_of_handlers:
2933.Lstore_boolean_result:
2934 ldrb w0, [sp]
2935 b .Lcleanup_and_return
2936.Lstore_char_result:
2937 ldrh w0, [sp]
2938 b .Lcleanup_and_return
2939.Lstore_float_result:
2940 ldr s0, [sp]
2941 str s0, [sp, #32]
2942 b .Lcleanup_and_return
2943.Lstore_double_result:
2944 ldr d0, [sp]
2945 str d0, [sp, #32]
2946 b .Lcleanup_and_return
2947.Lstore_long_result:
2948 ldr x0, [sp]
2949 // Fall-through
2950.Lcleanup_and_return:
2951 DECREASE_FRAME 16
2952 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002953 REFRESH_MARKING_REGISTER
Orion Hodsonac141392017-01-13 11:53:47 +00002954 RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
2955
2956 .section .rodata // Place handler table in read-only section away from text.
2957 .align 2
2958.macro HANDLER_TABLE_OFFSET handler_label
2959 .byte (\handler_label - .Lstart_of_handlers) / 4
2960.endm
2961.Lhandler_table:
2962 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // A
2963 HANDLER_TABLE_OFFSET(.Lstore_long_result) // B (byte)
2964 HANDLER_TABLE_OFFSET(.Lstore_char_result) // C (char)
2965 HANDLER_TABLE_OFFSET(.Lstore_double_result) // D (double)
2966 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // E
2967 HANDLER_TABLE_OFFSET(.Lstore_float_result) // F (float)
2968 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // G
2969 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // H
2970 HANDLER_TABLE_OFFSET(.Lstore_long_result) // I (int)
2971 HANDLER_TABLE_OFFSET(.Lstore_long_result) // J (long)
2972 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // K
2973 HANDLER_TABLE_OFFSET(.Lstore_long_result) // L (object - references are compressed and only 32-bits)
2974 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // M
2975 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // N
2976 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // O
2977 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // P
2978 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Q
2979 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // R
2980 HANDLER_TABLE_OFFSET(.Lstore_long_result) // S (short)
2981 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // T
2982 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // U
2983 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // V (void)
2984 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // W
2985 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // X
2986 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Y
2987 HANDLER_TABLE_OFFSET(.Lstore_boolean_result) // Z (boolean)
2988 .text
2989
2990END art_quick_invoke_polymorphic