blob: 35f5c5628278cfc4d1c17f911418ef9a039daf06 [file] [log] [blame]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_arm64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21
22 /*
23 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010024 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Stuart Monteithb95a5342014-03-12 13:32:32 +000025 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010026.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
27 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +080028 adrp xIP0, :got:_ZN3art7Runtime9instance_E
29 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000030
31 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010032 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +000033
Vladimir Markofd36f1f2016-08-03 18:49:58 +010034 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves];
35 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070036
37 sub sp, sp, #176
38 .cfi_adjust_cfa_offset 176
39
40 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010041#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176)
42#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043#endif
44
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010045 // Stack alignment filler [sp, #8].
46 // FP callee-saves.
47 stp d8, d9, [sp, #16]
48 stp d10, d11, [sp, #32]
49 stp d12, d13, [sp, #48]
50 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070051
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010052 // GP callee-saves
53 stp x19, x20, [sp, #80]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070054 .cfi_rel_offset x19, 80
Andreas Gampe5c1e4352014-04-21 19:28:24 -070055 .cfi_rel_offset x20, 88
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010056
57 stp x21, x22, [sp, #96]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070058 .cfi_rel_offset x21, 96
Andreas Gampe5c1e4352014-04-21 19:28:24 -070059 .cfi_rel_offset x22, 104
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010060
61 stp x23, x24, [sp, #112]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062 .cfi_rel_offset x23, 112
Andreas Gampe5c1e4352014-04-21 19:28:24 -070063 .cfi_rel_offset x24, 120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010064
65 stp x25, x26, [sp, #128]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070066 .cfi_rel_offset x25, 128
Andreas Gampe5c1e4352014-04-21 19:28:24 -070067 .cfi_rel_offset x26, 136
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010068
69 stp x27, x28, [sp, #144]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070070 .cfi_rel_offset x27, 144
Andreas Gampe5c1e4352014-04-21 19:28:24 -070071 .cfi_rel_offset x28, 152
Andreas Gampe5c1e4352014-04-21 19:28:24 -070072
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010073 stp x29, xLR, [sp, #160]
74 .cfi_rel_offset x29, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -070075 .cfi_rel_offset x30, 168
76
Vladimir Markofd36f1f2016-08-03 18:49:58 +010077 // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010078 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070079 // Place sp in Thread::Current()->top_quick_frame.
80 mov xIP0, sp
81 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +000082.endm
83
Zheng Xub551fdc2014-07-25 11:49:42 +080084 /*
85 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010086 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
Zheng Xub551fdc2014-07-25 11:49:42 +080087 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010088.macro SETUP_SAVE_REFS_ONLY_FRAME
89 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +080090 adrp xIP0, :got:_ZN3art7Runtime9instance_E
91 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
92
93 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010094 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Zheng Xub551fdc2014-07-25 11:49:42 +080095
Vladimir Markofd36f1f2016-08-03 18:49:58 +010096 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly];
97 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +080098
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010099 sub sp, sp, #96
100 .cfi_adjust_cfa_offset 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800101
102 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100103#if (FRAME_SIZE_SAVE_REFS_ONLY != 96)
104#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected."
Zheng Xub551fdc2014-07-25 11:49:42 +0800105#endif
106
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100107 // GP callee-saves.
108 // x20 paired with ArtMethod* - see below.
109 stp x21, x22, [sp, #16]
110 .cfi_rel_offset x21, 16
111 .cfi_rel_offset x22, 24
Zheng Xub551fdc2014-07-25 11:49:42 +0800112
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100113 stp x23, x24, [sp, #32]
114 .cfi_rel_offset x23, 32
115 .cfi_rel_offset x24, 40
Zheng Xub551fdc2014-07-25 11:49:42 +0800116
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100117 stp x25, x26, [sp, #48]
118 .cfi_rel_offset x25, 48
119 .cfi_rel_offset x26, 56
Zheng Xub551fdc2014-07-25 11:49:42 +0800120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100121 stp x27, x28, [sp, #64]
122 .cfi_rel_offset x27, 64
123 .cfi_rel_offset x28, 72
Zheng Xub551fdc2014-07-25 11:49:42 +0800124
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100125 stp x29, xLR, [sp, #80]
126 .cfi_rel_offset x29, 80
127 .cfi_rel_offset x30, 88
Zheng Xub551fdc2014-07-25 11:49:42 +0800128
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100129 // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100130 stp xIP0, x20, [sp]
131 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800132
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700133 // Place sp in Thread::Current()->top_quick_frame.
134 mov xIP0, sp
135 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800136.endm
137
138// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100139.macro RESTORE_SAVE_REFS_ONLY_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100140 // Callee-saves.
141 ldr x20, [sp, #8]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700142 .cfi_restore x20
Zheng Xu69a50302015-04-14 20:04:41 +0800143
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100144 ldp x21, x22, [sp, #16]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700145 .cfi_restore x21
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700146 .cfi_restore x22
Zheng Xu69a50302015-04-14 20:04:41 +0800147
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100148 ldp x23, x24, [sp, #32]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700149 .cfi_restore x23
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700150 .cfi_restore x24
Zheng Xu69a50302015-04-14 20:04:41 +0800151
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100152 ldp x25, x26, [sp, #48]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700153 .cfi_restore x25
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700154 .cfi_restore x26
Zheng Xu69a50302015-04-14 20:04:41 +0800155
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100156 ldp x27, x28, [sp, #64]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700157 .cfi_restore x27
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700158 .cfi_restore x28
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700159
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100160 ldp x29, xLR, [sp, #80]
Zheng Xu69a50302015-04-14 20:04:41 +0800161 .cfi_restore x29
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700162 .cfi_restore x30
163
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100164 add sp, sp, #96
165 .cfi_adjust_cfa_offset -96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000166.endm
167
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100168.macro POP_SAVE_REFS_ONLY_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100169 add sp, sp, #96
170 .cfi_adjust_cfa_offset - 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700171.endm
172
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100173.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
174 RESTORE_SAVE_REFS_ONLY_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800175 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000176.endm
177
178
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100179.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800180 sub sp, sp, #224
181 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000182
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700183 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100184#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224)
185#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700186#endif
187
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100188 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800189 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100190 stp d0, d1, [sp, #16]
191 stp d2, d3, [sp, #32]
192 stp d4, d5, [sp, #48]
193 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000194
Zheng Xu69a50302015-04-14 20:04:41 +0800195 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100196 stp x1, x2, [sp, #80]
197 .cfi_rel_offset x1, 80
198 .cfi_rel_offset x2, 88
Stuart Monteithb95a5342014-03-12 13:32:32 +0000199
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100200 stp x3, x4, [sp, #96]
201 .cfi_rel_offset x3, 96
202 .cfi_rel_offset x4, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700203
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100204 stp x5, x6, [sp, #112]
205 .cfi_rel_offset x5, 112
206 .cfi_rel_offset x6, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700207
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100208 // x7, Callee-saves.
209 stp x7, x20, [sp, #128]
210 .cfi_rel_offset x7, 128
Zheng Xu69a50302015-04-14 20:04:41 +0800211 .cfi_rel_offset x20, 136
212
Zheng Xub551fdc2014-07-25 11:49:42 +0800213 stp x21, x22, [sp, #144]
214 .cfi_rel_offset x21, 144
215 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700216
Zheng Xub551fdc2014-07-25 11:49:42 +0800217 stp x23, x24, [sp, #160]
218 .cfi_rel_offset x23, 160
219 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700220
Zheng Xub551fdc2014-07-25 11:49:42 +0800221 stp x25, x26, [sp, #176]
222 .cfi_rel_offset x25, 176
223 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700224
Zheng Xub551fdc2014-07-25 11:49:42 +0800225 stp x27, x28, [sp, #192]
226 .cfi_rel_offset x27, 192
227 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700228
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100229 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800230 stp x29, xLR, [sp, #208]
231 .cfi_rel_offset x29, 208
232 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700233
Stuart Monteithb95a5342014-03-12 13:32:32 +0000234.endm
235
236 /*
237 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100238 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000239 *
240 * TODO This is probably too conservative - saving FP & LR.
241 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100242.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
243 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800244 adrp xIP0, :got:_ZN3art7Runtime9instance_E
245 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000246
247 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100248 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000249
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100250 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs];
251 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000252
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100253 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000254
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100255 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs].
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700256 // Place sp in Thread::Current()->top_quick_frame.
257 mov xIP0, sp
258 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
259.endm
260
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100261.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
262 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700263 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
264 // Place sp in Thread::Current()->top_quick_frame.
265 mov xIP0, sp
266 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000267.endm
268
Zheng Xub551fdc2014-07-25 11:49:42 +0800269// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100270.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800271 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100272 ldp d0, d1, [sp, #16]
273 ldp d2, d3, [sp, #32]
274 ldp d4, d5, [sp, #48]
275 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000276
Zheng Xu69a50302015-04-14 20:04:41 +0800277 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100278 ldp x1, x2, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700279 .cfi_restore x1
280 .cfi_restore x2
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100281
282 ldp x3, x4, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700283 .cfi_restore x3
284 .cfi_restore x4
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100285
286 ldp x5, x6, [sp, #112]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700287 .cfi_restore x5
Zheng Xu69a50302015-04-14 20:04:41 +0800288 .cfi_restore x6
Andreas Gampe03906cf2014-04-07 12:08:28 -0700289
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100290 // x7, Callee-saves.
291 ldp x7, x20, [sp, #128]
292 .cfi_restore x7
Zheng Xu69a50302015-04-14 20:04:41 +0800293 .cfi_restore x20
294
Zheng Xub551fdc2014-07-25 11:49:42 +0800295 ldp x21, x22, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700296 .cfi_restore x21
297 .cfi_restore x22
298
Zheng Xub551fdc2014-07-25 11:49:42 +0800299 ldp x23, x24, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700300 .cfi_restore x23
301 .cfi_restore x24
302
Zheng Xub551fdc2014-07-25 11:49:42 +0800303 ldp x25, x26, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700304 .cfi_restore x25
305 .cfi_restore x26
306
Zheng Xub551fdc2014-07-25 11:49:42 +0800307 ldp x27, x28, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700308 .cfi_restore x27
309 .cfi_restore x28
310
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100311 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800312 ldp x29, xLR, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700313 .cfi_restore x29
314 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000315
Zheng Xub551fdc2014-07-25 11:49:42 +0800316 add sp, sp, #224
317 .cfi_adjust_cfa_offset -224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000318.endm
319
Vladimir Marko952dbb12016-07-28 12:01:51 +0100320 /*
321 * Macro that sets up the callee save frame to conform with
322 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
323 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100324.macro SETUP_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100325 sub sp, sp, #512
326 .cfi_adjust_cfa_offset 512
327
328 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100329#if (FRAME_SIZE_SAVE_EVERYTHING != 512)
330#error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100331#endif
332
333 // Save FP registers.
Vladimir Markode5f1942016-08-10 12:30:05 +0100334 str d0, [sp, #8]
335 stp d1, d2, [sp, #16]
336 stp d3, d4, [sp, #32]
337 stp d5, d6, [sp, #48]
338 stp d7, d8, [sp, #64]
339 stp d9, d10, [sp, #80]
340 stp d11, d12, [sp, #96]
341 stp d13, d14, [sp, #112]
342 stp d15, d16, [sp, #128]
343 stp d17, d18, [sp, #144]
344 stp d19, d20, [sp, #160]
345 stp d21, d22, [sp, #176]
346 stp d23, d24, [sp, #192]
347 stp d25, d26, [sp, #208]
348 stp d27, d28, [sp, #224]
349 stp d29, d30, [sp, #240]
350 str d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100351
352 // Save core registers.
353 str x0, [sp, #264]
354 .cfi_rel_offset x0, 264
355
356 stp x1, x2, [sp, #272]
357 .cfi_rel_offset x1, 272
358 .cfi_rel_offset x2, 280
359
360 stp x3, x4, [sp, #288]
361 .cfi_rel_offset x3, 288
362 .cfi_rel_offset x4, 296
363
364 stp x5, x6, [sp, #304]
365 .cfi_rel_offset x5, 304
366 .cfi_rel_offset x6, 312
367
368 stp x7, x8, [sp, #320]
369 .cfi_rel_offset x7, 320
370 .cfi_rel_offset x8, 328
371
372 stp x9, x10, [sp, #336]
373 .cfi_rel_offset x9, 336
374 .cfi_rel_offset x10, 344
375
376 stp x11, x12, [sp, #352]
377 .cfi_rel_offset x11, 352
378 .cfi_rel_offset x12, 360
379
380 stp x13, x14, [sp, #368]
381 .cfi_rel_offset x13, 368
382 .cfi_rel_offset x14, 376
383
384 stp x15, x16, [sp, #384]
385 .cfi_rel_offset x15, 384
386 .cfi_rel_offset x16, 392
387
388 stp x17, x18, [sp, #400]
389 .cfi_rel_offset x17, 400
390 .cfi_rel_offset x18, 408
391
392 stp x19, x20, [sp, #416]
393 .cfi_rel_offset x19, 416
394 .cfi_rel_offset x20, 424
395
396 stp x21, x22, [sp, #432]
397 .cfi_rel_offset x21, 432
398 .cfi_rel_offset x22, 440
399
400 stp x23, x24, [sp, #448]
401 .cfi_rel_offset x23, 448
402 .cfi_rel_offset x24, 456
403
404 stp x25, x26, [sp, #464]
405 .cfi_rel_offset x25, 464
406 .cfi_rel_offset x26, 472
407
408 stp x27, x28, [sp, #480]
409 .cfi_rel_offset x27, 480
410 .cfi_rel_offset x28, 488
411
412 stp x29, xLR, [sp, #496]
413 .cfi_rel_offset x29, 496
414 .cfi_rel_offset x30, 504
415
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100416 // art::Runtime** xIP0 = &art::Runtime::instance_
Vladimir Marko952dbb12016-07-28 12:01:51 +0100417 adrp xIP0, :got:_ZN3art7Runtime9instance_E
418 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
419
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100420 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Vladimir Marko952dbb12016-07-28 12:01:51 +0100421
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100422 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything];
423 ldr xIP0, [xIP0, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100424
425 // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything].
426 str xIP0, [sp]
427 // Place sp in Thread::Current()->top_quick_frame.
428 mov xIP0, sp
429 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
430.endm
431
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100432.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100433 // Restore FP registers.
Vladimir Markode5f1942016-08-10 12:30:05 +0100434 ldr d0, [sp, #8]
435 ldp d1, d2, [sp, #16]
436 ldp d3, d4, [sp, #32]
437 ldp d5, d6, [sp, #48]
438 ldp d7, d8, [sp, #64]
439 ldp d9, d10, [sp, #80]
440 ldp d11, d12, [sp, #96]
441 ldp d13, d14, [sp, #112]
442 ldp d15, d16, [sp, #128]
443 ldp d17, d18, [sp, #144]
444 ldp d19, d20, [sp, #160]
445 ldp d21, d22, [sp, #176]
446 ldp d23, d24, [sp, #192]
447 ldp d25, d26, [sp, #208]
448 ldp d27, d28, [sp, #224]
449 ldp d29, d30, [sp, #240]
450 ldr d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100451
452 // Restore core registers.
453 ldr x0, [sp, #264]
454 .cfi_restore x0
455
456 ldp x1, x2, [sp, #272]
457 .cfi_restore x1
458 .cfi_restore x2
459
460 ldp x3, x4, [sp, #288]
461 .cfi_restore x3
462 .cfi_restore x4
463
464 ldp x5, x6, [sp, #304]
465 .cfi_restore x5
466 .cfi_restore x6
467
468 ldp x7, x8, [sp, #320]
469 .cfi_restore x7
470 .cfi_restore x8
471
472 ldp x9, x10, [sp, #336]
473 .cfi_restore x9
474 .cfi_restore x10
475
476 ldp x11, x12, [sp, #352]
477 .cfi_restore x11
478 .cfi_restore x12
479
480 ldp x13, x14, [sp, #368]
481 .cfi_restore x13
482 .cfi_restore x14
483
484 ldp x15, x16, [sp, #384]
485 .cfi_restore x15
486 .cfi_restore x16
487
488 ldp x17, x18, [sp, #400]
489 .cfi_restore x17
490 .cfi_restore x18
491
492 ldp x19, x20, [sp, #416]
493 .cfi_restore x19
494 .cfi_restore x20
495
496 ldp x21, x22, [sp, #432]
497 .cfi_restore x21
498 .cfi_restore x22
499
500 ldp x23, x24, [sp, #448]
501 .cfi_restore x23
502 .cfi_restore x24
503
504 ldp x25, x26, [sp, #464]
505 .cfi_restore x25
506 .cfi_restore x26
507
508 ldp x27, x28, [sp, #480]
509 .cfi_restore x27
510 .cfi_restore x28
511
512 ldp x29, xLR, [sp, #496]
513 .cfi_restore x29
514 .cfi_restore x30
515
516 add sp, sp, #512
517 .cfi_adjust_cfa_offset -512
518.endm
519
Stuart Monteithb95a5342014-03-12 13:32:32 +0000520.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700521 cbnz x0, 1f // result non-zero branch over
522 ret // return
5231:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000524.endm
525
526.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700527 cbz x0, 1f // result zero branch over
528 ret // return
5291:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000530.endm
531
532 /*
533 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
534 * exception is Thread::Current()->exception_
535 */
536.macro DELIVER_PENDING_EXCEPTION
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100537 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000538 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000539
540 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700541 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000542 brk 0 // Unreached
543.endm
544
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700545.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
546 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
547 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000548 ret
5491:
550 DELIVER_PENDING_EXCEPTION
551.endm
552
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700553.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800554 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700555.endm
556
557// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
558.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
559 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
560.endm
561
562.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
563 cbnz w0, 1f // result non-zero branch over
564 ret // return
5651:
566 DELIVER_PENDING_EXCEPTION
567.endm
568
Stuart Monteithb95a5342014-03-12 13:32:32 +0000569.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
570 .extern \cxx_name
571ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100572 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800573 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700574 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000575END \c_name
576.endm
577
578.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
579 .extern \cxx_name
580ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100581 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800582 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700583 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000584 brk 0
585END \c_name
586.endm
587
588.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
589 .extern \cxx_name
590ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100591 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800592 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700593 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000594 brk 0
595END \c_name
596.endm
597
598 /*
599 * Called by managed code, saves callee saves and then calls artThrowException
600 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
601 */
602ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
603
604 /*
605 * Called by managed code to create and deliver a NullPointerException.
606 */
607NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
608
609 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100610 * Call installed by a signal handler to create and deliver a NullPointerException.
611 */
612ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
613
614 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000615 * Called by managed code to create and deliver an ArithmeticException.
616 */
617NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
618
619 /*
620 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
621 * index, arg2 holds limit.
622 */
623TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
624
625 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100626 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
627 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
628 */
629TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
630
631 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000632 * Called by managed code to create and deliver a StackOverflowError.
633 */
634NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
635
636 /*
637 * Called by managed code to create and deliver a NoSuchMethodError.
638 */
639ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
640
641 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000642 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700643 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100644 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700645 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000646 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700647 * 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 +0000648 * of the target Method* in x0 and method->code_ in x1.
649 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700650 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000651 * thread and we branch to another stub to deliver it.
652 *
653 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
654 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700655 *
656 * Adapted from ARM32 code.
657 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800658 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000659 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700660.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000661 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100662 SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700663 // Helper signature is always
664 // (method_idx, *this_object, *caller_method, *self, sp)
665
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100666 mov x2, xSELF // pass Thread::Current
667 mov x3, sp
668 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800669 mov xIP0, x1 // save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100670 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700671 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800672 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07006731:
674 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700675.endm
676.macro INVOKE_TRAMPOLINE c_name, cxx_name
677ENTRY \c_name
678 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000679END \c_name
680.endm
681
Stuart Monteithb95a5342014-03-12 13:32:32 +0000682INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
683
684INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
685INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
686INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
687INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
688
Andreas Gampe03906cf2014-04-07 12:08:28 -0700689
690.macro INVOKE_STUB_CREATE_FRAME
691
Zheng Xu69a50302015-04-14 20:04:41 +0800692SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700693SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
Andreas Gampecf4035a2014-05-28 22:43:01 -0700694
Andreas Gampe03906cf2014-04-07 12:08:28 -0700695
Zheng Xu48241e72014-05-23 11:52:42 +0800696 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700697 .cfi_register sp,x9
698
Zheng Xu48241e72014-05-23 11:52:42 +0800699 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700700 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
Zheng Xu48241e72014-05-23 11:52:42 +0800701 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
702 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700703
Zheng Xu48241e72014-05-23 11:52:42 +0800704 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
705 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700706 .cfi_adjust_cfa_offset SAVE_SIZE
707
Nicolas Geoffray48088462014-12-12 10:29:38 +0000708 str x28, [x10, #112]
709 .cfi_rel_offset x28, 112
710
711 stp x26, x27, [x10, #96]
712 .cfi_rel_offset x26, 96
713 .cfi_rel_offset x27, 104
714
715 stp x24, x25, [x10, #80]
716 .cfi_rel_offset x24, 80
717 .cfi_rel_offset x25, 88
718
719 stp x22, x23, [x10, #64]
720 .cfi_rel_offset x22, 64
721 .cfi_rel_offset x23, 72
722
723 stp x20, x21, [x10, #48]
724 .cfi_rel_offset x20, 48
725 .cfi_rel_offset x21, 56
726
Zheng Xu69a50302015-04-14 20:04:41 +0800727 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700728 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700729 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700730
Zheng Xu48241e72014-05-23 11:52:42 +0800731 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700732 .cfi_rel_offset x4, 16
733 .cfi_rel_offset x5, 24
734
Zheng Xu48241e72014-05-23 11:52:42 +0800735 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700736 .cfi_rel_offset x29, 0
737 .cfi_rel_offset x30, 8
738
Zheng Xu48241e72014-05-23 11:52:42 +0800739 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700740 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800741 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700742
743 // Copy arguments into stack frame.
744 // Use simple copy routine for now.
745 // 4 bytes per slot.
746 // X1 - source address
747 // W2 - args length
748 // X9 - destination address.
749 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700750 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700751
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700752 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
753 // does not have unique-id variables.
7541:
Andreas Gampe03906cf2014-04-07 12:08:28 -0700755 cmp w2, #0
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700756 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700757 sub w2, w2, #4 // Need 65536 bytes of range.
758 ldr w10, [x1, x2]
759 str w10, [x9, x2]
760
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700761 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700762
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07007632:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700764 // Store null into ArtMethod* at bottom of frame.
765 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700766.endm
767
768.macro INVOKE_STUB_CALL_AND_RETURN
769
770 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700771 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700772 // Branch to method.
773 blr x9
774
775 // Restore return value address and shorty address.
776 ldp x4,x5, [xFP, #16]
777 .cfi_restore x4
778 .cfi_restore x5
779
Nicolas Geoffray48088462014-12-12 10:29:38 +0000780 ldr x28, [xFP, #112]
781 .cfi_restore x28
782
783 ldp x26, x27, [xFP, #96]
784 .cfi_restore x26
785 .cfi_restore x27
786
787 ldp x24, x25, [xFP, #80]
788 .cfi_restore x24
789 .cfi_restore x25
790
791 ldp x22, x23, [xFP, #64]
792 .cfi_restore x22
793 .cfi_restore x23
794
795 ldp x20, x21, [xFP, #48]
796 .cfi_restore x20
797 .cfi_restore x21
798
Andreas Gampe03906cf2014-04-07 12:08:28 -0700799 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
800 ldrb w10, [x5]
801
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700802 // Check the return type and store the correct register into the jvalue in memory.
803 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
804
Andreas Gampe03906cf2014-04-07 12:08:28 -0700805 // Don't set anything for a void type.
806 cmp w10, #'V'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700807 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700808
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700809 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700810 cmp w10, #'D'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700811 bne 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700812 str d0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700813 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700814
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07008151: // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700816 cmp w10, #'F'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700817 bne 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700818 str s0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700819 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700820
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07008212: // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700822 str x0, [x4]
823
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07008243: // Finish up.
Zheng Xu69a50302015-04-14 20:04:41 +0800825 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700826 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700827 mov sp, x2
828 .cfi_restore sp
829
Andreas Gamped58342c2014-06-05 14:18:08 -0700830 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700831 .cfi_restore x29
832 .cfi_restore x30
833
834 ret
835
836.endm
837
838
Stuart Monteithb95a5342014-03-12 13:32:32 +0000839/*
840 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
841 * uint32_t *args, x1
842 * uint32_t argsize, w2
843 * Thread *self, x3
844 * JValue *result, x4
845 * char *shorty); x5
846 * +----------------------+
847 * | |
848 * | C/C++ frame |
849 * | LR'' |
850 * | FP'' | <- SP'
851 * +----------------------+
852 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800853 * | x28 | <- TODO: Remove callee-saves.
854 * | : |
855 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000856 * | SP' |
857 * | X5 |
858 * | X4 | Saved registers
859 * | LR' |
860 * | FP' | <- FP
861 * +----------------------+
862 * | uint32_t out[n-1] |
863 * | : : | Outs
864 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700865 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000866 * +----------------------+
867 *
868 * Outgoing registers:
869 * x0 - Method*
870 * x1-x7 - integer parameters.
871 * d0-d7 - Floating point parameters.
872 * xSELF = self
873 * SP = & of ArtMethod*
874 * x1 = "this" pointer.
875 *
876 */
877ENTRY art_quick_invoke_stub
878 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700879 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000880
881 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
882 // Parse the passed shorty to determine which register to load.
883 // Load addresses for routines that load WXSD registers.
884 adr x11, .LstoreW2
885 adr x12, .LstoreX2
886 adr x13, .LstoreS0
887 adr x14, .LstoreD0
888
889 // Initialize routine offsets to 0 for integers and floats.
890 // x8 for integers, x15 for floating point.
891 mov x8, #0
892 mov x15, #0
893
894 add x10, x5, #1 // Load shorty address, plus one to skip return value.
895 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
896
897 // Loop to fill registers.
898.LfillRegisters:
899 ldrb w17, [x10], #1 // Load next character in signature, and increment.
900 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
901
902 cmp w17, #'F' // is this a float?
903 bne .LisDouble
904
905 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700906 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000907
908 add x17, x13, x15 // Calculate subroutine to jump to.
909 br x17
910
911.LisDouble:
912 cmp w17, #'D' // is this a double?
913 bne .LisLong
914
915 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700916 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000917
918 add x17, x14, x15 // Calculate subroutine to jump to.
919 br x17
920
921.LisLong:
922 cmp w17, #'J' // is this a long?
923 bne .LisOther
924
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700925 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700926 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000927
928 add x17, x12, x8 // Calculate subroutine to jump to.
929 br x17
930
Stuart Monteithb95a5342014-03-12 13:32:32 +0000931.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700932 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700933 beq .Ladvance4
934
Stuart Monteithb95a5342014-03-12 13:32:32 +0000935 add x17, x11, x8 // Calculate subroutine to jump to.
936 br x17
937
Andreas Gampe03906cf2014-04-07 12:08:28 -0700938.Ladvance4:
939 add x9, x9, #4
940 b .LfillRegisters
941
942.Ladvance8:
943 add x9, x9, #8
944 b .LfillRegisters
945
Stuart Monteithb95a5342014-03-12 13:32:32 +0000946// Macro for loading a parameter into a register.
947// counter - the register with offset into these tables
948// size - the size of the register - 4 or 8 bytes.
949// register - the name of the register to be loaded.
950.macro LOADREG counter size register return
951 ldr \register , [x9], #\size
952 add \counter, \counter, 12
953 b \return
954.endm
955
956// Store ints.
957.LstoreW2:
958 LOADREG x8 4 w2 .LfillRegisters
959 LOADREG x8 4 w3 .LfillRegisters
960 LOADREG x8 4 w4 .LfillRegisters
961 LOADREG x8 4 w5 .LfillRegisters
962 LOADREG x8 4 w6 .LfillRegisters
963 LOADREG x8 4 w7 .LfillRegisters
964
965// Store longs.
966.LstoreX2:
967 LOADREG x8 8 x2 .LfillRegisters
968 LOADREG x8 8 x3 .LfillRegisters
969 LOADREG x8 8 x4 .LfillRegisters
970 LOADREG x8 8 x5 .LfillRegisters
971 LOADREG x8 8 x6 .LfillRegisters
972 LOADREG x8 8 x7 .LfillRegisters
973
974// Store singles.
975.LstoreS0:
976 LOADREG x15 4 s0 .LfillRegisters
977 LOADREG x15 4 s1 .LfillRegisters
978 LOADREG x15 4 s2 .LfillRegisters
979 LOADREG x15 4 s3 .LfillRegisters
980 LOADREG x15 4 s4 .LfillRegisters
981 LOADREG x15 4 s5 .LfillRegisters
982 LOADREG x15 4 s6 .LfillRegisters
983 LOADREG x15 4 s7 .LfillRegisters
984
985// Store doubles.
986.LstoreD0:
987 LOADREG x15 8 d0 .LfillRegisters
988 LOADREG x15 8 d1 .LfillRegisters
989 LOADREG x15 8 d2 .LfillRegisters
990 LOADREG x15 8 d3 .LfillRegisters
991 LOADREG x15 8 d4 .LfillRegisters
992 LOADREG x15 8 d5 .LfillRegisters
993 LOADREG x15 8 d6 .LfillRegisters
994 LOADREG x15 8 d7 .LfillRegisters
995
996
997.LcallFunction:
998
Andreas Gampe03906cf2014-04-07 12:08:28 -0700999 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +00001000
Stuart Monteithb95a5342014-03-12 13:32:32 +00001001END art_quick_invoke_stub
1002
1003/* extern"C"
1004 * void art_quick_invoke_static_stub(ArtMethod *method, x0
1005 * uint32_t *args, x1
1006 * uint32_t argsize, w2
1007 * Thread *self, x3
1008 * JValue *result, x4
1009 * char *shorty); x5
1010 */
1011ENTRY art_quick_invoke_static_stub
1012 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -07001013 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001014
1015 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
1016 // Parse the passed shorty to determine which register to load.
1017 // Load addresses for routines that load WXSD registers.
1018 adr x11, .LstoreW1_2
1019 adr x12, .LstoreX1_2
1020 adr x13, .LstoreS0_2
1021 adr x14, .LstoreD0_2
1022
1023 // Initialize routine offsets to 0 for integers and floats.
1024 // x8 for integers, x15 for floating point.
1025 mov x8, #0
1026 mov x15, #0
1027
1028 add x10, x5, #1 // Load shorty address, plus one to skip return value.
1029
1030 // Loop to fill registers.
1031.LfillRegisters2:
1032 ldrb w17, [x10], #1 // Load next character in signature, and increment.
1033 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
1034
1035 cmp w17, #'F' // is this a float?
1036 bne .LisDouble2
1037
1038 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -07001039 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001040
1041 add x17, x13, x15 // Calculate subroutine to jump to.
1042 br x17
1043
1044.LisDouble2:
1045 cmp w17, #'D' // is this a double?
1046 bne .LisLong2
1047
1048 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -07001049 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001050
1051 add x17, x14, x15 // Calculate subroutine to jump to.
1052 br x17
1053
1054.LisLong2:
1055 cmp w17, #'J' // is this a long?
1056 bne .LisOther2
1057
1058 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -07001059 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001060
1061 add x17, x12, x8 // Calculate subroutine to jump to.
1062 br x17
1063
Stuart Monteithb95a5342014-03-12 13:32:32 +00001064.LisOther2: // Everything else takes one vReg.
1065 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -07001066 beq .Ladvance4_2
1067
Stuart Monteithb95a5342014-03-12 13:32:32 +00001068 add x17, x11, x8 // Calculate subroutine to jump to.
1069 br x17
1070
Andreas Gampe03906cf2014-04-07 12:08:28 -07001071.Ladvance4_2:
1072 add x9, x9, #4
1073 b .LfillRegisters2
1074
1075.Ladvance8_2:
1076 add x9, x9, #8
1077 b .LfillRegisters2
1078
Stuart Monteithb95a5342014-03-12 13:32:32 +00001079// Store ints.
1080.LstoreW1_2:
1081 LOADREG x8 4 w1 .LfillRegisters2
1082 LOADREG x8 4 w2 .LfillRegisters2
1083 LOADREG x8 4 w3 .LfillRegisters2
1084 LOADREG x8 4 w4 .LfillRegisters2
1085 LOADREG x8 4 w5 .LfillRegisters2
1086 LOADREG x8 4 w6 .LfillRegisters2
1087 LOADREG x8 4 w7 .LfillRegisters2
1088
1089// Store longs.
1090.LstoreX1_2:
1091 LOADREG x8 8 x1 .LfillRegisters2
1092 LOADREG x8 8 x2 .LfillRegisters2
1093 LOADREG x8 8 x3 .LfillRegisters2
1094 LOADREG x8 8 x4 .LfillRegisters2
1095 LOADREG x8 8 x5 .LfillRegisters2
1096 LOADREG x8 8 x6 .LfillRegisters2
1097 LOADREG x8 8 x7 .LfillRegisters2
1098
1099// Store singles.
1100.LstoreS0_2:
1101 LOADREG x15 4 s0 .LfillRegisters2
1102 LOADREG x15 4 s1 .LfillRegisters2
1103 LOADREG x15 4 s2 .LfillRegisters2
1104 LOADREG x15 4 s3 .LfillRegisters2
1105 LOADREG x15 4 s4 .LfillRegisters2
1106 LOADREG x15 4 s5 .LfillRegisters2
1107 LOADREG x15 4 s6 .LfillRegisters2
1108 LOADREG x15 4 s7 .LfillRegisters2
1109
1110// Store doubles.
1111.LstoreD0_2:
1112 LOADREG x15 8 d0 .LfillRegisters2
1113 LOADREG x15 8 d1 .LfillRegisters2
1114 LOADREG x15 8 d2 .LfillRegisters2
1115 LOADREG x15 8 d3 .LfillRegisters2
1116 LOADREG x15 8 d4 .LfillRegisters2
1117 LOADREG x15 8 d5 .LfillRegisters2
1118 LOADREG x15 8 d6 .LfillRegisters2
1119 LOADREG x15 8 d7 .LfillRegisters2
1120
1121
1122.LcallFunction2:
1123
Andreas Gampe03906cf2014-04-07 12:08:28 -07001124 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +00001125
Stuart Monteithb95a5342014-03-12 13:32:32 +00001126END art_quick_invoke_static_stub
1127
Andreas Gampe03906cf2014-04-07 12:08:28 -07001128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001129
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001130/* extern"C" void art_quick_osr_stub(void** stack, x0
1131 * size_t stack_size_in_bytes, x1
1132 * const uin8_t* native_pc, x2
1133 * JValue *result, x3
1134 * char *shorty, x4
1135 * Thread *self) x5
1136 */
1137ENTRY art_quick_osr_stub
1138SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
1139 mov x9, sp // Save stack pointer.
1140 .cfi_register sp,x9
1141
1142 sub x10, sp, # SAVE_SIZE
1143 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
1144 mov sp, x10 // Set new SP.
1145
1146 str x28, [sp, #112]
1147 stp x26, x27, [sp, #96]
1148 stp x24, x25, [sp, #80]
1149 stp x22, x23, [sp, #64]
1150 stp x20, x21, [sp, #48]
1151 stp x9, x19, [sp, #32] // Save old stack pointer and x19.
1152 stp x3, x4, [sp, #16] // Save result and shorty addresses.
1153 stp xFP, xLR, [sp] // Store LR & FP.
1154 mov xSELF, x5 // Move thread pointer into SELF register.
1155
1156 sub sp, sp, #16
1157 str xzr, [sp] // Store null for ArtMethod* slot
1158 // Branch to stub.
1159 bl .Losr_entry
1160 add sp, sp, #16
1161
1162 // Restore return value address and shorty address.
1163 ldp x3,x4, [sp, #16]
1164 ldr x28, [sp, #112]
1165 ldp x26, x27, [sp, #96]
1166 ldp x24, x25, [sp, #80]
1167 ldp x22, x23, [sp, #64]
1168 ldp x20, x21, [sp, #48]
1169
1170 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1171 ldrb w10, [x4]
1172
1173 // Check the return type and store the correct register into the jvalue in memory.
1174
1175 // Don't set anything for a void type.
1176 cmp w10, #'V'
1177 beq .Losr_exit
1178
1179 // Is it a double?
1180 cmp w10, #'D'
1181 bne .Lno_double
1182 str d0, [x3]
1183 b .Losr_exit
1184
1185.Lno_double: // Is it a float?
1186 cmp w10, #'F'
1187 bne .Lno_float
1188 str s0, [x3]
1189 b .Losr_exit
1190
1191.Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits.
1192 str x0, [x3]
1193
1194.Losr_exit: // Finish up.
1195 ldp x2, x19, [sp, #32] // Restore stack pointer and x19.
1196 ldp xFP, xLR, [sp] // Restore old frame pointer and link register.
1197 mov sp, x2
1198 ret
1199
1200.Losr_entry:
1201 // Update stack pointer for the callee
1202 sub sp, sp, x1
1203
1204 // Update link register slot expected by the callee.
1205 sub w1, w1, #8
1206 str lr, [sp, x1]
1207
1208 // Copy arguments into stack frame.
1209 // Use simple copy routine for now.
1210 // 4 bytes per slot.
1211 // X0 - source address
1212 // W1 - args length
1213 // SP - destination address.
1214 // W10 - temporary
1215.Losr_loop_entry:
1216 cmp w1, #0
1217 beq .Losr_loop_exit
1218 sub w1, w1, #4
1219 ldr w10, [x0, x1]
1220 str w10, [sp, x1]
1221 b .Losr_loop_entry
1222
1223.Losr_loop_exit:
1224 // Branch to the OSR entry point.
1225 br x2
1226
1227END art_quick_osr_stub
1228
Stuart Monteithb95a5342014-03-12 13:32:32 +00001229 /*
1230 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1231 */
1232
1233ENTRY art_quick_do_long_jump
1234 // Load FPRs
1235 ldp d0, d1, [x1], #16
1236 ldp d2, d3, [x1], #16
1237 ldp d4, d5, [x1], #16
1238 ldp d6, d7, [x1], #16
1239 ldp d8, d9, [x1], #16
1240 ldp d10, d11, [x1], #16
1241 ldp d12, d13, [x1], #16
1242 ldp d14, d15, [x1], #16
1243 ldp d16, d17, [x1], #16
1244 ldp d18, d19, [x1], #16
1245 ldp d20, d21, [x1], #16
1246 ldp d22, d23, [x1], #16
1247 ldp d24, d25, [x1], #16
1248 ldp d26, d27, [x1], #16
1249 ldp d28, d29, [x1], #16
1250 ldp d30, d31, [x1]
1251
1252 // Load GPRs
1253 // TODO: lots of those are smashed, could optimize.
1254 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001255 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001256 ldp x28, x29, [x0], #-16
1257 ldp x26, x27, [x0], #-16
1258 ldp x24, x25, [x0], #-16
1259 ldp x22, x23, [x0], #-16
1260 ldp x20, x21, [x0], #-16
1261 ldp x18, x19, [x0], #-16
1262 ldp x16, x17, [x0], #-16
1263 ldp x14, x15, [x0], #-16
1264 ldp x12, x13, [x0], #-16
1265 ldp x10, x11, [x0], #-16
1266 ldp x8, x9, [x0], #-16
1267 ldp x6, x7, [x0], #-16
1268 ldp x4, x5, [x0], #-16
1269 ldp x2, x3, [x0], #-16
1270 mov sp, x1
1271
Andreas Gampe639bdd12015-06-03 11:22:45 -07001272 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1273 ldr x1, [x0, #33*8]
1274 // And the value of x0.
1275 ldr x0, [x0]
1276
1277 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001278END art_quick_do_long_jump
1279
Andreas Gampef4e910b2014-04-29 16:55:52 -07001280 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001281 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1282 * possibly null object to lock.
1283 *
1284 * Derived from arm32 code.
1285 */
1286 .extern artLockObjectFromCode
1287ENTRY art_quick_lock_object
1288 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001289 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001290.Lretry_lock:
1291 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1292 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001293 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001294 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001295 cbnz w3, .Lnot_unlocked // already thin locked
1296 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1297 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001298 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001299 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001300 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001301 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001302.Lnot_unlocked: // x1: original lock word
1303 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001304 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1305 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1306 uxth w2, w2 // zero top 16 bits
1307 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1308 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001309 mov x3, x1 // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001310 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001311 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 -07001312 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 -08001313 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1314 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1315 stxr w3, w2, [x4]
1316 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001317 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001318.Llock_stxr_fail:
1319 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001320.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001321 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001322 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001323 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001324 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001325 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1326END art_quick_lock_object
1327
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001328ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001329 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001330 mov x1, xSELF // pass Thread::Current
1331 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001332 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001333 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1334END art_quick_lock_object_no_inline
1335
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001336 /*
1337 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1338 * x0 holds the possibly null object to lock.
1339 *
1340 * Derived from arm32 code.
1341 */
1342 .extern artUnlockObjectFromCode
1343ENTRY art_quick_unlock_object
1344 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001345 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1346.Lretry_unlock:
1347#ifndef USE_READ_BARRIER
1348 ldr w1, [x4]
1349#else
1350 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1351#endif
1352 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001353 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1354 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001355 mov x3, x1 // copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001356 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001357 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001358 uxth w3, w3 // zero top 16 bits
1359 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001360 mov x3, x1 // copy lock word to detect transition to unlocked
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001361 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001362 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001363 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001364 // transition to unlocked
1365 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001366 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED // w3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -07001367 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001368#ifndef USE_READ_BARRIER
1369 str w3, [x4]
1370#else
1371 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1372 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1373#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001374 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001375.Lrecursive_thin_unlock: // w1: original lock word
1376 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1377#ifndef USE_READ_BARRIER
1378 str w1, [x4]
1379#else
1380 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1381 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1382#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001383 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001384.Lunlock_stxr_fail:
1385 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001386.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001387 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001388 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001389 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001390 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001391 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1392END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001393
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001394ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001395 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001396 mov x1, xSELF // pass Thread::Current
1397 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001398 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001399 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1400END art_quick_unlock_object_no_inline
1401
Andreas Gampe525cde22014-04-22 15:44:50 -07001402 /*
1403 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1404 * artThrowClassCastException.
1405 */
1406 .extern artThrowClassCastException
1407ENTRY art_quick_check_cast
1408 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001409 // Stack needs to be 16B aligned on calls.
1410 stp x0, x1, [sp,#-32]!
Andreas Gampe525cde22014-04-22 15:44:50 -07001411 .cfi_adjust_cfa_offset 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001412 .cfi_rel_offset x0, 0
1413 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001414 str xLR, [sp, #24]
Andreas Gampe525cde22014-04-22 15:44:50 -07001415 .cfi_rel_offset x30, 24
1416
1417 // Call runtime code
1418 bl artIsAssignableFromCode
1419
1420 // Check for exception
1421 cbz x0, .Lthrow_class_cast_exception
1422
1423 // Restore and return
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001424 ldr xLR, [sp, #24]
1425 .cfi_restore x30
1426 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001427 .cfi_restore x0
1428 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001429 .cfi_adjust_cfa_offset -32
1430 ret
1431
Andreas Gampe6b90d422015-06-26 19:49:24 -07001432 .cfi_adjust_cfa_offset 32 // Reset unwind info so following code unwinds.
1433
Andreas Gampe525cde22014-04-22 15:44:50 -07001434.Lthrow_class_cast_exception:
1435 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001436 ldr xLR, [sp, #24]
1437 .cfi_restore x30
1438 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001439 .cfi_restore x0
1440 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001441 .cfi_adjust_cfa_offset -32
1442
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001443 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001444 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001445 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001446 brk 0 // We should not return here...
1447END art_quick_check_cast
1448
Man Cao1aee9002015-07-14 22:31:42 -07001449// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1450.macro POP_REG_NE xReg, offset, xExclude
1451 .ifnc \xReg, \xExclude
1452 ldr \xReg, [sp, #\offset] // restore xReg
1453 .cfi_restore \xReg
1454 .endif
1455.endm
1456
Roland Levillain4359e612016-07-20 11:32:19 +01001457// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1458// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1459.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1460 .ifc \xReg1, \xExclude
1461 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1462 .else
1463 .ifc \xReg2, \xExclude
1464 ldr \xReg1, [sp, #\offset] // restore xReg1
1465 .else
1466 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1467 .endif
1468 .endif
1469 .cfi_restore \xReg1
1470 .cfi_restore \xReg2
1471.endm
1472
Man Cao1aee9002015-07-14 22:31:42 -07001473 /*
1474 * Macro to insert read barrier, only used in art_quick_aput_obj.
1475 * xDest, wDest and xObj are registers, offset is a defined literal such as
1476 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1477 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1478 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1479 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001480.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001481#ifdef USE_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001482#ifdef USE_BAKER_READ_BARRIER
1483 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1484 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1485 // False dependency to avoid needing load/load fence.
1486 add \xObj, \xObj, \xTemp, lsr #32
1487 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1488 UNPOISON_HEAP_REF \wDest
1489 b .Lrb_exit\number
1490#endif
1491.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001492 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
1493 stp x0, x1, [sp, #-48]!
1494 .cfi_adjust_cfa_offset 48
1495 .cfi_rel_offset x0, 0
1496 .cfi_rel_offset x1, 8
1497 stp x2, x3, [sp, #16]
1498 .cfi_rel_offset x2, 16
1499 .cfi_rel_offset x3, 24
1500 stp x4, xLR, [sp, #32]
1501 .cfi_rel_offset x4, 32
1502 .cfi_rel_offset x30, 40
1503
Man Cao63069212015-08-21 15:51:39 -07001504 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001505 .ifnc \xObj, x1
1506 mov x1, \xObj // pass xObj
1507 .endif
1508 mov w2, #\offset // pass offset
1509 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1510 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1511 .ifnc \wDest, w0
1512 mov \wDest, w0 // save return value in wDest
1513 .endif
1514
1515 // Conditionally restore saved registers
1516 POP_REG_NE x0, 0, \xDest
1517 POP_REG_NE x1, 8, \xDest
1518 POP_REG_NE x2, 16, \xDest
1519 POP_REG_NE x3, 24, \xDest
1520 POP_REG_NE x4, 32, \xDest
1521 ldr xLR, [sp, #40]
1522 .cfi_restore x30
1523 add sp, sp, #48
1524 .cfi_adjust_cfa_offset -48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001525.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001526#else
1527 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1528 UNPOISON_HEAP_REF \wDest
1529#endif // USE_READ_BARRIER
1530.endm
1531
Andreas Gampef4e910b2014-04-29 16:55:52 -07001532 /*
1533 * Entry from managed code for array put operations of objects where the value being stored
1534 * needs to be checked for compatibility.
1535 * x0 = array, x1 = index, x2 = value
1536 *
1537 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1538 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1539 * using index-zero-extension in load/stores.
1540 *
1541 * Temporaries: x3, x4
1542 * TODO: x4 OK? ip seems wrong here.
1543 */
1544ENTRY art_quick_aput_obj_with_null_and_bound_check
1545 tst x0, x0
1546 bne art_quick_aput_obj_with_bound_check
1547 b art_quick_throw_null_pointer_exception
1548END art_quick_aput_obj_with_null_and_bound_check
1549
1550ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001551 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001552 cmp w3, w1
1553 bhi art_quick_aput_obj
1554 mov x0, x1
1555 mov x1, x3
1556 b art_quick_throw_array_bounds
1557END art_quick_aput_obj_with_bound_check
1558
Man Cao1aee9002015-07-14 22:31:42 -07001559#ifdef USE_READ_BARRIER
1560 .extern artReadBarrierSlow
1561#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001562ENTRY art_quick_aput_obj
1563 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001564 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1565 // This also zero-extends to x3
1566 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1567 // This also zero-extends to x3
1568 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1569 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001570 cmp w3, w4 // value's type == array's component type - trivial assignability
1571 bne .Lcheck_assignability
1572.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001573 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001574 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001575 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001576 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1577 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1578 lsr x0, x0, #7
1579 strb w3, [x3, x0]
1580 ret
1581.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001582 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001583 // "Compress" = do nothing
1584 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1585 ret
1586.Lcheck_assignability:
1587 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001588 stp x0, x1, [sp,#-32]!
1589 .cfi_adjust_cfa_offset 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001590 .cfi_rel_offset x0, 0
1591 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001592 stp x2, xLR, [sp, #16]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001593 .cfi_rel_offset x2, 16
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001594 .cfi_rel_offset x30, 24
Andreas Gampef4e910b2014-04-29 16:55:52 -07001595
1596 // Call runtime code
1597 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1598 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1599 bl artIsAssignableFromCode
1600
1601 // Check for exception
1602 cbz x0, .Lthrow_array_store_exception
1603
1604 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001605 ldp x2, x30, [sp, #16]
1606 .cfi_restore x2
1607 .cfi_restore x30
1608 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001609 .cfi_restore x0
1610 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001611 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001612
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001613 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001614 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001615 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001616 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1617 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1618 lsr x0, x0, #7
1619 strb w3, [x3, x0]
1620 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001621 .cfi_adjust_cfa_offset 32 // 4 restores after cbz for unwinding.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001622.Lthrow_array_store_exception:
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001623 ldp x2, x30, [sp, #16]
1624 .cfi_restore x2
1625 .cfi_restore x30
1626 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001627 .cfi_restore x0
1628 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001629 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001630
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001631 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gampef4e910b2014-04-29 16:55:52 -07001632 mov x1, x2 // Pass value.
1633 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001634 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001635 brk 0 // Unreached.
1636END art_quick_aput_obj
1637
Stuart Monteithb95a5342014-03-12 13:32:32 +00001638// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001639.macro ONE_ARG_DOWNCALL name, entrypoint, return
1640 .extern \entrypoint
1641ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001642 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001643 mov x1, xSELF // pass Thread::Current
1644 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001645 RESTORE_SAVE_REFS_ONLY_FRAME
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001646 \return
1647END \name
1648.endm
1649
1650// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001651.macro TWO_ARG_DOWNCALL name, entrypoint, return
1652 .extern \entrypoint
1653ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001654 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001655 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001656 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001657 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001658 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001659END \name
1660.endm
1661
Jeff Hao848f70a2014-01-15 13:49:50 -08001662// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001663.macro THREE_ARG_DOWNCALL name, entrypoint, return
1664 .extern \entrypoint
1665ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001666 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001667 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001668 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001669 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001670 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001671END \name
1672.endm
1673
Jeff Hao848f70a2014-01-15 13:49:50 -08001674// Macro to facilitate adding new allocation entrypoints.
1675.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1676 .extern \entrypoint
1677ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001678 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001679 mov x4, xSELF // pass Thread::Current
1680 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001681 RESTORE_SAVE_REFS_ONLY_FRAME
Jeff Hao848f70a2014-01-15 13:49:50 -08001682 \return
1683 DELIVER_PENDING_EXCEPTION
1684END \name
1685.endm
1686
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001687// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001688.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1689 .extern \entrypoint
1690ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001691 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1692 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001693 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001694 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001695 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001696 \return
1697END \name
1698.endm
1699
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001700.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1701 .extern \entrypoint
1702ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001703 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1704 ldr x2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001705 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001706 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001707 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001708 \return
1709END \name
1710.endm
1711
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001712.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1713 .extern \entrypoint
1714ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001715 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1716 ldr x3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001717 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001718 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001719 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001720 \return
1721END \name
1722.endm
1723
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001724.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1725 cbz w0, 1f // result zero branch over
1726 ret // return
17271:
1728 DELIVER_PENDING_EXCEPTION
1729.endm
1730
Matteo Franchindfd891a2014-04-30 12:17:17 +01001731 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001732 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1733 * failure.
1734 */
1735TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1736
1737 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001738 * Entry from managed code when uninitialized static storage, this stub will run the class
1739 * initializer and deliver the exception on error. On success the static storage base is
1740 * returned.
1741 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001742ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001743
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001744ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1745ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001746
Fred Shih37f05ef2014-07-16 18:38:08 -07001747ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1748ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1749ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1750ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001751ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1752ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1753ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1754
Fred Shih37f05ef2014-07-16 18:38:08 -07001755TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1756TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1757TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1758TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001759TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1760TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1761TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1762
Fred Shih37f05ef2014-07-16 18:38:08 -07001763TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1764TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001765TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1766TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1767
Fred Shih37f05ef2014-07-16 18:38:08 -07001768THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1769THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001770THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001771THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001772THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1773
1774// This is separated out as the argument order is different.
1775 .extern artSet64StaticFromCode
1776ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001777 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1778 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Calin Juravlee460d1d2015-09-29 04:52:17 +01001779 // x2 contains the parameter
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001780 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001781 bl artSet64StaticFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001782 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001783 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1784END art_quick_set64_static
1785
Matteo Franchindfd891a2014-04-30 12:17:17 +01001786 /*
1787 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001788 * exception on error. On success the String is returned. w0 holds the string index. The fast
1789 * path check for hit in strings cache has already been performed.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001790 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001791ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001792
Stuart Monteithb95a5342014-03-12 13:32:32 +00001793// Generate the allocation entrypoints for each allocator.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001794GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_REGION_TLAB_ALLOCATORS
1795// Comment out allocators that have arm64 specific asm.
1796// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) implemented in asm
1797// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1798// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1799GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1800// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) implemented in asm
1801// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
1802GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1803GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB)
1804GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1805GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1806GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1807GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001808
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001809// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1810ENTRY art_quick_alloc_object_rosalloc
1811 // Fast path rosalloc allocation.
1812 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1813 // x2-x7: free.
1814 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1815 // Load the class (x2)
1816 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1817 cbz x2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
1818 // Check class status.
1819 ldr w3, [x2, #MIRROR_CLASS_STATUS_OFFSET]
1820 cmp x3, #MIRROR_CLASS_STATUS_INITIALIZED
1821 bne .Lart_quick_alloc_object_rosalloc_slow_path
1822 // Add a fake dependence from the
1823 // following access flag and size
1824 // loads to the status load.
1825 // This is to prevent those loads
1826 // from being reordered above the
1827 // status load and reading wrong
1828 // values (an alternative is to use
1829 // a load-acquire for the status).
1830 eor x3, x3, x3
1831 add x2, x2, x3
1832 // Check access flags has
1833 // kAccClassIsFinalizable
1834 ldr w3, [x2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1835 tst x3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1836 bne .Lart_quick_alloc_object_rosalloc_slow_path
1837 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1838 // allocation stack has room.
1839 // ldp won't work due to large offset.
1840 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1841 cmp x3, x4
1842 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1843 ldr w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (x3)
1844 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1845 // local allocation
1846 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1847 // Compute the rosalloc bracket index
1848 // from the size.
1849 // Align up the size by the rosalloc
1850 // bracket quantum size and divide
1851 // by the quantum size and subtract
1852 // by 1. This code is a shorter but
1853 // equivalent version.
1854 sub x3, x3, #1
1855 lsr x3, x3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1856 // Load the rosalloc run (x4)
1857 add x4, xSELF, x3, lsl #POINTER_SIZE_SHIFT
1858 ldr x4, [x4, #THREAD_ROSALLOC_RUNS_OFFSET]
1859 // Load the free list head (x3). This
1860 // will be the return val.
1861 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1862 cbz x3, .Lart_quick_alloc_object_rosalloc_slow_path
1863 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1864 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1865 // and update the list head with the
1866 // next pointer.
1867 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1868 // Store the class pointer in the
1869 // header. This also overwrites the
1870 // next pointer. The offsets are
1871 // asserted to match.
1872#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1873#error "Class pointer needs to overwrite next pointer."
1874#endif
1875 POISON_HEAP_REF w2
1876 str w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001877 // Fence. This is "ish" not "ishst" so
1878 // that it also ensures ordering of
1879 // the class status load with respect
1880 // to later accesses to the class
1881 // object. Alternatively we could use
1882 // "ishst" if we use load-acquire for
1883 // the class status load.)
1884 // Needs to be done before pushing on
1885 // allocation since Heap::VisitObjects
1886 // relies on seeing the class pointer.
1887 // b/28790624
1888 dmb ish
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001889 // Push the new object onto the thread
1890 // local allocation stack and
1891 // increment the thread local
1892 // allocation stack top.
1893 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1894 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1895 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1896 // Decrement the size of the free list
1897 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1898 sub x1, x1, #1
1899 // TODO: consider combining this store
1900 // and the list head store above using
1901 // strd.
1902 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001903
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001904 mov x0, x3 // Set the return value and return.
1905 ret
1906.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001907 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001908 mov x2, xSELF // pass Thread::Current
1909 bl artAllocObjectFromCodeRosAlloc // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001910 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001911 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1912END art_quick_alloc_object_rosalloc
Stuart Monteithb95a5342014-03-12 13:32:32 +00001913
Mathieu Chartier8261d022016-08-08 09:41:04 -07001914
1915// The common fast path code for art_quick_alloc_array_region_tlab.
1916.macro ALLOC_ARRAY_TLAB_FAST_PATH slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1917 // Check null class
1918 cbz \wClass, \slowPathLabel
1919 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED \slowPathLabel, \xClass, \wClass, \xCount, \wCount, \xTemp0, \wTemp0, \xTemp1, \wTemp1, \xTemp2, \wTemp2
1920.endm
1921
1922// The common fast path code for art_quick_alloc_array_region_tlab.
1923.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1924 // Array classes are never finalizable or uninitialized, no need to check.
1925 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1926 UNPOISON_HEAP_REF \wTemp0
1927 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1928 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1929 // bits.
1930 // xCount is holding a 32 bit value,
1931 // it can not overflow.
1932 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1933 // Add array data offset and alignment.
1934 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1935#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1936#error Long array data offset must be 4 greater than int array data offset.
1937#endif
1938
1939 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1940 // component size shift is 3
1941 // (for 64 bit alignment).
1942 and \xTemp0, \xTemp0, #4
1943 add \xTemp1, \xTemp1, \xTemp0
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001944 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask
1945 // (addr + 7) & ~7. The mask must
1946 // be 64 bits to keep high bits in
1947 // case of overflow.
1948 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1949 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1950 // 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 -07001951 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1952 bhs \slowPathLabel // path.
1953
1954 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1955 // we use (end - begin) to handle
1956 // negative size arrays. It is
1957 // assumed that a negative size will
1958 // always be greater unsigned than
1959 // region size.
1960 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1961 sub \xTemp2, \xTemp2, \xTemp0
1962 cmp \xTemp1, \xTemp2
1963 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001964 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1965 // Move old thread_local_pos to x0
1966 // for the return value.
1967 mov x0, \xTemp0
1968 add \xTemp0, \xTemp0, \xTemp1
1969 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1970 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1971 add \xTemp0, \xTemp0, #1
1972 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1973 POISON_HEAP_REF \wClass
1974 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1975 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1976 // Fence.
1977 dmb ishst
1978 ret
1979.endm
1980
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001981// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1982//
1983// x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current
1984// x3-x7: free.
1985// Need to preserve x0 and x1 to the slow path.
1986.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1987 cbz x2, \slowPathLabel // Check null class
Mathieu Chartier8261d022016-08-08 09:41:04 -07001988 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED \slowPathLabel
1989.endm
1990
1991.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel
1992 ldr w3, [x2, #MIRROR_CLASS_STATUS_OFFSET] // Check class status.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001993 cmp x3, #MIRROR_CLASS_STATUS_INITIALIZED
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001994 bne \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001995 // Add a fake dependence from the
1996 // following access flag and size
1997 // loads to the status load.
1998 // This is to prevent those loads
1999 // from being reordered above the
2000 // status load and reading wrong
2001 // values (an alternative is to use
2002 // a load-acquire for the status).
2003 eor x3, x3, x3
2004 add x2, x2, x3
Mathieu Chartier8261d022016-08-08 09:41:04 -07002005 ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED \slowPathLabel
2006.endm
2007
2008.macro ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002009 // Check access flags has
2010 // kAccClassIsFinalizable.
2011 ldr w3, [x2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002012 tbnz x3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT, \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002013 // Load thread_local_pos (x4) and
2014 // thread_local_end (x5).
2015 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
2016 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
2017 sub x6, x5, x4 // Compute the remaining buf size.
2018 ldr w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (x7).
2019 cmp x7, x6 // Check if it fits. OK to do this
2020 // before rounding up the object size
2021 // assuming the buf size alignment.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002022 bhi \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002023 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
2024 // Round up the object size by the
2025 // object alignment. (addr + 7) & ~7.
2026 add x7, x7, #OBJECT_ALIGNMENT_MASK
2027 and x7, x7, #OBJECT_ALIGNMENT_MASK_TOGGLED
2028 // Move old thread_local_pos to x0
2029 // for the return value.
2030 mov x0, x4
2031 add x5, x0, x7
2032 str x5, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
2033 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
2034 add x5, x5, #1
2035 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
2036 POISON_HEAP_REF w2
2037 str w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
2038 // Fence. This is "ish" not "ishst" so
2039 // that the code after this allocation
2040 // site will see the right values in
2041 // the fields of the class.
2042 // Alternatively we could use "ishst"
2043 // if we use load-acquire for the
2044 // class status load.)
2045 dmb ish
2046 ret
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002047.endm
2048
2049// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
2050ENTRY art_quick_alloc_object_tlab
2051 // Fast path tlab allocation.
2052 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
2053 // x2-x7: free.
2054#if defined(USE_READ_BARRIER)
2055 mvn x0, xzr // Read barrier not supported here.
2056 ret // Return -1.
2057#endif
2058 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
2059 // Load the class (x2)
2060 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
2061 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002062.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002063 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002064 mov x2, xSELF // Pass Thread::Current.
2065 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002066 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07002067 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
2068END art_quick_alloc_object_tlab
2069
Mathieu Chartier8261d022016-08-08 09:41:04 -07002070// The common code for art_quick_alloc_object_*region_tlab
2071.macro GENERATE_ALLOC_OBJECT_REGION_TLAB name, entrypoint, fast_path, is_resolved
2072ENTRY \name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002073 // Fast path region tlab allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07002074 // x0: type_idx/resolved class/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
2075 // If is_resolved is 1 then x0 is the resolved type, otherwise it is the index.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002076 // x2-x7: free.
2077#if !defined(USE_READ_BARRIER)
2078 mvn x0, xzr // Read barrier must be enabled here.
2079 ret // Return -1.
2080#endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07002081.if \is_resolved
2082 mov x2, x0 // class is actually stored in x0 already
2083.else
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002084 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
2085 // Load the class (x2)
2086 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
Mathieu Chartier8261d022016-08-08 09:41:04 -07002087.endif
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002088 // Most common case: GC is not marking.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002089 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
Mathieu Chartier8261d022016-08-08 09:41:04 -07002090 cbnz x3, .Lmarking\name
2091.Ldo_allocation\name:
2092 \fast_path .Lslow_path\name
2093.Lmarking\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002094 // GC is marking, check the lock word of the class for the mark bit.
2095 // If the class is null, go slow path. The check is required to read the lock word.
Mathieu Chartier8261d022016-08-08 09:41:04 -07002096 cbz w2, .Lslow_path\name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002097 // Class is not null, check mark bit in lock word.
2098 ldr w3, [x2, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2099 // If the bit is not zero, do the allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07002100 tbnz w3, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002101 // The read barrier slow path. Mark
2102 // the class.
2103 stp x0, x1, [sp, #-32]! // Save registers (x0, x1, lr).
2104 str xLR, [sp, #16] // Align sp by 16 bytes.
2105 mov x0, x2 // Pass the class as the first param.
2106 bl artReadBarrierMark
2107 mov x2, x0 // Get the (marked) class back.
2108 ldp x0, x1, [sp, #0] // Restore registers.
2109 ldr xLR, [sp, #16]
2110 add sp, sp, #32
Mathieu Chartier8261d022016-08-08 09:41:04 -07002111 b .Ldo_allocation\name
2112.Lslow_path\name:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002113 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002114 mov x2, xSELF // Pass Thread::Current.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002115 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
2116 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07002117 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Mathieu Chartier8261d022016-08-08 09:41:04 -07002118END \name
2119.endm
2120
2121GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_region_tlab, artAllocObjectFromCodeRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH, 0
2122GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 1
2123GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED, 1
2124
2125// The common code for art_quick_alloc_array_*region_tlab
2126.macro GENERATE_ALLOC_ARRAY_REGION_TLAB name, entrypoint, fast_path, is_resolved
2127ENTRY \name
2128 // Fast path array allocation for region tlab allocation.
2129 // x0: uint32_t type_idx
2130 // x1: int32_t component_count
2131 // x2: ArtMethod* method
2132 // x3-x7: free.
2133#if !defined(USE_READ_BARRIER)
2134 mvn x0, xzr // Read barrier must be enabled here.
2135 ret // Return -1.
2136#endif
2137.if \is_resolved
2138 mov x3, x0
2139 // If already resolved, class is stored in x0
2140.else
2141 ldr x3, [x2, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
2142 // Load the class (x2)
2143 ldr w3, [x3, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
2144.endif
2145 // Most common case: GC is not marking.
2146 ldr w4, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
2147 cbnz x4, .Lmarking\name
2148.Ldo_allocation\name:
2149 \fast_path .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
2150.Lmarking\name:
2151 // GC is marking, check the lock word of the class for the mark bit.
2152 // If the class is null, go slow path. The check is required to read the lock word.
2153 cbz w3, .Lslow_path\name
2154 // Class is not null, check mark bit in lock word.
2155 ldr w4, [x3, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2156 // If the bit is not zero, do the allocation.
2157 tbnz w4, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
2158 // The read barrier slow path. Mark
2159 // the class.
2160 stp x0, x1, [sp, #-32]! // Save registers (x0, x1, x2, lr).
2161 stp x2, xLR, [sp, #16]
2162 mov x0, x3 // Pass the class as the first param.
2163 bl artReadBarrierMark
2164 mov x3, x0 // Get the (marked) class back.
2165 ldp x2, xLR, [sp, #16]
2166 ldp x0, x1, [sp], #32 // Restore registers.
2167 b .Ldo_allocation\name
2168.Lslow_path\name:
2169 // x0: uint32_t type_idx / mirror::Class* klass (if resolved)
2170 // x1: int32_t component_count
2171 // x2: ArtMethod* method
2172 // x3: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002173 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Mathieu Chartier8261d022016-08-08 09:41:04 -07002174 mov x3, xSELF // pass Thread::Current
2175 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002176 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier8261d022016-08-08 09:41:04 -07002177 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
2178END \name
2179.endm
2180
2181GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_region_tlab, artAllocArrayFromCodeRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH, 0
2182// TODO: art_quick_alloc_array_resolved_region_tlab seems to not get called. Investigate compiler.
2183GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED, 1
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08002184
Zheng Xu48241e72014-05-23 11:52:42 +08002185 /*
Zheng Xu69a50302015-04-14 20:04:41 +08002186 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08002187 */
2188 .extern artTestSuspendFromCode
2189ENTRY art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002190 SETUP_SAVE_EVERYTHING_FRAME // save callee saves for stack crawl
Zheng Xu48241e72014-05-23 11:52:42 +08002191 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002192 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002193 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01002194 ret
Zheng Xu48241e72014-05-23 11:52:42 +08002195END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00002196
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002197ENTRY art_quick_implicit_suspend
2198 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002199 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002200 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002201 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002202END art_quick_implicit_suspend
2203
Andreas Gampee62a07e2014-03-26 14:53:21 -07002204 /*
2205 * Called by managed code that is attempting to call a method on a proxy class. On entry
2206 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2207 * method agrees with a ref and args callee save frame.
2208 */
2209 .extern artQuickProxyInvokeHandler
2210ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002211 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07002212 mov x2, xSELF // pass Thread::Current
2213 mov x3, sp // pass SP
2214 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002215 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07002216 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002217 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07002218 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07002219 ret // return on success
2220.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002221 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07002222 DELIVER_PENDING_EXCEPTION
2223END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00002224
Andreas Gampe51f76352014-05-21 08:28:48 -07002225 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002226 * Called to resolve an imt conflict.
2227 * x0 is the conflict ArtMethod.
2228 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2229 *
2230 * Note that this stub writes to xIP0, xIP1, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002231 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002232 .extern artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002233ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002234 ldr xIP0, [sp, #0] // Load referrer
2235 ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64] // Load dex cache methods array
2236 ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT] // Load interface method
2237 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2238 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2239.Limt_table_iterate:
2240 cmp x0, xIP0
2241 // Branch if found. Benchmarks have shown doing a branch here is better.
2242 beq .Limt_table_found
2243 // If the entry is null, the interface method is not in the ImtConflictTable.
2244 cbz x0, .Lconflict_trampoline
2245 // Iterate over the entries of the ImtConflictTable.
2246 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2247 b .Limt_table_iterate
2248.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002249 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002250 // and jump to it.
2251 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2252 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2253 br xIP0
2254.Lconflict_trampoline:
2255 // Call the runtime stub to populate the ImtConflictTable and jump to the
2256 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002257 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002258END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002259
2260ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002261 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002262 mov x2, xSELF
2263 mov x3, sp
2264 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002265 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002266 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002267 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002268 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08002269 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000022701:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002271 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002272 DELIVER_PENDING_EXCEPTION
2273END art_quick_resolution_trampoline
2274
2275/*
2276 * Generic JNI frame layout:
2277 *
2278 * #-------------------#
2279 * | |
2280 * | caller method... |
2281 * #-------------------# <--- SP on entry
2282 * | Return X30/LR |
2283 * | X29/FP | callee save
2284 * | X28 | callee save
2285 * | X27 | callee save
2286 * | X26 | callee save
2287 * | X25 | callee save
2288 * | X24 | callee save
2289 * | X23 | callee save
2290 * | X22 | callee save
2291 * | X21 | callee save
2292 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002293 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002294 * | X7 | arg7
2295 * | X6 | arg6
2296 * | X5 | arg5
2297 * | X4 | arg4
2298 * | X3 | arg3
2299 * | X2 | arg2
2300 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002301 * | D7 | float arg 8
2302 * | D6 | float arg 7
2303 * | D5 | float arg 6
2304 * | D4 | float arg 5
2305 * | D3 | float arg 4
2306 * | D2 | float arg 3
2307 * | D1 | float arg 2
2308 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002309 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002310 * #-------------------#
2311 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002312 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002313 * #-------------------#
2314 * | JNI Call Stack |
2315 * #-------------------# <--- SP on native call
2316 * | |
2317 * | Stack for Regs | The trampoline assembly will pop these values
2318 * | | into registers for native call
2319 * #-------------------#
2320 * | Native code ptr |
2321 * #-------------------#
2322 * | Free scratch |
2323 * #-------------------#
2324 * | Ptr to (1) | <--- SP
2325 * #-------------------#
2326 */
2327 /*
2328 * Called to do a generic JNI down-call
2329 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002330ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002331 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002332
2333 // Save SP , so we can have static CFI info.
2334 mov x28, sp
2335 .cfi_def_cfa_register x28
2336
2337 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002338 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002339 mov xFP, sp
2340
Zheng Xub551fdc2014-07-25 11:49:42 +08002341 mov xIP0, #5120
2342 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002343
2344 // prepare for artQuickGenericJniTrampoline call
2345 // (Thread*, SP)
2346 // x0 x1 <= C calling convention
2347 // xSELF xFP <= where they are
2348
2349 mov x0, xSELF // Thread*
2350 mov x1, xFP
2351 bl artQuickGenericJniTrampoline // (Thread*, sp)
2352
Andreas Gampec200a4a2014-06-16 18:39:09 -07002353 // The C call will have registered the complete save-frame on success.
2354 // The result of the call is:
2355 // x0: pointer to native code, 0 on error.
2356 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002357
Andreas Gampec200a4a2014-06-16 18:39:09 -07002358 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002359 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002360
Andreas Gampec200a4a2014-06-16 18:39:09 -07002361 // Release part of the alloca.
2362 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002363
Andreas Gampec200a4a2014-06-16 18:39:09 -07002364 // Save the code pointer
2365 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002366
2367 // Load parameters from frame into registers.
2368 // TODO Check with artQuickGenericJniTrampoline.
2369 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002370 ldp x0, x1, [sp]
2371 ldp x2, x3, [sp, #16]
2372 ldp x4, x5, [sp, #32]
2373 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002374
Andreas Gampec200a4a2014-06-16 18:39:09 -07002375 ldp d0, d1, [sp, #64]
2376 ldp d2, d3, [sp, #80]
2377 ldp d4, d5, [sp, #96]
2378 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002379
Andreas Gampec200a4a2014-06-16 18:39:09 -07002380 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002381
Zheng Xub551fdc2014-07-25 11:49:42 +08002382 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002383
2384 // result sign extension is handled in C code
2385 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002386 // (Thread*, result, result_f)
2387 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002388 mov x1, x0 // Result (from saved).
2389 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002390 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002391
2392 bl artQuickGenericJniEndTrampoline
2393
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002394 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002395 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002396 cbnz x2, .Lexception_in_native
2397
Stuart Monteithb95a5342014-03-12 13:32:32 +00002398 // Tear down the alloca.
2399 mov sp, x28
2400 .cfi_def_cfa_register sp
2401
Stuart Monteithb95a5342014-03-12 13:32:32 +00002402 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002403 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002404
2405 // store into fpr, for when it's a fpr return...
2406 fmov d0, x0
2407 ret
2408
Stuart Monteithb95a5342014-03-12 13:32:32 +00002409.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002410 // Move to x1 then sp to please assembler.
2411 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
2412 mov sp, x1
2413 .cfi_def_cfa_register sp
2414 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002415 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002416END art_quick_generic_jni_trampoline
2417
2418/*
2419 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2420 * of a quick call:
2421 * x0 = method being called/to bridge to.
2422 * x1..x7, d0..d7 = arguments to that method.
2423 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002424ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002425 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002426
2427 // x0 will contain mirror::ArtMethod* method.
2428 mov x1, xSELF // How to get Thread::Current() ???
2429 mov x2, sp
2430
2431 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2432 // mirror::ArtMethod** sp)
2433 bl artQuickToInterpreterBridge
2434
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002435 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002436
2437 fmov d0, x0
2438
2439 RETURN_OR_DELIVER_PENDING_EXCEPTION
2440END art_quick_to_interpreter_bridge
2441
Andreas Gamped58342c2014-06-05 14:18:08 -07002442
2443//
2444// Instrumentation-related stubs
2445//
2446 .extern artInstrumentationMethodEntryFromCode
2447ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002448 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002449
Zheng Xub551fdc2014-07-25 11:49:42 +08002450 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002451
2452 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002453 mov x3, xLR
2454 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07002455
Zheng Xub551fdc2014-07-25 11:49:42 +08002456 mov xIP0, x0 // x0 = result of call.
2457 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002458
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002459 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07002460 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002461 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07002462END art_quick_instrumentation_entry
2463
2464 .extern artInstrumentationMethodExitFromCode
2465ENTRY art_quick_instrumentation_exit
2466 mov xLR, #0 // Clobber LR for later checks.
2467
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002468 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002469
2470 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
2471 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
2472 // easier to have an extra small stack area.
2473
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002474 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07002475 .cfi_adjust_cfa_offset 16
2476 str d0, [sp, #8] // Save floating-point result.
2477
Andreas Gamped58342c2014-06-05 14:18:08 -07002478 add x1, sp, #16 // Pass SP.
2479 mov x2, x0 // Pass integer result.
2480 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002481 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07002482 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
2483
Zheng Xub551fdc2014-07-25 11:49:42 +08002484 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07002485 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
2486
2487 ldr d0, [sp, #8] // Restore floating-point result.
2488 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
2489 .cfi_adjust_cfa_offset 16
2490
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002491 POP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002492
Zheng Xub551fdc2014-07-25 11:49:42 +08002493 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07002494END art_quick_instrumentation_exit
2495
2496 /*
2497 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2498 * will long jump to the upcall with a special exception of -1.
2499 */
2500 .extern artDeoptimize
2501ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002502 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002503 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002504 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002505 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002506END art_quick_deoptimize
2507
Sebastien Hertz07474662015-08-25 15:12:33 +00002508 /*
2509 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2510 * will long jump to the upcall with a special exception of -1.
2511 */
2512 .extern artDeoptimizeFromCompiledCode
2513ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002514 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002515 mov x0, xSELF // Pass thread.
2516 bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*)
2517 brk 0
2518END art_quick_deoptimize_from_compiled_code
2519
Andreas Gamped58342c2014-06-05 14:18:08 -07002520
Serban Constantinescu169489b2014-06-11 16:43:35 +01002521 /*
2522 * String's indexOf.
2523 *
2524 * TODO: Not very optimized.
2525 * On entry:
2526 * x0: string object (known non-null)
2527 * w1: char to match (known <= 0xFFFF)
2528 * w2: Starting offset in string data
2529 */
2530ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002531 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08002532 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01002533
2534 /* Clamp start to [0..count] */
2535 cmp w2, #0
2536 csel w2, wzr, w2, lt
2537 cmp w2, w3
2538 csel w2, w3, w2, gt
2539
Serban Constantinescu169489b2014-06-11 16:43:35 +01002540 /* Save a copy to compute result */
2541 mov x5, x0
2542
2543 /* Build pointer to start of data to compare and pre-bias */
2544 add x0, x0, x2, lsl #1
2545 sub x0, x0, #2
2546
2547 /* Compute iteration count */
2548 sub w2, w3, w2
2549
2550 /*
2551 * At this point we have:
2552 * x0: start of the data to test
2553 * w1: char to compare
2554 * w2: iteration count
2555 * x5: original start of string data
2556 */
2557
2558 subs w2, w2, #4
2559 b.lt .Lindexof_remainder
2560
2561.Lindexof_loop4:
2562 ldrh w6, [x0, #2]!
2563 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002564 ldrh wIP0, [x0, #2]!
2565 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002566 cmp w6, w1
2567 b.eq .Lmatch_0
2568 cmp w7, w1
2569 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002570 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002571 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002572 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002573 b.eq .Lmatch_3
2574 subs w2, w2, #4
2575 b.ge .Lindexof_loop4
2576
2577.Lindexof_remainder:
2578 adds w2, w2, #4
2579 b.eq .Lindexof_nomatch
2580
2581.Lindexof_loop1:
2582 ldrh w6, [x0, #2]!
2583 cmp w6, w1
2584 b.eq .Lmatch_3
2585 subs w2, w2, #1
2586 b.ne .Lindexof_loop1
2587
2588.Lindexof_nomatch:
2589 mov x0, #-1
2590 ret
2591
2592.Lmatch_0:
2593 sub x0, x0, #6
2594 sub x0, x0, x5
2595 asr x0, x0, #1
2596 ret
2597.Lmatch_1:
2598 sub x0, x0, #4
2599 sub x0, x0, x5
2600 asr x0, x0, #1
2601 ret
2602.Lmatch_2:
2603 sub x0, x0, #2
2604 sub x0, x0, x5
2605 asr x0, x0, #1
2606 ret
2607.Lmatch_3:
2608 sub x0, x0, x5
2609 asr x0, x0, #1
2610 ret
2611END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002612
2613 /*
2614 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002615 * getting its argument and returning its result through W register
2616 * `wreg` (corresponding to X register `xreg`), saving and restoring
2617 * all caller-save registers.
2618 *
2619 * If `wreg` is different from `w0`, the generated function follows a
2620 * non-standard runtime calling convention:
2621 * - register `wreg` is used to pass the (sole) argument of this
2622 * function (instead of W0);
2623 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002624 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002625 * - W0 is treated like a normal (non-argument) caller-save register;
2626 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002627 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002628 */
Roland Levillain4359e612016-07-20 11:32:19 +01002629.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002630ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002631 // Reference is null, no work to do at all.
2632 cbz \wreg, .Lret_rb_\name
Roland Levillain4359e612016-07-20 11:32:19 +01002633 /*
2634 * Allocate 46 stack slots * 8 = 368 bytes:
2635 * - 20 slots for core registers X0-X19
2636 * - 24 slots for floating-point registers D0-D7 and D16-D31
2637 * - 1 slot for return address register XLR
2638 * - 1 padding slot for 16-byte stack alignment
2639 */
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002640 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2641 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2642 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lslow_path_rb_\name
2643 ret
2644.Lslow_path_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002645 // Save all potentially live caller-save core registers.
2646 stp x0, x1, [sp, #-368]!
2647 .cfi_adjust_cfa_offset 368
2648 .cfi_rel_offset x0, 0
2649 .cfi_rel_offset x1, 8
2650 stp x2, x3, [sp, #16]
2651 .cfi_rel_offset x2, 16
2652 .cfi_rel_offset x3, 24
2653 stp x4, x5, [sp, #32]
2654 .cfi_rel_offset x4, 32
2655 .cfi_rel_offset x5, 40
2656 stp x6, x7, [sp, #48]
2657 .cfi_rel_offset x6, 48
2658 .cfi_rel_offset x7, 56
2659 stp x8, x9, [sp, #64]
2660 .cfi_rel_offset x8, 64
2661 .cfi_rel_offset x9, 72
2662 stp x10, x11, [sp, #80]
2663 .cfi_rel_offset x10, 80
2664 .cfi_rel_offset x11, 88
2665 stp x12, x13, [sp, #96]
2666 .cfi_rel_offset x12, 96
2667 .cfi_rel_offset x13, 104
2668 stp x14, x15, [sp, #112]
2669 .cfi_rel_offset x14, 112
2670 .cfi_rel_offset x15, 120
2671 stp x16, x17, [sp, #128]
2672 .cfi_rel_offset x16, 128
2673 .cfi_rel_offset x17, 136
2674 stp x18, x19, [sp, #144]
2675 .cfi_rel_offset x18, 144
2676 .cfi_rel_offset x19, 152
2677 // Save all potentially live caller-save floating-point registers.
2678 stp d0, d1, [sp, #160]
2679 stp d2, d3, [sp, #176]
2680 stp d4, d5, [sp, #192]
2681 stp d6, d7, [sp, #208]
2682 stp d16, d17, [sp, #224]
2683 stp d18, d19, [sp, #240]
2684 stp d20, d21, [sp, #256]
2685 stp d22, d23, [sp, #272]
2686 stp d24, d25, [sp, #288]
2687 stp d26, d27, [sp, #304]
2688 stp d28, d29, [sp, #320]
2689 stp d30, d31, [sp, #336]
2690 // Save return address.
2691 str xLR, [sp, #352]
2692 .cfi_rel_offset x30, 352
2693 // (sp + #360 is a padding slot)
2694
2695 .ifnc \wreg, w0
2696 mov w0, \wreg // Pass arg1 - obj from `wreg`
2697 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002698 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002699 .ifnc \wreg, w0
2700 mov \wreg, w0 // Return result into `wreg`
2701 .endif
2702
2703 // Restore core regs, except `xreg`, as `wreg` is used to return the
2704 // result of this function (simply remove it from the stack instead).
2705 POP_REGS_NE x0, x1, 0, \xreg
2706 POP_REGS_NE x2, x3, 16, \xreg
2707 POP_REGS_NE x4, x5, 32, \xreg
2708 POP_REGS_NE x6, x7, 48, \xreg
2709 POP_REGS_NE x8, x9, 64, \xreg
2710 POP_REGS_NE x10, x11, 80, \xreg
2711 POP_REGS_NE x12, x13, 96, \xreg
2712 POP_REGS_NE x14, x15, 112, \xreg
2713 POP_REGS_NE x16, x17, 128, \xreg
2714 POP_REGS_NE x18, x19, 144, \xreg
2715 // Restore floating-point registers.
2716 ldp d0, d1, [sp, #160]
2717 ldp d2, d3, [sp, #176]
2718 ldp d4, d5, [sp, #192]
2719 ldp d6, d7, [sp, #208]
2720 ldp d16, d17, [sp, #224]
2721 ldp d18, d19, [sp, #240]
2722 ldp d20, d21, [sp, #256]
2723 ldp d22, d23, [sp, #272]
2724 ldp d24, d25, [sp, #288]
2725 ldp d26, d27, [sp, #304]
2726 ldp d28, d29, [sp, #320]
2727 ldp d30, d31, [sp, #336]
2728 // Restore return address and remove padding.
2729 ldr xLR, [sp, #352]
Roland Levillain02b75802016-07-13 11:54:35 +01002730 .cfi_restore x30
Roland Levillain4359e612016-07-20 11:32:19 +01002731 add sp, sp, #368
2732 .cfi_adjust_cfa_offset -368
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002733.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002734 ret
2735END \name
2736.endm
2737
Roland Levillain4359e612016-07-20 11:32:19 +01002738READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2739READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2740READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2741READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2742READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2743READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2744READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2745READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2746READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2747READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2748READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2749READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2750READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2751READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2752READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2753READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
2754READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16
2755READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2756READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2757READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2758READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2759READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2760READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2761READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2762READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2763READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2764READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2765READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2766READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2767READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29