blob: 96a1cadab9da0b86446ed5af6b365c0325de2f44 [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
1065SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
1066 mov x9, sp // Save stack pointer.
1067 .cfi_register sp,x9
1068
1069 sub x10, sp, # SAVE_SIZE
1070 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
1071 mov sp, x10 // Set new SP.
1072
1073 str x28, [sp, #112]
1074 stp x26, x27, [sp, #96]
1075 stp x24, x25, [sp, #80]
1076 stp x22, x23, [sp, #64]
1077 stp x20, x21, [sp, #48]
1078 stp x9, x19, [sp, #32] // Save old stack pointer and x19.
1079 stp x3, x4, [sp, #16] // Save result and shorty addresses.
1080 stp xFP, xLR, [sp] // Store LR & FP.
1081 mov xSELF, x5 // Move thread pointer into SELF register.
Roland Levillain97c46462017-05-11 14:04:03 +01001082 REFRESH_MARKING_REGISTER
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001083
1084 sub sp, sp, #16
1085 str xzr, [sp] // Store null for ArtMethod* slot
1086 // Branch to stub.
1087 bl .Losr_entry
1088 add sp, sp, #16
1089
1090 // Restore return value address and shorty address.
1091 ldp x3,x4, [sp, #16]
1092 ldr x28, [sp, #112]
1093 ldp x26, x27, [sp, #96]
1094 ldp x24, x25, [sp, #80]
1095 ldp x22, x23, [sp, #64]
1096 ldp x20, x21, [sp, #48]
1097
1098 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1099 ldrb w10, [x4]
1100
1101 // Check the return type and store the correct register into the jvalue in memory.
1102
1103 // Don't set anything for a void type.
1104 cmp w10, #'V'
1105 beq .Losr_exit
1106
1107 // Is it a double?
1108 cmp w10, #'D'
1109 bne .Lno_double
1110 str d0, [x3]
1111 b .Losr_exit
1112
1113.Lno_double: // Is it a float?
1114 cmp w10, #'F'
1115 bne .Lno_float
1116 str s0, [x3]
1117 b .Losr_exit
1118
1119.Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits.
1120 str x0, [x3]
1121
1122.Losr_exit: // Finish up.
1123 ldp x2, x19, [sp, #32] // Restore stack pointer and x19.
1124 ldp xFP, xLR, [sp] // Restore old frame pointer and link register.
1125 mov sp, x2
1126 ret
1127
1128.Losr_entry:
1129 // Update stack pointer for the callee
1130 sub sp, sp, x1
1131
1132 // Update link register slot expected by the callee.
1133 sub w1, w1, #8
1134 str lr, [sp, x1]
1135
1136 // Copy arguments into stack frame.
1137 // Use simple copy routine for now.
1138 // 4 bytes per slot.
1139 // X0 - source address
1140 // W1 - args length
1141 // SP - destination address.
1142 // W10 - temporary
1143.Losr_loop_entry:
1144 cmp w1, #0
1145 beq .Losr_loop_exit
1146 sub w1, w1, #4
1147 ldr w10, [x0, x1]
1148 str w10, [sp, x1]
1149 b .Losr_loop_entry
1150
1151.Losr_loop_exit:
1152 // Branch to the OSR entry point.
1153 br x2
1154
1155END art_quick_osr_stub
1156
Stuart Monteithb95a5342014-03-12 13:32:32 +00001157 /*
1158 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1159 */
1160
1161ENTRY art_quick_do_long_jump
1162 // Load FPRs
1163 ldp d0, d1, [x1], #16
1164 ldp d2, d3, [x1], #16
1165 ldp d4, d5, [x1], #16
1166 ldp d6, d7, [x1], #16
1167 ldp d8, d9, [x1], #16
1168 ldp d10, d11, [x1], #16
1169 ldp d12, d13, [x1], #16
1170 ldp d14, d15, [x1], #16
1171 ldp d16, d17, [x1], #16
1172 ldp d18, d19, [x1], #16
1173 ldp d20, d21, [x1], #16
1174 ldp d22, d23, [x1], #16
1175 ldp d24, d25, [x1], #16
1176 ldp d26, d27, [x1], #16
1177 ldp d28, d29, [x1], #16
1178 ldp d30, d31, [x1]
1179
1180 // Load GPRs
1181 // TODO: lots of those are smashed, could optimize.
1182 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001183 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001184 ldp x28, x29, [x0], #-16
1185 ldp x26, x27, [x0], #-16
1186 ldp x24, x25, [x0], #-16
1187 ldp x22, x23, [x0], #-16
1188 ldp x20, x21, [x0], #-16
Roland Levillain97c46462017-05-11 14:04:03 +01001189 ldp x18, x19, [x0], #-16 // X18 & xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +00001190 ldp x16, x17, [x0], #-16
1191 ldp x14, x15, [x0], #-16
1192 ldp x12, x13, [x0], #-16
1193 ldp x10, x11, [x0], #-16
1194 ldp x8, x9, [x0], #-16
1195 ldp x6, x7, [x0], #-16
1196 ldp x4, x5, [x0], #-16
1197 ldp x2, x3, [x0], #-16
1198 mov sp, x1
1199
Roland Levillain97c46462017-05-11 14:04:03 +01001200 REFRESH_MARKING_REGISTER
1201
Andreas Gampe639bdd12015-06-03 11:22:45 -07001202 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1203 ldr x1, [x0, #33*8]
1204 // And the value of x0.
1205 ldr x0, [x0]
1206
1207 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001208END art_quick_do_long_jump
1209
Andreas Gampef4e910b2014-04-29 16:55:52 -07001210 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001211 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1212 * possibly null object to lock.
1213 *
1214 * Derived from arm32 code.
1215 */
1216 .extern artLockObjectFromCode
1217ENTRY art_quick_lock_object
1218 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001219 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001220.Lretry_lock:
1221 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
Hans Boehm67eda382017-01-17 15:03:38 -08001222 ldaxr w1, [x4] // acquire needed only in most common case
1223 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001224 cbnz w3, .Lnot_unlocked // already thin locked
1225 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1226 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001227 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001228 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001229 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001230.Lnot_unlocked: // x1: original lock word
1231 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001232 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1233 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1234 uxth w2, w2 // zero top 16 bits
1235 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1236 // else contention, go to slow path
Hans Boehm67eda382017-01-17 15:03:38 -08001237 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001238 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 -07001239 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 -08001240 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1241 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1242 stxr w3, w2, [x4]
1243 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001244 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001245.Llock_stxr_fail:
1246 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001247.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001248 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001249 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001250 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001251 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001252 REFRESH_MARKING_REGISTER
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001253 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1254END art_quick_lock_object
1255
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001256ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001257 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001258 mov x1, xSELF // pass Thread::Current
1259 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001260 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001261 REFRESH_MARKING_REGISTER
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001262 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1263END art_quick_lock_object_no_inline
1264
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001265 /*
1266 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1267 * x0 holds the possibly null object to lock.
1268 *
1269 * Derived from arm32 code.
1270 */
1271 .extern artUnlockObjectFromCode
1272ENTRY art_quick_unlock_object
1273 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001274 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1275.Lretry_unlock:
1276#ifndef USE_READ_BARRIER
1277 ldr w1, [x4]
1278#else
1279 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1280#endif
1281 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001282 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1283 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hans Boehm67eda382017-01-17 15:03:38 -08001284 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001285 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001286 uxth w3, w3 // zero top 16 bits
1287 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hans Boehm67eda382017-01-17 15:03:38 -08001288 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001289 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001290 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001291 // transition to unlocked
Hans Boehm67eda382017-01-17 15:03:38 -08001292 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 -08001293#ifndef USE_READ_BARRIER
Hans Boehm67eda382017-01-17 15:03:38 -08001294 stlr w3, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001295#else
Hans Boehm67eda382017-01-17 15:03:38 -08001296 stlxr w2, w3, [x4] // Need to use atomic instructions for read barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001297 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1298#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001299 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001300.Lrecursive_thin_unlock: // w1: original lock word
1301 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1302#ifndef USE_READ_BARRIER
1303 str w1, [x4]
1304#else
1305 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1306 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1307#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001308 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001309.Lunlock_stxr_fail:
Hans Boehm67eda382017-01-17 15:03:38 -08001310 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001311.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001312 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001313 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001314 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001315 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001316 REFRESH_MARKING_REGISTER
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001317 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1318END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001319
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001320ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001321 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001322 mov x1, xSELF // pass Thread::Current
1323 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001324 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001325 REFRESH_MARKING_REGISTER
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001326 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1327END art_quick_unlock_object_no_inline
1328
Andreas Gampe525cde22014-04-22 15:44:50 -07001329 /*
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001330 * Entry from managed code that calls artInstanceOfFromCode and on failure calls
1331 * artThrowClassCastExceptionForObject.
Andreas Gampe525cde22014-04-22 15:44:50 -07001332 */
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001333 .extern artInstanceOfFromCode
1334 .extern artThrowClassCastExceptionForObject
1335ENTRY art_quick_check_instance_of
Andreas Gampe525cde22014-04-22 15:44:50 -07001336 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001337 // Stack needs to be 16B aligned on calls.
Vladimir Marko215076b2016-09-07 18:05:55 +01001338 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1339 SAVE_REG xLR, 24
Andreas Gampe525cde22014-04-22 15:44:50 -07001340
1341 // Call runtime code
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001342 bl artInstanceOfFromCode
Andreas Gampe525cde22014-04-22 15:44:50 -07001343
1344 // Check for exception
1345 cbz x0, .Lthrow_class_cast_exception
1346
1347 // Restore and return
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001348 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001349 RESTORE_REG xLR, 24
1350 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001351 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001352 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001353 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampe6b90d422015-06-26 19:49:24 -07001354
Andreas Gampe525cde22014-04-22 15:44:50 -07001355.Lthrow_class_cast_exception:
1356 // Restore
Vladimir Marko215076b2016-09-07 18:05:55 +01001357 RESTORE_REG xLR, 24
1358 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001359
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001360 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001361 mov x2, xSELF // pass Thread::Current
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001362 bl artThrowClassCastExceptionForObject // (Object*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001363 brk 0 // We should not return here...
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001364END art_quick_check_instance_of
Andreas Gampe525cde22014-04-22 15:44:50 -07001365
Man Cao1aee9002015-07-14 22:31:42 -07001366// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1367.macro POP_REG_NE xReg, offset, xExclude
1368 .ifnc \xReg, \xExclude
1369 ldr \xReg, [sp, #\offset] // restore xReg
1370 .cfi_restore \xReg
1371 .endif
1372.endm
1373
Roland Levillain4359e612016-07-20 11:32:19 +01001374// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1375// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1376.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1377 .ifc \xReg1, \xExclude
1378 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1379 .else
1380 .ifc \xReg2, \xExclude
1381 ldr \xReg1, [sp, #\offset] // restore xReg1
1382 .else
1383 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1384 .endif
1385 .endif
1386 .cfi_restore \xReg1
1387 .cfi_restore \xReg2
1388.endm
1389
Man Cao1aee9002015-07-14 22:31:42 -07001390 /*
1391 * Macro to insert read barrier, only used in art_quick_aput_obj.
1392 * xDest, wDest and xObj are registers, offset is a defined literal such as
1393 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1394 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1395 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1396 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001397.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001398#ifdef USE_READ_BARRIER
Roland Levillain97c46462017-05-11 14:04:03 +01001399# ifdef USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001400 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1401 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1402 // False dependency to avoid needing load/load fence.
1403 add \xObj, \xObj, \xTemp, lsr #32
1404 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1405 UNPOISON_HEAP_REF \wDest
1406 b .Lrb_exit\number
Roland Levillain97c46462017-05-11 14:04:03 +01001407# endif // USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001408.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001409 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
Vladimir Marko215076b2016-09-07 18:05:55 +01001410 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1411 SAVE_TWO_REGS x2, x3, 16
1412 SAVE_TWO_REGS x4, xLR, 32
Man Cao1aee9002015-07-14 22:31:42 -07001413
Man Cao63069212015-08-21 15:51:39 -07001414 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001415 .ifnc \xObj, x1
1416 mov x1, \xObj // pass xObj
1417 .endif
1418 mov w2, #\offset // pass offset
1419 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1420 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1421 .ifnc \wDest, w0
1422 mov \wDest, w0 // save return value in wDest
1423 .endif
1424
1425 // Conditionally restore saved registers
1426 POP_REG_NE x0, 0, \xDest
1427 POP_REG_NE x1, 8, \xDest
1428 POP_REG_NE x2, 16, \xDest
1429 POP_REG_NE x3, 24, \xDest
1430 POP_REG_NE x4, 32, \xDest
Vladimir Marko215076b2016-09-07 18:05:55 +01001431 RESTORE_REG xLR, 40
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001432 DECREASE_FRAME 48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001433.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001434#else
1435 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1436 UNPOISON_HEAP_REF \wDest
1437#endif // USE_READ_BARRIER
1438.endm
1439
Man Cao1aee9002015-07-14 22:31:42 -07001440#ifdef USE_READ_BARRIER
1441 .extern artReadBarrierSlow
1442#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001443ENTRY art_quick_aput_obj
1444 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001445 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1446 // This also zero-extends to x3
1447 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1448 // This also zero-extends to x3
1449 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1450 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001451 cmp w3, w4 // value's type == array's component type - trivial assignability
1452 bne .Lcheck_assignability
1453.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001454 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001455 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001456 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001457 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1458 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001459 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001460 strb w3, [x3, x0]
1461 ret
1462.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001463 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001464 // "Compress" = do nothing
1465 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1466 ret
1467.Lcheck_assignability:
1468 // Store arguments and link register
Vladimir Marko215076b2016-09-07 18:05:55 +01001469 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1470 SAVE_TWO_REGS x2, xLR, 16
Andreas Gampef4e910b2014-04-29 16:55:52 -07001471
1472 // Call runtime code
1473 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1474 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1475 bl artIsAssignableFromCode
1476
1477 // Check for exception
1478 cbz x0, .Lthrow_array_store_exception
1479
1480 // Restore
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001481 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001482 RESTORE_TWO_REGS x2, xLR, 16
1483 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001484
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001485 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001486 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001487 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001488 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1489 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001490 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001491 strb w3, [x3, x0]
1492 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001493 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001494 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampef4e910b2014-04-29 16:55:52 -07001495.Lthrow_array_store_exception:
Vladimir Marko215076b2016-09-07 18:05:55 +01001496 RESTORE_TWO_REGS x2, xLR, 16
1497 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001498
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001499 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko908eb222016-09-14 10:29:18 +01001500 mov x1, x2 // Pass value.
1501 mov x2, xSELF // Pass Thread::Current.
1502 bl artThrowArrayStoreException // (Object*, Object*, Thread*).
1503 brk 0 // Unreached.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001504END art_quick_aput_obj
1505
Stuart Monteithb95a5342014-03-12 13:32:32 +00001506// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001507.macro ONE_ARG_DOWNCALL name, entrypoint, return
1508 .extern \entrypoint
1509ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001510 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001511 mov x1, xSELF // pass Thread::Current
1512 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001513 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001514 REFRESH_MARKING_REGISTER
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001515 \return
1516END \name
1517.endm
1518
1519// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001520.macro TWO_ARG_DOWNCALL name, entrypoint, return
1521 .extern \entrypoint
1522ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001523 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001524 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001525 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001526 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001527 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001528 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001529END \name
1530.endm
1531
Jeff Hao848f70a2014-01-15 13:49:50 -08001532// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001533.macro THREE_ARG_DOWNCALL name, entrypoint, return
1534 .extern \entrypoint
1535ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001536 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001537 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001538 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001539 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001540 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001541 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001542END \name
1543.endm
1544
Jeff Hao848f70a2014-01-15 13:49:50 -08001545// Macro to facilitate adding new allocation entrypoints.
1546.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1547 .extern \entrypoint
1548ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001549 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001550 mov x4, xSELF // pass Thread::Current
1551 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001552 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001553 REFRESH_MARKING_REGISTER
Jeff Hao848f70a2014-01-15 13:49:50 -08001554 \return
Jeff Hao848f70a2014-01-15 13:49:50 -08001555END \name
1556.endm
1557
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001558// Macros taking opportunity of code similarities for downcalls.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001559.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1560 .extern \entrypoint
1561ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001562 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001563 mov x1, xSELF // pass Thread::Current
1564 bl \entrypoint // (uint32_t type_idx, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001565 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001566 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001567 \return
1568END \name
1569.endm
1570
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001571.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1572 .extern \entrypoint
1573ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001574 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001575 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001576 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001577 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001578 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001579 \return
1580END \name
1581.endm
1582
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001583.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1584 .extern \entrypoint
1585ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001586 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001587 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001588 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001589 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001590 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001591 \return
1592END \name
1593.endm
1594
Vladimir Markoea4c1262017-02-06 19:59:33 +00001595// Macro for string and type resolution and initialization.
Mingyao Yang0a87a652017-04-12 13:43:15 -07001596.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL name, entrypoint, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Markoea4c1262017-02-06 19:59:33 +00001597 .extern \entrypoint
1598ENTRY \name
Mingyao Yang0a87a652017-04-12 13:43:15 -07001599 SETUP_SAVE_EVERYTHING_FRAME \runtime_method_offset // save everything for stack crawl
Vladimir Markoea4c1262017-02-06 19:59:33 +00001600 mov x1, xSELF // pass Thread::Current
1601 bl \entrypoint // (int32_t index, Thread* self)
1602 cbz w0, 1f // If result is null, deliver the OOME.
1603 .cfi_remember_state
1604 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
Roland Levillain97c46462017-05-11 14:04:03 +01001605 REFRESH_MARKING_REGISTER
Vladimir Markoea4c1262017-02-06 19:59:33 +00001606 ret // return
1607 .cfi_restore_state
1608 .cfi_def_cfa_offset FRAME_SIZE_SAVE_EVERYTHING // workaround for clang bug: 31975598
16091:
1610 DELIVER_PENDING_EXCEPTION_FRAME_READY
1611END \name
1612.endm
1613
Mingyao Yang0a87a652017-04-12 13:43:15 -07001614.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT name, entrypoint
1615 ONE_ARG_SAVE_EVERYTHING_DOWNCALL \name, \entrypoint, RUNTIME_SAVE_EVERYTHING_FOR_CLINIT_METHOD_OFFSET
1616.endm
1617
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001618.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1619 cbz w0, 1f // result zero branch over
1620 ret // return
16211:
1622 DELIVER_PENDING_EXCEPTION
1623.endm
1624
Matteo Franchindfd891a2014-04-30 12:17:17 +01001625 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001626 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1627 * failure.
1628 */
1629TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1630
1631 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001632 * Entry from managed code when uninitialized static storage, this stub will run the class
1633 * initializer and deliver the exception on error. On success the static storage base is
1634 * returned.
1635 */
Mingyao Yang0a87a652017-04-12 13:43:15 -07001636ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_static_storage, artInitializeStaticStorageFromCode
1637ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_type, artInitializeTypeFromCode
Vladimir Markoea4c1262017-02-06 19:59:33 +00001638ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode
1639ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_string, artResolveStringFromCode
Matteo Franchindfd891a2014-04-30 12:17:17 +01001640
Roland Levillain809f5b12018-01-04 14:05:59 +00001641// Note: Functions `art{Get,Set}<Kind>{Static,Instance}FromCompiledCode` are
1642// defined with a macro in runtime/entrypoints/quick/quick_field_entrypoints.cc.
Roland Levillain97c46462017-05-11 14:04:03 +01001643
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001644ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1645ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1646ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1647ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1648ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1649ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1650ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001651
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001652TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1653TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1654TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1655TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1656TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1657TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1658TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001659
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001660TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1661TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1662TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1663TWO_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1664TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001665
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001666THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1667THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1668THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1669THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1670THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001671
Stuart Monteithb95a5342014-03-12 13:32:32 +00001672// Generate the allocation entrypoints for each allocator.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001673GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
Mathieu Chartier8261d022016-08-08 09:41:04 -07001674// Comment out allocators that have arm64 specific asm.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001675// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1676// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1677GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001678// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001679// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
1680// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
1681// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
1682// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001683GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1684GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1685GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001686
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001687// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
1688// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
1689GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
1690// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
1691// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_tlab, TLAB)
1692// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_tlab, TLAB)
1693// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_tlab, TLAB)
1694// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_tlab, TLAB)
1695GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_tlab, TLAB)
1696GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_tlab, TLAB)
1697GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_tlab, TLAB)
1698
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001699// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1700// If isInitialized=0 the compiler can only assume it's been at least resolved.
1701.macro ART_QUICK_ALLOC_OBJECT_ROSALLOC c_name, cxx_name, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001702ENTRY \c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001703 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001704 // x0: type, xSELF(x19): Thread::Current
1705 // x1-x7: free.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001706 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1707 // allocation stack has room.
1708 // ldp won't work due to large offset.
1709 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1710 cmp x3, x4
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001711 bhs .Lslow_path\c_name
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001712 ldr w3, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3)
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001713 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001714 // local allocation. Also does the
1715 // finalizable and initialization
1716 // checks.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001717 // When isInitialized == 0, then the class is potentially not yet initialized.
1718 // If the class is not yet initialized, the object size will be very large to force the branch
1719 // below to be taken.
1720 //
1721 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001722 bhs .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001723 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001724 // from the size. Since the size is
1725 // already aligned we can combine the
1726 // two shifts together.
1727 add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1728 // Subtract pointer size since ther
1729 // are no runs for 0 byte allocations
1730 // and the size is already aligned.
1731 ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001732 // Load the free list head (x3). This
1733 // will be the return val.
1734 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001735 cbz x3, .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001736 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1737 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1738 // and update the list head with the
1739 // next pointer.
1740 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1741 // Store the class pointer in the
1742 // header. This also overwrites the
1743 // next pointer. The offsets are
1744 // asserted to match.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001745
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001746#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1747#error "Class pointer needs to overwrite next pointer."
1748#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001749 POISON_HEAP_REF w0
1750 str w0, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001751 // Push the new object onto the thread
1752 // local allocation stack and
1753 // increment the thread local
1754 // allocation stack top.
1755 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1756 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1757 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1758 // Decrement the size of the free list
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001759
1760 // After this "STR" the object is published to the thread local allocation stack,
1761 // and it will be observable from a runtime internal (eg. Heap::VisitObjects) point of view.
1762 // It is not yet visible to the running (user) compiled code until after the return.
1763 //
1764 // To avoid the memory barrier prior to the "STR", a trick is employed, by differentiating
1765 // the state of the allocation stack slot. It can be a pointer to one of:
1766 // 0) Null entry, because the stack was bumped but the new pointer wasn't written yet.
1767 // (The stack initial state is "null" pointers).
1768 // 1) A partially valid object, with an invalid class pointer to the next free rosalloc slot.
1769 // 2) A fully valid object, with a valid class pointer pointing to a real class.
1770 // Other states are not allowed.
1771 //
1772 // An object that is invalid only temporarily, and will eventually become valid.
1773 // The internal runtime code simply checks if the object is not null or is partial and then
1774 // ignores it.
1775 //
1776 // (Note: The actual check is done by seeing if a non-null object has a class pointer pointing
1777 // to ClassClass, and that the ClassClass's class pointer is self-cyclic. A rosalloc free slot
1778 // "next" pointer is not-cyclic.)
1779 //
1780 // See also b/28790624 for a listing of CLs dealing with this race.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001781 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1782 sub x1, x1, #1
1783 // TODO: consider combining this store
1784 // and the list head store above using
1785 // strd.
1786 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001787
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001788 mov x0, x3 // Set the return value and return.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001789.if \isInitialized == 0
1790 // This barrier is only necessary when the allocation also requires
1791 // a class initialization check.
1792 //
1793 // If the class is already observably initialized, then new-instance allocations are protected
1794 // from publishing by the compiler which inserts its own StoreStore barrier.
1795 dmb ish
1796 // Use a "dmb ish" fence here because if there are later loads of statics (e.g. class size),
1797 // they should happen-after the implicit initialization check.
1798 //
1799 // TODO: Remove this dmb for class initialization checks (b/36692143) by introducing
1800 // a new observably-initialized class state.
1801.endif
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001802 ret
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001803.Lslow_path\c_name:
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001804 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1805 mov x1, xSELF // pass Thread::Current
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001806 bl \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001807 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001808 REFRESH_MARKING_REGISTER
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001809 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001810END \c_name
1811.endm
1812
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001813ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_resolved_rosalloc, artAllocObjectFromCodeResolvedRosAlloc, /* isInitialized */ 0
1814ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_initialized_rosalloc, artAllocObjectFromCodeInitializedRosAlloc, /* isInitialized */ 1
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001815
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001816// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1817// If isInitialized=0 the compiler can only assume it's been at least resolved.
1818.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001819 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1820 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
1821 ldr w7, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7).
1822 add x6, x4, x7 // Add object size to tlab pos.
1823 cmp x6, x5 // Check if it fits, overflow works
1824 // since the tlab pos and end are 32
1825 // bit values.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001826
1827 // When isInitialized == 0, then the class is potentially not yet initialized.
1828 // If the class is not yet initialized, the object size will be very large to force the branch
1829 // below to be taken.
1830 //
1831 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001832 bhi \slowPathLabel
1833 str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1834 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1835 add x5, x5, #1
1836 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1837 POISON_HEAP_REF w0
1838 str w0, [x4, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1839 // Fence. This is "ish" not "ishst" so
1840 // that the code after this allocation
1841 // site will see the right values in
1842 // the fields of the class.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001843 mov x0, x4
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001844.if \isInitialized == 0
1845 // This barrier is only necessary when the allocation also requires
1846 // a class initialization check.
1847 //
1848 // If the class is already observably initialized, then new-instance allocations are protected
1849 // from publishing by the compiler which inserts its own StoreStore barrier.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001850 dmb ish
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001851 // Use a "dmb ish" fence here because if there are later loads of statics (e.g. class size),
1852 // they should happen-after the implicit initialization check.
1853 //
1854 // TODO: Remove this dmb for class initialization checks (b/36692143) by introducing
1855 // a new observably-initialized class state.
1856.endif
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001857 ret
1858.endm
1859
1860// The common code for art_quick_alloc_object_*region_tlab
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001861.macro GENERATE_ALLOC_OBJECT_RESOLVED_TLAB name, entrypoint, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001862ENTRY \name
1863 // Fast path region tlab allocation.
1864 // x0: type, xSELF(x19): Thread::Current
1865 // x1-x7: free.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001866 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED .Lslow_path\name, \isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001867.Lslow_path\name:
1868 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
1869 mov x1, xSELF // Pass Thread::Current.
1870 bl \entrypoint // (mirror::Class*, Thread*)
1871 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001872 REFRESH_MARKING_REGISTER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001873 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1874END \name
1875.endm
1876
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001877GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, /* isInitialized */ 0
1878GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, /* isInitialized */ 1
1879GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_tlab, artAllocObjectFromCodeResolvedTLAB, /* isInitialized */ 0
1880GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_tlab, artAllocObjectFromCodeInitializedTLAB, /* isInitialized */ 1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001881
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001882.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 +01001883 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignment mask
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001884 // (addr + 7) & ~7. The mask must
1885 // be 64 bits to keep high bits in
1886 // case of overflow.
1887 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1888 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1889 // 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 -07001890 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1891 bhs \slowPathLabel // path.
1892
1893 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1894 // we use (end - begin) to handle
1895 // negative size arrays. It is
1896 // assumed that a negative size will
1897 // always be greater unsigned than
1898 // region size.
1899 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1900 sub \xTemp2, \xTemp2, \xTemp0
1901 cmp \xTemp1, \xTemp2
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001902
1903 // The array class is always initialized here. Unlike new-instance,
1904 // this does not act as a double test.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001905 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001906 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1907 // Move old thread_local_pos to x0
1908 // for the return value.
1909 mov x0, \xTemp0
1910 add \xTemp0, \xTemp0, \xTemp1
1911 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1912 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1913 add \xTemp0, \xTemp0, #1
1914 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1915 POISON_HEAP_REF \wClass
1916 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1917 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1918 // Fence.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001919// new-array is special. The class is loaded and immediately goes to the Initialized state
1920// before it is published. Therefore the only fence needed is for the publication of the object.
1921// See ClassLinker::CreateArrayClass() for more details.
1922
1923// For publication of the new array, we don't need a 'dmb ishst' here.
1924// The compiler generates 'dmb ishst' for all new-array insts.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001925 ret
1926.endm
1927
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001928.macro GENERATE_ALLOC_ARRAY_TLAB name, entrypoint, size_setup
Mathieu Chartier8261d022016-08-08 09:41:04 -07001929ENTRY \name
1930 // Fast path array allocation for region tlab allocation.
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001931 // x0: mirror::Class* type
Mathieu Chartier8261d022016-08-08 09:41:04 -07001932 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001933 // x2-x7: free.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001934 mov x3, x0
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001935 \size_setup x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1936 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 -07001937.Lslow_path\name:
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001938 // x0: mirror::Class* klass
Mathieu Chartier8261d022016-08-08 09:41:04 -07001939 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001940 // x2: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001941 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001942 mov x2, xSELF // pass Thread::Current
Mathieu Chartier8261d022016-08-08 09:41:04 -07001943 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001944 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001945 REFRESH_MARKING_REGISTER
Mathieu Chartier8261d022016-08-08 09:41:04 -07001946 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1947END \name
1948.endm
1949
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001950.macro COMPUTE_ARRAY_SIZE_UNKNOWN xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1951 // Array classes are never finalizable or uninitialized, no need to check.
1952 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1953 UNPOISON_HEAP_REF \wTemp0
1954 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1955 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1956 // bits.
1957 // xCount is holding a 32 bit value,
1958 // it can not overflow.
1959 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1960 // Add array data offset and alignment.
1961 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1962#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1963#error Long array data offset must be 4 greater than int array data offset.
1964#endif
1965
1966 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1967 // component size shift is 3
1968 // (for 64 bit alignment).
1969 and \xTemp0, \xTemp0, #4
1970 add \xTemp1, \xTemp1, \xTemp0
1971.endm
1972
1973.macro COMPUTE_ARRAY_SIZE_8 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1974 // Add array data offset and alignment.
1975 add \xTemp1, \xCount, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1976.endm
1977
1978.macro COMPUTE_ARRAY_SIZE_16 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1979 lsl \xTemp1, \xCount, #1
1980 // Add array data offset and alignment.
1981 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1982.endm
1983
1984.macro COMPUTE_ARRAY_SIZE_32 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1985 lsl \xTemp1, \xCount, #2
1986 // Add array data offset and alignment.
1987 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1988.endm
1989
1990.macro COMPUTE_ARRAY_SIZE_64 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1991 lsl \xTemp1, \xCount, #3
1992 // Add array data offset and alignment.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001993 add \xTemp1, \xTemp1, #(MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001994.endm
1995
Roland Levillain97c46462017-05-11 14:04:03 +01001996// TODO(ngeoffray): art_quick_alloc_array_resolved_region_tlab is not used for arm64, remove
1997// the entrypoint once all backends have been updated to use the size variants.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001998GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1999GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_8
2000GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_16
2001GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_32
2002GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_64
2003GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
2004GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_8
2005GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_16
2006GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_32
2007GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_64
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08002008
Zheng Xu48241e72014-05-23 11:52:42 +08002009 /*
Zheng Xu69a50302015-04-14 20:04:41 +08002010 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08002011 */
2012 .extern artTestSuspendFromCode
2013ENTRY art_quick_test_suspend
Mingyao Yang0a87a652017-04-12 13:43:15 -07002014 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 +08002015 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002016 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002017 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002018 REFRESH_MARKING_REGISTER
Vladimir Marko952dbb12016-07-28 12:01:51 +01002019 ret
Zheng Xu48241e72014-05-23 11:52:42 +08002020END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00002021
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002022ENTRY art_quick_implicit_suspend
2023 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002024 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002025 bl artTestSuspendFromCode // (Thread*)
Roland Levillain97c46462017-05-11 14:04:03 +01002026 RESTORE_SAVE_REFS_ONLY_FRAME
2027 REFRESH_MARKING_REGISTER
2028 ret
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002029END art_quick_implicit_suspend
2030
Andreas Gampee62a07e2014-03-26 14:53:21 -07002031 /*
2032 * Called by managed code that is attempting to call a method on a proxy class. On entry
2033 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2034 * method agrees with a ref and args callee save frame.
2035 */
2036 .extern artQuickProxyInvokeHandler
2037ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002038 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07002039 mov x2, xSELF // pass Thread::Current
2040 mov x3, sp // pass SP
2041 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002042 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07002043 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002044 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Roland Levillain97c46462017-05-11 14:04:03 +01002045 REFRESH_MARKING_REGISTER
Andreas Gamped1e91672014-06-02 22:50:05 -07002046 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07002047 ret // return on success
2048.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002049 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07002050 DELIVER_PENDING_EXCEPTION
2051END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00002052
Andreas Gampe51f76352014-05-21 08:28:48 -07002053 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002054 * Called to resolve an imt conflict.
2055 * x0 is the conflict ArtMethod.
2056 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2057 *
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002058 * Note that this stub writes to xIP0, xIP1, x13-x15, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002059 */
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002060 .extern artLookupResolvedMethod
Andreas Gampe51f76352014-05-21 08:28:48 -07002061ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002062 ldr xIP0, [sp, #0] // Load referrer
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002063 // Load the declaring class (without read barrier) and access flags (for obsolete method check).
2064 // The obsolete flag is set with suspended threads, so we do not need an acquire operation here.
2065#if ART_METHOD_ACCESS_FLAGS_OFFSET != ART_METHOD_DECLARING_CLASS_OFFSET + 4
2066#error "Expecting declaring class and access flags to be consecutive for LDP."
2067#endif
2068 ldp wIP0, w15, [xIP0, #ART_METHOD_DECLARING_CLASS_OFFSET]
2069 // If the method is obsolete, just go through the dex cache miss slow path.
2070 tbnz x15, #ACC_OBSOLETE_METHOD_SHIFT, .Limt_conflict_trampoline_dex_cache_miss
2071 ldr wIP0, [xIP0, #MIRROR_CLASS_DEX_CACHE_OFFSET] // Load the DexCache (without read barrier).
2072 UNPOISON_HEAP_REF wIP0
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002073 ubfx x15, xIP1, #0, #METHOD_DEX_CACHE_HASH_BITS // Calculate DexCache method slot index.
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002074 ldr xIP0, [xIP0, #MIRROR_DEX_CACHE_RESOLVED_METHODS_OFFSET] // Load the resolved methods.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002075 add xIP0, xIP0, x15, lsl #(POINTER_SIZE_SHIFT + 1) // Load DexCache method slot address.
2076
2077 // Relaxed atomic load x14:x15 from the dex cache slot.
2078.Limt_conflict_trampoline_retry_load:
2079 ldxp x14, x15, [xIP0]
2080 stxp w13, x14, x15, [xIP0]
2081 cbnz w13, .Limt_conflict_trampoline_retry_load
2082
2083 cmp x15, xIP1 // Compare method index to see if we had a DexCache method hit.
2084 bne .Limt_conflict_trampoline_dex_cache_miss
2085.Limt_conflict_trampoline_have_interface_method:
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002086 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2087 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2088.Limt_table_iterate:
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002089 cmp x0, x14
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002090 // Branch if found. Benchmarks have shown doing a branch here is better.
2091 beq .Limt_table_found
2092 // If the entry is null, the interface method is not in the ImtConflictTable.
2093 cbz x0, .Lconflict_trampoline
2094 // Iterate over the entries of the ImtConflictTable.
2095 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2096 b .Limt_table_iterate
2097.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002098 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002099 // and jump to it.
2100 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2101 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2102 br xIP0
2103.Lconflict_trampoline:
2104 // Call the runtime stub to populate the ImtConflictTable and jump to the
2105 // resolved method.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002106 mov x0, x14 // Load interface method
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002107 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002108.Limt_conflict_trampoline_dex_cache_miss:
2109 // We're not creating a proper runtime method frame here,
2110 // artLookupResolvedMethod() is not allowed to walk the stack.
2111
2112 // Save GPR args and return address, allocate space for FPR args, align stack.
2113 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2114 SAVE_TWO_REGS x2, x3, 16
2115 SAVE_TWO_REGS x4, x5, 32
2116 SAVE_TWO_REGS x6, x7, 48
2117 SAVE_REG xLR, (8 * 8 + 8 * 8 + 8)
2118
2119 // Save FPR args.
2120 stp d0, d1, [sp, #64]
2121 stp d2, d3, [sp, #80]
2122 stp d4, d5, [sp, #96]
2123 stp d6, d7, [sp, #112]
2124
2125 mov x0, xIP1 // Pass method index.
2126 ldr x1, [sp, #(8 * 8 + 8 * 8 + 8 + 8)] // Pass referrer.
2127 bl artLookupResolvedMethod // (uint32_t method_index, ArtMethod* referrer)
2128 mov x14, x0 // Move the interface method to x14 where the loop above expects it.
2129
2130 // Restore FPR args.
2131 ldp d0, d1, [sp, #64]
2132 ldp d2, d3, [sp, #80]
2133 ldp d4, d5, [sp, #96]
2134 ldp d6, d7, [sp, #112]
2135
2136 // Restore GPR args and return address.
2137 RESTORE_REG xLR, (8 * 8 + 8 * 8 + 8)
2138 RESTORE_TWO_REGS x2, x3, 16
2139 RESTORE_TWO_REGS x4, x5, 32
2140 RESTORE_TWO_REGS x6, x7, 48
2141 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2142
2143 // If the method wasn't resolved, skip the lookup and go to artInvokeInterfaceTrampoline().
2144 cbz x14, .Lconflict_trampoline
2145 b .Limt_conflict_trampoline_have_interface_method
Andreas Gampe51f76352014-05-21 08:28:48 -07002146END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002147
2148ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002149 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002150 mov x2, xSELF
2151 mov x3, sp
2152 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002153 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002154 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002155 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002156 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002157 REFRESH_MARKING_REGISTER
Zheng Xub551fdc2014-07-25 11:49:42 +08002158 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000021591:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002160 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002161 DELIVER_PENDING_EXCEPTION
2162END art_quick_resolution_trampoline
2163
2164/*
2165 * Generic JNI frame layout:
2166 *
2167 * #-------------------#
2168 * | |
2169 * | caller method... |
2170 * #-------------------# <--- SP on entry
2171 * | Return X30/LR |
2172 * | X29/FP | callee save
2173 * | X28 | callee save
2174 * | X27 | callee save
2175 * | X26 | callee save
2176 * | X25 | callee save
2177 * | X24 | callee save
2178 * | X23 | callee save
2179 * | X22 | callee save
2180 * | X21 | callee save
2181 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002182 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002183 * | X7 | arg7
2184 * | X6 | arg6
2185 * | X5 | arg5
2186 * | X4 | arg4
2187 * | X3 | arg3
2188 * | X2 | arg2
2189 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002190 * | D7 | float arg 8
2191 * | D6 | float arg 7
2192 * | D5 | float arg 6
2193 * | D4 | float arg 5
2194 * | D3 | float arg 4
2195 * | D2 | float arg 3
2196 * | D1 | float arg 2
2197 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002198 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002199 * #-------------------#
2200 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002201 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002202 * #-------------------#
2203 * | JNI Call Stack |
2204 * #-------------------# <--- SP on native call
2205 * | |
2206 * | Stack for Regs | The trampoline assembly will pop these values
2207 * | | into registers for native call
2208 * #-------------------#
2209 * | Native code ptr |
2210 * #-------------------#
2211 * | Free scratch |
2212 * #-------------------#
2213 * | Ptr to (1) | <--- SP
2214 * #-------------------#
2215 */
2216 /*
2217 * Called to do a generic JNI down-call
2218 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002219ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002220 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002221
2222 // Save SP , so we can have static CFI info.
2223 mov x28, sp
2224 .cfi_def_cfa_register x28
2225
2226 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002227 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002228 mov xFP, sp
2229
Zheng Xub551fdc2014-07-25 11:49:42 +08002230 mov xIP0, #5120
2231 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002232
2233 // prepare for artQuickGenericJniTrampoline call
2234 // (Thread*, SP)
2235 // x0 x1 <= C calling convention
2236 // xSELF xFP <= where they are
2237
2238 mov x0, xSELF // Thread*
2239 mov x1, xFP
2240 bl artQuickGenericJniTrampoline // (Thread*, sp)
2241
Andreas Gampec200a4a2014-06-16 18:39:09 -07002242 // The C call will have registered the complete save-frame on success.
2243 // The result of the call is:
2244 // x0: pointer to native code, 0 on error.
2245 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002246
Andreas Gampec200a4a2014-06-16 18:39:09 -07002247 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002248 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002249
Andreas Gampec200a4a2014-06-16 18:39:09 -07002250 // Release part of the alloca.
2251 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002252
Andreas Gampec200a4a2014-06-16 18:39:09 -07002253 // Save the code pointer
2254 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002255
2256 // Load parameters from frame into registers.
2257 // TODO Check with artQuickGenericJniTrampoline.
2258 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002259 ldp x0, x1, [sp]
2260 ldp x2, x3, [sp, #16]
2261 ldp x4, x5, [sp, #32]
2262 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002263
Andreas Gampec200a4a2014-06-16 18:39:09 -07002264 ldp d0, d1, [sp, #64]
2265 ldp d2, d3, [sp, #80]
2266 ldp d4, d5, [sp, #96]
2267 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002268
Andreas Gampec200a4a2014-06-16 18:39:09 -07002269 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002270
Zheng Xub551fdc2014-07-25 11:49:42 +08002271 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002272
2273 // result sign extension is handled in C code
2274 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002275 // (Thread*, result, result_f)
2276 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002277 mov x1, x0 // Result (from saved).
2278 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002279 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002280
2281 bl artQuickGenericJniEndTrampoline
2282
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002283 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002284 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002285 cbnz x2, .Lexception_in_native
2286
Stuart Monteithb95a5342014-03-12 13:32:32 +00002287 // Tear down the alloca.
2288 mov sp, x28
2289 .cfi_def_cfa_register sp
2290
Stuart Monteithb95a5342014-03-12 13:32:32 +00002291 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002292 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002293 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002294
2295 // store into fpr, for when it's a fpr return...
2296 fmov d0, x0
2297 ret
2298
Stuart Monteithb95a5342014-03-12 13:32:32 +00002299.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002300 // Move to x1 then sp to please assembler.
2301 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Vladimir Marko2196c652017-11-30 16:16:07 +00002302 add sp, x1, #-1 // Remove the GenericJNI tag.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002303 .cfi_def_cfa_register sp
2304 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002305 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002306END art_quick_generic_jni_trampoline
2307
2308/*
2309 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2310 * of a quick call:
2311 * x0 = method being called/to bridge to.
2312 * x1..x7, d0..d7 = arguments to that method.
2313 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002314ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002315 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002316
2317 // x0 will contain mirror::ArtMethod* method.
2318 mov x1, xSELF // How to get Thread::Current() ???
2319 mov x2, sp
2320
2321 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2322 // mirror::ArtMethod** sp)
2323 bl artQuickToInterpreterBridge
2324
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002325 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Roland Levillain97c46462017-05-11 14:04:03 +01002326 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002327
2328 fmov d0, x0
2329
2330 RETURN_OR_DELIVER_PENDING_EXCEPTION
2331END art_quick_to_interpreter_bridge
2332
Alex Lightdb01a092017-04-03 15:39:55 -07002333/*
2334 * Called to attempt to execute an obsolete method.
2335 */
2336ONE_ARG_RUNTIME_EXCEPTION art_invoke_obsolete_method_stub, artInvokeObsoleteMethod
2337
Andreas Gamped58342c2014-06-05 14:18:08 -07002338
2339//
2340// Instrumentation-related stubs
2341//
2342 .extern artInstrumentationMethodEntryFromCode
2343ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002344 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002345
Zheng Xub551fdc2014-07-25 11:49:42 +08002346 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002347
2348 mov x2, xSELF
Alex Lightb7edcda2017-04-27 13:20:31 -07002349 mov x3, sp // Pass SP
2350 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, SP)
Andreas Gamped58342c2014-06-05 14:18:08 -07002351
Zheng Xub551fdc2014-07-25 11:49:42 +08002352 mov xIP0, x0 // x0 = result of call.
2353 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002354
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002355 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Roland Levillain97c46462017-05-11 14:04:03 +01002356 REFRESH_MARKING_REGISTER
Alex Lightb7edcda2017-04-27 13:20:31 -07002357 cbz xIP0, 1f // Deliver the pending exception if method is null.
Andreas Gamped58342c2014-06-05 14:18:08 -07002358 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002359 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Alex Lightb7edcda2017-04-27 13:20:31 -07002360
23611:
2362 DELIVER_PENDING_EXCEPTION
Andreas Gamped58342c2014-06-05 14:18:08 -07002363END art_quick_instrumentation_entry
2364
2365 .extern artInstrumentationMethodExitFromCode
2366ENTRY art_quick_instrumentation_exit
2367 mov xLR, #0 // Clobber LR for later checks.
Mingyao Yang2ee17902017-08-30 11:37:08 -07002368 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002369
Mingyao Yang2ee17902017-08-30 11:37:08 -07002370 add x3, sp, #8 // Pass floating-point result pointer, in kSaveEverything frame.
2371 add x2, sp, #264 // Pass integer result pointer, in kSaveEverything frame.
2372 mov x1, sp // Pass SP.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002373 mov x0, xSELF // Pass Thread.
Alex Lightb7edcda2017-04-27 13:20:31 -07002374 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res*, fpr_res*)
Andreas Gamped58342c2014-06-05 14:18:08 -07002375
Mingyao Yang2ee17902017-08-30 11:37:08 -07002376 cbz x0, .Ldo_deliver_instrumentation_exception
2377 // Handle error
2378 cbnz x1, .Ldeoptimize
2379 // Normal return.
2380 str x0, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2381 // Set return pc.
2382 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002383 REFRESH_MARKING_REGISTER
Mingyao Yang2ee17902017-08-30 11:37:08 -07002384 br lr
2385.Ldo_deliver_instrumentation_exception:
2386 DELIVER_PENDING_EXCEPTION_FRAME_READY
2387.Ldeoptimize:
2388 str x1, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2389 // Set return pc.
2390 RESTORE_SAVE_EVERYTHING_FRAME
2391 // Jump to art_quick_deoptimize.
2392 b art_quick_deoptimize
Andreas Gamped58342c2014-06-05 14:18:08 -07002393END art_quick_instrumentation_exit
2394
2395 /*
2396 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2397 * will long jump to the upcall with a special exception of -1.
2398 */
2399 .extern artDeoptimize
2400ENTRY art_quick_deoptimize
Mingyao Yang2ee17902017-08-30 11:37:08 -07002401 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002402 mov x0, xSELF // Pass thread.
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002403 bl artDeoptimize // (Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002404 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002405END art_quick_deoptimize
2406
Sebastien Hertz07474662015-08-25 15:12:33 +00002407 /*
2408 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2409 * will long jump to the upcall with a special exception of -1.
2410 */
2411 .extern artDeoptimizeFromCompiledCode
2412ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002413 SETUP_SAVE_EVERYTHING_FRAME
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002414 mov x1, xSELF // Pass thread.
2415 bl artDeoptimizeFromCompiledCode // (DeoptimizationKind, Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002416 brk 0
2417END art_quick_deoptimize_from_compiled_code
2418
Andreas Gamped58342c2014-06-05 14:18:08 -07002419
Serban Constantinescu169489b2014-06-11 16:43:35 +01002420 /*
2421 * String's indexOf.
2422 *
2423 * TODO: Not very optimized.
2424 * On entry:
2425 * x0: string object (known non-null)
2426 * w1: char to match (known <= 0xFFFF)
2427 * w2: Starting offset in string data
2428 */
2429ENTRY art_quick_indexof
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002430#if (STRING_COMPRESSION_FEATURE)
2431 ldr w4, [x0, #MIRROR_STRING_COUNT_OFFSET]
2432#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002433 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002434#endif
Jeff Hao848f70a2014-01-15 13:49:50 -08002435 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
jessicahandojo05765752016-09-09 19:01:32 -07002436#if (STRING_COMPRESSION_FEATURE)
2437 /* w4 holds count (with flag) and w3 holds actual length */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002438 lsr w3, w4, #1
jessicahandojo05765752016-09-09 19:01:32 -07002439#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002440 /* Clamp start to [0..count] */
2441 cmp w2, #0
2442 csel w2, wzr, w2, lt
2443 cmp w2, w3
2444 csel w2, w3, w2, gt
2445
Serban Constantinescu169489b2014-06-11 16:43:35 +01002446 /* Save a copy to compute result */
2447 mov x5, x0
2448
jessicahandojo05765752016-09-09 19:01:32 -07002449#if (STRING_COMPRESSION_FEATURE)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002450 tbz w4, #0, .Lstring_indexof_compressed
jessicahandojo05765752016-09-09 19:01:32 -07002451#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002452 /* Build pointer to start of data to compare and pre-bias */
2453 add x0, x0, x2, lsl #1
2454 sub x0, x0, #2
Serban Constantinescu169489b2014-06-11 16:43:35 +01002455 /* Compute iteration count */
2456 sub w2, w3, w2
2457
2458 /*
2459 * At this point we have:
2460 * x0: start of the data to test
2461 * w1: char to compare
2462 * w2: iteration count
2463 * x5: original start of string data
2464 */
2465
2466 subs w2, w2, #4
2467 b.lt .Lindexof_remainder
2468
2469.Lindexof_loop4:
2470 ldrh w6, [x0, #2]!
2471 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002472 ldrh wIP0, [x0, #2]!
2473 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002474 cmp w6, w1
2475 b.eq .Lmatch_0
2476 cmp w7, w1
2477 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002478 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002479 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002480 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002481 b.eq .Lmatch_3
2482 subs w2, w2, #4
2483 b.ge .Lindexof_loop4
2484
2485.Lindexof_remainder:
2486 adds w2, w2, #4
2487 b.eq .Lindexof_nomatch
2488
2489.Lindexof_loop1:
2490 ldrh w6, [x0, #2]!
2491 cmp w6, w1
2492 b.eq .Lmatch_3
2493 subs w2, w2, #1
2494 b.ne .Lindexof_loop1
2495
2496.Lindexof_nomatch:
2497 mov x0, #-1
2498 ret
2499
2500.Lmatch_0:
2501 sub x0, x0, #6
2502 sub x0, x0, x5
2503 asr x0, x0, #1
2504 ret
2505.Lmatch_1:
2506 sub x0, x0, #4
2507 sub x0, x0, x5
2508 asr x0, x0, #1
2509 ret
2510.Lmatch_2:
2511 sub x0, x0, #2
2512 sub x0, x0, x5
2513 asr x0, x0, #1
2514 ret
2515.Lmatch_3:
2516 sub x0, x0, x5
2517 asr x0, x0, #1
2518 ret
jessicahandojo05765752016-09-09 19:01:32 -07002519#if (STRING_COMPRESSION_FEATURE)
2520 /*
2521 * Comparing compressed string character-per-character with
2522 * input character
2523 */
2524.Lstring_indexof_compressed:
2525 add x0, x0, x2
2526 sub x0, x0, #1
2527 sub w2, w3, w2
2528.Lstring_indexof_compressed_loop:
2529 subs w2, w2, #1
2530 b.lt .Lindexof_nomatch
2531 ldrb w6, [x0, #1]!
2532 cmp w6, w1
2533 b.eq .Lstring_indexof_compressed_matched
2534 b .Lstring_indexof_compressed_loop
2535.Lstring_indexof_compressed_matched:
2536 sub x0, x0, x5
2537 ret
2538#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002539END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002540
2541 /*
2542 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002543 * getting its argument and returning its result through W register
2544 * `wreg` (corresponding to X register `xreg`), saving and restoring
2545 * all caller-save registers.
2546 *
2547 * If `wreg` is different from `w0`, the generated function follows a
2548 * non-standard runtime calling convention:
2549 * - register `wreg` is used to pass the (sole) argument of this
2550 * function (instead of W0);
2551 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002552 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002553 * - W0 is treated like a normal (non-argument) caller-save register;
2554 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002555 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002556 */
Roland Levillain4359e612016-07-20 11:32:19 +01002557.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002558ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002559 // Reference is null, no work to do at all.
2560 cbz \wreg, .Lret_rb_\name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002561 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2562 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002563 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lnot_marked_rb_\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002564.Lret_rb_\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002565 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002566.Lnot_marked_rb_\name:
2567 // 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 +01002568 tst wIP0, wIP0, lsl #1
2569 bmi .Lret_forwarding_address\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002570.Lslow_rb_\name:
Vladimir Markoea4c1262017-02-06 19:59:33 +00002571 /*
2572 * Allocate 44 stack slots * 8 = 352 bytes:
2573 * - 20 slots for core registers X0-15, X17-X19, LR
2574 * - 24 slots for floating-point registers D0-D7 and D16-D31
2575 */
2576 // We must not clobber IP1 since code emitted for HLoadClass and HLoadString
2577 // relies on IP1 being preserved.
Roland Levillain4359e612016-07-20 11:32:19 +01002578 // Save all potentially live caller-save core registers.
Vladimir Markoea4c1262017-02-06 19:59:33 +00002579 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
Vladimir Marko215076b2016-09-07 18:05:55 +01002580 SAVE_TWO_REGS x2, x3, 16
2581 SAVE_TWO_REGS x4, x5, 32
2582 SAVE_TWO_REGS x6, x7, 48
2583 SAVE_TWO_REGS x8, x9, 64
2584 SAVE_TWO_REGS x10, x11, 80
2585 SAVE_TWO_REGS x12, x13, 96
2586 SAVE_TWO_REGS x14, x15, 112
Vladimir Markoea4c1262017-02-06 19:59:33 +00002587 SAVE_TWO_REGS x17, x18, 128 // Skip x16, i.e. IP0.
2588 SAVE_TWO_REGS x19, xLR, 144 // Save also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002589 // Save all potentially live caller-save floating-point registers.
2590 stp d0, d1, [sp, #160]
2591 stp d2, d3, [sp, #176]
2592 stp d4, d5, [sp, #192]
2593 stp d6, d7, [sp, #208]
2594 stp d16, d17, [sp, #224]
2595 stp d18, d19, [sp, #240]
2596 stp d20, d21, [sp, #256]
2597 stp d22, d23, [sp, #272]
2598 stp d24, d25, [sp, #288]
2599 stp d26, d27, [sp, #304]
2600 stp d28, d29, [sp, #320]
2601 stp d30, d31, [sp, #336]
Roland Levillain4359e612016-07-20 11:32:19 +01002602
2603 .ifnc \wreg, w0
2604 mov w0, \wreg // Pass arg1 - obj from `wreg`
2605 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002606 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002607 .ifnc \wreg, w0
2608 mov \wreg, w0 // Return result into `wreg`
2609 .endif
2610
2611 // Restore core regs, except `xreg`, as `wreg` is used to return the
2612 // result of this function (simply remove it from the stack instead).
2613 POP_REGS_NE x0, x1, 0, \xreg
2614 POP_REGS_NE x2, x3, 16, \xreg
2615 POP_REGS_NE x4, x5, 32, \xreg
2616 POP_REGS_NE x6, x7, 48, \xreg
2617 POP_REGS_NE x8, x9, 64, \xreg
2618 POP_REGS_NE x10, x11, 80, \xreg
2619 POP_REGS_NE x12, x13, 96, \xreg
2620 POP_REGS_NE x14, x15, 112, \xreg
Vladimir Markoea4c1262017-02-06 19:59:33 +00002621 POP_REGS_NE x17, x18, 128, \xreg
2622 POP_REGS_NE x19, xLR, 144, \xreg // Restore also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002623 // Restore floating-point registers.
2624 ldp d0, d1, [sp, #160]
2625 ldp d2, d3, [sp, #176]
2626 ldp d4, d5, [sp, #192]
2627 ldp d6, d7, [sp, #208]
2628 ldp d16, d17, [sp, #224]
2629 ldp d18, d19, [sp, #240]
2630 ldp d20, d21, [sp, #256]
2631 ldp d22, d23, [sp, #272]
2632 ldp d24, d25, [sp, #288]
2633 ldp d26, d27, [sp, #304]
2634 ldp d28, d29, [sp, #320]
2635 ldp d30, d31, [sp, #336]
Vladimir Markoea4c1262017-02-06 19:59:33 +00002636 // Remove frame and return.
2637 DECREASE_FRAME 352
Roland Levillain02b75802016-07-13 11:54:35 +01002638 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002639.Lret_forwarding_address\name:
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002640 // Shift left by the forwarding address shift. This clears out the state bits since they are
2641 // in the top 2 bits of the lock word.
Vladimir Markob9d01112017-03-31 10:55:41 +01002642 lsl \wreg, wIP0, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002643 ret
Roland Levillain02b75802016-07-13 11:54:35 +01002644END \name
2645.endm
2646
Roland Levillain4359e612016-07-20 11:32:19 +01002647READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2648READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2649READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2650READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2651READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2652READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2653READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2654READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2655READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2656READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2657READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2658READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2659READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2660READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2661READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2662READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
Mathieu Chartier36c22712016-08-12 13:19:44 -07002663// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
Roland Levillain4359e612016-07-20 11:32:19 +01002664READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2665READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2666READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2667READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2668READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2669READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2670READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2671READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2672READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2673READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2674READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2675READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2676READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29
Orion Hodsonac141392017-01-13 11:53:47 +00002677
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002678
2679.macro SELECT_X_OR_W_FOR_MACRO macro_to_use, x, w, xreg
2680 .if \xreg
2681 \macro_to_use \x
2682 .else
2683 \macro_to_use \w
2684 .endif
2685.endm
2686
2687.macro FOR_REGISTERS macro_for_register, macro_for_reserved_register, xreg
2688 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x0, w0, \xreg
2689 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x1, w1, \xreg
2690 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x2, w2, \xreg
2691 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x3, w3, \xreg
2692 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x4, w4, \xreg
2693 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x5, w5, \xreg
2694 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x6, w6, \xreg
2695 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x7, w7, \xreg
2696 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x8, w8, \xreg
2697 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x9, w9, \xreg
2698 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x10, w10, \xreg
2699 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x11, w11, \xreg
2700 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x12, w12, \xreg
2701 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x13, w13, \xreg
2702 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x14, w14, \xreg
2703 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x15, w15, \xreg
2704 \macro_for_reserved_register // IP0 is reserved
2705 \macro_for_reserved_register // IP1 is reserved
2706 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x18, w18, \xreg
2707 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x19, w19, \xreg
2708 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x20, w20, \xreg
2709 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x21, w21, \xreg
2710 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x22, w22, \xreg
2711 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x23, w23, \xreg
2712 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x24, w24, \xreg
2713 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x25, w25, \xreg
2714 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x26, w26, \xreg
2715 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x27, w27, \xreg
2716 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x28, w28, \xreg
2717 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x29, w29, \xreg
2718 \macro_for_reserved_register // lr is reserved
2719 \macro_for_reserved_register // sp is reserved
2720.endm
2721
2722.macro FOR_XREGISTERS macro_for_register, macro_for_reserved_register
2723 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 1
2724.endm
2725
2726.macro FOR_WREGISTERS macro_for_register, macro_for_reserved_register
2727 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 0
2728.endm
2729
2730.macro BRK0_BRK0
2731 brk 0
2732 brk 0
2733.endm
2734
2735#if BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET != BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
2736#error "Array and field introspection code sharing requires same LDR offset."
2737#endif
2738.macro INTROSPECTION_ARRAY_LOAD index_reg
2739 ldr wIP0, [xIP0, \index_reg, lsl #2]
2740 b art_quick_read_barrier_mark_introspection
2741.endm
2742
2743.macro MOV_WIP0_TO_WREG_AND_BL_LR reg
2744 mov \reg, wIP0
2745 br lr // Do not use RET as we do not enter the entrypoint with "BL".
2746.endm
2747
2748.macro READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH ldr_offset
2749 /*
2750 * Allocate 44 stack slots * 8 = 352 bytes:
2751 * - 19 slots for core registers X0-15, X18-X19, LR
2752 * - 1 slot padding
2753 * - 24 slots for floating-point registers D0-D7 and D16-D31
2754 */
2755 // Save all potentially live caller-save core registers.
2756 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
2757 SAVE_TWO_REGS x2, x3, 16
2758 SAVE_TWO_REGS x4, x5, 32
2759 SAVE_TWO_REGS x6, x7, 48
2760 SAVE_TWO_REGS x8, x9, 64
2761 SAVE_TWO_REGS x10, x11, 80
2762 SAVE_TWO_REGS x12, x13, 96
2763 SAVE_TWO_REGS x14, x15, 112
2764 SAVE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2765 SAVE_REG xLR, 144 // Save return address, skip padding at 152.
2766 // Save all potentially live caller-save floating-point registers.
2767 stp d0, d1, [sp, #160]
2768 stp d2, d3, [sp, #176]
2769 stp d4, d5, [sp, #192]
2770 stp d6, d7, [sp, #208]
2771 stp d16, d17, [sp, #224]
2772 stp d18, d19, [sp, #240]
2773 stp d20, d21, [sp, #256]
2774 stp d22, d23, [sp, #272]
2775 stp d24, d25, [sp, #288]
2776 stp d26, d27, [sp, #304]
2777 stp d28, d29, [sp, #320]
2778 stp d30, d31, [sp, #336]
2779
2780 mov x0, xIP0
2781 bl artReadBarrierMark // artReadBarrierMark(obj)
2782 mov xIP0, x0
2783
2784 // Restore core regs, except x0 and x1 as the return register switch case
2785 // address calculation is smoother with an extra register.
2786 RESTORE_TWO_REGS x2, x3, 16
2787 RESTORE_TWO_REGS x4, x5, 32
2788 RESTORE_TWO_REGS x6, x7, 48
2789 RESTORE_TWO_REGS x8, x9, 64
2790 RESTORE_TWO_REGS x10, x11, 80
2791 RESTORE_TWO_REGS x12, x13, 96
2792 RESTORE_TWO_REGS x14, x15, 112
2793 RESTORE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2794 RESTORE_REG xLR, 144 // Restore return address.
Nicolas Geoffray7015e762017-07-02 21:37:02 +01002795 // Restore caller-save floating-point registers.
2796 ldp d0, d1, [sp, #160]
2797 ldp d2, d3, [sp, #176]
2798 ldp d4, d5, [sp, #192]
2799 ldp d6, d7, [sp, #208]
2800 ldp d16, d17, [sp, #224]
2801 ldp d18, d19, [sp, #240]
2802 ldp d20, d21, [sp, #256]
2803 ldp d22, d23, [sp, #272]
2804 ldp d24, d25, [sp, #288]
2805 ldp d26, d27, [sp, #304]
2806 ldp d28, d29, [sp, #320]
2807 ldp d30, d31, [sp, #336]
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002808
2809 ldr x0, [lr, #\ldr_offset] // Load the instruction.
2810 adr xIP1, .Lmark_introspection_return_switch
2811 bfi xIP1, x0, #3, #5 // Calculate switch case address.
2812 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 352
2813 br xIP1
2814.endm
2815
2816 /*
2817 * Use introspection to load a reference from the same address as the LDR
2818 * instruction in generated code would load (unless loaded by the thunk,
2819 * see below), call ReadBarrier::Mark() with that reference if needed
2820 * and return it in the same register as the LDR instruction would load.
2821 *
2822 * The entrypoint is called through a thunk that differs across load kinds.
2823 * For field and array loads the LDR instruction in generated code follows
2824 * the branch to the thunk, i.e. the LDR is at [LR, #-4], and the thunk
2825 * knows the holder and performs the gray bit check, returning to the LDR
2826 * instruction if the object is not gray, so this entrypoint no longer
2827 * needs to know anything about the holder. For GC root loads, the LDR
2828 * instruction in generated code precedes the branch to the thunk (i.e.
2829 * the LDR is at [LR, #-8]) and the thunk does not do the gray bit check.
2830 *
2831 * For field accesses and array loads with a constant index the thunk loads
2832 * the reference into IP0 using introspection and calls the main entrypoint,
Vladimir Markod1ef8732017-04-18 13:55:13 +01002833 * art_quick_read_barrier_mark_introspection. With heap poisoning enabled,
2834 * the passed reference is poisoned.
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002835 *
2836 * For array accesses with non-constant index, the thunk inserts the bits
2837 * 16-21 of the LDR instruction to the entrypoint address, effectively
2838 * calculating a switch case label based on the index register (bits 16-20)
2839 * and adding an extra offset (bit 21 is set) to differentiate from the
2840 * main entrypoint, then moves the base register to IP0 and jumps to the
2841 * switch case. Therefore we need to align the main entrypoint to 512 bytes,
2842 * accounting for a 256-byte offset followed by 32 array entrypoints
2843 * starting at art_quick_read_barrier_mark_introspection_arrays, each
2844 * containing an LDR (register) and a branch to the main entrypoint.
2845 *
2846 * For GC root accesses we cannot use the main entrypoint because of the
2847 * different offset where the LDR instruction in generated code is located.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002848 * (And even with heap poisoning enabled, GC roots are not poisoned.)
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002849 * To re-use the same entrypoint pointer in generated code, we make sure
2850 * that the gc root entrypoint (a copy of the entrypoint with a different
2851 * offset for introspection loads) is located at a known offset (768 bytes,
2852 * or BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET) from the main
2853 * entrypoint and the GC root thunk adjusts the entrypoint pointer, moves
2854 * the root register to IP0 and jumps to the customized entrypoint,
2855 * art_quick_read_barrier_mark_introspection_gc_roots. The thunk also
2856 * performs all the fast-path checks, so we need just the slow path.
2857 *
2858 * The code structure is
2859 * art_quick_read_barrier_mark_introspection:
2860 * Up to 256 bytes for the main entrypoint code.
2861 * Padding to 256 bytes if needed.
2862 * art_quick_read_barrier_mark_introspection_arrays:
2863 * Exactly 256 bytes for array load switch cases (32x2 instructions).
2864 * .Lmark_introspection_return_switch:
2865 * Exactly 256 bytes for return switch cases (32x2 instructions).
2866 * art_quick_read_barrier_mark_introspection_gc_roots:
2867 * GC root entrypoint code.
2868 */
2869 .balign 512
2870ENTRY art_quick_read_barrier_mark_introspection
2871 // At this point, IP0 contains the reference, IP1 can be freely used.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002872 // For heap poisoning, the reference is poisoned, so unpoison it first.
2873 UNPOISON_HEAP_REF wIP0
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002874 // If reference is null, just return it in the right register.
2875 cbz wIP0, .Lmark_introspection_return
2876 // Use wIP1 as temp and check the mark bit of the reference.
2877 ldr wIP1, [xIP0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2878 tbz wIP1, #LOCK_WORD_MARK_BIT_SHIFT, .Lmark_introspection_unmarked
2879.Lmark_introspection_return:
2880 // Without an extra register for the return switch case address calculation,
2881 // we exploit the high word of the xIP0 to temporarily store the ref_reg*8,
2882 // so the return switch below must move wIP0 instead of xIP0 to the register.
2883 ldr wIP1, [lr, #BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET] // Load the instruction.
2884 bfi xIP0, xIP1, #(32 + 3), #5 // Extract ref_reg*8 to high word in xIP0.
2885 adr xIP1, .Lmark_introspection_return_switch
2886 bfxil xIP1, xIP0, #32, #8 // Calculate return switch case address.
2887 br xIP1
2888.Lmark_introspection_unmarked:
2889 // Check if the top two bits are one, if this is the case it is a forwarding address.
2890 tst wIP1, wIP1, lsl #1
2891 bmi .Lmark_introspection_forwarding_address
2892 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET
2893
2894.Lmark_introspection_forwarding_address:
2895 // Shift left by the forwarding address shift. This clears out the state bits since they are
2896 // in the top 2 bits of the lock word.
2897 lsl wIP0, wIP1, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
2898 b .Lmark_introspection_return
2899
2900 // We're very close to the alloted 256B for the entrypoint code before the
2901 // array switch cases. Should we go a little bit over the limit, we can
2902 // move some code after the array switch cases and return switch cases.
2903 .balign 256
2904 .hidden art_quick_read_barrier_mark_introspection_arrays
2905 .global art_quick_read_barrier_mark_introspection_arrays
2906art_quick_read_barrier_mark_introspection_arrays:
2907 FOR_XREGISTERS INTROSPECTION_ARRAY_LOAD, BRK0_BRK0
2908.Lmark_introspection_return_switch:
2909 FOR_WREGISTERS MOV_WIP0_TO_WREG_AND_BL_LR, BRK0_BRK0
2910 .hidden art_quick_read_barrier_mark_introspection_gc_roots
2911 .global art_quick_read_barrier_mark_introspection_gc_roots
2912art_quick_read_barrier_mark_introspection_gc_roots:
2913 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET
2914END art_quick_read_barrier_mark_introspection
2915
Orion Hodsonac141392017-01-13 11:53:47 +00002916.extern artInvokePolymorphic
2917ENTRY art_quick_invoke_polymorphic
2918 SETUP_SAVE_REFS_AND_ARGS_FRAME // Save callee saves in case allocation triggers GC.
2919 mov x2, xSELF
2920 mov x3, sp
2921 INCREASE_FRAME 16 // Reserve space for JValue result.
2922 str xzr, [sp, #0] // Initialize result to zero.
2923 mov x0, sp // Set r0 to point to result.
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002924 bl artInvokePolymorphic // artInvokePolymorphic(result, receiver, thread, save_area)
Orion Hodsonac141392017-01-13 11:53:47 +00002925 uxtb w0, w0 // Result is the return type descriptor as a char.
2926 sub w0, w0, 'A' // Convert to zero based index.
2927 cmp w0, 'Z' - 'A'
2928 bhi .Lcleanup_and_return // Clean-up if out-of-bounds.
2929 adrp x1, .Lhandler_table // Compute address of handler table.
2930 add x1, x1, :lo12:.Lhandler_table
2931 ldrb w0, [x1, w0, uxtw] // Lookup handler offset in handler table.
2932 adr x1, .Lstart_of_handlers
2933 add x0, x1, w0, sxtb #2 // Convert relative offset to absolute address.
2934 br x0 // Branch to handler.
2935
2936.Lstart_of_handlers:
2937.Lstore_boolean_result:
2938 ldrb w0, [sp]
2939 b .Lcleanup_and_return
2940.Lstore_char_result:
2941 ldrh w0, [sp]
2942 b .Lcleanup_and_return
2943.Lstore_float_result:
2944 ldr s0, [sp]
2945 str s0, [sp, #32]
2946 b .Lcleanup_and_return
2947.Lstore_double_result:
2948 ldr d0, [sp]
2949 str d0, [sp, #32]
2950 b .Lcleanup_and_return
2951.Lstore_long_result:
2952 ldr x0, [sp]
2953 // Fall-through
2954.Lcleanup_and_return:
2955 DECREASE_FRAME 16
2956 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002957 REFRESH_MARKING_REGISTER
Orion Hodsonac141392017-01-13 11:53:47 +00002958 RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
2959
2960 .section .rodata // Place handler table in read-only section away from text.
2961 .align 2
2962.macro HANDLER_TABLE_OFFSET handler_label
2963 .byte (\handler_label - .Lstart_of_handlers) / 4
2964.endm
2965.Lhandler_table:
2966 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // A
2967 HANDLER_TABLE_OFFSET(.Lstore_long_result) // B (byte)
2968 HANDLER_TABLE_OFFSET(.Lstore_char_result) // C (char)
2969 HANDLER_TABLE_OFFSET(.Lstore_double_result) // D (double)
2970 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // E
2971 HANDLER_TABLE_OFFSET(.Lstore_float_result) // F (float)
2972 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // G
2973 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // H
2974 HANDLER_TABLE_OFFSET(.Lstore_long_result) // I (int)
2975 HANDLER_TABLE_OFFSET(.Lstore_long_result) // J (long)
2976 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // K
2977 HANDLER_TABLE_OFFSET(.Lstore_long_result) // L (object - references are compressed and only 32-bits)
2978 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // M
2979 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // N
2980 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // O
2981 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // P
2982 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Q
2983 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // R
2984 HANDLER_TABLE_OFFSET(.Lstore_long_result) // S (short)
2985 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // T
2986 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // U
2987 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // V (void)
2988 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // W
2989 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // X
2990 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Y
2991 HANDLER_TABLE_OFFSET(.Lstore_boolean_result) // Z (boolean)
2992 .text
2993
2994END art_quick_invoke_polymorphic