blob: ed3643612060a120be3cb01190b84a548af86980 [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
Ian Rogersce9eca62011-10-07 17:11:03 -07001029
Ian Rogersce9eca62011-10-07 17:11:03 -07001030 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001031 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -07001032 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001033THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1034THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1035THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1036THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1037
Ian Rogers1bddec32012-02-04 12:27:34 -08001038 /*
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001039 * Called by managed code to resolve an instance field and store a wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001040 */
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001041 .extern artSet64InstanceFromCompiledCode
Ian Rogers468532e2013-08-05 10:56:33 -07001042ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001043 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001044 @ r2:r3 contain the wide argument
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001045 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
1046 .cfi_adjust_cfa_offset 16
1047 bl artSet64InstanceFromCompiledCode @ (field_idx, Object*, new_val, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -08001048 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -08001049 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001050 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -07001051 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -08001052 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001053END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001054
Nicolas Geoffraya72859d2017-01-26 22:47:27 +00001055 .extern artSet64StaticFromCompiledCode
1056ENTRY art_quick_set64_static
1057 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
1058 @ r2:r3 contain the wide argument
1059 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
1060 .cfi_adjust_cfa_offset 16
1061 bl artSet64StaticFromCompiledCode @ (field_idx, new_val, Thread*)
1062 add sp, #16 @ release out args
1063 .cfi_adjust_cfa_offset -16
1064 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
1065 RETURN_IF_RESULT_IS_ZERO
1066 DELIVER_PENDING_EXCEPTION
1067END art_quick_set64_static
1068
Ian Rogers1bddec32012-02-04 12:27:34 -08001069 /*
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001070 * Entry from managed code to resolve a string, this stub will
1071 * check the dex cache for a matching string (the fast path), and if not found,
1072 * it will allocate a String and deliver an exception on error.
1073 * On success the String is returned. R0 holds the string index.
Brian Carlstromaded5f72011-10-07 17:15:04 -07001074 */
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001075
1076ENTRY art_quick_resolve_string
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001077 SETUP_SAVE_EVERYTHING_FRAME r1 @ save everything in case of GC
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001078 mov r1, r9 @ pass Thread::Current
1079 bl artResolveStringFromCode @ (uint32_t type_idx, Thread*)
1080 cbz r0, 1f @ If result is null, deliver the OOME.
1081 .cfi_remember_state
1082 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_R0
Christina Wadsworth56ece932016-08-22 18:16:15 -07001083 bx lr
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001084 .cfi_restore_state
10851:
1086 DELIVER_PENDING_EXCEPTION_FRAME_READY
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001087END art_quick_resolve_string
Ian Rogersb886da82011-09-23 16:27:54 -07001088
Mathieu Chartier7410f292013-11-24 13:17:35 -08001089// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001090GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -08001091
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001092// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_RESOLVED_OBJECT(_rosalloc, RosAlloc).
1093ENTRY art_quick_alloc_object_resolved_rosalloc
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001094 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001095 // r0: type/return value, r9: Thread::Current
1096 // r1, r2, r3, r12: free.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001097 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1098 // allocation stack has room.
1099 // TODO: consider using ldrd.
1100 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1101 cmp r3, r12
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001102 bhs .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001103
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001104 ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3)
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001105 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001106 // local allocation. Also does the
1107 // initialized and finalizable checks.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001108 bhs .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001109 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001110 // from the size. Since the size is
1111 // already aligned we can combine the
1112 // two shifts together.
1113 add r12, r9, r3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1114 // Subtract pointer size since ther
1115 // are no runs for 0 byte allocations
1116 // and the size is already aligned.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001117 // Load the rosalloc run (r12)
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001118 ldr r12, [r12, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001119 // Load the free list head (r3). This
1120 // will be the return val.
1121 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001122 cbz r3, .Lart_quick_alloc_object_resolved_rosalloc_slow_path
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001123 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1124 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1125 // and update the list head with the
1126 // next pointer.
1127 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1128 // Store the class pointer in the
1129 // header. This also overwrites the
1130 // next pointer. The offsets are
1131 // asserted to match.
1132#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1133#error "Class pointer needs to overwrite next pointer."
1134#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001135 POISON_HEAP_REF r0
1136 str r0, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001137 // Fence. This is "ish" not "ishst" so
1138 // that it also ensures ordering of
1139 // the class status load with respect
1140 // to later accesses to the class
1141 // object. Alternatively we could use
1142 // "ishst" if we use load-acquire for
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001143 // the object size load.
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001144 // Needs to be done before pushing on
1145 // allocation since Heap::VisitObjects
1146 // relies on seeing the class pointer.
1147 // b/28790624
1148 dmb ish
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001149 // Push the new object onto the thread
1150 // local allocation stack and
1151 // increment the thread local
1152 // allocation stack top.
1153 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1154 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1155 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1156 // Decrement the size of the free list
1157 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1158 sub r1, #1
1159 // TODO: consider combining this store
1160 // and the list head store above using
1161 // strd.
1162 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001163
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001164 mov r0, r3 // Set the return value and return.
1165 bx lr
1166
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001167.Lart_quick_alloc_object_resolved_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001168 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001169 mov r1, r9 @ pass Thread::Current
1170 bl artAllocObjectFromCodeResolvedRosAlloc @ (mirror::Class* cls, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001171 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001172 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001173END art_quick_alloc_object_resolved_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001174
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001175// The common fast path code for art_quick_alloc_object_resolved_tlab
1176// and art_quick_alloc_object_resolved_region_tlab.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001177//
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001178// r0: type r9: Thread::Current, r1, r2, r3, r12: free.
1179// Need to preserve r0 to the slow path.
1180.macro ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH slowPathLabel
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001181 // Load thread_local_pos (r12) and
1182 // thread_local_end (r3) with ldrd.
1183 // Check constraints for ldrd.
1184#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1185#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1186#endif
1187 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1188 sub r12, r3, r12 // Compute the remaining buf size.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001189 ldr r3, [r0, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3).
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001190 cmp r3, r12 // Check if it fits.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001191 bhi \slowPathLabel
1192 // "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 -08001193 // Reload old thread_local_pos (r0)
1194 // for the return value.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001195 ldr r2, [r9, #THREAD_LOCAL_POS_OFFSET]
1196 add r1, r2, r3
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001197 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1198 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1199 add r1, r1, #1
1200 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001201 POISON_HEAP_REF r0
1202 str r0, [r2, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001203 // Fence. This is "ish" not "ishst" so
1204 // that the code after this allocation
1205 // site will see the right values in
1206 // the fields of the class.
1207 // Alternatively we could use "ishst"
1208 // if we use load-acquire for the
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001209 // object size load.)
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001210 mov r0, r2
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001211 dmb ish
1212 bx lr
1213.endm
1214
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001215// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_RESOLVED_OBJECT(_tlab, TLAB).
1216ENTRY art_quick_alloc_object_resolved_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001217 // Fast path tlab allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001218 // r0: type, r9: Thread::Current
1219 // r1, r2, r3, r12: free.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001220#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001221 mvn r0, #0 // Read barrier not supported here.
1222 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001223#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001224 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lart_quick_alloc_object_resolved_tlab_slow_path
1225.Lart_quick_alloc_object_resolved_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001226 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001227 mov r1, r9 // Pass Thread::Current.
1228 bl artAllocObjectFromCodeResolvedTLAB // (mirror::Class* klass, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001229 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001230 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001231END art_quick_alloc_object_resolved_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001232
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001233// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1234ENTRY art_quick_alloc_object_resolved_region_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001235 // Fast path tlab allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001236 // r0: type, r9: Thread::Current, r1, r2, r3, r12: free.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001237#if !defined(USE_READ_BARRIER)
1238 eor r0, r0, r0 // Read barrier must be enabled here.
1239 sub r0, r0, #1 // Return -1.
1240 bx lr
1241#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001242 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lart_quick_alloc_object_resolved_region_tlab_slow_path
1243.Lart_quick_alloc_object_resolved_region_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001244 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001245 mov r1, r9 // Pass Thread::Current.
1246 bl artAllocObjectFromCodeResolvedRegionTLAB // (mirror::Class* klass, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001247 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001248 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001249END art_quick_alloc_object_resolved_region_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001250
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001251 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001252 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001253 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001254 .extern artTestSuspendFromCode
1255ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001256#ifdef ARM_R4_SUSPEND_FLAG
Vladimir Marko952dbb12016-07-28 12:01:51 +01001257 ldrh rSUSPEND, [rSELF, #THREAD_FLAGS_OFFSET]
1258 cbnz rSUSPEND, 1f @ check Thread::Current()->suspend_count_ == 0
1259 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1260 bx lr @ return if suspend_count_ == 0
Ian Rogers637859c2013-08-27 14:35:54 -070012611:
Vladimir Marko952dbb12016-07-28 12:01:51 +01001262 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Wei Jin04f4d8a2014-05-29 18:04:29 -07001263#endif
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001264 SETUP_SAVE_EVERYTHING_FRAME r0 @ save everything for GC stack crawl
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001265 mov r0, rSELF
Vladimir Marko952dbb12016-07-28 12:01:51 +01001266 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001267 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001268 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001269END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001270
Dave Allison83252962014-04-03 16:33:48 -07001271ENTRY art_quick_implicit_suspend
1272 mov r0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001273 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001274 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001275 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001276END art_quick_implicit_suspend
1277
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001278 /*
1279 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001280 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1281 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001282 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001283 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001284ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001285 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001286 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001287 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001288 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001289 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001290 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001291 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1292 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1293 RESTORE_SAVE_REFS_ONLY_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001294 cbnz r2, 1f @ success if no exception is pending
1295 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001296 bx lr @ return on success
12971:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001298 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001299END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001300
Jeff Hao88474b42013-10-23 16:24:40 -07001301 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001302 * Called to resolve an imt conflict.
1303 * r0 is the conflict ArtMethod.
1304 * r12 is a hidden argument that holds the target interface method's dex method index.
1305 *
1306 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001307 */
1308ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001309 ldr r4, [sp, #0] // Load referrer
1310 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1311 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1312 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1313 ldr r4, [r0] // Load first entry in ImtConflictTable.
1314.Limt_table_iterate:
1315 cmp r4, r12
1316 // Branch if found. Benchmarks have shown doing a branch here is better.
1317 beq .Limt_table_found
1318 // If the entry is null, the interface method is not in the ImtConflictTable.
1319 cbz r4, .Lconflict_trampoline
1320 // Iterate over the entries of the ImtConflictTable.
1321 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1322 b .Limt_table_iterate
1323.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001324 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001325 // and jump to it.
1326 ldr r0, [r0, #__SIZEOF_POINTER__]
1327 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1328.Lconflict_trampoline:
1329 // Call the runtime stub to populate the ImtConflictTable and jump to the
1330 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001331 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001332END art_quick_imt_conflict_trampoline
1333
Ian Rogers468532e2013-08-05 10:56:33 -07001334 .extern artQuickResolutionTrampoline
1335ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001336 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001337 mov r2, r9 @ pass Thread::Current
1338 mov r3, sp @ pass SP
1339 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001340 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001341 mov r12, r0
1342 ldr r0, [sp, #0] @ load resolved method in r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001343 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001344 bx r12 @ tail-call into actual code
13451:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001346 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001347 DELIVER_PENDING_EXCEPTION
1348END art_quick_resolution_trampoline
1349
Andreas Gampec200a4a2014-06-16 18:39:09 -07001350 /*
1351 * Called to do a generic JNI down-call
1352 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001353ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001354 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001355
1356 // Save rSELF
1357 mov r11, rSELF
1358 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1359 mov r10, sp
1360 .cfi_def_cfa_register r10
1361
1362 sub sp, sp, #5120
1363
1364 // prepare for artQuickGenericJniTrampoline call
1365 // (Thread*, SP)
1366 // r0 r1 <= C calling convention
1367 // rSELF r10 <= where they are
1368
1369 mov r0, rSELF // Thread*
1370 mov r1, r10
1371 blx artQuickGenericJniTrampoline // (Thread*, sp)
1372
1373 // The C call will have registered the complete save-frame on success.
1374 // The result of the call is:
1375 // r0: pointer to native code, 0 on error.
1376 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1377
1378 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001379 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001380
1381 // Release part of the alloca.
1382 mov sp, r1
1383
1384 // Save the code pointer
1385 mov r12, r0
1386
1387 // Load parameters from frame into registers.
1388 pop {r0-r3}
1389
1390 // Softfloat.
1391 // TODO: Change to hardfloat when supported.
1392
1393 blx r12 // native call.
1394
1395 // result sign extension is handled in C code
1396 // prepare for artQuickGenericJniEndTrampoline call
1397 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001398 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001399 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001400 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001401
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001402 push {r0-r1}
1403 mov r3, r1
1404 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001405 mov r0, r11
1406
1407 blx artQuickGenericJniEndTrampoline
1408
Andreas Gampec200a4a2014-06-16 18:39:09 -07001409 // Restore self pointer.
1410 mov r9, r11
1411
1412 // Pending exceptions possible.
1413 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1414 cbnz r2, .Lexception_in_native
1415
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001416 // Tear down the alloca.
1417 mov sp, r10
1418 .cfi_def_cfa_register sp
1419
Zheng Xu5667fdb2014-10-23 18:29:55 +08001420 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001421 add sp, #FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
1422 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY)
1423 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001424
Zheng Xu5667fdb2014-10-23 18:29:55 +08001425 // store into fpr, for when it's a fpr return...
1426 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001427 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001428 // Undo the unwinding information from above since it doesn't apply below.
1429 .cfi_def_cfa_register r10
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001430 .cfi_adjust_cfa_offset FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
Andreas Gampec200a4a2014-06-16 18:39:09 -07001431
Andreas Gampec200a4a2014-06-16 18:39:09 -07001432.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001433 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1434 .cfi_def_cfa_register sp
1435 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001436 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001437END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001438
Ian Rogers468532e2013-08-05 10:56:33 -07001439 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001440ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001441 SETUP_SAVE_REFS_AND_ARGS_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001442 mov r1, r9 @ pass Thread::Current
1443 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001444 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001445 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001446 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001447 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1448 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1449 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001450 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001451 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1452 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014531:
Ian Rogers7db619b2013-01-16 18:35:48 -08001454 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001455END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001456
jeffhaoe343b762011-12-05 16:36:44 -08001457 /*
jeffhao0791adc2012-04-04 11:14:32 -07001458 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001459 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001460 .extern artInstrumentationMethodEntryFromCode
1461 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001462ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001463 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001464 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
1465 @ preserve r0 (not normally an arg) knowing there is a spare slot in kSaveRefsAndArgs.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001466 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001467 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001468 mov r3, lr @ pass LR
1469 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001470 mov r12, r0 @ r12 holds reference to code
1471 ldr r0, [sp, #4] @ restore r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001472 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001473 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001474@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001475 .type art_quick_instrumentation_exit, #function
1476 .global art_quick_instrumentation_exit
1477art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001478 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001479 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 -08001480 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001481 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001482 .cfi_adjust_cfa_offset 8
1483 .cfi_rel_offset r0, 0
1484 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001485 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001486 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001487 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1488 @ need to align by 16.
1489 .cfi_adjust_cfa_offset 8
1490 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001491 mov r2, r0 @ pass return value as gpr_res
1492 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001493 mov r0, r9 @ pass Thread::Current
1494 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001495 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001496 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001497 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001498
Ian Rogers306057f2012-11-26 12:45:53 -08001499 mov r2, r0 @ link register saved by instrumentation
1500 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001501 vpop {d0} @ restore fp return value
1502 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001503 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001504 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001505 .cfi_restore r0
1506 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001507 add sp, #32 @ remove callee save frame
1508 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001509 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001510END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001511
Ian Rogers306057f2012-11-26 12:45:53 -08001512 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001513 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1514 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001515 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001516 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001517ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001518 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001519 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001520 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001521END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001522
Ian Rogers324e1902012-09-09 12:17:52 -07001523 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001524 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001525 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001526 */
1527 .extern artDeoptimizeFromCompiledCode
1528ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001529 SETUP_SAVE_EVERYTHING_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001530 mov r0, r9 @ Set up args.
1531 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1532END art_quick_deoptimize_from_compiled_code
1533
1534 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001535 * Signed 64-bit integer multiply.
1536 *
1537 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1538 * WX
1539 * x YZ
1540 * --------
1541 * ZW ZX
1542 * YW YX
1543 *
1544 * The low word of the result holds ZX, the high word holds
1545 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1546 * it doesn't fit in the low 64 bits.
1547 *
1548 * Unlike most ARM math operations, multiply instructions have
1549 * restrictions on using the same register more than once (Rd and Rm
1550 * cannot be the same).
1551 */
1552 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001553ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001554 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001555 .cfi_adjust_cfa_offset 8
1556 .cfi_rel_offset r9, 0
1557 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001558 mul ip, r2, r1 @ ip<- ZxW
1559 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1560 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1561 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1562 mov r0,r9
1563 mov r1,r10
1564 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001565 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001566 .cfi_restore r9
1567 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001568 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001569END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001570
buzbee54330722011-08-23 16:46:55 -07001571 /*
1572 * Long integer shift. This is different from the generic 32/64-bit
1573 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1574 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1575 * 6 bits.
1576 * On entry:
1577 * r0: low word
1578 * r1: high word
1579 * r2: shift count
1580 */
1581 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001582ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001583 and r2, r2, #63 @ r2<- r2 & 0x3f
1584 mov r1, r1, asl r2 @ r1<- r1 << r2
1585 rsb r3, r2, #32 @ r3<- 32 - r2
1586 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1587 subs ip, r2, #32 @ ip<- r2 - 32
1588 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1589 mov r0, r0, asl r2 @ r0<- r0 << r2
1590 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001591END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001592
buzbee54330722011-08-23 16:46:55 -07001593 /*
1594 * Long integer shift. This is different from the generic 32/64-bit
1595 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1596 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1597 * 6 bits.
1598 * On entry:
1599 * r0: low word
1600 * r1: high word
1601 * r2: shift count
1602 */
1603 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001604ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001605 and r2, r2, #63 @ r0<- r0 & 0x3f
1606 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1607 rsb r3, r2, #32 @ r3<- 32 - r2
1608 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1609 subs ip, r2, #32 @ ip<- r2 - 32
1610 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1611 mov r1, r1, asr r2 @ r1<- r1 >> r2
1612 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001613END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001614
buzbee54330722011-08-23 16:46:55 -07001615 /*
1616 * Long integer shift. This is different from the generic 32/64-bit
1617 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1618 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1619 * 6 bits.
1620 * On entry:
1621 * r0: low word
1622 * r1: high word
1623 * r2: shift count
1624 */
1625 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001626ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001627 and r2, r2, #63 @ r0<- r0 & 0x3f
1628 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1629 rsb r3, r2, #32 @ r3<- 32 - r2
1630 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1631 subs ip, r2, #32 @ ip<- r2 - 32
1632 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1633 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1634 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001635END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001636
buzbeefc9e6fa2012-03-23 15:14:29 -07001637 /*
1638 * String's indexOf.
1639 *
1640 * On entry:
1641 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001642 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001643 * r2: Starting offset in string data
1644 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001645ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001646 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001647 .cfi_adjust_cfa_offset 16
1648 .cfi_rel_offset r4, 0
1649 .cfi_rel_offset r10, 4
1650 .cfi_rel_offset r11, 8
1651 .cfi_rel_offset lr, 12
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001652#if (STRING_COMPRESSION_FEATURE)
1653 ldr r4, [r0, #MIRROR_STRING_COUNT_OFFSET]
1654#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001655 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001656#endif
Jeff Hao848f70a2014-01-15 13:49:50 -08001657 add r0, #MIRROR_STRING_VALUE_OFFSET
jessicahandojo05765752016-09-09 19:01:32 -07001658#if (STRING_COMPRESSION_FEATURE)
1659 /* r4 count (with flag) and r3 holds actual length */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001660 lsr r3, r4, #1
jessicahandojo05765752016-09-09 19:01:32 -07001661#endif
buzbeefc9e6fa2012-03-23 15:14:29 -07001662 /* Clamp start to [0..count] */
1663 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001664 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001665 movlt r2, #0
1666 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001667 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001668 movgt r2, r3
1669
buzbeefc9e6fa2012-03-23 15:14:29 -07001670 /* Save a copy in r12 to later compute result */
1671 mov r12, r0
1672
1673 /* Build pointer to start of data to compare and pre-bias */
jessicahandojo05765752016-09-09 19:01:32 -07001674#if (STRING_COMPRESSION_FEATURE)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001675 lsrs r4, r4, #1
1676 bcc .Lstring_indexof_compressed
jessicahandojo05765752016-09-09 19:01:32 -07001677#endif
buzbeefc9e6fa2012-03-23 15:14:29 -07001678 add r0, r0, r2, lsl #1
1679 sub r0, #2
1680
1681 /* Compute iteration count */
1682 sub r2, r3, r2
1683
1684 /*
1685 * At this point we have:
1686 * r0: start of data to test
1687 * r1: char to compare
1688 * r2: iteration count
jessicahandojo05765752016-09-09 19:01:32 -07001689 * r4: compression style (used temporarily)
buzbeefc9e6fa2012-03-23 15:14:29 -07001690 * r12: original start of string data
1691 * r3, r4, r10, r11 available for loading string data
1692 */
1693
1694 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001695 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001696
Ian Rogers5d885c82014-02-21 20:06:23 -08001697.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001698 ldrh r3, [r0, #2]!
1699 ldrh r4, [r0, #2]!
1700 ldrh r10, [r0, #2]!
1701 ldrh r11, [r0, #2]!
1702 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001703 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001704 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001705 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001706 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001707 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001708 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001709 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001710 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001711 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001712
Ian Rogers5d885c82014-02-21 20:06:23 -08001713.Lindexof_remainder:
1714 adds r2, #4
1715 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001716
Ian Rogers5d885c82014-02-21 20:06:23 -08001717.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001718 ldrh r3, [r0, #2]!
1719 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001720 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001721 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001722 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001723
Ian Rogers5d885c82014-02-21 20:06:23 -08001724.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001725 mov r0, #-1
1726 pop {r4, r10-r11, pc}
1727
Ian Rogers5d885c82014-02-21 20:06:23 -08001728.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001729 sub r0, #6
1730 sub r0, r12
1731 asr r0, r0, #1
1732 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001733.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001734 sub r0, #4
1735 sub r0, r12
1736 asr r0, r0, #1
1737 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001738.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001739 sub r0, #2
1740 sub r0, r12
1741 asr r0, r0, #1
1742 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001743.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001744 sub r0, r12
1745 asr r0, r0, #1
1746 pop {r4, r10-r11, pc}
jessicahandojo05765752016-09-09 19:01:32 -07001747#if (STRING_COMPRESSION_FEATURE)
1748.Lstring_indexof_compressed:
1749 add r0, r0, r2
1750 sub r0, #1
1751 sub r2, r3, r2
1752.Lstring_indexof_compressed_loop:
1753 subs r2, #1
1754 blt .Lindexof_nomatch
1755 ldrb r3, [r0, #1]!
1756 cmp r3, r1
1757 beq .Lstring_indexof_compressed_matched
1758 b .Lstring_indexof_compressed_loop
1759.Lstring_indexof_compressed_matched:
1760 sub r0, r12
1761 pop {r4, r10-r11, pc}
1762#endif
Ian Rogers9329bbb2013-02-08 19:56:30 -08001763END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001764
Zheng Xu5667fdb2014-10-23 18:29:55 +08001765 /* Assembly routines used to handle ABI differences. */
1766
1767 /* double fmod(double a, double b) */
1768 .extern fmod
1769ENTRY art_quick_fmod
1770 push {lr}
1771 .cfi_adjust_cfa_offset 4
1772 .cfi_rel_offset lr, 0
1773 sub sp, #4
1774 .cfi_adjust_cfa_offset 4
1775 vmov r0, r1, d0
1776 vmov r2, r3, d1
1777 bl fmod
1778 vmov d0, r0, r1
1779 add sp, #4
1780 .cfi_adjust_cfa_offset -4
1781 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001782END art_quick_fmod
1783
1784 /* float fmodf(float a, float b) */
1785 .extern fmodf
1786ENTRY art_quick_fmodf
1787 push {lr}
1788 .cfi_adjust_cfa_offset 4
1789 .cfi_rel_offset lr, 0
1790 sub sp, #4
1791 .cfi_adjust_cfa_offset 4
1792 vmov r0, r1, d0
1793 bl fmodf
1794 vmov s0, r0
1795 add sp, #4
1796 .cfi_adjust_cfa_offset -4
1797 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001798END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001799
1800 /* int64_t art_d2l(double d) */
1801 .extern art_d2l
1802ENTRY art_quick_d2l
1803 vmov r0, r1, d0
1804 b art_d2l
1805END art_quick_d2l
1806
1807 /* int64_t art_f2l(float f) */
1808 .extern art_f2l
1809ENTRY art_quick_f2l
1810 vmov r0, s0
1811 b art_f2l
1812END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001813
1814 /* float art_l2f(int64_t l) */
1815 .extern art_l2f
1816ENTRY art_quick_l2f
1817 push {lr}
1818 .cfi_adjust_cfa_offset 4
1819 .cfi_rel_offset lr, 0
1820 sub sp, #4
1821 .cfi_adjust_cfa_offset 4
1822 bl art_l2f
1823 vmov s0, r0
1824 add sp, #4
1825 .cfi_adjust_cfa_offset -4
1826 pop {pc}
1827END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001828
Mathieu Chartier36c22712016-08-12 13:19:44 -07001829.macro CONDITIONAL_CBZ reg, reg_if, dest
1830.ifc \reg, \reg_if
1831 cbz \reg, \dest
1832.endif
1833.endm
1834
1835.macro CONDITIONAL_CMPBZ reg, reg_if, dest
1836.ifc \reg, \reg_if
1837 cmp \reg, #0
1838 beq \dest
1839.endif
1840.endm
1841
1842// Use CBZ if the register is in {r0, r7} otherwise compare and branch.
1843.macro SMART_CBZ reg, dest
1844 CONDITIONAL_CBZ \reg, r0, \dest
1845 CONDITIONAL_CBZ \reg, r1, \dest
1846 CONDITIONAL_CBZ \reg, r2, \dest
1847 CONDITIONAL_CBZ \reg, r3, \dest
1848 CONDITIONAL_CBZ \reg, r4, \dest
1849 CONDITIONAL_CBZ \reg, r5, \dest
1850 CONDITIONAL_CBZ \reg, r6, \dest
1851 CONDITIONAL_CBZ \reg, r7, \dest
1852 CONDITIONAL_CMPBZ \reg, r8, \dest
1853 CONDITIONAL_CMPBZ \reg, r9, \dest
1854 CONDITIONAL_CMPBZ \reg, r10, \dest
1855 CONDITIONAL_CMPBZ \reg, r11, \dest
1856 CONDITIONAL_CMPBZ \reg, r12, \dest
1857 CONDITIONAL_CMPBZ \reg, r13, \dest
1858 CONDITIONAL_CMPBZ \reg, r14, \dest
1859 CONDITIONAL_CMPBZ \reg, r15, \dest
1860.endm
1861
Roland Levillain02b75802016-07-13 11:54:35 +01001862 /*
1863 * Create a function `name` calling the ReadBarrier::Mark routine,
1864 * getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001865 * `reg`, saving and restoring all caller-save registers.
1866 *
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001867 * IP is clobbered; `reg` must not be IP.
1868 *
Roland Levillain4359e612016-07-20 11:32:19 +01001869 * If `reg` is different from `r0`, the generated function follows a
1870 * non-standard runtime calling convention:
1871 * - register `reg` is used to pass the (sole) argument of this
1872 * function (instead of R0);
1873 * - register `reg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001874 * (instead of R0);
Roland Levillain02b75802016-07-13 11:54:35 +01001875 * - R0 is treated like a normal (non-argument) caller-save register;
1876 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001877 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001878 */
1879.macro READ_BARRIER_MARK_REG name, reg
1880ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001881 // Null check so that we can load the lock word.
Mathieu Chartier36c22712016-08-12 13:19:44 -07001882 SMART_CBZ \reg, .Lret_rb_\name
1883 // Check lock word for mark bit, if marked return. Use IP for scratch since it is blocked.
1884 ldr ip, [\reg, MIRROR_OBJECT_LOCK_WORD_OFFSET]
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001885 tst ip, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001886 beq .Lnot_marked_rb_\name
Mathieu Chartier36c22712016-08-12 13:19:44 -07001887 // Already marked, return right away.
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001888.Lret_rb_\name:
Mathieu Chartier36c22712016-08-12 13:19:44 -07001889 bx lr
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001890
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001891.Lnot_marked_rb_\name:
1892 // Test that both the forwarding state bits are 1.
1893 mvn ip, ip
1894 tst ip, #(LOCK_WORD_STATE_FORWARDING_ADDRESS << LOCK_WORD_STATE_SHIFT)
1895 beq .Lret_forwarding_address\name
1896
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001897.Lslow_rb_\name:
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001898 // Save IP: the kSaveEverything entrypoint art_quick_resolve_string makes a tail call here.
1899 push {r0-r4, r9, ip, lr} @ save return address, core caller-save registers and ip
Roland Levillain4359e612016-07-20 11:32:19 +01001900 .cfi_adjust_cfa_offset 32
1901 .cfi_rel_offset r0, 0
1902 .cfi_rel_offset r1, 4
1903 .cfi_rel_offset r2, 8
1904 .cfi_rel_offset r3, 12
1905 .cfi_rel_offset r4, 16
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001906 .cfi_rel_offset r9, 20
1907 .cfi_rel_offset ip, 24
Roland Levillain4359e612016-07-20 11:32:19 +01001908 .cfi_rel_offset lr, 28
Roland Levillain4359e612016-07-20 11:32:19 +01001909
1910 .ifnc \reg, r0
1911 mov r0, \reg @ pass arg1 - obj from `reg`
1912 .endif
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001913
1914 vpush {s0-s15} @ save floating-point caller-save registers
1915 .cfi_adjust_cfa_offset 64
Roland Levillain4359e612016-07-20 11:32:19 +01001916 bl artReadBarrierMark @ r0 <- artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01001917 vpop {s0-s15} @ restore floating-point registers
1918 .cfi_adjust_cfa_offset -64
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001919
1920 .ifc \reg, r0 @ Save result to the stack slot or destination register.
1921 str r0, [sp, #0]
1922 .else
1923 .ifc \reg, r1
1924 str r0, [sp, #4]
1925 .else
1926 .ifc \reg, r2
1927 str r0, [sp, #8]
1928 .else
1929 .ifc \reg, r3
1930 str r0, [sp, #12]
1931 .else
1932 .ifc \reg, r4
1933 str r0, [sp, #16]
1934 .else
1935 .ifc \reg, r9
1936 str r0, [sp, #20]
1937 .else
1938 mov \reg, r0
1939 .endif
1940 .endif
1941 .endif
1942 .endif
1943 .endif
1944 .endif
1945
1946 pop {r0-r4, r9, ip, lr} @ restore caller-save registers
1947 .cfi_adjust_cfa_offset -32
1948 .cfi_restore r0
1949 .cfi_restore r1
1950 .cfi_restore r2
1951 .cfi_restore r3
1952 .cfi_restore r4
1953 .cfi_restore r9
1954 .cfi_restore ip
1955 .cfi_restore lr
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001956 bx lr
Mathieu Chartier6f198e32016-11-03 11:15:04 -07001957.Lret_forwarding_address\name:
1958 // Shift left by the forwarding address shift. This clears out the state bits since they are
1959 // in the top 2 bits of the lock word.
1960 mvn ip, ip
1961 lsl \reg, ip, #LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
1962 bx lr
Roland Levillain02b75802016-07-13 11:54:35 +01001963END \name
1964.endm
1965
Roland Levillain4359e612016-07-20 11:32:19 +01001966READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, r0
Roland Levillain02b75802016-07-13 11:54:35 +01001967READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1968READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1969READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1970READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1971READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1972READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1973READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1974READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1975READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1976READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1977READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11
Orion Hodsonac141392017-01-13 11:53:47 +00001978
1979.extern artInvokePolymorphic
1980ENTRY art_quick_invoke_polymorphic
1981 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
1982 mov r2, r9 @ pass Thread::Current
1983 mov r3, sp @ pass SP
1984 mov r0, #0 @ initialize 64-bit JValue as zero.
1985 str r0, [sp, #-4]!
1986 .cfi_adjust_cfa_offset 4
1987 str r0, [sp, #-4]!
1988 .cfi_adjust_cfa_offset 4
1989 mov r0, sp @ pass JValue for return result as first argument.
1990 bl artInvokePolymorphic @ artInvokePolymorphic(JValue, receiver, Thread*, SP)
1991 sub r0, 'A' @ return value is descriptor of handle's return type.
1992 cmp r0, 'Z' - 'A' @ check if value is in bounds of handler table
1993 bgt .Lcleanup_and_return @ and clean-up if not.
1994 adr r1, .Lhandler_table
1995 tbb [r0, r1] @ branch to handler for return value based on return type.
1996
1997.Lstart_of_handlers:
1998.Lstore_boolean_result:
1999 ldrb r0, [sp] @ Copy boolean value to return value of this function.
2000 b .Lcleanup_and_return
2001.Lstore_char_result:
2002 ldrh r0, [sp] @ Copy char value to return value of this function.
2003 b .Lcleanup_and_return
2004.Lstore_float_result:
2005 vldr s0, [sp] @ Copy float value from JValue result to the context restored by
2006 vstr s0, [sp, #16] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
2007 b .Lcleanup_and_return
2008.Lstore_double_result:
2009 vldr d0, [sp] @ Copy double value from JValue result to the context restored by
2010 vstr d0, [sp, #16] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
2011 b .Lcleanup_and_return
2012.Lstore_long_result:
2013 ldr r1, [sp, #4] @ Copy the upper bits from JValue result to the context restored by
2014 str r1, [sp, #80] @ RESTORE_SAVE_REFS_AND_ARGS_FRAME.
2015 // Fall-through for lower bits.
2016.Lstore_int_result:
2017 ldr r0, [sp] @ Copy int value to return value of this function.
2018 // Fall-through to clean up and return.
2019.Lcleanup_and_return:
2020 add sp, #8
2021 .cfi_adjust_cfa_offset -8
2022 RESTORE_SAVE_REFS_AND_ARGS_FRAME
2023 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r2
2024
2025.macro HANDLER_TABLE_OFFSET handler_label
2026 .byte (\handler_label - .Lstart_of_handlers) / 2
2027.endm
2028
2029.Lhandler_table:
2030 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // A
2031 HANDLER_TABLE_OFFSET(.Lstore_int_result) // B (byte)
2032 HANDLER_TABLE_OFFSET(.Lstore_char_result) // C (char)
2033 HANDLER_TABLE_OFFSET(.Lstore_double_result) // D (double)
2034 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // E
2035 HANDLER_TABLE_OFFSET(.Lstore_float_result) // F (float)
2036 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // G
2037 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // H
2038 HANDLER_TABLE_OFFSET(.Lstore_int_result) // I (int)
2039 HANDLER_TABLE_OFFSET(.Lstore_long_result) // J (long)
2040 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // K
2041 HANDLER_TABLE_OFFSET(.Lstore_int_result) // L (object)
2042 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // M
2043 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // N
2044 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // O
2045 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // P
2046 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Q
2047 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // R
2048 HANDLER_TABLE_OFFSET(.Lstore_int_result) // S (short)
2049 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // T
2050 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // U
2051 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // V (void)
2052 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // W
2053 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // X
2054 HANDLER_TABLE_OFFSET(.Lcleanup_and_return) // Y
2055 HANDLER_TABLE_OFFSET(.Lstore_boolean_result) // Z (boolean)
2056.purgem HANDLER_TABLE_OFFSET
2057END art_quick_invoke_polymorphic