blob: 9919e98d6b50f209ebb2d34ba8e14b1905de122d [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"
David Srbecky946bb092018-03-09 17:23:01 +000018#include "interpreter/cfi_asm_support.h"
Stuart Monteithb95a5342014-03-12 13:32:32 +000019
20#include "arch/quick_alloc_entrypoints.S"
21
22
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010023.macro INCREASE_FRAME frame_adjustment
24 sub sp, sp, #(\frame_adjustment)
25 .cfi_adjust_cfa_offset (\frame_adjustment)
26.endm
27
28.macro DECREASE_FRAME frame_adjustment
29 add sp, sp, #(\frame_adjustment)
30 .cfi_adjust_cfa_offset -(\frame_adjustment)
31.endm
32
Vladimir Marko215076b2016-09-07 18:05:55 +010033.macro SAVE_REG reg, offset
34 str \reg, [sp, #(\offset)]
35 .cfi_rel_offset \reg, (\offset)
36.endm
37
38.macro RESTORE_REG reg, offset
39 ldr \reg, [sp, #(\offset)]
40 .cfi_restore \reg
41.endm
42
Roland Levillain97c46462017-05-11 14:04:03 +010043.macro SAVE_REG_INCREASE_FRAME reg, frame_adjustment
44 str \reg, [sp, #-(\frame_adjustment)]!
45 .cfi_adjust_cfa_offset (\frame_adjustment)
46 .cfi_rel_offset \reg, 0
47.endm
48
49.macro RESTORE_REG_DECREASE_FRAME reg, frame_adjustment
50 ldr \reg, [sp], #(\frame_adjustment)
51 .cfi_restore \reg
52 .cfi_adjust_cfa_offset -(\frame_adjustment)
53.endm
54
Vladimir Marko215076b2016-09-07 18:05:55 +010055.macro SAVE_TWO_REGS reg1, reg2, offset
56 stp \reg1, \reg2, [sp, #(\offset)]
57 .cfi_rel_offset \reg1, (\offset)
58 .cfi_rel_offset \reg2, (\offset) + 8
59.endm
60
61.macro RESTORE_TWO_REGS reg1, reg2, offset
62 ldp \reg1, \reg2, [sp, #(\offset)]
63 .cfi_restore \reg1
64 .cfi_restore \reg2
65.endm
66
67.macro SAVE_TWO_REGS_INCREASE_FRAME reg1, reg2, frame_adjustment
68 stp \reg1, \reg2, [sp, #-(\frame_adjustment)]!
69 .cfi_adjust_cfa_offset (\frame_adjustment)
70 .cfi_rel_offset \reg1, 0
71 .cfi_rel_offset \reg2, 8
72.endm
73
74.macro RESTORE_TWO_REGS_DECREASE_FRAME reg1, reg2, frame_adjustment
75 ldp \reg1, \reg2, [sp], #(\frame_adjustment)
76 .cfi_restore \reg1
77 .cfi_restore \reg2
78 .cfi_adjust_cfa_offset -(\frame_adjustment)
79.endm
80
Stuart Monteithb95a5342014-03-12 13:32:32 +000081 /*
82 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010083 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Stuart Monteithb95a5342014-03-12 13:32:32 +000084 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010085.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
86 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +080087 adrp xIP0, :got:_ZN3art7Runtime9instance_E
88 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000089
90 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010091 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +000092
Vladimir Markofd36f1f2016-08-03 18:49:58 +010093 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves];
94 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070095
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010096 INCREASE_FRAME 176
Andreas Gampe5c1e4352014-04-21 19:28:24 -070097
98 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010099#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176)
100#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700101#endif
102
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100103 // Stack alignment filler [sp, #8].
104 // FP callee-saves.
105 stp d8, d9, [sp, #16]
106 stp d10, d11, [sp, #32]
107 stp d12, d13, [sp, #48]
108 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700109
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100110 // GP callee-saves
Vladimir Marko215076b2016-09-07 18:05:55 +0100111 SAVE_TWO_REGS x19, x20, 80
112 SAVE_TWO_REGS x21, x22, 96
113 SAVE_TWO_REGS x23, x24, 112
114 SAVE_TWO_REGS x25, x26, 128
115 SAVE_TWO_REGS x27, x28, 144
116 SAVE_TWO_REGS x29, xLR, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700117
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100118 // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100119 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700120 // Place sp in Thread::Current()->top_quick_frame.
121 mov xIP0, sp
122 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000123.endm
124
Zheng Xub551fdc2014-07-25 11:49:42 +0800125 /*
126 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100127 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
Zheng Xub551fdc2014-07-25 11:49:42 +0800128 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100129.macro SETUP_SAVE_REFS_ONLY_FRAME
130 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800131 adrp xIP0, :got:_ZN3art7Runtime9instance_E
132 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
133
134 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100135 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Zheng Xub551fdc2014-07-25 11:49:42 +0800136
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100137 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly];
138 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800139
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100140 INCREASE_FRAME 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800141
142 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100143#if (FRAME_SIZE_SAVE_REFS_ONLY != 96)
144#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected."
Zheng Xub551fdc2014-07-25 11:49:42 +0800145#endif
146
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100147 // GP callee-saves.
148 // x20 paired with ArtMethod* - see below.
Vladimir Marko215076b2016-09-07 18:05:55 +0100149 SAVE_TWO_REGS x21, x22, 16
150 SAVE_TWO_REGS x23, x24, 32
151 SAVE_TWO_REGS x25, x26, 48
152 SAVE_TWO_REGS x27, x28, 64
153 SAVE_TWO_REGS x29, xLR, 80
Zheng Xub551fdc2014-07-25 11:49:42 +0800154
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100155 // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly].
Roland Levillain97c46462017-05-11 14:04:03 +0100156 // Note: We could avoid saving X20 in the case of Baker read
157 // barriers, as it is overwritten by REFRESH_MARKING_REGISTER
158 // later; but it's not worth handling this special case.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100159 stp xIP0, x20, [sp]
160 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800161
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700162 // Place sp in Thread::Current()->top_quick_frame.
163 mov xIP0, sp
164 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800165.endm
166
167// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100168.macro RESTORE_SAVE_REFS_ONLY_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100169 // Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100170 // Note: Likewise, we could avoid restoring X20 in the case of Baker
171 // read barriers, as it is overwritten by REFRESH_MARKING_REGISTER
172 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100173 RESTORE_REG x20, 8
174 RESTORE_TWO_REGS x21, x22, 16
175 RESTORE_TWO_REGS x23, x24, 32
176 RESTORE_TWO_REGS x25, x26, 48
177 RESTORE_TWO_REGS x27, x28, 64
178 RESTORE_TWO_REGS x29, xLR, 80
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700179
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100180 DECREASE_FRAME 96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000181.endm
182
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100183.macro POP_SAVE_REFS_ONLY_FRAME
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100184 DECREASE_FRAME 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700185.endm
186
Stuart Monteithb95a5342014-03-12 13:32:32 +0000187
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100188.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100189 INCREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000190
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700191 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100192#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224)
193#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700194#endif
195
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100196 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800197 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100198 stp d0, d1, [sp, #16]
199 stp d2, d3, [sp, #32]
200 stp d4, d5, [sp, #48]
201 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000202
Zheng Xu69a50302015-04-14 20:04:41 +0800203 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100204 SAVE_TWO_REGS x1, x2, 80
205 SAVE_TWO_REGS x3, x4, 96
206 SAVE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700207
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100208 // x7, Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100209 // Note: We could avoid saving X20 in the case of Baker read
210 // barriers, as it is overwritten by REFRESH_MARKING_REGISTER
211 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100212 SAVE_TWO_REGS x7, x20, 128
213 SAVE_TWO_REGS x21, x22, 144
214 SAVE_TWO_REGS x23, x24, 160
215 SAVE_TWO_REGS x25, x26, 176
216 SAVE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700217
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100218 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100219 SAVE_TWO_REGS x29, xLR, 208
Andreas Gampe03906cf2014-04-07 12:08:28 -0700220
Stuart Monteithb95a5342014-03-12 13:32:32 +0000221.endm
222
223 /*
224 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100225 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000226 *
227 * TODO This is probably too conservative - saving FP & LR.
228 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100229.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
230 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800231 adrp xIP0, :got:_ZN3art7Runtime9instance_E
232 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000233
234 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100235 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000236
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100237 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs];
238 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000239
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100240 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000241
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100242 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs].
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700243 // Place sp in Thread::Current()->top_quick_frame.
244 mov xIP0, sp
245 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
246.endm
247
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100248.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
249 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700250 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
251 // Place sp in Thread::Current()->top_quick_frame.
252 mov xIP0, sp
253 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000254.endm
255
Zheng Xub551fdc2014-07-25 11:49:42 +0800256// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100257.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800258 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100259 ldp d0, d1, [sp, #16]
260 ldp d2, d3, [sp, #32]
261 ldp d4, d5, [sp, #48]
262 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000263
Zheng Xu69a50302015-04-14 20:04:41 +0800264 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100265 RESTORE_TWO_REGS x1, x2, 80
266 RESTORE_TWO_REGS x3, x4, 96
267 RESTORE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700268
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100269 // x7, Callee-saves.
Roland Levillain97c46462017-05-11 14:04:03 +0100270 // Note: Likewise, we could avoid restoring X20 in the case of Baker
271 // read barriers, as it is overwritten by REFRESH_MARKING_REGISTER
272 // later; but it's not worth handling this special case.
Vladimir Marko215076b2016-09-07 18:05:55 +0100273 RESTORE_TWO_REGS x7, x20, 128
274 RESTORE_TWO_REGS x21, x22, 144
275 RESTORE_TWO_REGS x23, x24, 160
276 RESTORE_TWO_REGS x25, x26, 176
277 RESTORE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700278
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100279 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100280 RESTORE_TWO_REGS x29, xLR, 208
Stuart Monteithb95a5342014-03-12 13:32:32 +0000281
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100282 DECREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000283.endm
284
Vladimir Marko952dbb12016-07-28 12:01:51 +0100285 /*
286 * Macro that sets up the callee save frame to conform with
287 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000288 * when the SP has already been decremented by FRAME_SIZE_SAVE_EVERYTHING
289 * and saving registers x29 and LR is handled elsewhere.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100290 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700291.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 +0100292 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100293#if (FRAME_SIZE_SAVE_EVERYTHING != 512)
294#error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100295#endif
296
297 // Save FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100298 // For better performance, store d0 and d31 separately, so that all STPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100299 str d0, [sp, #8]
300 stp d1, d2, [sp, #16]
301 stp d3, d4, [sp, #32]
302 stp d5, d6, [sp, #48]
303 stp d7, d8, [sp, #64]
304 stp d9, d10, [sp, #80]
305 stp d11, d12, [sp, #96]
306 stp d13, d14, [sp, #112]
307 stp d15, d16, [sp, #128]
308 stp d17, d18, [sp, #144]
309 stp d19, d20, [sp, #160]
310 stp d21, d22, [sp, #176]
311 stp d23, d24, [sp, #192]
312 stp d25, d26, [sp, #208]
313 stp d27, d28, [sp, #224]
314 stp d29, d30, [sp, #240]
315 str d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100316
317 // Save core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +0100318 SAVE_REG x0, 264
319 SAVE_TWO_REGS x1, x2, 272
320 SAVE_TWO_REGS x3, x4, 288
321 SAVE_TWO_REGS x5, x6, 304
322 SAVE_TWO_REGS x7, x8, 320
323 SAVE_TWO_REGS x9, x10, 336
324 SAVE_TWO_REGS x11, x12, 352
325 SAVE_TWO_REGS x13, x14, 368
326 SAVE_TWO_REGS x15, x16, 384
327 SAVE_TWO_REGS x17, x18, 400
328 SAVE_TWO_REGS x19, x20, 416
329 SAVE_TWO_REGS x21, x22, 432
330 SAVE_TWO_REGS x23, x24, 448
331 SAVE_TWO_REGS x25, x26, 464
332 SAVE_TWO_REGS x27, x28, 480
Vladimir Marko952dbb12016-07-28 12:01:51 +0100333
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100334 // art::Runtime** xIP0 = &art::Runtime::instance_
Vladimir Marko952dbb12016-07-28 12:01:51 +0100335 adrp xIP0, :got:_ZN3art7Runtime9instance_E
336 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
337
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100338 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Vladimir Marko952dbb12016-07-28 12:01:51 +0100339
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100340 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything];
Mingyao Yang0a87a652017-04-12 13:43:15 -0700341 ldr xIP0, [xIP0, \runtime_method_offset]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100342
343 // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything].
344 str xIP0, [sp]
345 // Place sp in Thread::Current()->top_quick_frame.
346 mov xIP0, sp
347 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
348.endm
349
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000350 /*
351 * Macro that sets up the callee save frame to conform with
352 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
353 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700354.macro SETUP_SAVE_EVERYTHING_FRAME runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000355 INCREASE_FRAME 512
356 SAVE_TWO_REGS x29, xLR, 496
Mingyao Yang0a87a652017-04-12 13:43:15 -0700357 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR \runtime_method_offset
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000358.endm
359
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100360.macro RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
Vladimir Marko952dbb12016-07-28 12:01:51 +0100361 // Restore FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100362 // For better performance, load d0 and d31 separately, so that all LDPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100363 ldr d0, [sp, #8]
364 ldp d1, d2, [sp, #16]
365 ldp d3, d4, [sp, #32]
366 ldp d5, d6, [sp, #48]
367 ldp d7, d8, [sp, #64]
368 ldp d9, d10, [sp, #80]
369 ldp d11, d12, [sp, #96]
370 ldp d13, d14, [sp, #112]
371 ldp d15, d16, [sp, #128]
372 ldp d17, d18, [sp, #144]
373 ldp d19, d20, [sp, #160]
374 ldp d21, d22, [sp, #176]
375 ldp d23, d24, [sp, #192]
376 ldp d25, d26, [sp, #208]
377 ldp d27, d28, [sp, #224]
378 ldp d29, d30, [sp, #240]
379 ldr d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100380
Roland Levillain97c46462017-05-11 14:04:03 +0100381 // Restore core registers, except x0.
Vladimir Marko215076b2016-09-07 18:05:55 +0100382 RESTORE_TWO_REGS x1, x2, 272
383 RESTORE_TWO_REGS x3, x4, 288
384 RESTORE_TWO_REGS x5, x6, 304
385 RESTORE_TWO_REGS x7, x8, 320
386 RESTORE_TWO_REGS x9, x10, 336
387 RESTORE_TWO_REGS x11, x12, 352
388 RESTORE_TWO_REGS x13, x14, 368
389 RESTORE_TWO_REGS x15, x16, 384
390 RESTORE_TWO_REGS x17, x18, 400
391 RESTORE_TWO_REGS x19, x20, 416
392 RESTORE_TWO_REGS x21, x22, 432
393 RESTORE_TWO_REGS x23, x24, 448
394 RESTORE_TWO_REGS x25, x26, 464
395 RESTORE_TWO_REGS x27, x28, 480
396 RESTORE_TWO_REGS x29, xLR, 496
Vladimir Marko952dbb12016-07-28 12:01:51 +0100397
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100398 DECREASE_FRAME 512
Vladimir Marko952dbb12016-07-28 12:01:51 +0100399.endm
400
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100401.macro RESTORE_SAVE_EVERYTHING_FRAME
Mingyao Yang0a87a652017-04-12 13:43:15 -0700402 RESTORE_REG x0, 264
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100403 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
404.endm
405
Roland Levillain97c46462017-05-11 14:04:03 +0100406// Macro to refresh the Marking Register (W20).
407//
408// This macro must be called at the end of functions implementing
409// entrypoints that possibly (directly or indirectly) perform a
410// suspend check (before they return).
411.macro REFRESH_MARKING_REGISTER
412#if defined(USE_READ_BARRIER) && defined(USE_BAKER_READ_BARRIER)
413 ldr wMR, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
414#endif
415.endm
416
Stuart Monteithb95a5342014-03-12 13:32:32 +0000417.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700418 cbnz x0, 1f // result non-zero branch over
419 ret // return
4201:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000421.endm
422
423.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700424 cbz x0, 1f // result zero branch over
425 ret // return
4261:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000427.endm
428
429 /*
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100430 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
431 * exception is Thread::Current()->exception_ when the runtime method frame is ready.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000432 */
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100433.macro DELIVER_PENDING_EXCEPTION_FRAME_READY
Stuart Monteithb95a5342014-03-12 13:32:32 +0000434 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000435
436 // Point of no return.
Vladimir Marko908eb222016-09-14 10:29:18 +0100437 bl artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000438 brk 0 // Unreached
439.endm
440
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100441 /*
442 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
443 * exception is Thread::Current()->exception_.
444 */
445.macro DELIVER_PENDING_EXCEPTION
446 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
447 DELIVER_PENDING_EXCEPTION_FRAME_READY
448.endm
449
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700450.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
451 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
452 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000453 ret
4541:
455 DELIVER_PENDING_EXCEPTION
456.endm
457
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700458.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800459 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700460.endm
461
462// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
463.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
464 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
465.endm
466
467.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
468 cbnz w0, 1f // result non-zero branch over
469 ret // return
4701:
471 DELIVER_PENDING_EXCEPTION
472.endm
473
Stuart Monteithb95a5342014-03-12 13:32:32 +0000474.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
475 .extern \cxx_name
476ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100477 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800478 mov x0, xSELF // pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100479 bl \cxx_name // \cxx_name(Thread*)
Vladimir Marko804b03f2016-09-14 16:26:36 +0100480 brk 0
481END \c_name
482.endm
483
484.macro NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
485 .extern \cxx_name
486ENTRY \c_name
487 SETUP_SAVE_EVERYTHING_FRAME // save all registers as basis for long jump context
488 mov x0, xSELF // pass Thread::Current
489 bl \cxx_name // \cxx_name(Thread*)
490 brk 0
Stuart Monteithb95a5342014-03-12 13:32:32 +0000491END \c_name
492.endm
493
494.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
495 .extern \cxx_name
496ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100497 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800498 mov x1, xSELF // pass Thread::Current.
Vladimir Marko908eb222016-09-14 10:29:18 +0100499 bl \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000500 brk 0
501END \c_name
502.endm
503
Vladimir Marko804b03f2016-09-14 16:26:36 +0100504.macro TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000505 .extern \cxx_name
506ENTRY \c_name
Vladimir Marko804b03f2016-09-14 16:26:36 +0100507 SETUP_SAVE_EVERYTHING_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800508 mov x2, xSELF // pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100509 bl \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000510 brk 0
511END \c_name
512.endm
513
514 /*
515 * Called by managed code, saves callee saves and then calls artThrowException
516 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
517 */
518ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
519
520 /*
521 * Called by managed code to create and deliver a NullPointerException.
522 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100523NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000524
525 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100526 * Call installed by a signal handler to create and deliver a NullPointerException.
527 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000528 .extern art_quick_throw_null_pointer_exception_from_signal
529ENTRY art_quick_throw_null_pointer_exception_from_signal
530 // The fault handler pushes the gc map address, i.e. "return address", to stack
531 // and passes the fault address in LR. So we need to set up the CFI info accordingly.
532 .cfi_def_cfa_offset __SIZEOF_POINTER__
533 .cfi_rel_offset lr, 0
534 // Save all registers as basis for long jump context.
535 INCREASE_FRAME (FRAME_SIZE_SAVE_EVERYTHING - __SIZEOF_POINTER__)
536 SAVE_REG x29, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__) // LR already saved.
537 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
538 mov x0, lr // pass the fault address stored in LR by the fault handler.
539 mov x1, xSELF // pass Thread::Current.
Vladimir Marko908eb222016-09-14 10:29:18 +0100540 bl artThrowNullPointerExceptionFromSignal // (arg, Thread*).
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000541 brk 0
542END art_quick_throw_null_pointer_exception_from_signal
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100543
544 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000545 * Called by managed code to create and deliver an ArithmeticException.
546 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100547NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_div_zero, artThrowDivZeroFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000548
549 /*
550 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
551 * index, arg2 holds limit.
552 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100553TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Stuart Monteithb95a5342014-03-12 13:32:32 +0000554
555 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100556 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
557 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
558 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100559TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_string_bounds, artThrowStringBoundsFromCode
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100560
561 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000562 * Called by managed code to create and deliver a StackOverflowError.
563 */
564NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
565
566 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000567 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700568 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100569 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700570 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000571 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700572 * 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 +0000573 * of the target Method* in x0 and method->code_ in x1.
574 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700575 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000576 * thread and we branch to another stub to deliver it.
577 *
578 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
579 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700580 *
581 * Adapted from ARM32 code.
582 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800583 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000584 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700585.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000586 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100587 SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700588 // Helper signature is always
589 // (method_idx, *this_object, *caller_method, *self, sp)
590
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100591 mov x2, xSELF // pass Thread::Current
592 mov x3, sp
593 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800594 mov xIP0, x1 // save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100595 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +0100596 REFRESH_MARKING_REGISTER
Andreas Gampe51f76352014-05-21 08:28:48 -0700597 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800598 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07005991:
600 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700601.endm
602.macro INVOKE_TRAMPOLINE c_name, cxx_name
603ENTRY \c_name
604 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000605END \c_name
606.endm
607
Stuart Monteithb95a5342014-03-12 13:32:32 +0000608INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
609
610INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
611INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
612INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
613INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
614
Andreas Gampe03906cf2014-04-07 12:08:28 -0700615
616.macro INVOKE_STUB_CREATE_FRAME
Vladimir Marko7e614112018-03-06 14:34:06 +0000617SAVE_SIZE=6*8 // x4, x5, x19, x20, FP, LR saved.
618 SAVE_TWO_REGS_INCREASE_FRAME x4, x5, SAVE_SIZE
619 SAVE_TWO_REGS x19, x20, 16
620 SAVE_TWO_REGS xFP, xLR, 32
Andreas Gampe03906cf2014-04-07 12:08:28 -0700621
Vladimir Marko7e614112018-03-06 14:34:06 +0000622 mov xFP, sp // Use xFP for frame pointer, as it's callee-saved.
623 .cfi_def_cfa_register xFP
Andreas Gampecf4035a2014-05-28 22:43:01 -0700624
Vladimir Marko7e614112018-03-06 14:34:06 +0000625 add x10, x2, #(__SIZEOF_POINTER__ + 0xf) // Reserve space for ArtMethod*, arguments and
626 and x10, x10, # ~0xf // round up for 16-byte stack alignment.
627 sub sp, sp, x10 // Adjust SP for ArtMethod*, args and alignment padding.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700628
Zheng Xu48241e72014-05-23 11:52:42 +0800629 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700630
631 // Copy arguments into stack frame.
632 // Use simple copy routine for now.
633 // 4 bytes per slot.
634 // X1 - source address
635 // W2 - args length
636 // X9 - destination address.
637 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700638 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700639
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700640 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
641 // does not have unique-id variables.
6421:
Vladimir Marko7e614112018-03-06 14:34:06 +0000643 cbz w2, 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700644 sub w2, w2, #4 // Need 65536 bytes of range.
645 ldr w10, [x1, x2]
646 str w10, [x9, x2]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700647 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700648
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006492:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700650 // Store null into ArtMethod* at bottom of frame.
651 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700652.endm
653
654.macro INVOKE_STUB_CALL_AND_RETURN
655
Roland Levillain97c46462017-05-11 14:04:03 +0100656 REFRESH_MARKING_REGISTER
657
Andreas Gampe03906cf2014-04-07 12:08:28 -0700658 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700659 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700660 // Branch to method.
661 blr x9
662
Vladimir Marko7e614112018-03-06 14:34:06 +0000663 // Pop the ArtMethod* (null), arguments and alignment padding from the stack.
664 mov sp, xFP
665 .cfi_def_cfa_register sp
Andreas Gampe03906cf2014-04-07 12:08:28 -0700666
Vladimir Marko7e614112018-03-06 14:34:06 +0000667 // Restore saved registers including value address and shorty address.
668 RESTORE_TWO_REGS x19, x20, 16
669 RESTORE_TWO_REGS xFP, xLR, 32
670 RESTORE_TWO_REGS_DECREASE_FRAME x4, x5, SAVE_SIZE
Nicolas Geoffray48088462014-12-12 10:29:38 +0000671
Andreas Gampe03906cf2014-04-07 12:08:28 -0700672 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
673 ldrb w10, [x5]
674
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700675 // Check the return type and store the correct register into the jvalue in memory.
676 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
677
Andreas Gampe03906cf2014-04-07 12:08:28 -0700678 // Don't set anything for a void type.
679 cmp w10, #'V'
Vladimir Marko7e614112018-03-06 14:34:06 +0000680 beq 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700681
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700682 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700683 cmp w10, #'D'
Vladimir Marko7e614112018-03-06 14:34:06 +0000684 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700685
Vladimir Marko7e614112018-03-06 14:34:06 +0000686 // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700687 cmp w10, #'F'
Vladimir Marko7e614112018-03-06 14:34:06 +0000688 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700689
Vladimir Marko7e614112018-03-06 14:34:06 +0000690 // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700691 str x0, [x4]
692
Vladimir Marko7e614112018-03-06 14:34:06 +00006931: // Finish up.
694 ret
Andreas Gampe03906cf2014-04-07 12:08:28 -0700695
Vladimir Marko7e614112018-03-06 14:34:06 +00006962: // Store double.
697 str d0, [x4]
698 ret
Andreas Gampe03906cf2014-04-07 12:08:28 -0700699
Vladimir Marko7e614112018-03-06 14:34:06 +00007003: // Store float.
701 str s0, [x4]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700702 ret
703
704.endm
705
706
Stuart Monteithb95a5342014-03-12 13:32:32 +0000707/*
708 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
709 * uint32_t *args, x1
710 * uint32_t argsize, w2
711 * Thread *self, x3
712 * JValue *result, x4
713 * char *shorty); x5
714 * +----------------------+
715 * | |
716 * | C/C++ frame |
717 * | LR'' |
718 * | FP'' | <- SP'
719 * +----------------------+
720 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800721 * | x28 | <- TODO: Remove callee-saves.
722 * | : |
723 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000724 * | SP' |
725 * | X5 |
726 * | X4 | Saved registers
727 * | LR' |
728 * | FP' | <- FP
729 * +----------------------+
730 * | uint32_t out[n-1] |
731 * | : : | Outs
732 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700733 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000734 * +----------------------+
735 *
736 * Outgoing registers:
737 * x0 - Method*
738 * x1-x7 - integer parameters.
739 * d0-d7 - Floating point parameters.
740 * xSELF = self
741 * SP = & of ArtMethod*
742 * x1 = "this" pointer.
743 *
744 */
745ENTRY art_quick_invoke_stub
746 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700747 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000748
749 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
750 // Parse the passed shorty to determine which register to load.
751 // Load addresses for routines that load WXSD registers.
752 adr x11, .LstoreW2
753 adr x12, .LstoreX2
754 adr x13, .LstoreS0
755 adr x14, .LstoreD0
756
757 // Initialize routine offsets to 0 for integers and floats.
758 // x8 for integers, x15 for floating point.
759 mov x8, #0
760 mov x15, #0
761
762 add x10, x5, #1 // Load shorty address, plus one to skip return value.
763 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
764
765 // Loop to fill registers.
766.LfillRegisters:
767 ldrb w17, [x10], #1 // Load next character in signature, and increment.
768 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
769
770 cmp w17, #'F' // is this a float?
771 bne .LisDouble
772
773 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700774 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000775
776 add x17, x13, x15 // Calculate subroutine to jump to.
777 br x17
778
779.LisDouble:
780 cmp w17, #'D' // is this a double?
781 bne .LisLong
782
783 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700784 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000785
786 add x17, x14, x15 // Calculate subroutine to jump to.
787 br x17
788
789.LisLong:
790 cmp w17, #'J' // is this a long?
791 bne .LisOther
792
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700793 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700794 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000795
796 add x17, x12, x8 // Calculate subroutine to jump to.
797 br x17
798
Stuart Monteithb95a5342014-03-12 13:32:32 +0000799.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700800 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700801 beq .Ladvance4
802
Stuart Monteithb95a5342014-03-12 13:32:32 +0000803 add x17, x11, x8 // Calculate subroutine to jump to.
804 br x17
805
Andreas Gampe03906cf2014-04-07 12:08:28 -0700806.Ladvance4:
807 add x9, x9, #4
808 b .LfillRegisters
809
810.Ladvance8:
811 add x9, x9, #8
812 b .LfillRegisters
813
Stuart Monteithb95a5342014-03-12 13:32:32 +0000814// Macro for loading a parameter into a register.
815// counter - the register with offset into these tables
816// size - the size of the register - 4 or 8 bytes.
817// register - the name of the register to be loaded.
818.macro LOADREG counter size register return
819 ldr \register , [x9], #\size
820 add \counter, \counter, 12
821 b \return
822.endm
823
824// Store ints.
825.LstoreW2:
826 LOADREG x8 4 w2 .LfillRegisters
827 LOADREG x8 4 w3 .LfillRegisters
828 LOADREG x8 4 w4 .LfillRegisters
829 LOADREG x8 4 w5 .LfillRegisters
830 LOADREG x8 4 w6 .LfillRegisters
831 LOADREG x8 4 w7 .LfillRegisters
832
833// Store longs.
834.LstoreX2:
835 LOADREG x8 8 x2 .LfillRegisters
836 LOADREG x8 8 x3 .LfillRegisters
837 LOADREG x8 8 x4 .LfillRegisters
838 LOADREG x8 8 x5 .LfillRegisters
839 LOADREG x8 8 x6 .LfillRegisters
840 LOADREG x8 8 x7 .LfillRegisters
841
842// Store singles.
843.LstoreS0:
844 LOADREG x15 4 s0 .LfillRegisters
845 LOADREG x15 4 s1 .LfillRegisters
846 LOADREG x15 4 s2 .LfillRegisters
847 LOADREG x15 4 s3 .LfillRegisters
848 LOADREG x15 4 s4 .LfillRegisters
849 LOADREG x15 4 s5 .LfillRegisters
850 LOADREG x15 4 s6 .LfillRegisters
851 LOADREG x15 4 s7 .LfillRegisters
852
853// Store doubles.
854.LstoreD0:
855 LOADREG x15 8 d0 .LfillRegisters
856 LOADREG x15 8 d1 .LfillRegisters
857 LOADREG x15 8 d2 .LfillRegisters
858 LOADREG x15 8 d3 .LfillRegisters
859 LOADREG x15 8 d4 .LfillRegisters
860 LOADREG x15 8 d5 .LfillRegisters
861 LOADREG x15 8 d6 .LfillRegisters
862 LOADREG x15 8 d7 .LfillRegisters
863
864
865.LcallFunction:
866
Andreas Gampe03906cf2014-04-07 12:08:28 -0700867 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000868
Stuart Monteithb95a5342014-03-12 13:32:32 +0000869END art_quick_invoke_stub
870
871/* extern"C"
872 * void art_quick_invoke_static_stub(ArtMethod *method, x0
873 * uint32_t *args, x1
874 * uint32_t argsize, w2
875 * Thread *self, x3
876 * JValue *result, x4
877 * char *shorty); x5
878 */
879ENTRY art_quick_invoke_static_stub
880 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700881 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000882
883 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
884 // Parse the passed shorty to determine which register to load.
885 // Load addresses for routines that load WXSD registers.
886 adr x11, .LstoreW1_2
887 adr x12, .LstoreX1_2
888 adr x13, .LstoreS0_2
889 adr x14, .LstoreD0_2
890
891 // Initialize routine offsets to 0 for integers and floats.
892 // x8 for integers, x15 for floating point.
893 mov x8, #0
894 mov x15, #0
895
896 add x10, x5, #1 // Load shorty address, plus one to skip return value.
897
898 // Loop to fill registers.
899.LfillRegisters2:
900 ldrb w17, [x10], #1 // Load next character in signature, and increment.
901 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
902
903 cmp w17, #'F' // is this a float?
904 bne .LisDouble2
905
906 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700907 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000908
909 add x17, x13, x15 // Calculate subroutine to jump to.
910 br x17
911
912.LisDouble2:
913 cmp w17, #'D' // is this a double?
914 bne .LisLong2
915
916 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700917 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000918
919 add x17, x14, x15 // Calculate subroutine to jump to.
920 br x17
921
922.LisLong2:
923 cmp w17, #'J' // is this a long?
924 bne .LisOther2
925
926 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700927 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000928
929 add x17, x12, x8 // Calculate subroutine to jump to.
930 br x17
931
Stuart Monteithb95a5342014-03-12 13:32:32 +0000932.LisOther2: // Everything else takes one vReg.
933 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700934 beq .Ladvance4_2
935
Stuart Monteithb95a5342014-03-12 13:32:32 +0000936 add x17, x11, x8 // Calculate subroutine to jump to.
937 br x17
938
Andreas Gampe03906cf2014-04-07 12:08:28 -0700939.Ladvance4_2:
940 add x9, x9, #4
941 b .LfillRegisters2
942
943.Ladvance8_2:
944 add x9, x9, #8
945 b .LfillRegisters2
946
Stuart Monteithb95a5342014-03-12 13:32:32 +0000947// Store ints.
948.LstoreW1_2:
949 LOADREG x8 4 w1 .LfillRegisters2
950 LOADREG x8 4 w2 .LfillRegisters2
951 LOADREG x8 4 w3 .LfillRegisters2
952 LOADREG x8 4 w4 .LfillRegisters2
953 LOADREG x8 4 w5 .LfillRegisters2
954 LOADREG x8 4 w6 .LfillRegisters2
955 LOADREG x8 4 w7 .LfillRegisters2
956
957// Store longs.
958.LstoreX1_2:
959 LOADREG x8 8 x1 .LfillRegisters2
960 LOADREG x8 8 x2 .LfillRegisters2
961 LOADREG x8 8 x3 .LfillRegisters2
962 LOADREG x8 8 x4 .LfillRegisters2
963 LOADREG x8 8 x5 .LfillRegisters2
964 LOADREG x8 8 x6 .LfillRegisters2
965 LOADREG x8 8 x7 .LfillRegisters2
966
967// Store singles.
968.LstoreS0_2:
969 LOADREG x15 4 s0 .LfillRegisters2
970 LOADREG x15 4 s1 .LfillRegisters2
971 LOADREG x15 4 s2 .LfillRegisters2
972 LOADREG x15 4 s3 .LfillRegisters2
973 LOADREG x15 4 s4 .LfillRegisters2
974 LOADREG x15 4 s5 .LfillRegisters2
975 LOADREG x15 4 s6 .LfillRegisters2
976 LOADREG x15 4 s7 .LfillRegisters2
977
978// Store doubles.
979.LstoreD0_2:
980 LOADREG x15 8 d0 .LfillRegisters2
981 LOADREG x15 8 d1 .LfillRegisters2
982 LOADREG x15 8 d2 .LfillRegisters2
983 LOADREG x15 8 d3 .LfillRegisters2
984 LOADREG x15 8 d4 .LfillRegisters2
985 LOADREG x15 8 d5 .LfillRegisters2
986 LOADREG x15 8 d6 .LfillRegisters2
987 LOADREG x15 8 d7 .LfillRegisters2
988
989
990.LcallFunction2:
991
Andreas Gampe03906cf2014-04-07 12:08:28 -0700992 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000993
Stuart Monteithb95a5342014-03-12 13:32:32 +0000994END art_quick_invoke_static_stub
995
Andreas Gampe03906cf2014-04-07 12:08:28 -0700996
Stuart Monteithb95a5342014-03-12 13:32:32 +0000997
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000998/* extern"C" void art_quick_osr_stub(void** stack, x0
999 * size_t stack_size_in_bytes, x1
Vladimir Marko7e614112018-03-06 14:34:06 +00001000 * const uint8_t* native_pc, x2
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001001 * JValue *result, x3
1002 * char *shorty, x4
1003 * Thread *self) x5
1004 */
1005ENTRY art_quick_osr_stub
Vladimir Markoa26f4162018-03-02 13:53:53 +00001006SAVE_SIZE=14*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, FP, LR saved.
1007 SAVE_TWO_REGS_INCREASE_FRAME x3, x4, SAVE_SIZE
1008 SAVE_TWO_REGS x19, x20, 16
1009 SAVE_TWO_REGS x21, x22, 32
1010 SAVE_TWO_REGS x23, x24, 48
1011 SAVE_TWO_REGS x25, x26, 64
1012 SAVE_TWO_REGS x27, x28, 80
1013 SAVE_TWO_REGS xFP, xLR, 96
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001014
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001015 mov xSELF, x5 // Move thread pointer into SELF register.
Roland Levillain97c46462017-05-11 14:04:03 +01001016 REFRESH_MARKING_REGISTER
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001017
Vladimir Markoa26f4162018-03-02 13:53:53 +00001018 INCREASE_FRAME 16
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001019 str xzr, [sp] // Store null for ArtMethod* slot
1020 // Branch to stub.
1021 bl .Losr_entry
Vladimir Markoa26f4162018-03-02 13:53:53 +00001022 .cfi_remember_state
1023 DECREASE_FRAME 16
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001024
Vladimir Markoa26f4162018-03-02 13:53:53 +00001025 // Restore saved registers including value address and shorty address.
1026 RESTORE_TWO_REGS x19, x20, 16
1027 RESTORE_TWO_REGS x21, x22, 32
1028 RESTORE_TWO_REGS x23, x24, 48
1029 RESTORE_TWO_REGS x25, x26, 64
1030 RESTORE_TWO_REGS x27, x28, 80
1031 RESTORE_TWO_REGS xFP, xLR, 96
1032 RESTORE_TWO_REGS_DECREASE_FRAME x3, x4, SAVE_SIZE
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001033
1034 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1035 ldrb w10, [x4]
1036
1037 // Check the return type and store the correct register into the jvalue in memory.
1038
1039 // Don't set anything for a void type.
1040 cmp w10, #'V'
1041 beq .Losr_exit
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001042 // Is it a double?
1043 cmp w10, #'D'
Vladimir Markoa26f4162018-03-02 13:53:53 +00001044 beq .Losr_return_double
1045 // Is it a float?
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001046 cmp w10, #'F'
Vladimir Markoa26f4162018-03-02 13:53:53 +00001047 beq .Losr_return_float
1048 // Just store x0. Doesn't matter if it is 64 or 32 bits.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001049 str x0, [x3]
Vladimir Markoa26f4162018-03-02 13:53:53 +00001050.Losr_exit:
1051 ret
1052.Losr_return_double:
1053 str d0, [x3]
1054 ret
1055.Losr_return_float:
1056 str s0, [x3]
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001057 ret
1058
1059.Losr_entry:
Vladimir Markoa26f4162018-03-02 13:53:53 +00001060 .cfi_restore_state // Reset unwind info so following code unwinds.
1061 .cfi_def_cfa_offset (SAVE_SIZE+16) // workaround for clang bug: 31975598
1062
1063 mov x9, sp // Save stack pointer.
1064 .cfi_def_cfa_register x9
1065
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001066 // Update stack pointer for the callee
1067 sub sp, sp, x1
1068
1069 // Update link register slot expected by the callee.
1070 sub w1, w1, #8
1071 str lr, [sp, x1]
1072
1073 // Copy arguments into stack frame.
1074 // Use simple copy routine for now.
1075 // 4 bytes per slot.
1076 // X0 - source address
1077 // W1 - args length
1078 // SP - destination address.
1079 // W10 - temporary
1080.Losr_loop_entry:
Vladimir Markoa26f4162018-03-02 13:53:53 +00001081 cbz w1, .Losr_loop_exit
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001082 sub w1, w1, #4
1083 ldr w10, [x0, x1]
1084 str w10, [sp, x1]
1085 b .Losr_loop_entry
1086
1087.Losr_loop_exit:
1088 // Branch to the OSR entry point.
1089 br x2
1090
1091END art_quick_osr_stub
1092
Stuart Monteithb95a5342014-03-12 13:32:32 +00001093 /*
1094 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1095 */
1096
1097ENTRY art_quick_do_long_jump
1098 // Load FPRs
1099 ldp d0, d1, [x1], #16
1100 ldp d2, d3, [x1], #16
1101 ldp d4, d5, [x1], #16
1102 ldp d6, d7, [x1], #16
1103 ldp d8, d9, [x1], #16
1104 ldp d10, d11, [x1], #16
1105 ldp d12, d13, [x1], #16
1106 ldp d14, d15, [x1], #16
1107 ldp d16, d17, [x1], #16
1108 ldp d18, d19, [x1], #16
1109 ldp d20, d21, [x1], #16
1110 ldp d22, d23, [x1], #16
1111 ldp d24, d25, [x1], #16
1112 ldp d26, d27, [x1], #16
1113 ldp d28, d29, [x1], #16
1114 ldp d30, d31, [x1]
1115
1116 // Load GPRs
1117 // TODO: lots of those are smashed, could optimize.
1118 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001119 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001120 ldp x28, x29, [x0], #-16
1121 ldp x26, x27, [x0], #-16
1122 ldp x24, x25, [x0], #-16
1123 ldp x22, x23, [x0], #-16
1124 ldp x20, x21, [x0], #-16
Roland Levillain97c46462017-05-11 14:04:03 +01001125 ldp x18, x19, [x0], #-16 // X18 & xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +00001126 ldp x16, x17, [x0], #-16
1127 ldp x14, x15, [x0], #-16
1128 ldp x12, x13, [x0], #-16
1129 ldp x10, x11, [x0], #-16
1130 ldp x8, x9, [x0], #-16
1131 ldp x6, x7, [x0], #-16
1132 ldp x4, x5, [x0], #-16
1133 ldp x2, x3, [x0], #-16
1134 mov sp, x1
1135
Roland Levillain97c46462017-05-11 14:04:03 +01001136 REFRESH_MARKING_REGISTER
1137
Andreas Gampe639bdd12015-06-03 11:22:45 -07001138 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1139 ldr x1, [x0, #33*8]
1140 // And the value of x0.
1141 ldr x0, [x0]
1142
1143 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001144END art_quick_do_long_jump
1145
Andreas Gampef4e910b2014-04-29 16:55:52 -07001146 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001147 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1148 * possibly null object to lock.
1149 *
1150 * Derived from arm32 code.
1151 */
1152 .extern artLockObjectFromCode
1153ENTRY art_quick_lock_object
1154 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001155 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001156.Lretry_lock:
1157 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
Hans Boehm67eda382017-01-17 15:03:38 -08001158 ldaxr w1, [x4] // acquire needed only in most common case
1159 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001160 cbnz w3, .Lnot_unlocked // already thin locked
1161 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1162 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001163 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001164 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001165 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001166.Lnot_unlocked: // x1: original lock word
1167 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001168 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1169 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1170 uxth w2, w2 // zero top 16 bits
1171 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1172 // else contention, go to slow path
Hans Boehm67eda382017-01-17 15:03:38 -08001173 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001174 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 -07001175 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 -08001176 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1177 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1178 stxr w3, w2, [x4]
1179 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001180 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001181.Llock_stxr_fail:
1182 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001183.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001184 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001185 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001186 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001187 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001188 REFRESH_MARKING_REGISTER
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001189 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1190END art_quick_lock_object
1191
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001192ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001193 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001194 mov x1, xSELF // pass Thread::Current
1195 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001196 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001197 REFRESH_MARKING_REGISTER
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001198 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1199END art_quick_lock_object_no_inline
1200
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001201 /*
1202 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1203 * x0 holds the possibly null object to lock.
1204 *
1205 * Derived from arm32 code.
1206 */
1207 .extern artUnlockObjectFromCode
1208ENTRY art_quick_unlock_object
1209 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001210 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1211.Lretry_unlock:
1212#ifndef USE_READ_BARRIER
1213 ldr w1, [x4]
1214#else
1215 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1216#endif
1217 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001218 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1219 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hans Boehm67eda382017-01-17 15:03:38 -08001220 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001221 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001222 uxth w3, w3 // zero top 16 bits
1223 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hans Boehm67eda382017-01-17 15:03:38 -08001224 and w3, w1, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001225 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001226 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001227 // transition to unlocked
Hans Boehm67eda382017-01-17 15:03:38 -08001228 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 -08001229#ifndef USE_READ_BARRIER
Hans Boehm67eda382017-01-17 15:03:38 -08001230 stlr w3, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001231#else
Hans Boehm67eda382017-01-17 15:03:38 -08001232 stlxr w2, w3, [x4] // Need to use atomic instructions for read barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001233 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1234#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001235 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001236.Lrecursive_thin_unlock: // w1: original lock word
1237 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1238#ifndef USE_READ_BARRIER
1239 str w1, [x4]
1240#else
1241 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1242 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1243#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001244 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001245.Lunlock_stxr_fail:
Hans Boehm67eda382017-01-17 15:03:38 -08001246 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001247.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001248 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001249 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001250 bl artUnlockObjectFromCode // (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_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001255
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001256ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001257 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001258 mov x1, xSELF // pass Thread::Current
1259 bl artUnlockObjectFromCode // (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_unlock_object_no_inline
1264
Andreas Gampe525cde22014-04-22 15:44:50 -07001265 /*
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001266 * Entry from managed code that calls artInstanceOfFromCode and on failure calls
1267 * artThrowClassCastExceptionForObject.
Andreas Gampe525cde22014-04-22 15:44:50 -07001268 */
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001269 .extern artInstanceOfFromCode
1270 .extern artThrowClassCastExceptionForObject
1271ENTRY art_quick_check_instance_of
Vladimir Marko175e7862018-03-27 09:03:13 +00001272 // Type check using the bit string passes null as the target class. In that case just throw.
1273 cbz x1, .Lthrow_class_cast_exception_for_bitstring_check
1274
Andreas Gampe525cde22014-04-22 15:44:50 -07001275 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001276 // Stack needs to be 16B aligned on calls.
Vladimir Marko215076b2016-09-07 18:05:55 +01001277 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1278 SAVE_REG xLR, 24
Andreas Gampe525cde22014-04-22 15:44:50 -07001279
1280 // Call runtime code
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001281 bl artInstanceOfFromCode
Andreas Gampe525cde22014-04-22 15:44:50 -07001282
Vladimir Markobf92b3f2018-01-17 18:11:30 +00001283 // Restore LR.
1284 RESTORE_REG xLR, 24
1285
Andreas Gampe525cde22014-04-22 15:44:50 -07001286 // Check for exception
1287 cbz x0, .Lthrow_class_cast_exception
1288
1289 // Restore and return
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001290 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001291 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001292 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001293 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001294 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampe6b90d422015-06-26 19:49:24 -07001295
Andreas Gampe525cde22014-04-22 15:44:50 -07001296.Lthrow_class_cast_exception:
1297 // Restore
Vladimir Marko215076b2016-09-07 18:05:55 +01001298 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001299
Vladimir Marko175e7862018-03-27 09:03:13 +00001300.Lthrow_class_cast_exception_for_bitstring_check:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001301 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001302 mov x2, xSELF // pass Thread::Current
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001303 bl artThrowClassCastExceptionForObject // (Object*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001304 brk 0 // We should not return here...
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001305END art_quick_check_instance_of
Andreas Gampe525cde22014-04-22 15:44:50 -07001306
Man Cao1aee9002015-07-14 22:31:42 -07001307// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1308.macro POP_REG_NE xReg, offset, xExclude
1309 .ifnc \xReg, \xExclude
1310 ldr \xReg, [sp, #\offset] // restore xReg
1311 .cfi_restore \xReg
1312 .endif
1313.endm
1314
Roland Levillain4359e612016-07-20 11:32:19 +01001315// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1316// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1317.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1318 .ifc \xReg1, \xExclude
1319 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1320 .else
1321 .ifc \xReg2, \xExclude
1322 ldr \xReg1, [sp, #\offset] // restore xReg1
1323 .else
1324 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1325 .endif
1326 .endif
1327 .cfi_restore \xReg1
1328 .cfi_restore \xReg2
1329.endm
1330
Man Cao1aee9002015-07-14 22:31:42 -07001331 /*
1332 * Macro to insert read barrier, only used in art_quick_aput_obj.
1333 * xDest, wDest and xObj are registers, offset is a defined literal such as
1334 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1335 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1336 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1337 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001338.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001339#ifdef USE_READ_BARRIER
Roland Levillain97c46462017-05-11 14:04:03 +01001340# ifdef USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001341 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1342 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1343 // False dependency to avoid needing load/load fence.
1344 add \xObj, \xObj, \xTemp, lsr #32
1345 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1346 UNPOISON_HEAP_REF \wDest
1347 b .Lrb_exit\number
Roland Levillain97c46462017-05-11 14:04:03 +01001348# endif // USE_BAKER_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001349.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001350 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
Vladimir Marko215076b2016-09-07 18:05:55 +01001351 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1352 SAVE_TWO_REGS x2, x3, 16
1353 SAVE_TWO_REGS x4, xLR, 32
Man Cao1aee9002015-07-14 22:31:42 -07001354
Man Cao63069212015-08-21 15:51:39 -07001355 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001356 .ifnc \xObj, x1
1357 mov x1, \xObj // pass xObj
1358 .endif
1359 mov w2, #\offset // pass offset
1360 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1361 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1362 .ifnc \wDest, w0
1363 mov \wDest, w0 // save return value in wDest
1364 .endif
1365
1366 // Conditionally restore saved registers
1367 POP_REG_NE x0, 0, \xDest
1368 POP_REG_NE x1, 8, \xDest
1369 POP_REG_NE x2, 16, \xDest
1370 POP_REG_NE x3, 24, \xDest
1371 POP_REG_NE x4, 32, \xDest
Vladimir Marko215076b2016-09-07 18:05:55 +01001372 RESTORE_REG xLR, 40
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001373 DECREASE_FRAME 48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001374.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001375#else
1376 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1377 UNPOISON_HEAP_REF \wDest
1378#endif // USE_READ_BARRIER
1379.endm
1380
Man Cao1aee9002015-07-14 22:31:42 -07001381#ifdef USE_READ_BARRIER
1382 .extern artReadBarrierSlow
1383#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001384ENTRY art_quick_aput_obj
1385 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001386 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1387 // This also zero-extends to x3
1388 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1389 // This also zero-extends to x3
1390 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1391 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001392 cmp w3, w4 // value's type == array's component type - trivial assignability
1393 bne .Lcheck_assignability
1394.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001395 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001396 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001397 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001398 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1399 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001400 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001401 strb w3, [x3, x0]
1402 ret
1403.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001404 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001405 // "Compress" = do nothing
1406 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1407 ret
1408.Lcheck_assignability:
1409 // Store arguments and link register
Vladimir Marko215076b2016-09-07 18:05:55 +01001410 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1411 SAVE_TWO_REGS x2, xLR, 16
Andreas Gampef4e910b2014-04-29 16:55:52 -07001412
1413 // Call runtime code
1414 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1415 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1416 bl artIsAssignableFromCode
1417
1418 // Check for exception
1419 cbz x0, .Lthrow_array_store_exception
1420
1421 // Restore
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001422 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001423 RESTORE_TWO_REGS x2, xLR, 16
1424 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001425
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001426 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001427 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001428 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001429 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1430 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001431 lsr x0, x0, #CARD_TABLE_CARD_SHIFT
Andreas Gampef4e910b2014-04-29 16:55:52 -07001432 strb w3, [x3, x0]
1433 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001434 .cfi_restore_state // Reset unwind info so following code unwinds.
Vladimir Marko112aa102016-12-01 11:53:54 +00001435 .cfi_def_cfa_offset 32 // workaround for clang bug: 31975598
Andreas Gampef4e910b2014-04-29 16:55:52 -07001436.Lthrow_array_store_exception:
Vladimir Marko215076b2016-09-07 18:05:55 +01001437 RESTORE_TWO_REGS x2, xLR, 16
1438 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001439
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001440 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko908eb222016-09-14 10:29:18 +01001441 mov x1, x2 // Pass value.
1442 mov x2, xSELF // Pass Thread::Current.
1443 bl artThrowArrayStoreException // (Object*, Object*, Thread*).
1444 brk 0 // Unreached.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001445END art_quick_aput_obj
1446
Stuart Monteithb95a5342014-03-12 13:32:32 +00001447// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001448.macro ONE_ARG_DOWNCALL name, entrypoint, return
1449 .extern \entrypoint
1450ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001451 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001452 mov x1, xSELF // pass Thread::Current
1453 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001454 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001455 REFRESH_MARKING_REGISTER
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001456 \return
1457END \name
1458.endm
1459
1460// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001461.macro TWO_ARG_DOWNCALL name, entrypoint, return
1462 .extern \entrypoint
1463ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001464 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001465 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001466 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001467 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001468 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001469 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001470END \name
1471.endm
1472
Jeff Hao848f70a2014-01-15 13:49:50 -08001473// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001474.macro THREE_ARG_DOWNCALL name, entrypoint, return
1475 .extern \entrypoint
1476ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001477 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001478 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001479 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001480 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001481 REFRESH_MARKING_REGISTER
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001482 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001483END \name
1484.endm
1485
Jeff Hao848f70a2014-01-15 13:49:50 -08001486// Macro to facilitate adding new allocation entrypoints.
1487.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1488 .extern \entrypoint
1489ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001490 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001491 mov x4, xSELF // pass Thread::Current
1492 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001493 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001494 REFRESH_MARKING_REGISTER
Jeff Hao848f70a2014-01-15 13:49:50 -08001495 \return
Jeff Hao848f70a2014-01-15 13:49:50 -08001496END \name
1497.endm
1498
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001499// Macros taking opportunity of code similarities for downcalls.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001500.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1501 .extern \entrypoint
1502ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001503 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001504 mov x1, xSELF // pass Thread::Current
1505 bl \entrypoint // (uint32_t type_idx, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001506 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001507 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001508 \return
1509END \name
1510.endm
1511
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001512.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1513 .extern \entrypoint
1514ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001515 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001516 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001517 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001518 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001519 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001520 \return
1521END \name
1522.endm
1523
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001524.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1525 .extern \entrypoint
1526ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001527 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001528 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001529 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001530 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001531 REFRESH_MARKING_REGISTER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001532 \return
1533END \name
1534.endm
1535
Orion Hodson18259d72018-04-12 11:18:23 +01001536 /*
1537 * Macro for resolution and initialization of indexed DEX file
1538 * constants such as classes and strings.
1539 */
Mingyao Yang0a87a652017-04-12 13:43:15 -07001540.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL name, entrypoint, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Markoea4c1262017-02-06 19:59:33 +00001541 .extern \entrypoint
1542ENTRY \name
Mingyao Yang0a87a652017-04-12 13:43:15 -07001543 SETUP_SAVE_EVERYTHING_FRAME \runtime_method_offset // save everything for stack crawl
Vladimir Markoea4c1262017-02-06 19:59:33 +00001544 mov x1, xSELF // pass Thread::Current
1545 bl \entrypoint // (int32_t index, Thread* self)
1546 cbz w0, 1f // If result is null, deliver the OOME.
1547 .cfi_remember_state
1548 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_X0
Roland Levillain97c46462017-05-11 14:04:03 +01001549 REFRESH_MARKING_REGISTER
Vladimir Markoea4c1262017-02-06 19:59:33 +00001550 ret // return
1551 .cfi_restore_state
1552 .cfi_def_cfa_offset FRAME_SIZE_SAVE_EVERYTHING // workaround for clang bug: 31975598
15531:
1554 DELIVER_PENDING_EXCEPTION_FRAME_READY
1555END \name
1556.endm
1557
Mingyao Yang0a87a652017-04-12 13:43:15 -07001558.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT name, entrypoint
1559 ONE_ARG_SAVE_EVERYTHING_DOWNCALL \name, \entrypoint, RUNTIME_SAVE_EVERYTHING_FOR_CLINIT_METHOD_OFFSET
1560.endm
1561
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001562.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1563 cbz w0, 1f // result zero branch over
1564 ret // return
15651:
1566 DELIVER_PENDING_EXCEPTION
1567.endm
1568
Matteo Franchindfd891a2014-04-30 12:17:17 +01001569 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001570 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1571 * failure.
1572 */
1573TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1574
1575 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001576 * Entry from managed code when uninitialized static storage, this stub will run the class
1577 * initializer and deliver the exception on error. On success the static storage base is
1578 * returned.
1579 */
Mingyao Yang0a87a652017-04-12 13:43:15 -07001580ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_static_storage, artInitializeStaticStorageFromCode
1581ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_type, artInitializeTypeFromCode
Vladimir Markoea4c1262017-02-06 19:59:33 +00001582ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode
Orion Hodson18259d72018-04-12 11:18:23 +01001583ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_method_type, artResolveMethodTypeFromCode
Vladimir Markoea4c1262017-02-06 19:59:33 +00001584ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_string, artResolveStringFromCode
Matteo Franchindfd891a2014-04-30 12:17:17 +01001585
Roland Levillain809f5b12018-01-04 14:05:59 +00001586// Note: Functions `art{Get,Set}<Kind>{Static,Instance}FromCompiledCode` are
1587// defined with a macro in runtime/entrypoints/quick/quick_field_entrypoints.cc.
Roland Levillain97c46462017-05-11 14:04:03 +01001588
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001589ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1590ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1591ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1592ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1593ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1594ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1595ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001596
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001597TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1598TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1599TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1600TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1601TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1602TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1603TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001604
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001605TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1606TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1607TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1608TWO_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1609TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001610
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001611THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1612THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1613THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1614THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1615THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001616
Stuart Monteithb95a5342014-03-12 13:32:32 +00001617// Generate the allocation entrypoints for each allocator.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001618GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
Mathieu Chartier8261d022016-08-08 09:41:04 -07001619// Comment out allocators that have arm64 specific asm.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001620// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1621// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1622GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001623// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001624// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
1625// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
1626// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
1627// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
Mathieu Chartier8261d022016-08-08 09:41:04 -07001628GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1629GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1630GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001631
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001632// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
1633// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
1634GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
1635// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
1636// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_tlab, TLAB)
1637// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_tlab, TLAB)
1638// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_tlab, TLAB)
1639// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_tlab, TLAB)
1640GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_tlab, TLAB)
1641GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_tlab, TLAB)
1642GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_tlab, TLAB)
1643
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001644// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1645// If isInitialized=0 the compiler can only assume it's been at least resolved.
1646.macro ART_QUICK_ALLOC_OBJECT_ROSALLOC c_name, cxx_name, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001647ENTRY \c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001648 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001649 // x0: type, xSELF(x19): Thread::Current
1650 // x1-x7: free.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001651 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1652 // allocation stack has room.
1653 // ldp won't work due to large offset.
1654 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1655 cmp x3, x4
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001656 bhs .Lslow_path\c_name
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001657 ldr w3, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3)
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001658 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001659 // local allocation. Also does the
1660 // finalizable and initialization
1661 // checks.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001662 // When isInitialized == 0, then the class is potentially not yet initialized.
1663 // If the class is not yet initialized, the object size will be very large to force the branch
1664 // below to be taken.
1665 //
1666 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001667 bhs .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001668 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001669 // from the size. Since the size is
1670 // already aligned we can combine the
1671 // two shifts together.
1672 add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1673 // Subtract pointer size since ther
1674 // are no runs for 0 byte allocations
1675 // and the size is already aligned.
1676 ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001677 // Load the free list head (x3). This
1678 // will be the return val.
1679 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001680 cbz x3, .Lslow_path\c_name
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001681 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1682 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1683 // and update the list head with the
1684 // next pointer.
1685 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1686 // Store the class pointer in the
1687 // header. This also overwrites the
1688 // next pointer. The offsets are
1689 // asserted to match.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001690
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001691#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1692#error "Class pointer needs to overwrite next pointer."
1693#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001694 POISON_HEAP_REF w0
1695 str w0, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001696 // Push the new object onto the thread
1697 // local allocation stack and
1698 // increment the thread local
1699 // allocation stack top.
1700 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1701 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1702 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1703 // Decrement the size of the free list
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001704
1705 // After this "STR" the object is published to the thread local allocation stack,
1706 // and it will be observable from a runtime internal (eg. Heap::VisitObjects) point of view.
1707 // It is not yet visible to the running (user) compiled code until after the return.
1708 //
1709 // To avoid the memory barrier prior to the "STR", a trick is employed, by differentiating
1710 // the state of the allocation stack slot. It can be a pointer to one of:
1711 // 0) Null entry, because the stack was bumped but the new pointer wasn't written yet.
1712 // (The stack initial state is "null" pointers).
1713 // 1) A partially valid object, with an invalid class pointer to the next free rosalloc slot.
1714 // 2) A fully valid object, with a valid class pointer pointing to a real class.
1715 // Other states are not allowed.
1716 //
1717 // An object that is invalid only temporarily, and will eventually become valid.
1718 // The internal runtime code simply checks if the object is not null or is partial and then
1719 // ignores it.
1720 //
1721 // (Note: The actual check is done by seeing if a non-null object has a class pointer pointing
1722 // to ClassClass, and that the ClassClass's class pointer is self-cyclic. A rosalloc free slot
1723 // "next" pointer is not-cyclic.)
1724 //
1725 // See also b/28790624 for a listing of CLs dealing with this race.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001726 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1727 sub x1, x1, #1
1728 // TODO: consider combining this store
1729 // and the list head store above using
1730 // strd.
1731 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001732
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001733 mov x0, x3 // Set the return value and return.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001734.if \isInitialized == 0
1735 // This barrier is only necessary when the allocation also requires
1736 // a class initialization check.
1737 //
1738 // If the class is already observably initialized, then new-instance allocations are protected
1739 // from publishing by the compiler which inserts its own StoreStore barrier.
1740 dmb ish
1741 // Use a "dmb ish" fence here because if there are later loads of statics (e.g. class size),
1742 // they should happen-after the implicit initialization check.
1743 //
1744 // TODO: Remove this dmb for class initialization checks (b/36692143) by introducing
1745 // a new observably-initialized class state.
1746.endif
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001747 ret
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001748.Lslow_path\c_name:
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001749 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1750 mov x1, xSELF // pass Thread::Current
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001751 bl \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001752 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001753 REFRESH_MARKING_REGISTER
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001754 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001755END \c_name
1756.endm
1757
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001758ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_resolved_rosalloc, artAllocObjectFromCodeResolvedRosAlloc, /* isInitialized */ 0
1759ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_initialized_rosalloc, artAllocObjectFromCodeInitializedRosAlloc, /* isInitialized */ 1
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001760
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001761// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1762// If isInitialized=0 the compiler can only assume it's been at least resolved.
1763.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001764 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1765 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
1766 ldr w7, [x0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7).
1767 add x6, x4, x7 // Add object size to tlab pos.
1768 cmp x6, x5 // Check if it fits, overflow works
1769 // since the tlab pos and end are 32
1770 // bit values.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001771
1772 // When isInitialized == 0, then the class is potentially not yet initialized.
1773 // If the class is not yet initialized, the object size will be very large to force the branch
1774 // below to be taken.
1775 //
1776 // See InitializeClassVisitors in class-inl.h for more details.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001777 bhi \slowPathLabel
1778 str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1779 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1780 add x5, x5, #1
1781 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1782 POISON_HEAP_REF w0
1783 str w0, [x4, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1784 // Fence. This is "ish" not "ishst" so
1785 // that the code after this allocation
1786 // site will see the right values in
1787 // the fields of the class.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001788 mov x0, x4
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.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001795 dmb ish
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001796 // 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
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001802 ret
1803.endm
1804
1805// The common code for art_quick_alloc_object_*region_tlab
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001806.macro GENERATE_ALLOC_OBJECT_RESOLVED_TLAB name, entrypoint, isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001807ENTRY \name
1808 // Fast path region tlab allocation.
1809 // x0: type, xSELF(x19): Thread::Current
1810 // x1-x7: free.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001811 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED .Lslow_path\name, \isInitialized
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001812.Lslow_path\name:
1813 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
1814 mov x1, xSELF // Pass Thread::Current.
1815 bl \entrypoint // (mirror::Class*, Thread*)
1816 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001817 REFRESH_MARKING_REGISTER
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001818 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1819END \name
1820.endm
1821
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001822GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, /* isInitialized */ 0
1823GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, /* isInitialized */ 1
1824GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_resolved_tlab, artAllocObjectFromCodeResolvedTLAB, /* isInitialized */ 0
1825GENERATE_ALLOC_OBJECT_RESOLVED_TLAB art_quick_alloc_object_initialized_tlab, artAllocObjectFromCodeInitializedTLAB, /* isInitialized */ 1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001826
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001827.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 +01001828 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignment mask
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001829 // (addr + 7) & ~7. The mask must
1830 // be 64 bits to keep high bits in
1831 // case of overflow.
1832 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1833 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1834 // 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 -07001835 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1836 bhs \slowPathLabel // path.
1837
1838 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1839 // we use (end - begin) to handle
1840 // negative size arrays. It is
1841 // assumed that a negative size will
1842 // always be greater unsigned than
1843 // region size.
1844 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1845 sub \xTemp2, \xTemp2, \xTemp0
1846 cmp \xTemp1, \xTemp2
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001847
1848 // The array class is always initialized here. Unlike new-instance,
1849 // this does not act as a double test.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001850 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001851 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1852 // Move old thread_local_pos to x0
1853 // for the return value.
1854 mov x0, \xTemp0
1855 add \xTemp0, \xTemp0, \xTemp1
1856 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1857 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1858 add \xTemp0, \xTemp0, #1
1859 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1860 POISON_HEAP_REF \wClass
1861 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1862 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1863 // Fence.
Igor Murashkin2f470ed2017-05-18 15:50:59 -07001864// new-array is special. The class is loaded and immediately goes to the Initialized state
1865// before it is published. Therefore the only fence needed is for the publication of the object.
1866// See ClassLinker::CreateArrayClass() for more details.
1867
1868// For publication of the new array, we don't need a 'dmb ishst' here.
1869// The compiler generates 'dmb ishst' for all new-array insts.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001870 ret
1871.endm
1872
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001873.macro GENERATE_ALLOC_ARRAY_TLAB name, entrypoint, size_setup
Mathieu Chartier8261d022016-08-08 09:41:04 -07001874ENTRY \name
1875 // Fast path array allocation for region tlab allocation.
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001876 // x0: mirror::Class* type
Mathieu Chartier8261d022016-08-08 09:41:04 -07001877 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001878 // x2-x7: free.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001879 mov x3, x0
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001880 \size_setup x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1881 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 -07001882.Lslow_path\name:
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001883 // x0: mirror::Class* klass
Mathieu Chartier8261d022016-08-08 09:41:04 -07001884 // x1: int32_t component_count
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001885 // x2: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001886 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Nicolas Geoffraye761bcc2017-01-19 08:59:37 +00001887 mov x2, xSELF // pass Thread::Current
Mathieu Chartier8261d022016-08-08 09:41:04 -07001888 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001889 RESTORE_SAVE_REFS_ONLY_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001890 REFRESH_MARKING_REGISTER
Mathieu Chartier8261d022016-08-08 09:41:04 -07001891 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1892END \name
1893.endm
1894
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001895.macro COMPUTE_ARRAY_SIZE_UNKNOWN xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1896 // Array classes are never finalizable or uninitialized, no need to check.
1897 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1898 UNPOISON_HEAP_REF \wTemp0
1899 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1900 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1901 // bits.
1902 // xCount is holding a 32 bit value,
1903 // it can not overflow.
1904 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1905 // Add array data offset and alignment.
1906 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1907#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1908#error Long array data offset must be 4 greater than int array data offset.
1909#endif
1910
1911 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1912 // component size shift is 3
1913 // (for 64 bit alignment).
1914 and \xTemp0, \xTemp0, #4
1915 add \xTemp1, \xTemp1, \xTemp0
1916.endm
1917
1918.macro COMPUTE_ARRAY_SIZE_8 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1919 // Add array data offset and alignment.
1920 add \xTemp1, \xCount, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1921.endm
1922
1923.macro COMPUTE_ARRAY_SIZE_16 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1924 lsl \xTemp1, \xCount, #1
1925 // Add array data offset and alignment.
1926 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1927.endm
1928
1929.macro COMPUTE_ARRAY_SIZE_32 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1930 lsl \xTemp1, \xCount, #2
1931 // Add array data offset and alignment.
1932 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1933.endm
1934
1935.macro COMPUTE_ARRAY_SIZE_64 xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1936 lsl \xTemp1, \xCount, #3
1937 // Add array data offset and alignment.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001938 add \xTemp1, \xTemp1, #(MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
Nicolas Geoffrayb048cb72017-01-23 22:50:24 +00001939.endm
1940
Roland Levillain97c46462017-05-11 14:04:03 +01001941// TODO(ngeoffray): art_quick_alloc_array_resolved_region_tlab is not used for arm64, remove
1942// the entrypoint once all backends have been updated to use the size variants.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001943GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1944GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_8
1945GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_16
1946GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_32
1947GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_64
1948GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1949GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_8
1950GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_16
1951GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_32
1952GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_64
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001953
Zheng Xu48241e72014-05-23 11:52:42 +08001954 /*
Zheng Xu69a50302015-04-14 20:04:41 +08001955 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08001956 */
1957 .extern artTestSuspendFromCode
1958ENTRY art_quick_test_suspend
Mingyao Yang0a87a652017-04-12 13:43:15 -07001959 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 +08001960 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001961 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001962 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01001963 REFRESH_MARKING_REGISTER
Vladimir Marko952dbb12016-07-28 12:01:51 +01001964 ret
Zheng Xu48241e72014-05-23 11:52:42 +08001965END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001966
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001967ENTRY art_quick_implicit_suspend
1968 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001969 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001970 bl artTestSuspendFromCode // (Thread*)
Roland Levillain97c46462017-05-11 14:04:03 +01001971 RESTORE_SAVE_REFS_ONLY_FRAME
1972 REFRESH_MARKING_REGISTER
1973 ret
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001974END art_quick_implicit_suspend
1975
Andreas Gampee62a07e2014-03-26 14:53:21 -07001976 /*
1977 * Called by managed code that is attempting to call a method on a proxy class. On entry
1978 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1979 * method agrees with a ref and args callee save frame.
1980 */
1981 .extern artQuickProxyInvokeHandler
1982ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001983 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001984 mov x2, xSELF // pass Thread::Current
1985 mov x3, sp // pass SP
1986 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001987 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001988 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001989 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Roland Levillain97c46462017-05-11 14:04:03 +01001990 REFRESH_MARKING_REGISTER
Andreas Gamped1e91672014-06-02 22:50:05 -07001991 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001992 ret // return on success
1993.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001994 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001995 DELIVER_PENDING_EXCEPTION
1996END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001997
Andreas Gampe51f76352014-05-21 08:28:48 -07001998 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001999 * Called to resolve an imt conflict.
2000 * x0 is the conflict ArtMethod.
2001 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2002 *
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002003 * Note that this stub writes to xIP0, xIP1, x13-x15, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002004 */
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002005 .extern artLookupResolvedMethod
Andreas Gampe51f76352014-05-21 08:28:48 -07002006ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002007 ldr xIP0, [sp, #0] // Load referrer
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002008 // Load the declaring class (without read barrier) and access flags (for obsolete method check).
2009 // The obsolete flag is set with suspended threads, so we do not need an acquire operation here.
2010#if ART_METHOD_ACCESS_FLAGS_OFFSET != ART_METHOD_DECLARING_CLASS_OFFSET + 4
2011#error "Expecting declaring class and access flags to be consecutive for LDP."
2012#endif
2013 ldp wIP0, w15, [xIP0, #ART_METHOD_DECLARING_CLASS_OFFSET]
2014 // If the method is obsolete, just go through the dex cache miss slow path.
2015 tbnz x15, #ACC_OBSOLETE_METHOD_SHIFT, .Limt_conflict_trampoline_dex_cache_miss
2016 ldr wIP0, [xIP0, #MIRROR_CLASS_DEX_CACHE_OFFSET] // Load the DexCache (without read barrier).
2017 UNPOISON_HEAP_REF wIP0
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002018 ubfx x15, xIP1, #0, #METHOD_DEX_CACHE_HASH_BITS // Calculate DexCache method slot index.
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002019 ldr xIP0, [xIP0, #MIRROR_DEX_CACHE_RESOLVED_METHODS_OFFSET] // Load the resolved methods.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002020 add xIP0, xIP0, x15, lsl #(POINTER_SIZE_SHIFT + 1) // Load DexCache method slot address.
2021
2022 // Relaxed atomic load x14:x15 from the dex cache slot.
2023.Limt_conflict_trampoline_retry_load:
2024 ldxp x14, x15, [xIP0]
2025 stxp w13, x14, x15, [xIP0]
2026 cbnz w13, .Limt_conflict_trampoline_retry_load
2027
2028 cmp x15, xIP1 // Compare method index to see if we had a DexCache method hit.
2029 bne .Limt_conflict_trampoline_dex_cache_miss
2030.Limt_conflict_trampoline_have_interface_method:
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002031 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2032 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2033.Limt_table_iterate:
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002034 cmp x0, x14
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002035 // Branch if found. Benchmarks have shown doing a branch here is better.
2036 beq .Limt_table_found
2037 // If the entry is null, the interface method is not in the ImtConflictTable.
2038 cbz x0, .Lconflict_trampoline
2039 // Iterate over the entries of the ImtConflictTable.
2040 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2041 b .Limt_table_iterate
2042.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002043 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002044 // and jump to it.
2045 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2046 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2047 br xIP0
2048.Lconflict_trampoline:
2049 // Call the runtime stub to populate the ImtConflictTable and jump to the
2050 // resolved method.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002051 mov x0, x14 // Load interface method
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002052 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002053.Limt_conflict_trampoline_dex_cache_miss:
2054 // We're not creating a proper runtime method frame here,
2055 // artLookupResolvedMethod() is not allowed to walk the stack.
2056
2057 // Save GPR args and return address, allocate space for FPR args, align stack.
2058 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2059 SAVE_TWO_REGS x2, x3, 16
2060 SAVE_TWO_REGS x4, x5, 32
2061 SAVE_TWO_REGS x6, x7, 48
2062 SAVE_REG xLR, (8 * 8 + 8 * 8 + 8)
2063
2064 // Save FPR args.
2065 stp d0, d1, [sp, #64]
2066 stp d2, d3, [sp, #80]
2067 stp d4, d5, [sp, #96]
2068 stp d6, d7, [sp, #112]
2069
2070 mov x0, xIP1 // Pass method index.
2071 ldr x1, [sp, #(8 * 8 + 8 * 8 + 8 + 8)] // Pass referrer.
2072 bl artLookupResolvedMethod // (uint32_t method_index, ArtMethod* referrer)
2073 mov x14, x0 // Move the interface method to x14 where the loop above expects it.
2074
2075 // Restore FPR args.
2076 ldp d0, d1, [sp, #64]
2077 ldp d2, d3, [sp, #80]
2078 ldp d4, d5, [sp, #96]
2079 ldp d6, d7, [sp, #112]
2080
2081 // Restore GPR args and return address.
2082 RESTORE_REG xLR, (8 * 8 + 8 * 8 + 8)
2083 RESTORE_TWO_REGS x2, x3, 16
2084 RESTORE_TWO_REGS x4, x5, 32
2085 RESTORE_TWO_REGS x6, x7, 48
2086 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, (8 * 8 + 8 * 8 + 8 + 8)
2087
2088 // If the method wasn't resolved, skip the lookup and go to artInvokeInterfaceTrampoline().
2089 cbz x14, .Lconflict_trampoline
2090 b .Limt_conflict_trampoline_have_interface_method
Andreas Gampe51f76352014-05-21 08:28:48 -07002091END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002092
2093ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002094 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002095 mov x2, xSELF
2096 mov x3, sp
2097 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002098 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002099 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002100 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002101 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002102 REFRESH_MARKING_REGISTER
Zheng Xub551fdc2014-07-25 11:49:42 +08002103 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000021041:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002105 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002106 DELIVER_PENDING_EXCEPTION
2107END art_quick_resolution_trampoline
2108
2109/*
2110 * Generic JNI frame layout:
2111 *
2112 * #-------------------#
2113 * | |
2114 * | caller method... |
2115 * #-------------------# <--- SP on entry
2116 * | Return X30/LR |
2117 * | X29/FP | callee save
2118 * | X28 | callee save
2119 * | X27 | callee save
2120 * | X26 | callee save
2121 * | X25 | callee save
2122 * | X24 | callee save
2123 * | X23 | callee save
2124 * | X22 | callee save
2125 * | X21 | callee save
2126 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002127 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002128 * | X7 | arg7
2129 * | X6 | arg6
2130 * | X5 | arg5
2131 * | X4 | arg4
2132 * | X3 | arg3
2133 * | X2 | arg2
2134 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002135 * | D7 | float arg 8
2136 * | D6 | float arg 7
2137 * | D5 | float arg 6
2138 * | D4 | float arg 5
2139 * | D3 | float arg 4
2140 * | D2 | float arg 3
2141 * | D1 | float arg 2
2142 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002143 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002144 * #-------------------#
2145 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002146 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002147 * #-------------------#
2148 * | JNI Call Stack |
2149 * #-------------------# <--- SP on native call
2150 * | |
2151 * | Stack for Regs | The trampoline assembly will pop these values
2152 * | | into registers for native call
2153 * #-------------------#
2154 * | Native code ptr |
2155 * #-------------------#
2156 * | Free scratch |
2157 * #-------------------#
2158 * | Ptr to (1) | <--- SP
2159 * #-------------------#
2160 */
2161 /*
2162 * Called to do a generic JNI down-call
2163 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002164ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002165 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002166
2167 // Save SP , so we can have static CFI info.
2168 mov x28, sp
2169 .cfi_def_cfa_register x28
2170
2171 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002172 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002173 mov xFP, sp
2174
Zheng Xub551fdc2014-07-25 11:49:42 +08002175 mov xIP0, #5120
2176 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002177
2178 // prepare for artQuickGenericJniTrampoline call
2179 // (Thread*, SP)
2180 // x0 x1 <= C calling convention
2181 // xSELF xFP <= where they are
2182
2183 mov x0, xSELF // Thread*
2184 mov x1, xFP
2185 bl artQuickGenericJniTrampoline // (Thread*, sp)
2186
Andreas Gampec200a4a2014-06-16 18:39:09 -07002187 // The C call will have registered the complete save-frame on success.
2188 // The result of the call is:
2189 // x0: pointer to native code, 0 on error.
2190 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002191
Andreas Gampec200a4a2014-06-16 18:39:09 -07002192 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002193 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002194
Andreas Gampec200a4a2014-06-16 18:39:09 -07002195 // Release part of the alloca.
2196 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002197
Andreas Gampec200a4a2014-06-16 18:39:09 -07002198 // Save the code pointer
2199 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002200
2201 // Load parameters from frame into registers.
2202 // TODO Check with artQuickGenericJniTrampoline.
2203 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002204 ldp x0, x1, [sp]
2205 ldp x2, x3, [sp, #16]
2206 ldp x4, x5, [sp, #32]
2207 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002208
Andreas Gampec200a4a2014-06-16 18:39:09 -07002209 ldp d0, d1, [sp, #64]
2210 ldp d2, d3, [sp, #80]
2211 ldp d4, d5, [sp, #96]
2212 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002213
Andreas Gampec200a4a2014-06-16 18:39:09 -07002214 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002215
Zheng Xub551fdc2014-07-25 11:49:42 +08002216 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002217
2218 // result sign extension is handled in C code
2219 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002220 // (Thread*, result, result_f)
2221 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002222 mov x1, x0 // Result (from saved).
2223 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002224 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002225
2226 bl artQuickGenericJniEndTrampoline
2227
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002228 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002229 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002230 cbnz x2, .Lexception_in_native
2231
Stuart Monteithb95a5342014-03-12 13:32:32 +00002232 // Tear down the alloca.
2233 mov sp, x28
2234 .cfi_def_cfa_register sp
2235
Stuart Monteithb95a5342014-03-12 13:32:32 +00002236 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002237 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002238 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002239
2240 // store into fpr, for when it's a fpr return...
2241 fmov d0, x0
2242 ret
2243
Stuart Monteithb95a5342014-03-12 13:32:32 +00002244.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002245 // Move to x1 then sp to please assembler.
2246 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Vladimir Marko2196c652017-11-30 16:16:07 +00002247 add sp, x1, #-1 // Remove the GenericJNI tag.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002248 .cfi_def_cfa_register sp
2249 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002250 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002251END art_quick_generic_jni_trampoline
2252
2253/*
2254 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2255 * of a quick call:
2256 * x0 = method being called/to bridge to.
2257 * x1..x7, d0..d7 = arguments to that method.
2258 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002259ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002260 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002261
2262 // x0 will contain mirror::ArtMethod* method.
2263 mov x1, xSELF // How to get Thread::Current() ???
2264 mov x2, sp
2265
2266 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2267 // mirror::ArtMethod** sp)
2268 bl artQuickToInterpreterBridge
2269
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002270 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Roland Levillain97c46462017-05-11 14:04:03 +01002271 REFRESH_MARKING_REGISTER
Stuart Monteithb95a5342014-03-12 13:32:32 +00002272
2273 fmov d0, x0
2274
2275 RETURN_OR_DELIVER_PENDING_EXCEPTION
2276END art_quick_to_interpreter_bridge
2277
Alex Lightdb01a092017-04-03 15:39:55 -07002278/*
2279 * Called to attempt to execute an obsolete method.
2280 */
2281ONE_ARG_RUNTIME_EXCEPTION art_invoke_obsolete_method_stub, artInvokeObsoleteMethod
2282
Andreas Gamped58342c2014-06-05 14:18:08 -07002283
2284//
2285// Instrumentation-related stubs
2286//
2287 .extern artInstrumentationMethodEntryFromCode
2288ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002289 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002290
Zheng Xub551fdc2014-07-25 11:49:42 +08002291 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002292
2293 mov x2, xSELF
Alex Lightb7edcda2017-04-27 13:20:31 -07002294 mov x3, sp // Pass SP
2295 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, SP)
Andreas Gamped58342c2014-06-05 14:18:08 -07002296
Zheng Xub551fdc2014-07-25 11:49:42 +08002297 mov xIP0, x0 // x0 = result of call.
2298 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002299
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002300 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Roland Levillain97c46462017-05-11 14:04:03 +01002301 REFRESH_MARKING_REGISTER
Alex Lightb7edcda2017-04-27 13:20:31 -07002302 cbz xIP0, 1f // Deliver the pending exception if method is null.
Andreas Gamped58342c2014-06-05 14:18:08 -07002303 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002304 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Alex Lightb7edcda2017-04-27 13:20:31 -07002305
23061:
2307 DELIVER_PENDING_EXCEPTION
Andreas Gamped58342c2014-06-05 14:18:08 -07002308END art_quick_instrumentation_entry
2309
2310 .extern artInstrumentationMethodExitFromCode
2311ENTRY art_quick_instrumentation_exit
2312 mov xLR, #0 // Clobber LR for later checks.
Mingyao Yang2ee17902017-08-30 11:37:08 -07002313 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002314
Mingyao Yang2ee17902017-08-30 11:37:08 -07002315 add x3, sp, #8 // Pass floating-point result pointer, in kSaveEverything frame.
2316 add x2, sp, #264 // Pass integer result pointer, in kSaveEverything frame.
2317 mov x1, sp // Pass SP.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002318 mov x0, xSELF // Pass Thread.
Alex Lightb7edcda2017-04-27 13:20:31 -07002319 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res*, fpr_res*)
Andreas Gamped58342c2014-06-05 14:18:08 -07002320
Mingyao Yang2ee17902017-08-30 11:37:08 -07002321 cbz x0, .Ldo_deliver_instrumentation_exception
2322 // Handle error
2323 cbnz x1, .Ldeoptimize
2324 // Normal return.
2325 str x0, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2326 // Set return pc.
2327 RESTORE_SAVE_EVERYTHING_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002328 REFRESH_MARKING_REGISTER
Mingyao Yang2ee17902017-08-30 11:37:08 -07002329 br lr
2330.Ldo_deliver_instrumentation_exception:
2331 DELIVER_PENDING_EXCEPTION_FRAME_READY
2332.Ldeoptimize:
2333 str x1, [sp, #FRAME_SIZE_SAVE_EVERYTHING - 8]
2334 // Set return pc.
2335 RESTORE_SAVE_EVERYTHING_FRAME
2336 // Jump to art_quick_deoptimize.
2337 b art_quick_deoptimize
Andreas Gamped58342c2014-06-05 14:18:08 -07002338END art_quick_instrumentation_exit
2339
2340 /*
2341 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2342 * will long jump to the upcall with a special exception of -1.
2343 */
2344 .extern artDeoptimize
2345ENTRY art_quick_deoptimize
Mingyao Yang2ee17902017-08-30 11:37:08 -07002346 SETUP_SAVE_EVERYTHING_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002347 mov x0, xSELF // Pass thread.
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002348 bl artDeoptimize // (Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002349 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002350END art_quick_deoptimize
2351
Sebastien Hertz07474662015-08-25 15:12:33 +00002352 /*
2353 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2354 * will long jump to the upcall with a special exception of -1.
2355 */
2356 .extern artDeoptimizeFromCompiledCode
2357ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002358 SETUP_SAVE_EVERYTHING_FRAME
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002359 mov x1, xSELF // Pass thread.
2360 bl artDeoptimizeFromCompiledCode // (DeoptimizationKind, Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002361 brk 0
2362END art_quick_deoptimize_from_compiled_code
2363
Andreas Gamped58342c2014-06-05 14:18:08 -07002364
Serban Constantinescu169489b2014-06-11 16:43:35 +01002365 /*
2366 * String's indexOf.
2367 *
2368 * TODO: Not very optimized.
2369 * On entry:
2370 * x0: string object (known non-null)
2371 * w1: char to match (known <= 0xFFFF)
2372 * w2: Starting offset in string data
2373 */
2374ENTRY art_quick_indexof
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002375#if (STRING_COMPRESSION_FEATURE)
2376 ldr w4, [x0, #MIRROR_STRING_COUNT_OFFSET]
2377#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002378 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002379#endif
Jeff Hao848f70a2014-01-15 13:49:50 -08002380 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
jessicahandojo05765752016-09-09 19:01:32 -07002381#if (STRING_COMPRESSION_FEATURE)
2382 /* w4 holds count (with flag) and w3 holds actual length */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002383 lsr w3, w4, #1
jessicahandojo05765752016-09-09 19:01:32 -07002384#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002385 /* Clamp start to [0..count] */
2386 cmp w2, #0
2387 csel w2, wzr, w2, lt
2388 cmp w2, w3
2389 csel w2, w3, w2, gt
2390
Serban Constantinescu169489b2014-06-11 16:43:35 +01002391 /* Save a copy to compute result */
2392 mov x5, x0
2393
jessicahandojo05765752016-09-09 19:01:32 -07002394#if (STRING_COMPRESSION_FEATURE)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002395 tbz w4, #0, .Lstring_indexof_compressed
jessicahandojo05765752016-09-09 19:01:32 -07002396#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002397 /* Build pointer to start of data to compare and pre-bias */
2398 add x0, x0, x2, lsl #1
2399 sub x0, x0, #2
Serban Constantinescu169489b2014-06-11 16:43:35 +01002400 /* Compute iteration count */
2401 sub w2, w3, w2
2402
2403 /*
2404 * At this point we have:
2405 * x0: start of the data to test
2406 * w1: char to compare
2407 * w2: iteration count
2408 * x5: original start of string data
2409 */
2410
2411 subs w2, w2, #4
2412 b.lt .Lindexof_remainder
2413
2414.Lindexof_loop4:
2415 ldrh w6, [x0, #2]!
2416 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002417 ldrh wIP0, [x0, #2]!
2418 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002419 cmp w6, w1
2420 b.eq .Lmatch_0
2421 cmp w7, w1
2422 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002423 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002424 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002425 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002426 b.eq .Lmatch_3
2427 subs w2, w2, #4
2428 b.ge .Lindexof_loop4
2429
2430.Lindexof_remainder:
2431 adds w2, w2, #4
2432 b.eq .Lindexof_nomatch
2433
2434.Lindexof_loop1:
2435 ldrh w6, [x0, #2]!
2436 cmp w6, w1
2437 b.eq .Lmatch_3
2438 subs w2, w2, #1
2439 b.ne .Lindexof_loop1
2440
2441.Lindexof_nomatch:
2442 mov x0, #-1
2443 ret
2444
2445.Lmatch_0:
2446 sub x0, x0, #6
2447 sub x0, x0, x5
2448 asr x0, x0, #1
2449 ret
2450.Lmatch_1:
2451 sub x0, x0, #4
2452 sub x0, x0, x5
2453 asr x0, x0, #1
2454 ret
2455.Lmatch_2:
2456 sub x0, x0, #2
2457 sub x0, x0, x5
2458 asr x0, x0, #1
2459 ret
2460.Lmatch_3:
2461 sub x0, x0, x5
2462 asr x0, x0, #1
2463 ret
jessicahandojo05765752016-09-09 19:01:32 -07002464#if (STRING_COMPRESSION_FEATURE)
2465 /*
2466 * Comparing compressed string character-per-character with
2467 * input character
2468 */
2469.Lstring_indexof_compressed:
2470 add x0, x0, x2
2471 sub x0, x0, #1
2472 sub w2, w3, w2
2473.Lstring_indexof_compressed_loop:
2474 subs w2, w2, #1
2475 b.lt .Lindexof_nomatch
2476 ldrb w6, [x0, #1]!
2477 cmp w6, w1
2478 b.eq .Lstring_indexof_compressed_matched
2479 b .Lstring_indexof_compressed_loop
2480.Lstring_indexof_compressed_matched:
2481 sub x0, x0, x5
2482 ret
2483#endif
Serban Constantinescu169489b2014-06-11 16:43:35 +01002484END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002485
2486 /*
2487 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002488 * getting its argument and returning its result through W register
2489 * `wreg` (corresponding to X register `xreg`), saving and restoring
2490 * all caller-save registers.
2491 *
2492 * If `wreg` is different from `w0`, the generated function follows a
2493 * non-standard runtime calling convention:
2494 * - register `wreg` is used to pass the (sole) argument of this
2495 * function (instead of W0);
2496 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002497 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002498 * - W0 is treated like a normal (non-argument) caller-save register;
2499 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002500 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002501 */
Roland Levillain4359e612016-07-20 11:32:19 +01002502.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002503ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002504 // Reference is null, no work to do at all.
2505 cbz \wreg, .Lret_rb_\name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002506 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2507 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002508 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lnot_marked_rb_\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002509.Lret_rb_\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002510 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002511.Lnot_marked_rb_\name:
2512 // 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 +01002513 tst wIP0, wIP0, lsl #1
2514 bmi .Lret_forwarding_address\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002515.Lslow_rb_\name:
Vladimir Markoea4c1262017-02-06 19:59:33 +00002516 /*
2517 * Allocate 44 stack slots * 8 = 352 bytes:
2518 * - 20 slots for core registers X0-15, X17-X19, LR
2519 * - 24 slots for floating-point registers D0-D7 and D16-D31
2520 */
2521 // We must not clobber IP1 since code emitted for HLoadClass and HLoadString
2522 // relies on IP1 being preserved.
Roland Levillain4359e612016-07-20 11:32:19 +01002523 // Save all potentially live caller-save core registers.
Vladimir Markoea4c1262017-02-06 19:59:33 +00002524 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
Vladimir Marko215076b2016-09-07 18:05:55 +01002525 SAVE_TWO_REGS x2, x3, 16
2526 SAVE_TWO_REGS x4, x5, 32
2527 SAVE_TWO_REGS x6, x7, 48
2528 SAVE_TWO_REGS x8, x9, 64
2529 SAVE_TWO_REGS x10, x11, 80
2530 SAVE_TWO_REGS x12, x13, 96
2531 SAVE_TWO_REGS x14, x15, 112
Vladimir Markoea4c1262017-02-06 19:59:33 +00002532 SAVE_TWO_REGS x17, x18, 128 // Skip x16, i.e. IP0.
2533 SAVE_TWO_REGS x19, xLR, 144 // Save also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002534 // Save all potentially live caller-save floating-point registers.
2535 stp d0, d1, [sp, #160]
2536 stp d2, d3, [sp, #176]
2537 stp d4, d5, [sp, #192]
2538 stp d6, d7, [sp, #208]
2539 stp d16, d17, [sp, #224]
2540 stp d18, d19, [sp, #240]
2541 stp d20, d21, [sp, #256]
2542 stp d22, d23, [sp, #272]
2543 stp d24, d25, [sp, #288]
2544 stp d26, d27, [sp, #304]
2545 stp d28, d29, [sp, #320]
2546 stp d30, d31, [sp, #336]
Roland Levillain4359e612016-07-20 11:32:19 +01002547
2548 .ifnc \wreg, w0
2549 mov w0, \wreg // Pass arg1 - obj from `wreg`
2550 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002551 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002552 .ifnc \wreg, w0
2553 mov \wreg, w0 // Return result into `wreg`
2554 .endif
2555
2556 // Restore core regs, except `xreg`, as `wreg` is used to return the
2557 // result of this function (simply remove it from the stack instead).
2558 POP_REGS_NE x0, x1, 0, \xreg
2559 POP_REGS_NE x2, x3, 16, \xreg
2560 POP_REGS_NE x4, x5, 32, \xreg
2561 POP_REGS_NE x6, x7, 48, \xreg
2562 POP_REGS_NE x8, x9, 64, \xreg
2563 POP_REGS_NE x10, x11, 80, \xreg
2564 POP_REGS_NE x12, x13, 96, \xreg
2565 POP_REGS_NE x14, x15, 112, \xreg
Vladimir Markoea4c1262017-02-06 19:59:33 +00002566 POP_REGS_NE x17, x18, 128, \xreg
2567 POP_REGS_NE x19, xLR, 144, \xreg // Restore also return address.
Roland Levillain4359e612016-07-20 11:32:19 +01002568 // Restore floating-point registers.
2569 ldp d0, d1, [sp, #160]
2570 ldp d2, d3, [sp, #176]
2571 ldp d4, d5, [sp, #192]
2572 ldp d6, d7, [sp, #208]
2573 ldp d16, d17, [sp, #224]
2574 ldp d18, d19, [sp, #240]
2575 ldp d20, d21, [sp, #256]
2576 ldp d22, d23, [sp, #272]
2577 ldp d24, d25, [sp, #288]
2578 ldp d26, d27, [sp, #304]
2579 ldp d28, d29, [sp, #320]
2580 ldp d30, d31, [sp, #336]
Vladimir Markoea4c1262017-02-06 19:59:33 +00002581 // Remove frame and return.
2582 DECREASE_FRAME 352
Roland Levillain02b75802016-07-13 11:54:35 +01002583 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002584.Lret_forwarding_address\name:
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002585 // Shift left by the forwarding address shift. This clears out the state bits since they are
2586 // in the top 2 bits of the lock word.
Vladimir Markob9d01112017-03-31 10:55:41 +01002587 lsl \wreg, wIP0, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002588 ret
Roland Levillain02b75802016-07-13 11:54:35 +01002589END \name
2590.endm
2591
Roland Levillain4359e612016-07-20 11:32:19 +01002592READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2593READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2594READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2595READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2596READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2597READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2598READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2599READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2600READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2601READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2602READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2603READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2604READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2605READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2606READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2607READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
Mathieu Chartier36c22712016-08-12 13:19:44 -07002608// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
Roland Levillain4359e612016-07-20 11:32:19 +01002609READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2610READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2611READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2612READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2613READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2614READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2615READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2616READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2617READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2618READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2619READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2620READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2621READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29
Orion Hodsonac141392017-01-13 11:53:47 +00002622
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002623
2624.macro SELECT_X_OR_W_FOR_MACRO macro_to_use, x, w, xreg
2625 .if \xreg
2626 \macro_to_use \x
2627 .else
2628 \macro_to_use \w
2629 .endif
2630.endm
2631
2632.macro FOR_REGISTERS macro_for_register, macro_for_reserved_register, xreg
2633 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x0, w0, \xreg
2634 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x1, w1, \xreg
2635 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x2, w2, \xreg
2636 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x3, w3, \xreg
2637 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x4, w4, \xreg
2638 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x5, w5, \xreg
2639 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x6, w6, \xreg
2640 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x7, w7, \xreg
2641 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x8, w8, \xreg
2642 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x9, w9, \xreg
2643 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x10, w10, \xreg
2644 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x11, w11, \xreg
2645 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x12, w12, \xreg
2646 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x13, w13, \xreg
2647 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x14, w14, \xreg
2648 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x15, w15, \xreg
2649 \macro_for_reserved_register // IP0 is reserved
2650 \macro_for_reserved_register // IP1 is reserved
2651 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x18, w18, \xreg
2652 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x19, w19, \xreg
2653 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x20, w20, \xreg
2654 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x21, w21, \xreg
2655 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x22, w22, \xreg
2656 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x23, w23, \xreg
2657 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x24, w24, \xreg
2658 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x25, w25, \xreg
2659 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x26, w26, \xreg
2660 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x27, w27, \xreg
2661 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x28, w28, \xreg
2662 SELECT_X_OR_W_FOR_MACRO \macro_for_register, x29, w29, \xreg
2663 \macro_for_reserved_register // lr is reserved
2664 \macro_for_reserved_register // sp is reserved
2665.endm
2666
2667.macro FOR_XREGISTERS macro_for_register, macro_for_reserved_register
2668 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 1
2669.endm
2670
2671.macro FOR_WREGISTERS macro_for_register, macro_for_reserved_register
2672 FOR_REGISTERS \macro_for_register, \macro_for_reserved_register, /* xreg */ 0
2673.endm
2674
2675.macro BRK0_BRK0
2676 brk 0
2677 brk 0
2678.endm
2679
2680#if BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET != BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
2681#error "Array and field introspection code sharing requires same LDR offset."
2682#endif
2683.macro INTROSPECTION_ARRAY_LOAD index_reg
2684 ldr wIP0, [xIP0, \index_reg, lsl #2]
2685 b art_quick_read_barrier_mark_introspection
2686.endm
2687
2688.macro MOV_WIP0_TO_WREG_AND_BL_LR reg
2689 mov \reg, wIP0
2690 br lr // Do not use RET as we do not enter the entrypoint with "BL".
2691.endm
2692
2693.macro READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH ldr_offset
2694 /*
2695 * Allocate 44 stack slots * 8 = 352 bytes:
2696 * - 19 slots for core registers X0-15, X18-X19, LR
2697 * - 1 slot padding
2698 * - 24 slots for floating-point registers D0-D7 and D16-D31
2699 */
2700 // Save all potentially live caller-save core registers.
2701 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 352
2702 SAVE_TWO_REGS x2, x3, 16
2703 SAVE_TWO_REGS x4, x5, 32
2704 SAVE_TWO_REGS x6, x7, 48
2705 SAVE_TWO_REGS x8, x9, 64
2706 SAVE_TWO_REGS x10, x11, 80
2707 SAVE_TWO_REGS x12, x13, 96
2708 SAVE_TWO_REGS x14, x15, 112
2709 SAVE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2710 SAVE_REG xLR, 144 // Save return address, skip padding at 152.
2711 // Save all potentially live caller-save floating-point registers.
2712 stp d0, d1, [sp, #160]
2713 stp d2, d3, [sp, #176]
2714 stp d4, d5, [sp, #192]
2715 stp d6, d7, [sp, #208]
2716 stp d16, d17, [sp, #224]
2717 stp d18, d19, [sp, #240]
2718 stp d20, d21, [sp, #256]
2719 stp d22, d23, [sp, #272]
2720 stp d24, d25, [sp, #288]
2721 stp d26, d27, [sp, #304]
2722 stp d28, d29, [sp, #320]
2723 stp d30, d31, [sp, #336]
2724
2725 mov x0, xIP0
2726 bl artReadBarrierMark // artReadBarrierMark(obj)
2727 mov xIP0, x0
2728
2729 // Restore core regs, except x0 and x1 as the return register switch case
2730 // address calculation is smoother with an extra register.
2731 RESTORE_TWO_REGS x2, x3, 16
2732 RESTORE_TWO_REGS x4, x5, 32
2733 RESTORE_TWO_REGS x6, x7, 48
2734 RESTORE_TWO_REGS x8, x9, 64
2735 RESTORE_TWO_REGS x10, x11, 80
2736 RESTORE_TWO_REGS x12, x13, 96
2737 RESTORE_TWO_REGS x14, x15, 112
2738 RESTORE_TWO_REGS x18, x19, 128 // Skip x16, x17, i.e. IP0, IP1.
2739 RESTORE_REG xLR, 144 // Restore return address.
Nicolas Geoffray7015e762017-07-02 21:37:02 +01002740 // Restore caller-save floating-point registers.
2741 ldp d0, d1, [sp, #160]
2742 ldp d2, d3, [sp, #176]
2743 ldp d4, d5, [sp, #192]
2744 ldp d6, d7, [sp, #208]
2745 ldp d16, d17, [sp, #224]
2746 ldp d18, d19, [sp, #240]
2747 ldp d20, d21, [sp, #256]
2748 ldp d22, d23, [sp, #272]
2749 ldp d24, d25, [sp, #288]
2750 ldp d26, d27, [sp, #304]
2751 ldp d28, d29, [sp, #320]
2752 ldp d30, d31, [sp, #336]
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002753
2754 ldr x0, [lr, #\ldr_offset] // Load the instruction.
2755 adr xIP1, .Lmark_introspection_return_switch
2756 bfi xIP1, x0, #3, #5 // Calculate switch case address.
2757 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 352
2758 br xIP1
2759.endm
2760
2761 /*
2762 * Use introspection to load a reference from the same address as the LDR
2763 * instruction in generated code would load (unless loaded by the thunk,
2764 * see below), call ReadBarrier::Mark() with that reference if needed
2765 * and return it in the same register as the LDR instruction would load.
2766 *
2767 * The entrypoint is called through a thunk that differs across load kinds.
2768 * For field and array loads the LDR instruction in generated code follows
2769 * the branch to the thunk, i.e. the LDR is at [LR, #-4], and the thunk
2770 * knows the holder and performs the gray bit check, returning to the LDR
2771 * instruction if the object is not gray, so this entrypoint no longer
2772 * needs to know anything about the holder. For GC root loads, the LDR
2773 * instruction in generated code precedes the branch to the thunk (i.e.
2774 * the LDR is at [LR, #-8]) and the thunk does not do the gray bit check.
2775 *
2776 * For field accesses and array loads with a constant index the thunk loads
2777 * the reference into IP0 using introspection and calls the main entrypoint,
Vladimir Markod1ef8732017-04-18 13:55:13 +01002778 * art_quick_read_barrier_mark_introspection. With heap poisoning enabled,
2779 * the passed reference is poisoned.
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002780 *
2781 * For array accesses with non-constant index, the thunk inserts the bits
2782 * 16-21 of the LDR instruction to the entrypoint address, effectively
2783 * calculating a switch case label based on the index register (bits 16-20)
2784 * and adding an extra offset (bit 21 is set) to differentiate from the
2785 * main entrypoint, then moves the base register to IP0 and jumps to the
2786 * switch case. Therefore we need to align the main entrypoint to 512 bytes,
2787 * accounting for a 256-byte offset followed by 32 array entrypoints
2788 * starting at art_quick_read_barrier_mark_introspection_arrays, each
2789 * containing an LDR (register) and a branch to the main entrypoint.
2790 *
2791 * For GC root accesses we cannot use the main entrypoint because of the
2792 * different offset where the LDR instruction in generated code is located.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002793 * (And even with heap poisoning enabled, GC roots are not poisoned.)
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002794 * To re-use the same entrypoint pointer in generated code, we make sure
2795 * that the gc root entrypoint (a copy of the entrypoint with a different
2796 * offset for introspection loads) is located at a known offset (768 bytes,
2797 * or BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET) from the main
2798 * entrypoint and the GC root thunk adjusts the entrypoint pointer, moves
2799 * the root register to IP0 and jumps to the customized entrypoint,
2800 * art_quick_read_barrier_mark_introspection_gc_roots. The thunk also
2801 * performs all the fast-path checks, so we need just the slow path.
2802 *
2803 * The code structure is
2804 * art_quick_read_barrier_mark_introspection:
2805 * Up to 256 bytes for the main entrypoint code.
2806 * Padding to 256 bytes if needed.
2807 * art_quick_read_barrier_mark_introspection_arrays:
2808 * Exactly 256 bytes for array load switch cases (32x2 instructions).
2809 * .Lmark_introspection_return_switch:
2810 * Exactly 256 bytes for return switch cases (32x2 instructions).
2811 * art_quick_read_barrier_mark_introspection_gc_roots:
2812 * GC root entrypoint code.
2813 */
2814 .balign 512
2815ENTRY art_quick_read_barrier_mark_introspection
2816 // At this point, IP0 contains the reference, IP1 can be freely used.
Vladimir Markod1ef8732017-04-18 13:55:13 +01002817 // For heap poisoning, the reference is poisoned, so unpoison it first.
2818 UNPOISON_HEAP_REF wIP0
Vladimir Markof4f2daa2017-03-20 18:26:59 +00002819 // If reference is null, just return it in the right register.
2820 cbz wIP0, .Lmark_introspection_return
2821 // Use wIP1 as temp and check the mark bit of the reference.
2822 ldr wIP1, [xIP0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2823 tbz wIP1, #LOCK_WORD_MARK_BIT_SHIFT, .Lmark_introspection_unmarked
2824.Lmark_introspection_return:
2825 // Without an extra register for the return switch case address calculation,
2826 // we exploit the high word of the xIP0 to temporarily store the ref_reg*8,
2827 // so the return switch below must move wIP0 instead of xIP0 to the register.
2828 ldr wIP1, [lr, #BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET] // Load the instruction.
2829 bfi xIP0, xIP1, #(32 + 3), #5 // Extract ref_reg*8 to high word in xIP0.
2830 adr xIP1, .Lmark_introspection_return_switch
2831 bfxil xIP1, xIP0, #32, #8 // Calculate return switch case address.
2832 br xIP1
2833.Lmark_introspection_unmarked:
2834 // Check if the top two bits are one, if this is the case it is a forwarding address.
2835 tst wIP1, wIP1, lsl #1
2836 bmi .Lmark_introspection_forwarding_address
2837 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET
2838
2839.Lmark_introspection_forwarding_address:
2840 // Shift left by the forwarding address shift. This clears out the state bits since they are
2841 // in the top 2 bits of the lock word.
2842 lsl wIP0, wIP1, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
2843 b .Lmark_introspection_return
2844
2845 // We're very close to the alloted 256B for the entrypoint code before the
2846 // array switch cases. Should we go a little bit over the limit, we can
2847 // move some code after the array switch cases and return switch cases.
2848 .balign 256
2849 .hidden art_quick_read_barrier_mark_introspection_arrays
2850 .global art_quick_read_barrier_mark_introspection_arrays
2851art_quick_read_barrier_mark_introspection_arrays:
2852 FOR_XREGISTERS INTROSPECTION_ARRAY_LOAD, BRK0_BRK0
2853.Lmark_introspection_return_switch:
2854 FOR_WREGISTERS MOV_WIP0_TO_WREG_AND_BL_LR, BRK0_BRK0
2855 .hidden art_quick_read_barrier_mark_introspection_gc_roots
2856 .global art_quick_read_barrier_mark_introspection_gc_roots
2857art_quick_read_barrier_mark_introspection_gc_roots:
2858 READ_BARRIER_MARK_INTROSPECTION_SLOW_PATH BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET
2859END art_quick_read_barrier_mark_introspection
2860
Orion Hodsonac141392017-01-13 11:53:47 +00002861.extern artInvokePolymorphic
2862ENTRY art_quick_invoke_polymorphic
2863 SETUP_SAVE_REFS_AND_ARGS_FRAME // Save callee saves in case allocation triggers GC.
2864 mov x2, xSELF
2865 mov x3, sp
2866 INCREASE_FRAME 16 // Reserve space for JValue result.
2867 str xzr, [sp, #0] // Initialize result to zero.
2868 mov x0, sp // Set r0 to point to result.
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002869 bl artInvokePolymorphic // artInvokePolymorphic(result, receiver, thread, save_area)
Orion Hodsonac141392017-01-13 11:53:47 +00002870 uxtb w0, w0 // Result is the return type descriptor as a char.
2871 sub w0, w0, 'A' // Convert to zero based index.
2872 cmp w0, 'Z' - 'A'
2873 bhi .Lcleanup_and_return // Clean-up if out-of-bounds.
2874 adrp x1, .Lhandler_table // Compute address of handler table.
2875 add x1, x1, :lo12:.Lhandler_table
2876 ldrb w0, [x1, w0, uxtw] // Lookup handler offset in handler table.
2877 adr x1, .Lstart_of_handlers
2878 add x0, x1, w0, sxtb #2 // Convert relative offset to absolute address.
2879 br x0 // Branch to handler.
2880
2881.Lstart_of_handlers:
2882.Lstore_boolean_result:
2883 ldrb w0, [sp]
2884 b .Lcleanup_and_return
2885.Lstore_char_result:
2886 ldrh w0, [sp]
2887 b .Lcleanup_and_return
2888.Lstore_float_result:
2889 ldr s0, [sp]
2890 str s0, [sp, #32]
2891 b .Lcleanup_and_return
2892.Lstore_double_result:
2893 ldr d0, [sp]
2894 str d0, [sp, #32]
2895 b .Lcleanup_and_return
2896.Lstore_long_result:
2897 ldr x0, [sp]
2898 // Fall-through
2899.Lcleanup_and_return:
2900 DECREASE_FRAME 16
2901 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Roland Levillain97c46462017-05-11 14:04:03 +01002902 REFRESH_MARKING_REGISTER
Orion Hodsonac141392017-01-13 11:53:47 +00002903 RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
2904
2905 .section .rodata // Place handler table in read-only section away from text.
2906 .align 2
2907.macro HANDLER_TABLE_OFFSET handler_label
2908 .byte (\handler_label - .Lstart_of_handlers) / 4
2909.endm
2910.Lhandler_table:
2911 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // A
2912 HANDLER_TABLE_OFFSET(.Lstore_long_result) // B (byte)
2913 HANDLER_TABLE_OFFSET(.Lstore_char_result) // C (char)
2914 HANDLER_TABLE_OFFSET(.Lstore_double_result) // D (double)
2915 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // E
2916 HANDLER_TABLE_OFFSET(.Lstore_float_result) // F (float)
2917 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // G
2918 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // H
2919 HANDLER_TABLE_OFFSET(.Lstore_long_result) // I (int)
2920 HANDLER_TABLE_OFFSET(.Lstore_long_result) // J (long)
2921 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // K
2922 HANDLER_TABLE_OFFSET(.Lstore_long_result) // L (object - references are compressed and only 32-bits)
2923 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // M
2924 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // N
2925 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // O
2926 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // P
2927 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Q
2928 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // R
2929 HANDLER_TABLE_OFFSET(.Lstore_long_result) // S (short)
2930 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // T
2931 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // U
2932 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // V (void)
2933 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // W
2934 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // X
2935 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Y
2936 HANDLER_TABLE_OFFSET(.Lstore_boolean_result) // Z (boolean)
2937 .text
2938
2939END art_quick_invoke_polymorphic
David Srbecky946bb092018-03-09 17:23:01 +00002940
2941// Wrap ExecuteSwitchImpl in assembly method which specifies DEX PC for unwinding.
2942// Argument 0: x0: The context pointer for ExecuteSwitchImpl.
2943// Argument 1: x1: Pointer to the templated ExecuteSwitchImpl to call.
2944// Argument 2: x2: The value of DEX PC (memory address of the methods bytecode).
2945ENTRY ExecuteSwitchImplAsm
2946 SAVE_TWO_REGS_INCREASE_FRAME x19, xLR, 16
2947 mov x19, x2 // x19 = DEX PC
2948 CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* x0 */, 19 /* x19 */, 0)
2949 blr x1 // Call the wrapped method.
2950 RESTORE_TWO_REGS_DECREASE_FRAME x19, xLR, 16
2951 ret
2952END ExecuteSwitchImplAsm