blob: d1225b323a1ad93342cb540ef7a17d4154253bb9 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
2 * Copyright (C) 2012 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
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_arm.S"
Ian Rogers9651f422011-09-19 20:26:07 -070018
Mathieu Chartier7410f292013-11-24 13:17:35 -080019#include "arch/quick_alloc_entrypoints.S"
20
Ian Rogersff1ed472011-09-20 13:46:24 -070021 /* Deliver the given exception */
22 .extern artDeliverExceptionFromCode
23 /* Deliver an exception pending on a thread */
24 .extern artDeliverPendingException
25
Ian Rogers4f0d07c2011-10-06 23:38:47 -070026 /*
Andreas Gampe76914b02015-07-17 20:14:50 -070027 * Macro to spill the GPRs.
Ian Rogers4f0d07c2011-10-06 23:38:47 -070028 */
Andreas Gampe76914b02015-07-17 20:14:50 -070029.macro SPILL_ALL_CALLEE_SAVE_GPRS
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070030 push {r4-r11, lr} @ 9 words (36 bytes) of callee saves.
Ian Rogers9329bbb2013-02-08 19:56:30 -080031 .cfi_adjust_cfa_offset 36
32 .cfi_rel_offset r4, 0
33 .cfi_rel_offset r5, 4
34 .cfi_rel_offset r6, 8
35 .cfi_rel_offset r7, 12
36 .cfi_rel_offset r8, 16
37 .cfi_rel_offset r9, 20
38 .cfi_rel_offset r10, 24
39 .cfi_rel_offset r11, 28
40 .cfi_rel_offset lr, 32
Andreas Gampe76914b02015-07-17 20:14:50 -070041.endm
42
43 /*
44 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010045 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Andreas Gampe76914b02015-07-17 20:14:50 -070046 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010047.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME rTemp
Andreas Gampe76914b02015-07-17 20:14:50 -070048 SPILL_ALL_CALLEE_SAVE_GPRS @ 9 words (36 bytes) of callee saves.
Zheng Xu5667fdb2014-10-23 18:29:55 +080049 vpush {s16-s31} @ 16 words (64 bytes) of floats.
Zheng Xu5667fdb2014-10-23 18:29:55 +080050 .cfi_adjust_cfa_offset 64
51 sub sp, #12 @ 3 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080052 .cfi_adjust_cfa_offset 12
Vladimir Marko3098c8c2016-06-14 17:43:17 +010053 RUNTIME_CURRENT1 \rTemp @ Load Runtime::Current into rTemp.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010054 @ Load kSaveAllCalleeSaves Method* into rTemp.
55 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
Vladimir Marko3098c8c2016-06-14 17:43:17 +010056 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070057 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070058
59 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010060#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 36 + 64 + 12)
61#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070063.endm
64
65 /*
66 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010067 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
Ian Rogers4f0d07c2011-10-06 23:38:47 -070068 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010069.macro SETUP_SAVE_REFS_ONLY_FRAME rTemp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070070 push {r5-r8, r10-r11, lr} @ 7 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -080071 .cfi_adjust_cfa_offset 28
72 .cfi_rel_offset r5, 0
73 .cfi_rel_offset r6, 4
74 .cfi_rel_offset r7, 8
75 .cfi_rel_offset r8, 12
76 .cfi_rel_offset r10, 16
77 .cfi_rel_offset r11, 20
78 .cfi_rel_offset lr, 24
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070079 sub sp, #4 @ bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080080 .cfi_adjust_cfa_offset 4
Vladimir Marko3098c8c2016-06-14 17:43:17 +010081 RUNTIME_CURRENT2 \rTemp @ Load Runtime::Current into rTemp.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010082 @ Load kSaveRefsOnly Method* into rTemp.
83 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
Vladimir Marko3098c8c2016-06-14 17:43:17 +010084 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070085 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070086
87 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010088#if (FRAME_SIZE_SAVE_REFS_ONLY != 28 + 4)
89#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070090#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070091.endm
92
Vladimir Markofd36f1f2016-08-03 18:49:58 +010093.macro RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070094 add sp, #4 @ bottom word holds Method*
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -070095 .cfi_adjust_cfa_offset -4
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070096 pop {r5-r8, r10-r11, lr} @ 7 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080097 .cfi_restore r5
98 .cfi_restore r6
99 .cfi_restore r7
100 .cfi_restore r8
101 .cfi_restore r10
102 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700103 .cfi_restore lr
104 .cfi_adjust_cfa_offset -28
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700105.endm
106
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100107.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
108 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700109 bx lr @ return
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700110.endm
111
112 /*
113 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100114 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700115 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100116.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Zheng Xu5667fdb2014-10-23 18:29:55 +0800117 push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves and args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800118 .cfi_adjust_cfa_offset 40
Jeff Hao5d917302013-02-27 17:57:33 -0800119 .cfi_rel_offset r1, 0
120 .cfi_rel_offset r2, 4
121 .cfi_rel_offset r3, 8
122 .cfi_rel_offset r5, 12
123 .cfi_rel_offset r6, 16
124 .cfi_rel_offset r7, 20
125 .cfi_rel_offset r8, 24
126 .cfi_rel_offset r10, 28
127 .cfi_rel_offset r11, 32
128 .cfi_rel_offset lr, 36
Zheng Xu5667fdb2014-10-23 18:29:55 +0800129 vpush {s0-s15} @ 16 words of float args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800130 .cfi_adjust_cfa_offset 64
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100131 sub sp, #8 @ 2 words of space, alignment padding and Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -0800132 .cfi_adjust_cfa_offset 8
Zheng Xu5667fdb2014-10-23 18:29:55 +0800133 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100134#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 40 + 64 + 8)
135#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM) size not as expected."
Zheng Xu5667fdb2014-10-23 18:29:55 +0800136#endif
137.endm
138
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100139.macro SETUP_SAVE_REFS_AND_ARGS_FRAME rTemp
140 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100141 RUNTIME_CURRENT3 \rTemp @ Load Runtime::Current into rTemp.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100142 @ Load kSaveRefsAndArgs Method* into rTemp.
143 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100144 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700145 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700146.endm
147
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100148.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
149 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
150 str r0, [sp, #0] @ Store ArtMethod* to bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700151 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
152.endm
153
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100154.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700155 add sp, #8 @ rewind sp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800156 .cfi_adjust_cfa_offset -8
157 vpop {s0-s15}
158 .cfi_adjust_cfa_offset -64
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700159 pop {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -0800160 .cfi_restore r1
161 .cfi_restore r2
162 .cfi_restore r3
163 .cfi_restore r5
164 .cfi_restore r6
165 .cfi_restore r7
166 .cfi_restore r8
167 .cfi_restore r10
168 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700169 .cfi_restore lr
Zheng Xu5667fdb2014-10-23 18:29:55 +0800170 .cfi_adjust_cfa_offset -40
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700171.endm
172
Vladimir Marko952dbb12016-07-28 12:01:51 +0100173 /*
174 * Macro that sets up the callee save frame to conform with
175 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000176 * when core registers are already saved.
177 */
178.macro SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED rTemp
179 @ 14 words of callee saves and args already saved.
180 vpush {d0-d15} @ 32 words, 2 for each of the 16 saved doubles.
181 .cfi_adjust_cfa_offset 128
182 sub sp, #8 @ 2 words of space, alignment padding and Method*
183 .cfi_adjust_cfa_offset 8
184 RUNTIME_CURRENT1 \rTemp @ Load Runtime::Current into rTemp.
185 @ Load kSaveEverything Method* into rTemp.
186 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET]
187 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
188 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
189
190 // Ugly compile-time check, but we only have the preprocessor.
191#if (FRAME_SIZE_SAVE_EVERYTHING != 56 + 128 + 8)
192#error "FRAME_SIZE_SAVE_EVERYTHING(ARM) size not as expected."
193#endif
194.endm
195
196 /*
197 * Macro that sets up the callee save frame to conform with
198 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100199 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100200.macro SETUP_SAVE_EVERYTHING_FRAME rTemp
Vladimir Marko952dbb12016-07-28 12:01:51 +0100201 push {r0-r12, lr} @ 14 words of callee saves and args.
202 .cfi_adjust_cfa_offset 56
203 .cfi_rel_offset r0, 0
204 .cfi_rel_offset r1, 4
205 .cfi_rel_offset r2, 8
206 .cfi_rel_offset r3, 12
207 .cfi_rel_offset r4, 16
208 .cfi_rel_offset r5, 20
209 .cfi_rel_offset r6, 24
210 .cfi_rel_offset r7, 28
211 .cfi_rel_offset r8, 32
212 .cfi_rel_offset r9, 36
213 .cfi_rel_offset r10, 40
214 .cfi_rel_offset r11, 44
215 .cfi_rel_offset ip, 48
216 .cfi_rel_offset lr, 52
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000217 SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED \rTemp
Vladimir Marko952dbb12016-07-28 12:01:51 +0100218.endm
219
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100220.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100221 add sp, #8 @ rewind sp
222 .cfi_adjust_cfa_offset -8
Vladimir Markode5f1942016-08-10 12:30:05 +0100223 vpop {d0-d15}
Vladimir Marko952dbb12016-07-28 12:01:51 +0100224 .cfi_adjust_cfa_offset -128
225 pop {r0-r12, lr} @ 14 words of callee saves
226 .cfi_restore r0
227 .cfi_restore r1
228 .cfi_restore r2
229 .cfi_restore r3
230 .cfi_restore r5
231 .cfi_restore r6
232 .cfi_restore r7
233 .cfi_restore r8
234 .cfi_restore r9
235 .cfi_restore r10
236 .cfi_restore r11
237 .cfi_restore r12
238 .cfi_restore lr
239 .cfi_adjust_cfa_offset -56
240.endm
241
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100242.macro RESTORE_SAVE_EVERYTHING_FRAME_KEEP_R0
243 add sp, #8 @ rewind sp
244 .cfi_adjust_cfa_offset -8
245 vpop {d0-d15}
246 .cfi_adjust_cfa_offset -128
247 add sp, #4 @ skip r0
248 .cfi_adjust_cfa_offset -4
249 .cfi_restore r0 @ debugger can no longer restore caller's r0
250 pop {r1-r12, lr} @ 13 words of callee saves
251 .cfi_restore r1
252 .cfi_restore r2
253 .cfi_restore r3
254 .cfi_restore r5
255 .cfi_restore r6
256 .cfi_restore r7
257 .cfi_restore r8
258 .cfi_restore r9
259 .cfi_restore r10
260 .cfi_restore r11
261 .cfi_restore r12
262 .cfi_restore lr
263 .cfi_adjust_cfa_offset -52
264.endm
265
Ian Rogers637859c2013-08-27 14:35:54 -0700266.macro RETURN_IF_RESULT_IS_ZERO
267 cbnz r0, 1f @ result non-zero branch over
268 bx lr @ return
2691:
270.endm
271
272.macro RETURN_IF_RESULT_IS_NON_ZERO
273 cbz r0, 1f @ result zero branch over
274 bx lr @ return
2751:
276.endm
277
Ian Rogersce9eca62011-10-07 17:11:03 -0700278 /*
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100279 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
280 * exception is Thread::Current()->exception_ when the runtime method frame is ready.
Ian Rogersce9eca62011-10-07 17:11:03 -0700281 */
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100282.macro DELIVER_PENDING_EXCEPTION_FRAME_READY
Ian Rogersce9eca62011-10-07 17:11:03 -0700283 mov r0, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100284 bl artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700285.endm
286
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100287 /*
288 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
289 * exception is Thread::Current()->exception_.
290 */
291.macro DELIVER_PENDING_EXCEPTION
292 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save callee saves for throw
293 DELIVER_PENDING_EXCEPTION_FRAME_READY
294.endm
295
Ian Rogers57b86d42012-03-27 16:05:41 -0700296.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700297 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800298ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100299 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700300 mov r0, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100301 bl \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800302END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700303.endm
buzbee44b412b2012-02-04 08:50:53 -0800304
Vladimir Marko804b03f2016-09-14 16:26:36 +0100305.macro NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
306 .extern \cxx_name
307ENTRY \c_name
308 SETUP_SAVE_EVERYTHING_FRAME r0 @ save all registers as basis for long jump context
309 mov r0, r9 @ pass Thread::Current
310 bl \cxx_name @ \cxx_name(Thread*)
311END \c_name
312.endm
313
Ian Rogers57b86d42012-03-27 16:05:41 -0700314.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700315 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800316ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100317 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r1 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700318 mov r1, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100319 bl \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800320END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700321.endm
Ian Rogers9651f422011-09-19 20:26:07 -0700322
Vladimir Marko804b03f2016-09-14 16:26:36 +0100323.macro TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700324 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800325ENTRY \c_name
Vladimir Marko804b03f2016-09-14 16:26:36 +0100326 SETUP_SAVE_EVERYTHING_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700327 mov r2, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100328 bl \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800329END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700330.endm
Ian Rogersbdb03912011-09-14 00:55:44 -0700331
Fred Shih37f05ef2014-07-16 18:38:08 -0700332.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
333 ldr \reg, [r9, #THREAD_EXCEPTION_OFFSET] // Get exception field.
334 cbnz \reg, 1f
335 bx lr
3361:
337 DELIVER_PENDING_EXCEPTION
338.endm
339
340.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
341 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r1
342.endm
343
344.macro RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
345 RETURN_IF_RESULT_IS_ZERO
346 DELIVER_PENDING_EXCEPTION
347.endm
348
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800349.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
350 RETURN_IF_RESULT_IS_NON_ZERO
351 DELIVER_PENDING_EXCEPTION
352.endm
353
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000354// Macros taking opportunity of code similarities for downcalls.
Fred Shih37f05ef2014-07-16 18:38:08 -0700355.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
356 .extern \entrypoint
357ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100358 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000359 mov r1, r9 @ pass Thread::Current
360 bl \entrypoint @ (uint32_t field_idx, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100361 RESTORE_SAVE_REFS_ONLY_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700362 \return
363END \name
364.endm
365
366.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
367 .extern \entrypoint
368ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100369 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000370 mov r2, r9 @ pass Thread::Current
371 bl \entrypoint @ (field_idx, Object*, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100372 RESTORE_SAVE_REFS_ONLY_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700373 \return
374END \name
375.endm
376
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800377.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
Fred Shih37f05ef2014-07-16 18:38:08 -0700378 .extern \entrypoint
379ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100380 SETUP_SAVE_REFS_ONLY_FRAME r3 @ save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000381 mov r3, r9 @ pass Thread::Current
382 bl \entrypoint @ (field_idx, Object*, new_val, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100383 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Fred Shih37f05ef2014-07-16 18:38:08 -0700384 \return
385END \name
386.endm
387
Ian Rogers57b86d42012-03-27 16:05:41 -0700388 /*
389 * Called by managed code, saves callee saves and then calls artThrowException
390 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
391 */
Ian Rogers468532e2013-08-05 10:56:33 -0700392ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Ian Rogers932746a2011-09-22 18:57:50 -0700393
Ian Rogers57b86d42012-03-27 16:05:41 -0700394 /*
395 * Called by managed code to create and deliver a NullPointerException.
396 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100397NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700398
Ian Rogers57b86d42012-03-27 16:05:41 -0700399 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100400 * Call installed by a signal handler to create and deliver a NullPointerException.
401 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000402 .extern art_quick_throw_null_pointer_exception_from_signal
403ENTRY art_quick_throw_null_pointer_exception_from_signal
404 // The fault handler pushes the gc map address, i.e. "return address", to stack
405 // and passes the fault address in LR. So we need to set up the CFI info accordingly.
406 .cfi_def_cfa_offset __SIZEOF_POINTER__
407 .cfi_rel_offset lr, 0
408 push {r0-r12} @ 13 words of callee saves and args; LR already saved.
409 .cfi_adjust_cfa_offset 52
410 .cfi_rel_offset r0, 0
411 .cfi_rel_offset r1, 4
412 .cfi_rel_offset r2, 8
413 .cfi_rel_offset r3, 12
414 .cfi_rel_offset r4, 16
415 .cfi_rel_offset r5, 20
416 .cfi_rel_offset r6, 24
417 .cfi_rel_offset r7, 28
418 .cfi_rel_offset r8, 32
419 .cfi_rel_offset r9, 36
420 .cfi_rel_offset r10, 40
421 .cfi_rel_offset r11, 44
422 .cfi_rel_offset ip, 48
423
424 @ save all registers as basis for long jump context
425 SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED r1
426 mov r0, lr @ pass the fault address stored in LR by the fault handler.
427 mov r1, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100428 bl artThrowNullPointerExceptionFromSignal @ (Thread*)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000429END art_quick_throw_null_pointer_exception_from_signal
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100430
431 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700432 * Called by managed code to create and deliver an ArithmeticException.
433 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100434NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700435
Ian Rogers57b86d42012-03-27 16:05:41 -0700436 /*
437 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
438 * index, arg2 holds limit.
439 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100440TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700441
442 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100443 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
444 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
445 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100446TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_string_bounds, artThrowStringBoundsFromCode
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100447
448 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700449 * Called by managed code to create and deliver a StackOverflowError.
450 */
Ian Rogers468532e2013-08-05 10:56:33 -0700451NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700452
453 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800454 * All generated callsites for interface invokes and invocation slow paths will load arguments
455 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100456 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700457 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700458 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800459 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
460 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700461 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700462 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800463 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700464 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700465 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
466 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700467 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700468.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800469 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100470 SETUP_SAVE_REFS_AND_ARGS_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100471 mov r2, r9 @ pass Thread::Current
472 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700473 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700474 mov r12, r1 @ save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100475 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700476 cbz r0, 1f @ did we find the target? if not go to exception delivery
477 bx r12 @ tail call to target
4781:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800479 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700480.endm
481.macro INVOKE_TRAMPOLINE c_name, cxx_name
482ENTRY \c_name
483 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800484END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800485.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800486
Logan Chien8dbb7082013-01-25 20:31:17 +0800487INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800488
Logan Chien8dbb7082013-01-25 20:31:17 +0800489INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
490INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
491INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
492INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700493
Ian Rogers57b86d42012-03-27 16:05:41 -0700494 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800495 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700496 * On entry:
497 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700498 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700499 * r2 = size of argument array in bytes
500 * r3 = (managed) thread pointer
501 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800502 * [sp + 4] = result_in_float
503 * [sp + 8] = core register argument array
504 * [sp + 12] = fp register argument array
505 * +-------------------------+
506 * | uint32_t* fp_reg_args |
507 * | uint32_t* core_reg_args |
508 * | result_in_float | <- Caller frame
509 * | Jvalue* result |
510 * +-------------------------+
511 * | lr |
512 * | r11 |
513 * | r9 |
514 * | r4 | <- r11
515 * +-------------------------+
516 * | uint32_t out[n-1] |
517 * | : : | Outs
518 * | uint32_t out[0] |
519 * | StackRef<ArtMethod> | <- SP value=null
520 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800521 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800522ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700523 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800524 mov r11, sp @ save the stack pointer
525 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800526
Jeff Hao5d917302013-02-27 17:57:33 -0800527 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800528
529 add r4, r2, #4 @ create space for method pointer in frame
530 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
531 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
532 mov sp, r4 @ 16B alignment ourselves.
533
534 mov r4, r0 @ save method*
535 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
536 bl memcpy @ memcpy (dest, src, bytes)
537 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700538 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800539
Nicolas Geoffray48088462014-12-12 10:29:38 +0000540 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800541 vldm ip, {s0-s15} @ copy s0 - s15
542
Nicolas Geoffray48088462014-12-12 10:29:38 +0000543 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800544 mov r0, r4 @ restore method*
545 add ip, ip, #4 @ skip r0
546 ldm ip, {r1-r3} @ copy r1 - r3
547
Wei Jin04f4d8a2014-05-29 18:04:29 -0700548#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800549 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700550#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700551
Mathieu Chartiere401d142015-04-22 13:56:20 -0700552 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800553 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800554
Jeff Hao6474d192013-03-26 14:08:09 -0700555 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800556 .cfi_def_cfa_register sp
557
Nicolas Geoffray48088462014-12-12 10:29:38 +0000558 ldr r4, [sp, #40] @ load result_is_float
559 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800560 cmp r4, #0
561 ite eq
562 strdeq r0, [r9] @ store r0/r1 into result pointer
563 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
564
Nicolas Geoffray48088462014-12-12 10:29:38 +0000565 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800566END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700567
Jeff Hao5d917302013-02-27 17:57:33 -0800568 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000569 * On stack replacement stub.
570 * On entry:
571 * r0 = stack to copy
572 * r1 = size of stack
573 * r2 = pc to call
574 * r3 = JValue* result
575 * [sp] = shorty
576 * [sp + 4] = thread
577 */
578ENTRY art_quick_osr_stub
579 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
580 mov r11, sp @ Save the stack pointer
581 mov r10, r1 @ Save size of stack
582 ldr r9, [r11, #40] @ Move managed thread pointer into r9
583 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000584 sub r7, sp, #12 @ Reserve space for stack pointer,
585 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000586 and r7, #0xFFFFFFF0 @ Align stack pointer
587 mov sp, r7 @ Update stack pointer
588 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000589 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000590 mov ip, #0
591 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
592 sub sp, sp, r1 @ Reserve space for callee stack
593 mov r2, r1
594 mov r1, r0
595 mov r0, sp
596 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
597 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000598 ldr r10, [sp, #8] @ Restore JValue* result
599 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000600 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000601 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000602 cmp r4, #68 @ Test if result type char == 'D'.
603 beq .Losr_fp_result
604 cmp r4, #70 @ Test if result type char == 'F'.
605 beq .Losr_fp_result
606 strd r0, [r10] @ Store r0/r1 into result pointer
607 b .Losr_exit
608.Losr_fp_result:
609 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
610.Losr_exit:
611 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
612.Losr_entry:
613 sub r10, r10, #4
614 str lr, [sp, r10] @ Store link register per the compiler ABI
615 bx r8
616END art_quick_osr_stub
617
618 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700619 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
620 */
Ian Rogers637859c2013-08-27 14:35:54 -0700621ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700622 vldm r1, {s0-s31} @ load all fprs from argument fprs_
623 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700624 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700625 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700626 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700627 ldr r0, [r0, #-12] @ load r0 value
628 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700629 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800630END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700631
Ian Rogers60db5ab2012-02-20 17:02:00 -0800632 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700633 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
634 * failure.
635 */
Ian Rogers832336b2014-10-08 15:35:22 -0700636TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700637
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700638 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700639 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
640 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700641 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800642 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700643ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800644 cbz r0, .Lslow_lock
645.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700646 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700647 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800648 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700649 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800650 cbnz r3, .Lnot_unlocked @ already thin locked
651 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
652 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700653 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800654 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700655 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700656 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800657.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
658 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800659 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700660 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
661 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800662 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700663 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800664 mov r3, r1 @ copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700665 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800666 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700667 lsr r3, r2, #LOCK_WORD_GC_STATE_SHIFT @ if the first gc state bit is set, we overflowed.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800668 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
669 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
670 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
671 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700672 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800673.Llock_strex_fail:
674 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800675.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100676 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700677 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700678 bl artLockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100679 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700680 RETURN_IF_RESULT_IS_ZERO
681 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700682END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700683
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700684ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100685 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700686 mov r1, r9 @ pass Thread::Current
687 bl artLockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100688 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700689 RETURN_IF_RESULT_IS_ZERO
690 DELIVER_PENDING_EXCEPTION
691END art_quick_lock_object_no_inline
692
Ian Rogersff1ed472011-09-20 13:46:24 -0700693 /*
694 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700695 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700696 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800697 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700698ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800699 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800700.Lretry_unlock:
701#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700702 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800703#else
704 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
705#endif
706 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800707 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700708 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800709 mov r3, r1 @ copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700710 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800711 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700712 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800713 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800714 mov r3, r1 @ copy lock word to detect transition to unlocked
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700715 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800716 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800717 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800718 @ transition to unlocked
719 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700720 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED @ r3: zero except for the preserved gc bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700721 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800722#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700723 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800724#else
725 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
726 cbnz r2, .Lunlock_strex_fail @ store failed, retry
727#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700728 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800729.Lrecursive_thin_unlock: @ r1: original lock word
730 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
731#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700732 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800733#else
734 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
735 cbnz r2, .Lunlock_strex_fail @ store failed, retry
736#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700737 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800738.Lunlock_strex_fail:
739 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800740.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700741 @ save callee saves in case exception allocation triggers GC
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100742 SETUP_SAVE_REFS_ONLY_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700743 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700744 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100745 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700746 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700747 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700748END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700749
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700750ENTRY art_quick_unlock_object_no_inline
751 @ save callee saves in case exception allocation triggers GC
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100752 SETUP_SAVE_REFS_ONLY_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700753 mov r1, r9 @ pass Thread::Current
754 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100755 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700756 RETURN_IF_RESULT_IS_ZERO
757 DELIVER_PENDING_EXCEPTION
758END art_quick_unlock_object_no_inline
759
Ian Rogersff1ed472011-09-20 13:46:24 -0700760 /*
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800761 * Entry from managed code that calls artInstanceOfFromCode and on failure calls
762 * artThrowClassCastExceptionForObject.
Ian Rogersff1ed472011-09-20 13:46:24 -0700763 */
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800764 .extern artInstanceOfFromCode
765 .extern artThrowClassCastExceptionForObject
766ENTRY art_quick_check_instance_of
Ian Rogersa9a82542013-10-04 11:17:26 -0700767 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700768 .cfi_adjust_cfa_offset 12
769 .cfi_rel_offset r0, 0
770 .cfi_rel_offset r1, 4
771 .cfi_rel_offset lr, 8
772 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700773 .cfi_adjust_cfa_offset 4
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800774 bl artInstanceOfFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800775 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700776 add sp, #4
777 .cfi_adjust_cfa_offset -4
778 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700779 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800780.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700781 add sp, #4
782 .cfi_adjust_cfa_offset -4
783 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700784 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800785 .cfi_restore r0
786 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700787 .cfi_restore lr
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100788 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700789 mov r2, r9 @ pass Thread::Current
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800790 bl artThrowClassCastExceptionForObject @ (Object*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700791 bkpt
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800792END art_quick_check_instance_of
buzbee4a3164f2011-09-03 11:25:10 -0700793
Man Cao1aee9002015-07-14 22:31:42 -0700794// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
795.macro POP_REG_NE rReg, offset, rExclude
796 .ifnc \rReg, \rExclude
797 ldr \rReg, [sp, #\offset] @ restore rReg
798 .cfi_restore \rReg
799 .endif
800.endm
801
Roland Levillain4359e612016-07-20 11:32:19 +0100802// Save rReg's value to [sp, #offset].
803.macro PUSH_REG rReg, offset
804 str \rReg, [sp, #\offset] @ save rReg
805 .cfi_rel_offset \rReg, \offset
806.endm
807
Man Cao1aee9002015-07-14 22:31:42 -0700808 /*
809 * Macro to insert read barrier, only used in art_quick_aput_obj.
810 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
811 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
812 */
813.macro READ_BARRIER rDest, rObj, offset
814#ifdef USE_READ_BARRIER
815 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
816 .cfi_adjust_cfa_offset 24
817 .cfi_rel_offset r0, 0
818 .cfi_rel_offset r1, 4
819 .cfi_rel_offset r2, 8
820 .cfi_rel_offset r3, 12
821 .cfi_rel_offset ip, 16
822 .cfi_rel_offset lr, 20
823 sub sp, #8 @ push padding
824 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700825 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700826 .ifnc \rObj, r1
827 mov r1, \rObj @ pass rObj
828 .endif
829 mov r2, #\offset @ pass offset
830 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
831 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
832 .ifnc \rDest, r0
833 mov \rDest, r0 @ save return value in rDest
834 .endif
835 add sp, #8 @ pop padding
836 .cfi_adjust_cfa_offset -8
837 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
838 POP_REG_NE r1, 4, \rDest
839 POP_REG_NE r2, 8, \rDest
840 POP_REG_NE r3, 12, \rDest
841 POP_REG_NE ip, 16, \rDest
842 add sp, #20
843 .cfi_adjust_cfa_offset -20
844 pop {lr} @ restore lr
845 .cfi_adjust_cfa_offset -4
846 .cfi_restore lr
847#else
848 ldr \rDest, [\rObj, #\offset]
849 UNPOISON_HEAP_REF \rDest
850#endif // USE_READ_BARRIER
851.endm
852
Man Cao1aee9002015-07-14 22:31:42 -0700853#ifdef USE_READ_BARRIER
854 .extern artReadBarrierSlow
855#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700856 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700857ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700858#ifdef USE_READ_BARRIER
859 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
860 tst r2, r2
861 beq .Ldo_aput_null
862#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800863 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700864#endif // USE_READ_BARRIER
865 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
866 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
867 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700868 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800869 bne .Lcheck_assignability
870.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700871 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700872 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700873 str r2, [r3, r1, lsl #2]
874 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
875 lsr r0, r0, #7
876 strb r3, [r3, r0]
877 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800878.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700879 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700880 str r2, [r3, r1, lsl #2]
881 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800882.Lcheck_assignability:
883 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700884 .cfi_adjust_cfa_offset 16
885 .cfi_rel_offset r0, 0
886 .cfi_rel_offset r1, 4
887 .cfi_rel_offset r2, 8
888 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700889 mov r1, ip
890 mov r0, r3
891 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800892 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700893 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700894 .cfi_restore r0
895 .cfi_restore r1
896 .cfi_restore r2
897 .cfi_restore lr
898 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700899 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700900 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700901 str r2, [r3, r1, lsl #2]
902 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
903 lsr r0, r0, #7
904 strb r3, [r3, r0]
905 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800906.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700907 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700908 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100909 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700910 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700911 mov r2, r9 @ pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +0100912 bl artThrowArrayStoreException @ (Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700913 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700914END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700915
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800916// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100917.macro ONE_ARG_DOWNCALL name, entrypoint, return
918 .extern \entrypoint
919ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100920 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100921 mov r1, r9 @ pass Thread::Current
922 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100923 RESTORE_SAVE_REFS_ONLY_FRAME
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100924 \return
925END \name
926.endm
927
928// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800929.macro TWO_ARG_DOWNCALL name, entrypoint, return
930 .extern \entrypoint
931ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100932 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800933 mov r2, r9 @ pass Thread::Current
934 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100935 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800936 \return
937END \name
938.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700939
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800940// Macro to facilitate adding new array allocation entrypoints.
941.macro THREE_ARG_DOWNCALL name, entrypoint, return
942 .extern \entrypoint
943ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100944 SETUP_SAVE_REFS_ONLY_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800945 mov r3, r9 @ pass Thread::Current
946 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
947 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100948 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800949 \return
950END \name
951.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700952
Jeff Hao848f70a2014-01-15 13:49:50 -0800953// Macro to facilitate adding new allocation entrypoints.
954.macro FOUR_ARG_DOWNCALL name, entrypoint, return
955 .extern \entrypoint
956ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100957 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800958 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800959 .cfi_adjust_cfa_offset 16
960 bl \entrypoint
961 add sp, #16 @ strip the extra frame
962 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100963 RESTORE_SAVE_REFS_ONLY_FRAME
Jeff Hao848f70a2014-01-15 13:49:50 -0800964 \return
965END \name
966.endm
967
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100968ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
969ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
970ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb093c6b2011-10-31 16:19:55 -0700971
Ian Rogersce9eca62011-10-07 17:11:03 -0700972 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700973 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700974 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000975ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
976ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
977ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
978ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
979ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
980ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700981 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700982 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700983 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000984 .extern artGet64StaticFromCompiledCode
Ian Rogers468532e2013-08-05 10:56:33 -0700985ENTRY art_quick_get64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100986 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000987 mov r1, r9 @ pass Thread::Current
988 bl artGet64StaticFromCompiledCode @ (uint32_t field_idx, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700989 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100990 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700991 cbnz r2, 1f @ success if no exception pending
992 bx lr @ return on success
9931:
Ian Rogersce9eca62011-10-07 17:11:03 -0700994 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700995END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700996
Ian Rogersce9eca62011-10-07 17:11:03 -0700997 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700998 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700999 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001000TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
1001TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
1002TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
1003TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
1004TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
1005TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -08001006 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001007 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001008 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001009 .extern artGet64InstanceFromCompiledCode
Ian Rogers468532e2013-08-05 10:56:33 -07001010ENTRY art_quick_get64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001011 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001012 mov r2, r9 @ pass Thread::Current
1013 bl artGet64InstanceFromCompiledCode @ (field_idx, Object*, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -07001014 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001015 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -07001016 cbnz r2, 1f @ success if no exception pending
1017 bx lr @ return on success
10181:
Ian Rogers1bddec32012-02-04 12:27:34 -08001019 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001020END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001021
Ian Rogers1bddec32012-02-04 12:27:34 -08001022 /*
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001023 * Called by managed code to resolve a static field and store a value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001024 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001025TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1026TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1027TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1028TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1029THREE_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -07001030
Ian Rogersce9eca62011-10-07 17:11:03 -07001031 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001032 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -07001033 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001034THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1035THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1036THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1037THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1038
Ian Rogers1bddec32012-02-04 12:27:34 -08001039 /*
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001040 * Called by managed code to resolve an instance field and store a wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001041 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001042 .extern artSet64InstanceFromCompiledCode
Ian Rogers468532e2013-08-05 10:56:33 -07001043ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001044 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001045 @ r2:r3 contain the wide argument
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001046 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
1047 .cfi_adjust_cfa_offset 16
1048 bl artSet64InstanceFromCompiledCode @ (field_idx, Object*, new_val, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -08001049 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -08001050 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001051 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -07001052 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -08001053 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001054END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001055
Ian Rogers1bddec32012-02-04 12:27:34 -08001056 /*
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001057 * Entry from managed code to resolve a string, this stub will
1058 * check the dex cache for a matching string (the fast path), and if not found,
1059 * it will allocate a String and deliver an exception on error.
1060 * On success the String is returned. R0 holds the string index.
Brian Carlstromaded5f72011-10-07 17:15:04 -07001061 */
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001062
1063ENTRY art_quick_resolve_string
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001064 SETUP_SAVE_EVERYTHING_FRAME r1 @ save everything in case of GC
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001065 mov r1, r9 @ pass Thread::Current
1066 bl artResolveStringFromCode @ (uint32_t type_idx, Thread*)
1067 cbz r0, 1f @ If result is null, deliver the OOME.
1068 .cfi_remember_state
1069 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_R0
Christina Wadsworth56ece932016-08-22 18:16:15 -07001070 bx lr
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001071 .cfi_restore_state
10721:
1073 DELIVER_PENDING_EXCEPTION_FRAME_READY
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001074END art_quick_resolve_string
Ian Rogersb886da82011-09-23 16:27:54 -07001075
Mathieu Chartier7410f292013-11-24 13:17:35 -08001076// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001077GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -08001078
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001079// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_RESOLVED_OBJECT(_rosalloc, RosAlloc).
1080ENTRY art_quick_alloc_object_resolved_rosalloc
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001081 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001082 // r0: type/return value, r9: Thread::Current
1083 // r1, r2, r3, r12: free.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001084 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1085 // allocation stack has room.
1086 // TODO: consider using ldrd.
1087 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1088 cmp r3, r12
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001089 bhs .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001090
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001091 ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3)
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001092 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001093 // local allocation. Also does the
1094 // initialized and finalizable checks.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001095 bhs .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001096 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001097 // from the size. Since the size is
1098 // already aligned we can combine the
1099 // two shifts together.
1100 add r12, r9, r3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1101 // Subtract pointer size since ther
1102 // are no runs for 0 byte allocations
1103 // and the size is already aligned.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001104 // Load the rosalloc run (r12)
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001105 ldr r12, [r12, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001106 // Load the free list head (r3). This
1107 // will be the return val.
1108 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001109 cbz r3, .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001110 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1111 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1112 // and update the list head with the
1113 // next pointer.
1114 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1115 // Store the class pointer in the
1116 // header. This also overwrites the
1117 // next pointer. The offsets are
1118 // asserted to match.
1119#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1120#error "Class pointer needs to overwrite next pointer."
1121#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001122 POISON_HEAP_REF r0
1123 str r0, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001124 // Fence. This is "ish" not "ishst" so
1125 // that it also ensures ordering of
1126 // the class status load with respect
1127 // to later accesses to the class
1128 // object. Alternatively we could use
1129 // "ishst" if we use load-acquire for
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001130 // the object size load.
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001131 // Needs to be done before pushing on
1132 // allocation since Heap::VisitObjects
1133 // relies on seeing the class pointer.
1134 // b/28790624
1135 dmb ish
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001136 // Push the new object onto the thread
1137 // local allocation stack and
1138 // increment the thread local
1139 // allocation stack top.
1140 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1141 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1142 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1143 // Decrement the size of the free list
1144 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1145 sub r1, #1
1146 // TODO: consider combining this store
1147 // and the list head store above using
1148 // strd.
1149 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001150
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001151 mov r0, r3 // Set the return value and return.
1152 bx lr
1153
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001154.Lart_quick_alloc_object_resolved_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001155 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001156 mov r1, r9 @ pass Thread::Current
1157 bl artAllocObjectFromCodeResolvedRosAlloc @ (mirror::Class* cls, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001158 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001159 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001160END art_quick_alloc_object_resolved_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001161
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001162// The common fast path code for art_quick_alloc_object_resolved_tlab
1163// and art_quick_alloc_object_resolved_region_tlab.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001164//
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001165// r0: type r9: Thread::Current, r1, r2, r3, r12: free.
1166// Need to preserve r0 to the slow path.
1167.macro ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH slowPathLabel
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001168 // Load thread_local_pos (r12) and
1169 // thread_local_end (r3) with ldrd.
1170 // Check constraints for ldrd.
1171#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1172#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1173#endif
1174 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1175 sub r12, r3, r12 // Compute the remaining buf size.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001176 ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3).
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001177 cmp r3, r12 // Check if it fits.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001178 bhi \slowPathLabel
1179 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001180 // Reload old thread_local_pos (r0)
1181 // for the return value.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001182 ldr r2, [r9, #THREAD_LOCAL_POS_OFFSET]
1183 add r1, r2, r3
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001184 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1185 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1186 add r1, r1, #1
1187 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001188 POISON_HEAP_REF r0
1189 str r0, [r2, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001190 // Fence. This is "ish" not "ishst" so
1191 // that the code after this allocation
1192 // site will see the right values in
1193 // the fields of the class.
1194 // Alternatively we could use "ishst"
1195 // if we use load-acquire for the
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001196 // object size load.)
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001197 mov r0, r2
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001198 dmb ish
1199 bx lr
1200.endm
1201
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001202// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_RESOLVED_OBJECT(_tlab, TLAB).
1203ENTRY art_quick_alloc_object_resolved_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001204 // Fast path tlab allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001205 // r0: type, r9: Thread::Current
1206 // r1, r2, r3, r12: free.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001207#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001208 mvn r0, #0 // Read barrier not supported here.
1209 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001210#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001211 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lart_quick_alloc_object_resolved_tlab_slow_path
1212.Lart_quick_alloc_object_resolved_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001213 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001214 mov r1, r9 // Pass Thread::Current.
1215 bl artAllocObjectFromCodeResolvedTLAB // (mirror::Class* klass, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001216 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001217 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001218END art_quick_alloc_object_resolved_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001219
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001220// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1221ENTRY art_quick_alloc_object_resolved_region_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001222 // Fast path tlab allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001223 // r0: type, r9: Thread::Current, r1, r2, r3, r12: free.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001224#if !defined(USE_READ_BARRIER)
1225 eor r0, r0, r0 // Read barrier must be enabled here.
1226 sub r0, r0, #1 // Return -1.
1227 bx lr
1228#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001229 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lart_quick_alloc_object_resolved_region_tlab_slow_path
1230.Lart_quick_alloc_object_resolved_region_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001231 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001232 mov r1, r9 // Pass Thread::Current.
1233 bl artAllocObjectFromCodeResolvedRegionTLAB // (mirror::Class* klass, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001234 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001235 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001236END art_quick_alloc_object_resolved_region_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001237
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001238 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001239 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001240 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001241 .extern artTestSuspendFromCode
1242ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001243#ifdef ARM_R4_SUSPEND_FLAG
Vladimir Marko952dbb12016-07-28 12:01:51 +01001244 ldrh rSUSPEND, [rSELF, #THREAD_FLAGS_OFFSET]
1245 cbnz rSUSPEND, 1f @ check Thread::Current()->suspend_count_ == 0
1246 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1247 bx lr @ return if suspend_count_ == 0
Ian Rogers637859c2013-08-27 14:35:54 -070012481:
Vladimir Marko952dbb12016-07-28 12:01:51 +01001249 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Wei Jin04f4d8a2014-05-29 18:04:29 -07001250#endif
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001251 SETUP_SAVE_EVERYTHING_FRAME r0 @ save everything for GC stack crawl
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001252 mov r0, rSELF
Vladimir Marko952dbb12016-07-28 12:01:51 +01001253 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001254 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001255 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001256END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001257
Dave Allison83252962014-04-03 16:33:48 -07001258ENTRY art_quick_implicit_suspend
1259 mov r0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001260 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001261 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001262 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001263END art_quick_implicit_suspend
1264
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001265 /*
1266 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001267 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1268 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001269 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001270 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001271ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001272 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001273 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001274 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001275 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001276 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001277 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001278 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1279 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1280 RESTORE_SAVE_REFS_ONLY_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001281 cbnz r2, 1f @ success if no exception is pending
1282 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001283 bx lr @ return on success
12841:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001285 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001286END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001287
Jeff Hao88474b42013-10-23 16:24:40 -07001288 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001289 * Called to resolve an imt conflict.
1290 * r0 is the conflict ArtMethod.
1291 * r12 is a hidden argument that holds the target interface method's dex method index.
1292 *
1293 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001294 */
1295ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001296 ldr r4, [sp, #0] // Load referrer
1297 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1298 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1299 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1300 ldr r4, [r0] // Load first entry in ImtConflictTable.
1301.Limt_table_iterate:
1302 cmp r4, r12
1303 // Branch if found. Benchmarks have shown doing a branch here is better.
1304 beq .Limt_table_found
1305 // If the entry is null, the interface method is not in the ImtConflictTable.
1306 cbz r4, .Lconflict_trampoline
1307 // Iterate over the entries of the ImtConflictTable.
1308 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1309 b .Limt_table_iterate
1310.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001311 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001312 // and jump to it.
1313 ldr r0, [r0, #__SIZEOF_POINTER__]
1314 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1315.Lconflict_trampoline:
1316 // Call the runtime stub to populate the ImtConflictTable and jump to the
1317 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001318 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001319END art_quick_imt_conflict_trampoline
1320
Ian Rogers468532e2013-08-05 10:56:33 -07001321 .extern artQuickResolutionTrampoline
1322ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001323 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001324 mov r2, r9 @ pass Thread::Current
1325 mov r3, sp @ pass SP
1326 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001327 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001328 mov r12, r0
1329 ldr r0, [sp, #0] @ load resolved method in r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001330 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001331 bx r12 @ tail-call into actual code
13321:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001333 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001334 DELIVER_PENDING_EXCEPTION
1335END art_quick_resolution_trampoline
1336
Andreas Gampec200a4a2014-06-16 18:39:09 -07001337 /*
1338 * Called to do a generic JNI down-call
1339 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001340ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001341 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001342
1343 // Save rSELF
1344 mov r11, rSELF
1345 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1346 mov r10, sp
1347 .cfi_def_cfa_register r10
1348
1349 sub sp, sp, #5120
1350
1351 // prepare for artQuickGenericJniTrampoline call
1352 // (Thread*, SP)
1353 // r0 r1 <= C calling convention
1354 // rSELF r10 <= where they are
1355
1356 mov r0, rSELF // Thread*
1357 mov r1, r10
1358 blx artQuickGenericJniTrampoline // (Thread*, sp)
1359
1360 // The C call will have registered the complete save-frame on success.
1361 // The result of the call is:
1362 // r0: pointer to native code, 0 on error.
1363 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1364
1365 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001366 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001367
1368 // Release part of the alloca.
1369 mov sp, r1
1370
1371 // Save the code pointer
1372 mov r12, r0
1373
1374 // Load parameters from frame into registers.
1375 pop {r0-r3}
1376
1377 // Softfloat.
1378 // TODO: Change to hardfloat when supported.
1379
1380 blx r12 // native call.
1381
1382 // result sign extension is handled in C code
1383 // prepare for artQuickGenericJniEndTrampoline call
1384 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001385 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001386 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001387 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001388
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001389 push {r0-r1}
1390 mov r3, r1
1391 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001392 mov r0, r11
1393
1394 blx artQuickGenericJniEndTrampoline
1395
Andreas Gampec200a4a2014-06-16 18:39:09 -07001396 // Restore self pointer.
1397 mov r9, r11
1398
1399 // Pending exceptions possible.
1400 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1401 cbnz r2, .Lexception_in_native
1402
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001403 // Tear down the alloca.
1404 mov sp, r10
1405 .cfi_def_cfa_register sp
1406
Zheng Xu5667fdb2014-10-23 18:29:55 +08001407 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001408 add sp, #FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
1409 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY)
1410 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001411
Zheng Xu5667fdb2014-10-23 18:29:55 +08001412 // store into fpr, for when it's a fpr return...
1413 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001414 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001415 // Undo the unwinding information from above since it doesn't apply below.
1416 .cfi_def_cfa_register r10
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001417 .cfi_adjust_cfa_offset FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
Andreas Gampec200a4a2014-06-16 18:39:09 -07001418
Andreas Gampec200a4a2014-06-16 18:39:09 -07001419.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001420 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1421 .cfi_def_cfa_register sp
1422 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001423 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001424END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001425
Ian Rogers468532e2013-08-05 10:56:33 -07001426 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001427ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001428 SETUP_SAVE_REFS_AND_ARGS_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001429 mov r1, r9 @ pass Thread::Current
1430 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001431 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001432 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001433 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001434 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1435 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1436 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001437 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001438 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1439 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014401:
Ian Rogers7db619b2013-01-16 18:35:48 -08001441 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001442END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001443
jeffhaoe343b762011-12-05 16:36:44 -08001444 /*
jeffhao0791adc2012-04-04 11:14:32 -07001445 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001446 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001447 .extern artInstrumentationMethodEntryFromCode
1448 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001449ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001450 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001451 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
1452 @ preserve r0 (not normally an arg) knowing there is a spare slot in kSaveRefsAndArgs.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001453 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001454 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001455 mov r3, lr @ pass LR
1456 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001457 mov r12, r0 @ r12 holds reference to code
1458 ldr r0, [sp, #4] @ restore r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001459 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001460 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001461@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001462 .type art_quick_instrumentation_exit, #function
1463 .global art_quick_instrumentation_exit
1464art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001465 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001466 SETUP_SAVE_REFS_ONLY_FRAME r2 @ set up frame knowing r2 and r3 must be dead on exit
Ian Rogers306057f2012-11-26 12:45:53 -08001467 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001468 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001469 .cfi_adjust_cfa_offset 8
1470 .cfi_rel_offset r0, 0
1471 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001472 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001473 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001474 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1475 @ need to align by 16.
1476 .cfi_adjust_cfa_offset 8
1477 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001478 mov r2, r0 @ pass return value as gpr_res
1479 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001480 mov r0, r9 @ pass Thread::Current
1481 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001482 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001483 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001484 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001485
Ian Rogers306057f2012-11-26 12:45:53 -08001486 mov r2, r0 @ link register saved by instrumentation
1487 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001488 vpop {d0} @ restore fp return value
1489 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001490 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001491 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001492 .cfi_restore r0
1493 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001494 add sp, #32 @ remove callee save frame
1495 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001496 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001497END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001498
Ian Rogers306057f2012-11-26 12:45:53 -08001499 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001500 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1501 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001502 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001503 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001504ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001505 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001506 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001507 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001508END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001509
Ian Rogers324e1902012-09-09 12:17:52 -07001510 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001511 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001512 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001513 */
1514 .extern artDeoptimizeFromCompiledCode
1515ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001516 SETUP_SAVE_EVERYTHING_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001517 mov r0, r9 @ Set up args.
1518 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1519END art_quick_deoptimize_from_compiled_code
1520
1521 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001522 * Signed 64-bit integer multiply.
1523 *
1524 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1525 * WX
1526 * x YZ
1527 * --------
1528 * ZW ZX
1529 * YW YX
1530 *
1531 * The low word of the result holds ZX, the high word holds
1532 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1533 * it doesn't fit in the low 64 bits.
1534 *
1535 * Unlike most ARM math operations, multiply instructions have
1536 * restrictions on using the same register more than once (Rd and Rm
1537 * cannot be the same).
1538 */
1539 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001540ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001541 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001542 .cfi_adjust_cfa_offset 8
1543 .cfi_rel_offset r9, 0
1544 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001545 mul ip, r2, r1 @ ip<- ZxW
1546 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1547 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1548 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1549 mov r0,r9
1550 mov r1,r10
1551 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001552 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001553 .cfi_restore r9
1554 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001555 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001556END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001557
buzbee54330722011-08-23 16:46:55 -07001558 /*
1559 * Long integer shift. This is different from the generic 32/64-bit
1560 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1561 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1562 * 6 bits.
1563 * On entry:
1564 * r0: low word
1565 * r1: high word
1566 * r2: shift count
1567 */
1568 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001569ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001570 and r2, r2, #63 @ r2<- r2 & 0x3f
1571 mov r1, r1, asl r2 @ r1<- r1 << r2
1572 rsb r3, r2, #32 @ r3<- 32 - r2
1573 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1574 subs ip, r2, #32 @ ip<- r2 - 32
1575 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1576 mov r0, r0, asl r2 @ r0<- r0 << r2
1577 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001578END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001579
buzbee54330722011-08-23 16:46:55 -07001580 /*
1581 * Long integer shift. This is different from the generic 32/64-bit
1582 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1583 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1584 * 6 bits.
1585 * On entry:
1586 * r0: low word
1587 * r1: high word
1588 * r2: shift count
1589 */
1590 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001591ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001592 and r2, r2, #63 @ r0<- r0 & 0x3f
1593 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1594 rsb r3, r2, #32 @ r3<- 32 - r2
1595 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1596 subs ip, r2, #32 @ ip<- r2 - 32
1597 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1598 mov r1, r1, asr r2 @ r1<- r1 >> r2
1599 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001600END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001601
buzbee54330722011-08-23 16:46:55 -07001602 /*
1603 * Long integer shift. This is different from the generic 32/64-bit
1604 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1605 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1606 * 6 bits.
1607 * On entry:
1608 * r0: low word
1609 * r1: high word
1610 * r2: shift count
1611 */
1612 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001613ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001614 and r2, r2, #63 @ r0<- r0 & 0x3f
1615 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1616 rsb r3, r2, #32 @ r3<- 32 - r2
1617 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1618 subs ip, r2, #32 @ ip<- r2 - 32
1619 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1620 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1621 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001622END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001623
buzbeefc9e6fa2012-03-23 15:14:29 -07001624 /*
1625 * String's indexOf.
1626 *
1627 * On entry:
1628 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001629 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001630 * r2: Starting offset in string data
1631 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001632ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001633 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001634 .cfi_adjust_cfa_offset 16
1635 .cfi_rel_offset r4, 0
1636 .cfi_rel_offset r10, 4
1637 .cfi_rel_offset r11, 8
1638 .cfi_rel_offset lr, 12
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001639#if (STRING_COMPRESSION_FEATURE)
1640 ldr r4, [r0, #MIRROR_STRING_COUNT_OFFSET]
1641#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001642 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001643#endif
Jeff Hao848f70a2014-01-15 13:49:50 -08001644 add r0, #MIRROR_STRING_VALUE_OFFSET
jessicahandojo05765752016-09-09 19:01:32 -07001645#if (STRING_COMPRESSION_FEATURE)
1646 /* r4 count (with flag) and r3 holds actual length */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001647 lsr r3, r4, #1
jessicahandojo05765752016-09-09 19:01:32 -07001648#endif
buzbeefc9e6fa2012-03-23 15:14:29 -07001649 /* Clamp start to [0..count] */
1650 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001651 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001652 movlt r2, #0
1653 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001654 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001655 movgt r2, r3
1656
buzbeefc9e6fa2012-03-23 15:14:29 -07001657 /* Save a copy in r12 to later compute result */
1658 mov r12, r0
1659
1660 /* Build pointer to start of data to compare and pre-bias */
jessicahandojo05765752016-09-09 19:01:32 -07001661#if (STRING_COMPRESSION_FEATURE)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001662 lsrs r4, r4, #1
1663 bcc .Lstring_indexof_compressed
jessicahandojo05765752016-09-09 19:01:32 -07001664#endif
buzbeefc9e6fa2012-03-23 15:14:29 -07001665 add r0, r0, r2, lsl #1
1666 sub r0, #2
1667
1668 /* Compute iteration count */
1669 sub r2, r3, r2
1670
1671 /*
1672 * At this point we have:
1673 * r0: start of data to test
1674 * r1: char to compare
1675 * r2: iteration count
jessicahandojo05765752016-09-09 19:01:32 -07001676 * r4: compression style (used temporarily)
buzbeefc9e6fa2012-03-23 15:14:29 -07001677 * r12: original start of string data
1678 * r3, r4, r10, r11 available for loading string data
1679 */
1680
1681 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001682 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001683
Ian Rogers5d885c82014-02-21 20:06:23 -08001684.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001685 ldrh r3, [r0, #2]!
1686 ldrh r4, [r0, #2]!
1687 ldrh r10, [r0, #2]!
1688 ldrh r11, [r0, #2]!
1689 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001690 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001691 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001692 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001693 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001694 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001695 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001696 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001697 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001698 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001699
Ian Rogers5d885c82014-02-21 20:06:23 -08001700.Lindexof_remainder:
1701 adds r2, #4
1702 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001703
Ian Rogers5d885c82014-02-21 20:06:23 -08001704.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001705 ldrh r3, [r0, #2]!
1706 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001707 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001708 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001709 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001710
Ian Rogers5d885c82014-02-21 20:06:23 -08001711.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001712 mov r0, #-1
1713 pop {r4, r10-r11, pc}
1714
Ian Rogers5d885c82014-02-21 20:06:23 -08001715.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001716 sub r0, #6
1717 sub r0, r12
1718 asr r0, r0, #1
1719 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001720.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001721 sub r0, #4
1722 sub r0, r12
1723 asr r0, r0, #1
1724 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001725.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001726 sub r0, #2
1727 sub r0, r12
1728 asr r0, r0, #1
1729 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001730.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001731 sub r0, r12
1732 asr r0, r0, #1
1733 pop {r4, r10-r11, pc}
jessicahandojo05765752016-09-09 19:01:32 -07001734#if (STRING_COMPRESSION_FEATURE)
1735.Lstring_indexof_compressed:
1736 add r0, r0, r2
1737 sub r0, #1
1738 sub r2, r3, r2
1739.Lstring_indexof_compressed_loop:
1740 subs r2, #1
1741 blt .Lindexof_nomatch
1742 ldrb r3, [r0, #1]!
1743 cmp r3, r1
1744 beq .Lstring_indexof_compressed_matched
1745 b .Lstring_indexof_compressed_loop
1746.Lstring_indexof_compressed_matched:
1747 sub r0, r12
1748 pop {r4, r10-r11, pc}
1749#endif
Ian Rogers9329bbb2013-02-08 19:56:30 -08001750END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001751
Zheng Xu5667fdb2014-10-23 18:29:55 +08001752 /* Assembly routines used to handle ABI differences. */
1753
1754 /* double fmod(double a, double b) */
1755 .extern fmod
1756ENTRY art_quick_fmod
1757 push {lr}
1758 .cfi_adjust_cfa_offset 4
1759 .cfi_rel_offset lr, 0
1760 sub sp, #4
1761 .cfi_adjust_cfa_offset 4
1762 vmov r0, r1, d0
1763 vmov r2, r3, d1
1764 bl fmod
1765 vmov d0, r0, r1
1766 add sp, #4
1767 .cfi_adjust_cfa_offset -4
1768 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001769END art_quick_fmod
1770
1771 /* float fmodf(float a, float b) */
1772 .extern fmodf
1773ENTRY art_quick_fmodf
1774 push {lr}
1775 .cfi_adjust_cfa_offset 4
1776 .cfi_rel_offset lr, 0
1777 sub sp, #4
1778 .cfi_adjust_cfa_offset 4
1779 vmov r0, r1, d0
1780 bl fmodf
1781 vmov s0, r0
1782 add sp, #4
1783 .cfi_adjust_cfa_offset -4
1784 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001785END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001786
1787 /* int64_t art_d2l(double d) */
1788 .extern art_d2l
1789ENTRY art_quick_d2l
1790 vmov r0, r1, d0
1791 b art_d2l
1792END art_quick_d2l
1793
1794 /* int64_t art_f2l(float f) */
1795 .extern art_f2l
1796ENTRY art_quick_f2l
1797 vmov r0, s0
1798 b art_f2l
1799END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001800
1801 /* float art_l2f(int64_t l) */
1802 .extern art_l2f
1803ENTRY art_quick_l2f
1804 push {lr}
1805 .cfi_adjust_cfa_offset 4
1806 .cfi_rel_offset lr, 0
1807 sub sp, #4
1808 .cfi_adjust_cfa_offset 4
1809 bl art_l2f
1810 vmov s0, r0
1811 add sp, #4
1812 .cfi_adjust_cfa_offset -4
1813 pop {pc}
1814END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001815
Mathieu Chartier36c22712016-08-12 13:19:44 -07001816.macro CONDITIONAL_CBZ reg, reg_if, dest
1817.ifc \reg, \reg_if
1818 cbz \reg, \dest
1819.endif
1820.endm
1821
1822.macro CONDITIONAL_CMPBZ reg, reg_if, dest
1823.ifc \reg, \reg_if
1824 cmp \reg, #0
1825 beq \dest
1826.endif
1827.endm
1828
1829// Use CBZ if the register is in {r0, r7} otherwise compare and branch.
1830.macro SMART_CBZ reg, dest
1831 CONDITIONAL_CBZ \reg, r0, \dest
1832 CONDITIONAL_CBZ \reg, r1, \dest
1833 CONDITIONAL_CBZ \reg, r2, \dest
1834 CONDITIONAL_CBZ \reg, r3, \dest
1835 CONDITIONAL_CBZ \reg, r4, \dest
1836 CONDITIONAL_CBZ \reg, r5, \dest
1837 CONDITIONAL_CBZ \reg, r6, \dest
1838 CONDITIONAL_CBZ \reg, r7, \dest
1839 CONDITIONAL_CMPBZ \reg, r8, \dest
1840 CONDITIONAL_CMPBZ \reg, r9, \dest
1841 CONDITIONAL_CMPBZ \reg, r10, \dest
1842 CONDITIONAL_CMPBZ \reg, r11, \dest
1843 CONDITIONAL_CMPBZ \reg, r12, \dest
1844 CONDITIONAL_CMPBZ \reg, r13, \dest
1845 CONDITIONAL_CMPBZ \reg, r14, \dest
1846 CONDITIONAL_CMPBZ \reg, r15, \dest
1847.endm
1848
Roland Levillain02b75802016-07-13 11:54:35 +01001849 /*
1850 * Create a function `name` calling the ReadBarrier::Mark routine,
1851 * getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001852 * `reg`, saving and restoring all caller-save registers.
1853 *
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001854 * IP is clobbered; `reg` must not be IP.
1855 *
Roland Levillain4359e612016-07-20 11:32:19 +01001856 * If `reg` is different from `r0`, the generated function follows a
1857 * non-standard runtime calling convention:
1858 * - register `reg` is used to pass the (sole) argument of this
1859 * function (instead of R0);
1860 * - register `reg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001861 * (instead of R0);
Roland Levillain02b75802016-07-13 11:54:35 +01001862 * - R0 is treated like a normal (non-argument) caller-save register;
1863 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001864 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001865 */
1866.macro READ_BARRIER_MARK_REG name, reg
1867ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001868 // Null check so that we can load the lock word.
Mathieu Chartier36c22712016-08-12 13:19:44 -07001869 SMART_CBZ \reg, .Lret_rb_\name
1870 // Check lock word for mark bit, if marked return. Use IP for scratch since it is blocked.
1871 ldr ip, [\reg, MIRROR_OBJECT_LOCK_WORD_OFFSET]
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001872 tst ip, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001873 beq .Lnot_marked_rb_\name
Mathieu Chartier36c22712016-08-12 13:19:44 -07001874 // Already marked, return right away.
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001875.Lret_rb_\name:
Mathieu Chartier36c22712016-08-12 13:19:44 -07001876 bx lr
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001877
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001878.Lnot_marked_rb_\name:
1879 // Test that both the forwarding state bits are 1.
1880 mvn ip, ip
1881 tst ip, #(LOCK_WORD_STATE_FORWARDING_ADDRESS << LOCK_WORD_STATE_SHIFT)
1882 beq .Lret_forwarding_address\name
1883
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001884.Lslow_rb_\name:
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001885 // Save IP: the kSaveEverything entrypoint art_quick_resolve_string makes a tail call here.
1886 push {r0-r4, r9, ip, lr} @ save return address, core caller-save registers and ip
Roland Levillain4359e612016-07-20 11:32:19 +01001887 .cfi_adjust_cfa_offset 32
1888 .cfi_rel_offset r0, 0
1889 .cfi_rel_offset r1, 4
1890 .cfi_rel_offset r2, 8
1891 .cfi_rel_offset r3, 12
1892 .cfi_rel_offset r4, 16
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001893 .cfi_rel_offset r9, 20
1894 .cfi_rel_offset ip, 24
Roland Levillain4359e612016-07-20 11:32:19 +01001895 .cfi_rel_offset lr, 28
Roland Levillain4359e612016-07-20 11:32:19 +01001896
1897 .ifnc \reg, r0
1898 mov r0, \reg @ pass arg1 - obj from `reg`
1899 .endif
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001900
1901 vpush {s0-s15} @ save floating-point caller-save registers
1902 .cfi_adjust_cfa_offset 64
Roland Levillain4359e612016-07-20 11:32:19 +01001903 bl artReadBarrierMark @ r0 <- artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01001904 vpop {s0-s15} @ restore floating-point registers
1905 .cfi_adjust_cfa_offset -64
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001906
1907 .ifc \reg, r0 @ Save result to the stack slot or destination register.
1908 str r0, [sp, #0]
1909 .else
1910 .ifc \reg, r1
1911 str r0, [sp, #4]
1912 .else
1913 .ifc \reg, r2
1914 str r0, [sp, #8]
1915 .else
1916 .ifc \reg, r3
1917 str r0, [sp, #12]
1918 .else
1919 .ifc \reg, r4
1920 str r0, [sp, #16]
1921 .else
1922 .ifc \reg, r9
1923 str r0, [sp, #20]
1924 .else
1925 mov \reg, r0
1926 .endif
1927 .endif
1928 .endif
1929 .endif
1930 .endif
1931 .endif
1932
1933 pop {r0-r4, r9, ip, lr} @ restore caller-save registers
1934 .cfi_adjust_cfa_offset -32
1935 .cfi_restore r0
1936 .cfi_restore r1
1937 .cfi_restore r2
1938 .cfi_restore r3
1939 .cfi_restore r4
1940 .cfi_restore r9
1941 .cfi_restore ip
1942 .cfi_restore lr
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001943 bx lr
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001944.Lret_forwarding_address\name:
1945 // Shift left by the forwarding address shift. This clears out the state bits since they are
1946 // in the top 2 bits of the lock word.
1947 mvn ip, ip
1948 lsl \reg, ip, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
1949 bx lr
Roland Levillain02b75802016-07-13 11:54:35 +01001950END \name
1951.endm
1952
Roland Levillain4359e612016-07-20 11:32:19 +01001953READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, r0
Roland Levillain02b75802016-07-13 11:54:35 +01001954READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1955READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1956READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1957READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1958READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1959READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1960READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1961READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1962READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1963READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1964READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11
Orion Hodsonac141392017-01-13 11:53:47 +00001965
1966.extern artInvokePolymorphic
1967ENTRY art_quick_invoke_polymorphic
1968 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
1969 mov r2, r9 @ pass Thread::Current
1970 mov r3, sp @ pass SP
1971 mov r0, #0 @ initialize 64-bit JValue as zero.
1972 str r0, [sp, #-4]!
1973 .cfi_adjust_cfa_offset 4
1974 str r0, [sp, #-4]!
1975 .cfi_adjust_cfa_offset 4
1976 mov r0, sp @ pass JValue for return result as first argument.
1977 bl artInvokePolymorphic @ artInvokePolymorphic(JValue, receiver, Thread*, SP)
1978 sub r0, 'A' @ return value is descriptor of handle's return type.
1979 cmp r0, 'Z' - 'A' @ check if value is in bounds of handler table
1980 bgt .Lcleanup_and_return @ and clean-up if not.
1981 adr r1, .Lhandler_table
1982 tbb [r0, r1] @ branch to handler for return value based on return type.
1983
1984.Lstart_of_handlers:
1985.Lstore_boolean_result:
1986 ldrb r0, [sp] @ Copy boolean value to return value of this function.
1987 b .Lcleanup_and_return
1988.Lstore_char_result:
1989 ldrh r0, [sp] @ Copy char value to return value of this function.
1990 b .Lcleanup_and_return
1991.Lstore_float_result:
1992 vldr s0, [sp] @ Copy float value from JValue result to the context restored by
1993 vstr s0, [sp, #16] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
1994 b .Lcleanup_and_return
1995.Lstore_double_result:
1996 vldr d0, [sp] @ Copy double value from JValue result to the context restored by
1997 vstr d0, [sp, #16] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
1998 b .Lcleanup_and_return
1999.Lstore_long_result:
2000 ldr r1, [sp, #4] @ Copy the upper bits from JValue result to the context restored by
2001 str r1, [sp, #80] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
2002 // Fall-through for lower bits.
2003.Lstore_int_result:
2004 ldr r0, [sp] @ Copy int value to return value of this function.
2005 // Fall-through to clean up and return.
2006.Lcleanup_and_return:
2007 add sp, #8
2008 .cfi_adjust_cfa_offset -8
2009 RESTORE_SAVE_REFS_AND_ARGS_FRAME
2010 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r2
2011
2012.macro HANDLER_TABLE_OFFSET handler_label
2013 .byte (\handler_label - .Lstart_of_handlers) / 2
2014.endm
2015
2016.Lhandler_table:
2017 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // A
2018 HANDLER_TABLE_OFFSET(.Lstore_int_result) // B (byte)
2019 HANDLER_TABLE_OFFSET(.Lstore_char_result) // C (char)
2020 HANDLER_TABLE_OFFSET(.Lstore_double_result) // D (double)
2021 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // E
2022 HANDLER_TABLE_OFFSET(.Lstore_float_result) // F (float)
2023 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // G
2024 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // H
2025 HANDLER_TABLE_OFFSET(.Lstore_int_result) // I (int)
2026 HANDLER_TABLE_OFFSET(.Lstore_long_result) // J (long)
2027 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // K
2028 HANDLER_TABLE_OFFSET(.Lstore_int_result) // L (object)
2029 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // M
2030 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // N
2031 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // O
2032 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // P
2033 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Q
2034 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // R
2035 HANDLER_TABLE_OFFSET(.Lstore_int_result) // S (short)
2036 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // T
2037 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // U
2038 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // V (void)
2039 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // W
2040 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // X
2041 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Y
2042 HANDLER_TABLE_OFFSET(.Lstore_boolean_result) // Z (boolean)
2043.purgem HANDLER_TABLE_OFFSET
2044END art_quick_invoke_polymorphic