blob: 3fc83ba7d1e2fc474afb11e6d2905aa0a59ef86c [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
Ian Rogers637859c2013-08-27 14:35:54 -0700242.macro RETURN_IF_RESULT_IS_ZERO
243 cbnz r0, 1f @ result non-zero branch over
244 bx lr @ return
2451:
246.endm
247
248.macro RETURN_IF_RESULT_IS_NON_ZERO
249 cbz r0, 1f @ result zero branch over
250 bx lr @ return
2511:
252.endm
253
Ian Rogersce9eca62011-10-07 17:11:03 -0700254 /*
255 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
256 * exception is Thread::Current()->exception_
257 */
258.macro DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -0800259 .fnend
260 .fnstart
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100261 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save callee saves for throw
Ian Rogersce9eca62011-10-07 17:11:03 -0700262 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700263 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700264.endm
265
Ian Rogers57b86d42012-03-27 16:05:41 -0700266.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700267 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800268ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100269 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700270 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700271 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800272END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700273.endm
buzbee44b412b2012-02-04 08:50:53 -0800274
Ian Rogers57b86d42012-03-27 16:05:41 -0700275.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700276 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800277ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100278 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r1 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700279 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700280 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800281END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700282.endm
Ian Rogers9651f422011-09-19 20:26:07 -0700283
Ian Rogers57b86d42012-03-27 16:05:41 -0700284.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700285 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800286ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100287 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700288 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700289 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800290END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700291.endm
Ian Rogersbdb03912011-09-14 00:55:44 -0700292
Fred Shih37f05ef2014-07-16 18:38:08 -0700293.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
294 ldr \reg, [r9, #THREAD_EXCEPTION_OFFSET] // Get exception field.
295 cbnz \reg, 1f
296 bx lr
2971:
298 DELIVER_PENDING_EXCEPTION
299.endm
300
301.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
302 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r1
303.endm
304
305.macro RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
306 RETURN_IF_RESULT_IS_ZERO
307 DELIVER_PENDING_EXCEPTION
308.endm
309
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800310.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
311 RETURN_IF_RESULT_IS_NON_ZERO
312 DELIVER_PENDING_EXCEPTION
313.endm
314
Fred Shih37f05ef2014-07-16 18:38:08 -0700315// Macros taking opportunity of code similarities for downcalls with referrer for non-wide fields.
316.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
317 .extern \entrypoint
318ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100319 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case of GC
320 ldr r1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700321 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700322 bl \entrypoint @ (uint32_t field_idx, const Method* referrer, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100323 RESTORE_SAVE_REFS_ONLY_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700324 \return
325END \name
326.endm
327
328.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
329 .extern \entrypoint
330ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100331 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
332 ldr r2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700333 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700334 bl \entrypoint @ (field_idx, Object*, referrer, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100335 RESTORE_SAVE_REFS_ONLY_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700336 \return
337END \name
338.endm
339
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800340.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
Fred Shih37f05ef2014-07-16 18:38:08 -0700341 .extern \entrypoint
342ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100343 SETUP_SAVE_REFS_ONLY_FRAME r3 @ save callee saves in case of GC
344 ldr r3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700345 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700346 .cfi_adjust_cfa_offset 16
347 bl \entrypoint @ (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700348 add sp, #16 @ release out args
349 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100350 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Fred Shih37f05ef2014-07-16 18:38:08 -0700351 \return
352END \name
353.endm
354
Ian Rogers57b86d42012-03-27 16:05:41 -0700355 /*
356 * Called by managed code, saves callee saves and then calls artThrowException
357 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
358 */
Ian Rogers468532e2013-08-05 10:56:33 -0700359ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Ian Rogers932746a2011-09-22 18:57:50 -0700360
Ian Rogers57b86d42012-03-27 16:05:41 -0700361 /*
362 * Called by managed code to create and deliver a NullPointerException.
363 */
Ian Rogers468532e2013-08-05 10:56:33 -0700364NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700365
Ian Rogers57b86d42012-03-27 16:05:41 -0700366 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100367 * Call installed by a signal handler to create and deliver a NullPointerException.
368 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000369 .extern art_quick_throw_null_pointer_exception_from_signal
370ENTRY art_quick_throw_null_pointer_exception_from_signal
371 // The fault handler pushes the gc map address, i.e. "return address", to stack
372 // and passes the fault address in LR. So we need to set up the CFI info accordingly.
373 .cfi_def_cfa_offset __SIZEOF_POINTER__
374 .cfi_rel_offset lr, 0
375 push {r0-r12} @ 13 words of callee saves and args; LR already saved.
376 .cfi_adjust_cfa_offset 52
377 .cfi_rel_offset r0, 0
378 .cfi_rel_offset r1, 4
379 .cfi_rel_offset r2, 8
380 .cfi_rel_offset r3, 12
381 .cfi_rel_offset r4, 16
382 .cfi_rel_offset r5, 20
383 .cfi_rel_offset r6, 24
384 .cfi_rel_offset r7, 28
385 .cfi_rel_offset r8, 32
386 .cfi_rel_offset r9, 36
387 .cfi_rel_offset r10, 40
388 .cfi_rel_offset r11, 44
389 .cfi_rel_offset ip, 48
390
391 @ save all registers as basis for long jump context
392 SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED r1
393 mov r0, lr @ pass the fault address stored in LR by the fault handler.
394 mov r1, r9 @ pass Thread::Current
395 b artThrowNullPointerExceptionFromSignal @ (Thread*)
396END art_quick_throw_null_pointer_exception_from_signal
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100397
398 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700399 * Called by managed code to create and deliver an ArithmeticException.
400 */
Ian Rogers468532e2013-08-05 10:56:33 -0700401NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700402
Ian Rogers57b86d42012-03-27 16:05:41 -0700403 /*
404 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
405 * index, arg2 holds limit.
406 */
Ian Rogers468532e2013-08-05 10:56:33 -0700407TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700408
409 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100410 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
411 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
412 */
413TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
414
415 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700416 * Called by managed code to create and deliver a StackOverflowError.
417 */
Ian Rogers468532e2013-08-05 10:56:33 -0700418NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700419
420 /*
421 * Called by managed code to create and deliver a NoSuchMethodError.
422 */
Ian Rogers468532e2013-08-05 10:56:33 -0700423ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700424
425 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800426 * All generated callsites for interface invokes and invocation slow paths will load arguments
427 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100428 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700429 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700430 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800431 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
432 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700433 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700434 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800435 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700436 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700437 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
438 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700439 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700440.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800441 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100442 SETUP_SAVE_REFS_AND_ARGS_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100443 mov r2, r9 @ pass Thread::Current
444 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700445 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700446 mov r12, r1 @ save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100447 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700448 cbz r0, 1f @ did we find the target? if not go to exception delivery
449 bx r12 @ tail call to target
4501:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800451 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700452.endm
453.macro INVOKE_TRAMPOLINE c_name, cxx_name
454ENTRY \c_name
455 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800456END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800457.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800458
Logan Chien8dbb7082013-01-25 20:31:17 +0800459INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800460
Logan Chien8dbb7082013-01-25 20:31:17 +0800461INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
462INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
463INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
464INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700465
Ian Rogers57b86d42012-03-27 16:05:41 -0700466 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800467 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700468 * On entry:
469 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700470 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700471 * r2 = size of argument array in bytes
472 * r3 = (managed) thread pointer
473 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800474 * [sp + 4] = result_in_float
475 * [sp + 8] = core register argument array
476 * [sp + 12] = fp register argument array
477 * +-------------------------+
478 * | uint32_t* fp_reg_args |
479 * | uint32_t* core_reg_args |
480 * | result_in_float | <- Caller frame
481 * | Jvalue* result |
482 * +-------------------------+
483 * | lr |
484 * | r11 |
485 * | r9 |
486 * | r4 | <- r11
487 * +-------------------------+
488 * | uint32_t out[n-1] |
489 * | : : | Outs
490 * | uint32_t out[0] |
491 * | StackRef<ArtMethod> | <- SP value=null
492 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800493 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800494ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700495 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800496 mov r11, sp @ save the stack pointer
497 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800498
Jeff Hao5d917302013-02-27 17:57:33 -0800499 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800500
501 add r4, r2, #4 @ create space for method pointer in frame
502 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
503 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
504 mov sp, r4 @ 16B alignment ourselves.
505
506 mov r4, r0 @ save method*
507 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
508 bl memcpy @ memcpy (dest, src, bytes)
509 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700510 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800511
Nicolas Geoffray48088462014-12-12 10:29:38 +0000512 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800513 vldm ip, {s0-s15} @ copy s0 - s15
514
Nicolas Geoffray48088462014-12-12 10:29:38 +0000515 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800516 mov r0, r4 @ restore method*
517 add ip, ip, #4 @ skip r0
518 ldm ip, {r1-r3} @ copy r1 - r3
519
Wei Jin04f4d8a2014-05-29 18:04:29 -0700520#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800521 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700522#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700523
Mathieu Chartiere401d142015-04-22 13:56:20 -0700524 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800525 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800526
Jeff Hao6474d192013-03-26 14:08:09 -0700527 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800528 .cfi_def_cfa_register sp
529
Nicolas Geoffray48088462014-12-12 10:29:38 +0000530 ldr r4, [sp, #40] @ load result_is_float
531 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800532 cmp r4, #0
533 ite eq
534 strdeq r0, [r9] @ store r0/r1 into result pointer
535 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
536
Nicolas Geoffray48088462014-12-12 10:29:38 +0000537 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800538END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700539
Jeff Hao5d917302013-02-27 17:57:33 -0800540 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000541 * On stack replacement stub.
542 * On entry:
543 * r0 = stack to copy
544 * r1 = size of stack
545 * r2 = pc to call
546 * r3 = JValue* result
547 * [sp] = shorty
548 * [sp + 4] = thread
549 */
550ENTRY art_quick_osr_stub
551 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
552 mov r11, sp @ Save the stack pointer
553 mov r10, r1 @ Save size of stack
554 ldr r9, [r11, #40] @ Move managed thread pointer into r9
555 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000556 sub r7, sp, #12 @ Reserve space for stack pointer,
557 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000558 and r7, #0xFFFFFFF0 @ Align stack pointer
559 mov sp, r7 @ Update stack pointer
560 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000561 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000562 mov ip, #0
563 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
564 sub sp, sp, r1 @ Reserve space for callee stack
565 mov r2, r1
566 mov r1, r0
567 mov r0, sp
568 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
569 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000570 ldr r10, [sp, #8] @ Restore JValue* result
571 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000572 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000573 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000574 cmp r4, #68 @ Test if result type char == 'D'.
575 beq .Losr_fp_result
576 cmp r4, #70 @ Test if result type char == 'F'.
577 beq .Losr_fp_result
578 strd r0, [r10] @ Store r0/r1 into result pointer
579 b .Losr_exit
580.Losr_fp_result:
581 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
582.Losr_exit:
583 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
584.Losr_entry:
585 sub r10, r10, #4
586 str lr, [sp, r10] @ Store link register per the compiler ABI
587 bx r8
588END art_quick_osr_stub
589
590 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700591 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
592 */
Ian Rogers637859c2013-08-27 14:35:54 -0700593ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700594 vldm r1, {s0-s31} @ load all fprs from argument fprs_
595 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700596 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700597 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700598 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700599 ldr r0, [r0, #-12] @ load r0 value
600 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700601 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800602END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700603
Ian Rogers60db5ab2012-02-20 17:02:00 -0800604 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700605 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
606 * failure.
607 */
Ian Rogers832336b2014-10-08 15:35:22 -0700608TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700609
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700610 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700611 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
612 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700613 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800614 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700615ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800616 cbz r0, .Lslow_lock
617.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700618 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700619 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800620 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700621 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800622 cbnz r3, .Lnot_unlocked @ already thin locked
623 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
624 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700625 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800626 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700627 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700628 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800629.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
630 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800631 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700632 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
633 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800634 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700635 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800636 mov r3, r1 @ copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700637 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800638 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 -0700639 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 -0800640 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
641 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
642 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
643 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700644 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800645.Llock_strex_fail:
646 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800647.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100648 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700649 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700650 bl artLockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100651 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700652 RETURN_IF_RESULT_IS_ZERO
653 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700654END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700655
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700656ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100657 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700658 mov r1, r9 @ pass Thread::Current
659 bl artLockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100660 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700661 RETURN_IF_RESULT_IS_ZERO
662 DELIVER_PENDING_EXCEPTION
663END art_quick_lock_object_no_inline
664
Ian Rogersff1ed472011-09-20 13:46:24 -0700665 /*
666 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700667 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700668 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800669 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700670ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800671 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800672.Lretry_unlock:
673#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700674 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800675#else
676 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
677#endif
678 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800679 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700680 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800681 mov r3, r1 @ copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700682 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800683 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700684 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800685 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800686 mov r3, r1 @ copy lock word to detect transition to unlocked
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700687 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800688 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800689 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800690 @ transition to unlocked
691 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700692 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED @ r3: zero except for the preserved gc bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700693 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800694#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700695 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800696#else
697 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
698 cbnz r2, .Lunlock_strex_fail @ store failed, retry
699#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700700 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800701.Lrecursive_thin_unlock: @ r1: original lock word
702 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
703#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700704 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800705#else
706 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
707 cbnz r2, .Lunlock_strex_fail @ store failed, retry
708#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700709 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800710.Lunlock_strex_fail:
711 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800712.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700713 @ save callee saves in case exception allocation triggers GC
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100714 SETUP_SAVE_REFS_ONLY_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700715 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700716 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100717 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700718 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700719 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700720END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700721
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700722ENTRY art_quick_unlock_object_no_inline
723 @ save callee saves in case exception allocation triggers GC
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100724 SETUP_SAVE_REFS_ONLY_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700725 mov r1, r9 @ pass Thread::Current
726 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100727 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700728 RETURN_IF_RESULT_IS_ZERO
729 DELIVER_PENDING_EXCEPTION
730END art_quick_unlock_object_no_inline
731
Ian Rogersff1ed472011-09-20 13:46:24 -0700732 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700733 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
734 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700735 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700736 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700737ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700738 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700739 .cfi_adjust_cfa_offset 12
740 .cfi_rel_offset r0, 0
741 .cfi_rel_offset r1, 4
742 .cfi_rel_offset lr, 8
743 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700744 .cfi_adjust_cfa_offset 4
745 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800746 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700747 add sp, #4
748 .cfi_adjust_cfa_offset -4
749 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700750 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800751.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700752 add sp, #4
753 .cfi_adjust_cfa_offset -4
754 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700755 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800756 .cfi_restore r0
757 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700758 .cfi_restore lr
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100759 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700760 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700761 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700762 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700763END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700764
Man Cao1aee9002015-07-14 22:31:42 -0700765// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
766.macro POP_REG_NE rReg, offset, rExclude
767 .ifnc \rReg, \rExclude
768 ldr \rReg, [sp, #\offset] @ restore rReg
769 .cfi_restore \rReg
770 .endif
771.endm
772
Roland Levillain4359e612016-07-20 11:32:19 +0100773// Save rReg's value to [sp, #offset].
774.macro PUSH_REG rReg, offset
775 str \rReg, [sp, #\offset] @ save rReg
776 .cfi_rel_offset \rReg, \offset
777.endm
778
Man Cao1aee9002015-07-14 22:31:42 -0700779 /*
780 * Macro to insert read barrier, only used in art_quick_aput_obj.
781 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
782 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
783 */
784.macro READ_BARRIER rDest, rObj, offset
785#ifdef USE_READ_BARRIER
786 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
787 .cfi_adjust_cfa_offset 24
788 .cfi_rel_offset r0, 0
789 .cfi_rel_offset r1, 4
790 .cfi_rel_offset r2, 8
791 .cfi_rel_offset r3, 12
792 .cfi_rel_offset ip, 16
793 .cfi_rel_offset lr, 20
794 sub sp, #8 @ push padding
795 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700796 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700797 .ifnc \rObj, r1
798 mov r1, \rObj @ pass rObj
799 .endif
800 mov r2, #\offset @ pass offset
801 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
802 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
803 .ifnc \rDest, r0
804 mov \rDest, r0 @ save return value in rDest
805 .endif
806 add sp, #8 @ pop padding
807 .cfi_adjust_cfa_offset -8
808 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
809 POP_REG_NE r1, 4, \rDest
810 POP_REG_NE r2, 8, \rDest
811 POP_REG_NE r3, 12, \rDest
812 POP_REG_NE ip, 16, \rDest
813 add sp, #20
814 .cfi_adjust_cfa_offset -20
815 pop {lr} @ restore lr
816 .cfi_adjust_cfa_offset -4
817 .cfi_restore lr
818#else
819 ldr \rDest, [\rObj, #\offset]
820 UNPOISON_HEAP_REF \rDest
821#endif // USE_READ_BARRIER
822.endm
823
Ian Rogerse51a5112011-09-23 14:16:35 -0700824 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700825 * Entry from managed code for array put operations of objects where the value being stored
826 * needs to be checked for compatibility.
827 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700828 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700829ENTRY art_quick_aput_obj_with_null_and_bound_check
830 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700831 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700832 b art_quick_throw_null_pointer_exception
833END art_quick_aput_obj_with_null_and_bound_check
834
Dan Albert58bea4a2014-08-09 18:08:07 -0700835 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700836ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700837 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700838 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700839 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700840 mov r0, r1
841 mov r1, r3
842 b art_quick_throw_array_bounds
843END art_quick_aput_obj_with_bound_check
844
Man Cao1aee9002015-07-14 22:31:42 -0700845#ifdef USE_READ_BARRIER
846 .extern artReadBarrierSlow
847#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700848 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700849ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700850#ifdef USE_READ_BARRIER
851 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
852 tst r2, r2
853 beq .Ldo_aput_null
854#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800855 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700856#endif // USE_READ_BARRIER
857 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
858 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
859 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700860 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800861 bne .Lcheck_assignability
862.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700863 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700864 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700865 str r2, [r3, r1, lsl #2]
866 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
867 lsr r0, r0, #7
868 strb r3, [r3, r0]
869 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800870.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700871 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700872 str r2, [r3, r1, lsl #2]
873 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800874.Lcheck_assignability:
875 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700876 .cfi_adjust_cfa_offset 16
877 .cfi_rel_offset r0, 0
878 .cfi_rel_offset r1, 4
879 .cfi_rel_offset r2, 8
880 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700881 mov r1, ip
882 mov r0, r3
883 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800884 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700885 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700886 .cfi_restore r0
887 .cfi_restore r1
888 .cfi_restore r2
889 .cfi_restore lr
890 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700891 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700892 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700893 str r2, [r3, r1, lsl #2]
894 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
895 lsr r0, r0, #7
896 strb r3, [r3, r0]
897 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800898.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700899 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700900 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100901 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700902 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700903 mov r2, r9 @ pass Thread::Current
904 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
905 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700906END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700907
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800908// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100909.macro ONE_ARG_DOWNCALL name, entrypoint, return
910 .extern \entrypoint
911ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100912 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100913 mov r1, r9 @ pass Thread::Current
914 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100915 RESTORE_SAVE_REFS_ONLY_FRAME
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100916 \return
917END \name
918.endm
919
920// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800921.macro TWO_ARG_DOWNCALL name, entrypoint, return
922 .extern \entrypoint
923ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100924 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800925 mov r2, r9 @ pass Thread::Current
926 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100927 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800928 \return
929END \name
930.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700931
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800932// Macro to facilitate adding new array allocation entrypoints.
933.macro THREE_ARG_DOWNCALL name, entrypoint, return
934 .extern \entrypoint
935ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100936 SETUP_SAVE_REFS_ONLY_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800937 mov r3, r9 @ pass Thread::Current
938 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
939 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100940 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800941 \return
942END \name
943.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700944
Jeff Hao848f70a2014-01-15 13:49:50 -0800945// Macro to facilitate adding new allocation entrypoints.
946.macro FOUR_ARG_DOWNCALL name, entrypoint, return
947 .extern \entrypoint
948ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100949 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800950 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800951 .cfi_adjust_cfa_offset 16
952 bl \entrypoint
953 add sp, #16 @ strip the extra frame
954 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100955 RESTORE_SAVE_REFS_ONLY_FRAME
Jeff Hao848f70a2014-01-15 13:49:50 -0800956 \return
957END \name
958.endm
959
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100960ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
961ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
962ONE_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 -0700963
Ian Rogersce9eca62011-10-07 17:11:03 -0700964 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700965 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700966 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700967ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
968ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
969ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
970ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
971ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
972ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700973 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700974 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700975 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800976 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700977ENTRY art_quick_get64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100978 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
979 ldr r1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700980 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700981 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700982 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100983 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700984 cbnz r2, 1f @ success if no exception pending
985 bx lr @ return on success
9861:
Ian Rogersce9eca62011-10-07 17:11:03 -0700987 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700988END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700989
Ian Rogersce9eca62011-10-07 17:11:03 -0700990 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700991 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700992 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700993TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
994TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
995TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
996TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
997TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
998TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800999 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001000 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001001 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001002 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001003ENTRY art_quick_get64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001004 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
1005 ldr r2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -08001006 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001007 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -07001008 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001009 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -07001010 cbnz r2, 1f @ success if no exception pending
1011 bx lr @ return on success
10121:
Ian Rogers1bddec32012-02-04 12:27:34 -08001013 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001014END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001015
Ian Rogers1bddec32012-02-04 12:27:34 -08001016 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001017 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001018 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001019TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1020TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1021TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1022TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -07001023 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001024 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +01001025 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -07001026 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001027 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001028ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001029 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001030 @ r2:r3 contain the wide argument
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001031 ldr r1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001032 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001033 .cfi_adjust_cfa_offset 16
1034 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -07001035 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -08001036 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001037 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -07001038 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -07001039 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001040END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -07001041
Ian Rogersce9eca62011-10-07 17:11:03 -07001042 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001043 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -07001044 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001045THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1046THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1047THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1048THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -08001049 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001050 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001051 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001052 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001053ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001054 SETUP_SAVE_REFS_ONLY_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001055 @ r2:r3 contain the wide argument
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001056 ldr r12, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] @ pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001057 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001058 .cfi_adjust_cfa_offset 12
1059 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001060 .cfi_adjust_cfa_offset 4
1061 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -08001062 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -08001063 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001064 RESTORE_SAVE_REFS_ONLY_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -07001065 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -08001066 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001067END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001068
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
1077 ldr r1, [sp] @ load referrer
1078 ldr r1, [r1, #ART_METHOD_DECLARING_CLASS_OFFSET] @ load declaring class
1079 ldr r1, [r1, #DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET] @ load string dex cache
1080 ubfx r2, r0, #0, #STRING_DEX_CACHE_HASH_BITS
1081 add r1, r1, r2, LSL #STRING_DEX_CACHE_ELEMENT_SIZE_SHIFT
1082 ldrd r2, r3, [r1] @ load index into r3 and pointer into r2
1083 cmp r0, r3
1084 bne .Lart_quick_resolve_string_slow_path
1085#ifdef USE_READ_BARRIER
Christina Wadsworth56ece932016-08-22 18:16:15 -07001086 ldr r3, [rSELF, #THREAD_IS_GC_MARKING_OFFSET]
1087 cbnz r3, .Lart_quick_resolve_string_marking
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001088#endif
1089 mov r0, r2
1090 bx lr
Christina Wadsworth56ece932016-08-22 18:16:15 -07001091// Slow path case, the index did not match
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001092.Lart_quick_resolve_string_slow_path:
Christina Wadsworth56ece932016-08-22 18:16:15 -07001093 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
1094 mov r1, r9 @ pass Thread::Current
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001095 mov r3, sp
Christina Wadsworth56ece932016-08-22 18:16:15 -07001096 bl artResolveStringFromCode @ (uint32_t type_idx, Method* method, Thread*)
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001097 RESTORE_SAVE_REFS_ONLY_FRAME
1098 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Christina Wadsworth56ece932016-08-22 18:16:15 -07001099// GC is marking case, need to check the mark bit.
1100.Lart_quick_resolve_string_marking:
1101 ldr r3, [r2, MIRROR_OBJECT_LOCK_WORD_OFFSET]
1102 tst r3, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
1103 mov r0, r2
1104 bne .Lart_quick_resolve_string_no_rb
1105 push {r1, r2, r3, lr} @ Save x1, LR
1106 .cfi_adjust_cfa_offset 16
1107 bl artReadBarrierMark @ Get the marked string back.
1108 pop {r1, r2, r3, lr} @ Restore registers.
1109 .cfi_adjust_cfa_offset -16
1110.Lart_quick_resolve_string_no_rb:
1111 bx lr
Christina Wadsworth35ef14b2016-08-19 11:24:48 -07001112END art_quick_resolve_string
Ian Rogersb886da82011-09-23 16:27:54 -07001113
Mathieu Chartier7410f292013-11-24 13:17:35 -08001114// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001115GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -08001116
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001117// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1118ENTRY art_quick_alloc_object_rosalloc
1119 // Fast path rosalloc allocation.
1120 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1121 // r2, r3, r12: free.
1122 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1123 // Load the class (r2)
1124 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1125 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001126
1127 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1128 // allocation stack has room.
1129 // TODO: consider using ldrd.
1130 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1131 cmp r3, r12
1132 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1133
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001134 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3)
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001135 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001136 // local allocation. Also does the
1137 // initialized and finalizable checks.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001138 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1139 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001140 // from the size. Since the size is
1141 // already aligned we can combine the
1142 // two shifts together.
1143 add r12, r9, r3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1144 // Subtract pointer size since ther
1145 // are no runs for 0 byte allocations
1146 // and the size is already aligned.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001147 // Load the rosalloc run (r12)
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001148 ldr r12, [r12, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001149 // Load the free list head (r3). This
1150 // will be the return val.
1151 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1152 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1153 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1154 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1155 // and update the list head with the
1156 // next pointer.
1157 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1158 // Store the class pointer in the
1159 // header. This also overwrites the
1160 // next pointer. The offsets are
1161 // asserted to match.
1162#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1163#error "Class pointer needs to overwrite next pointer."
1164#endif
1165 POISON_HEAP_REF r2
1166 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001167 // Fence. This is "ish" not "ishst" so
1168 // that it also ensures ordering of
1169 // the class status load with respect
1170 // to later accesses to the class
1171 // object. Alternatively we could use
1172 // "ishst" if we use load-acquire for
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001173 // the object size load.
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001174 // Needs to be done before pushing on
1175 // allocation since Heap::VisitObjects
1176 // relies on seeing the class pointer.
1177 // b/28790624
1178 dmb ish
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001179 // Push the new object onto the thread
1180 // local allocation stack and
1181 // increment the thread local
1182 // allocation stack top.
1183 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1184 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1185 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1186 // Decrement the size of the free list
1187 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1188 sub r1, #1
1189 // TODO: consider combining this store
1190 // and the list head store above using
1191 // strd.
1192 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001193
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001194 mov r0, r3 // Set the return value and return.
1195 bx lr
1196
1197.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001198 SETUP_SAVE_REFS_ONLY_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001199 mov r2, r9 @ pass Thread::Current
1200 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001201 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001202 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1203END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001204
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001205// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1206//
1207// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1208// Need to preserve r0 and r1 to the slow path.
1209.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1210 cbz r2, \slowPathLabel // Check null class
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001211 // Load thread_local_pos (r12) and
1212 // thread_local_end (r3) with ldrd.
1213 // Check constraints for ldrd.
1214#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1215#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1216#endif
1217 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1218 sub r12, r3, r12 // Compute the remaining buf size.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001219 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (r3).
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001220 cmp r3, r12 // Check if it fits.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001221 bhi \slowPathLabel
1222 // "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 -08001223 // Reload old thread_local_pos (r0)
1224 // for the return value.
1225 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1226 add r1, r0, r3
1227 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1228 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1229 add r1, r1, #1
1230 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1231 POISON_HEAP_REF r2
1232 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1233 // Fence. This is "ish" not "ishst" so
1234 // that the code after this allocation
1235 // site will see the right values in
1236 // the fields of the class.
1237 // Alternatively we could use "ishst"
1238 // if we use load-acquire for the
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001239 // object size load.)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001240 dmb ish
1241 bx lr
1242.endm
1243
1244// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1245ENTRY art_quick_alloc_object_tlab
1246 // Fast path tlab allocation.
1247 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1248 // r2, r3, r12: free.
1249#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001250 mvn r0, #0 // Read barrier not supported here.
1251 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001252#endif
1253 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1254 // Load the class (r2)
1255 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1256 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1257.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001258 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001259 mov r2, r9 // Pass Thread::Current.
1260 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001261 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001262 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1263END art_quick_alloc_object_tlab
1264
1265// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1266ENTRY art_quick_alloc_object_region_tlab
1267 // Fast path tlab allocation.
1268 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1269#if !defined(USE_READ_BARRIER)
1270 eor r0, r0, r0 // Read barrier must be enabled here.
1271 sub r0, r0, #1 // Return -1.
1272 bx lr
1273#endif
1274 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1275 // Load the class (r2)
1276 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1277 // Read barrier for class load.
1278 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
Mathieu Chartier36c22712016-08-12 13:19:44 -07001279 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_marking
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001280.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1281 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
Mathieu Chartier36c22712016-08-12 13:19:44 -07001282.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_marking:
1283 cbz r2, .Lart_quick_alloc_object_region_tlab_slow_path // Null check for loading lock word.
1284 // Check lock word for mark bit, if marked do the allocation.
1285 ldr r3, [r2, MIRROR_OBJECT_LOCK_WORD_OFFSET]
1286 ands r3, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
1287 bne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001288.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1289 // The read barrier slow path. Mark
1290 // the class.
1291 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1292 // to align sp by 16 bytes.
1293 mov r0, r2 // Pass the class as the first param.
1294 bl artReadBarrierMark
1295 mov r2, r0 // Get the (marked) class back.
1296 pop {r0, r1, r3, lr}
1297 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1298.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001299 SETUP_SAVE_REFS_ONLY_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001300 mov r2, r9 // Pass Thread::Current.
1301 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001302 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001303 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1304END art_quick_alloc_object_region_tlab
1305
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001306 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001307 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001308 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001309 .extern artTestSuspendFromCode
1310ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001311#ifdef ARM_R4_SUSPEND_FLAG
Vladimir Marko952dbb12016-07-28 12:01:51 +01001312 ldrh rSUSPEND, [rSELF, #THREAD_FLAGS_OFFSET]
1313 cbnz rSUSPEND, 1f @ check Thread::Current()->suspend_count_ == 0
1314 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1315 bx lr @ return if suspend_count_ == 0
Ian Rogers637859c2013-08-27 14:35:54 -070013161:
Vladimir Marko952dbb12016-07-28 12:01:51 +01001317 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Wei Jin04f4d8a2014-05-29 18:04:29 -07001318#endif
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001319 SETUP_SAVE_EVERYTHING_FRAME r0 @ save everything for GC stack crawl
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001320 mov r0, rSELF
Vladimir Marko952dbb12016-07-28 12:01:51 +01001321 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001322 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001323 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001324END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001325
Dave Allison83252962014-04-03 16:33:48 -07001326ENTRY art_quick_implicit_suspend
1327 mov r0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001328 SETUP_SAVE_REFS_ONLY_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001329 bl artTestSuspendFromCode @ (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001330 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001331END art_quick_implicit_suspend
1332
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001333 /*
1334 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001335 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1336 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001337 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001338 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001339ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001340 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001341 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001342 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001343 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001344 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001345 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001346 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1347 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1348 RESTORE_SAVE_REFS_ONLY_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001349 cbnz r2, 1f @ success if no exception is pending
1350 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001351 bx lr @ return on success
13521:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001353 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001354END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001355
Jeff Hao88474b42013-10-23 16:24:40 -07001356 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001357 * Called to resolve an imt conflict.
1358 * r0 is the conflict ArtMethod.
1359 * r12 is a hidden argument that holds the target interface method's dex method index.
1360 *
1361 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001362 */
1363ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001364 ldr r4, [sp, #0] // Load referrer
1365 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1366 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1367 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1368 ldr r4, [r0] // Load first entry in ImtConflictTable.
1369.Limt_table_iterate:
1370 cmp r4, r12
1371 // Branch if found. Benchmarks have shown doing a branch here is better.
1372 beq .Limt_table_found
1373 // If the entry is null, the interface method is not in the ImtConflictTable.
1374 cbz r4, .Lconflict_trampoline
1375 // Iterate over the entries of the ImtConflictTable.
1376 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1377 b .Limt_table_iterate
1378.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001379 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001380 // and jump to it.
1381 ldr r0, [r0, #__SIZEOF_POINTER__]
1382 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1383.Lconflict_trampoline:
1384 // Call the runtime stub to populate the ImtConflictTable and jump to the
1385 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001386 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001387END art_quick_imt_conflict_trampoline
1388
Ian Rogers468532e2013-08-05 10:56:33 -07001389 .extern artQuickResolutionTrampoline
1390ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001391 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001392 mov r2, r9 @ pass Thread::Current
1393 mov r3, sp @ pass SP
1394 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001395 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001396 mov r12, r0
1397 ldr r0, [sp, #0] @ load resolved method in r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001398 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001399 bx r12 @ tail-call into actual code
14001:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001401 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001402 DELIVER_PENDING_EXCEPTION
1403END art_quick_resolution_trampoline
1404
Andreas Gampec200a4a2014-06-16 18:39:09 -07001405 /*
1406 * Called to do a generic JNI down-call
1407 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001408ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001409 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001410
1411 // Save rSELF
1412 mov r11, rSELF
1413 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1414 mov r10, sp
1415 .cfi_def_cfa_register r10
1416
1417 sub sp, sp, #5120
1418
1419 // prepare for artQuickGenericJniTrampoline call
1420 // (Thread*, SP)
1421 // r0 r1 <= C calling convention
1422 // rSELF r10 <= where they are
1423
1424 mov r0, rSELF // Thread*
1425 mov r1, r10
1426 blx artQuickGenericJniTrampoline // (Thread*, sp)
1427
1428 // The C call will have registered the complete save-frame on success.
1429 // The result of the call is:
1430 // r0: pointer to native code, 0 on error.
1431 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1432
1433 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001434 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001435
1436 // Release part of the alloca.
1437 mov sp, r1
1438
1439 // Save the code pointer
1440 mov r12, r0
1441
1442 // Load parameters from frame into registers.
1443 pop {r0-r3}
1444
1445 // Softfloat.
1446 // TODO: Change to hardfloat when supported.
1447
1448 blx r12 // native call.
1449
1450 // result sign extension is handled in C code
1451 // prepare for artQuickGenericJniEndTrampoline call
1452 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001453 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001454 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001455 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001456
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001457 push {r0-r1}
1458 mov r3, r1
1459 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001460 mov r0, r11
1461
1462 blx artQuickGenericJniEndTrampoline
1463
Andreas Gampec200a4a2014-06-16 18:39:09 -07001464 // Restore self pointer.
1465 mov r9, r11
1466
1467 // Pending exceptions possible.
1468 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1469 cbnz r2, .Lexception_in_native
1470
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001471 // Tear down the alloca.
1472 mov sp, r10
1473 .cfi_def_cfa_register sp
1474
Zheng Xu5667fdb2014-10-23 18:29:55 +08001475 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001476 add sp, #FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
1477 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY)
1478 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001479
Zheng Xu5667fdb2014-10-23 18:29:55 +08001480 // store into fpr, for when it's a fpr return...
1481 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001482 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001483 // Undo the unwinding information from above since it doesn't apply below.
1484 .cfi_def_cfa_register r10
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001485 .cfi_adjust_cfa_offset FRAME_SIZE_SAVE_REFS_AND_ARGS-FRAME_SIZE_SAVE_REFS_ONLY
Andreas Gampec200a4a2014-06-16 18:39:09 -07001486
Andreas Gampec200a4a2014-06-16 18:39:09 -07001487.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001488 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1489 .cfi_def_cfa_register sp
1490 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001491 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001492END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001493
Ian Rogers468532e2013-08-05 10:56:33 -07001494 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001495ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001496 SETUP_SAVE_REFS_AND_ARGS_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001497 mov r1, r9 @ pass Thread::Current
1498 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001499 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001500 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001501 // Tear down the callee-save frame. Skip arg registers.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001502 add sp, #(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1503 .cfi_adjust_cfa_offset -(FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
1504 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001505 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001506 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1507 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070015081:
Ian Rogers7db619b2013-01-16 18:35:48 -08001509 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001510END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001511
jeffhaoe343b762011-12-05 16:36:44 -08001512 /*
jeffhao0791adc2012-04-04 11:14:32 -07001513 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001514 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001515 .extern artInstrumentationMethodEntryFromCode
1516 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001517ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001518 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001519 SETUP_SAVE_REFS_AND_ARGS_FRAME r2
1520 @ preserve r0 (not normally an arg) knowing there is a spare slot in kSaveRefsAndArgs.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001521 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001522 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001523 mov r3, lr @ pass LR
1524 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001525 mov r12, r0 @ r12 holds reference to code
1526 ldr r0, [sp, #4] @ restore r0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001527 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001528 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001529@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001530 .type art_quick_instrumentation_exit, #function
1531 .global art_quick_instrumentation_exit
1532art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001533 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001534 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 -08001535 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001536 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001537 .cfi_adjust_cfa_offset 8
1538 .cfi_rel_offset r0, 0
1539 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001540 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001541 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001542 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1543 @ need to align by 16.
1544 .cfi_adjust_cfa_offset 8
1545 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001546 mov r2, r0 @ pass return value as gpr_res
1547 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001548 mov r0, r9 @ pass Thread::Current
1549 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001550 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001551 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001552 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001553
Ian Rogers306057f2012-11-26 12:45:53 -08001554 mov r2, r0 @ link register saved by instrumentation
1555 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001556 vpop {d0} @ restore fp return value
1557 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001558 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001559 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001560 .cfi_restore r0
1561 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001562 add sp, #32 @ remove callee save frame
1563 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001564 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001565END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001566
Ian Rogers306057f2012-11-26 12:45:53 -08001567 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001568 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1569 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001570 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001571 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001572ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001573 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001574 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001575 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001576END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001577
Ian Rogers324e1902012-09-09 12:17:52 -07001578 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001579 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001580 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001581 */
1582 .extern artDeoptimizeFromCompiledCode
1583ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001584 SETUP_SAVE_EVERYTHING_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001585 mov r0, r9 @ Set up args.
1586 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1587END art_quick_deoptimize_from_compiled_code
1588
1589 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001590 * Signed 64-bit integer multiply.
1591 *
1592 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1593 * WX
1594 * x YZ
1595 * --------
1596 * ZW ZX
1597 * YW YX
1598 *
1599 * The low word of the result holds ZX, the high word holds
1600 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1601 * it doesn't fit in the low 64 bits.
1602 *
1603 * Unlike most ARM math operations, multiply instructions have
1604 * restrictions on using the same register more than once (Rd and Rm
1605 * cannot be the same).
1606 */
1607 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001608ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001609 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001610 .cfi_adjust_cfa_offset 8
1611 .cfi_rel_offset r9, 0
1612 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001613 mul ip, r2, r1 @ ip<- ZxW
1614 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1615 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1616 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1617 mov r0,r9
1618 mov r1,r10
1619 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001620 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001621 .cfi_restore r9
1622 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001623 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001624END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001625
buzbee54330722011-08-23 16:46:55 -07001626 /*
1627 * Long integer shift. This is different from the generic 32/64-bit
1628 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1629 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1630 * 6 bits.
1631 * On entry:
1632 * r0: low word
1633 * r1: high word
1634 * r2: shift count
1635 */
1636 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001637ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001638 and r2, r2, #63 @ r2<- r2 & 0x3f
1639 mov r1, r1, asl r2 @ r1<- r1 << r2
1640 rsb r3, r2, #32 @ r3<- 32 - r2
1641 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1642 subs ip, r2, #32 @ ip<- r2 - 32
1643 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1644 mov r0, r0, asl r2 @ r0<- r0 << r2
1645 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001646END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001647
buzbee54330722011-08-23 16:46:55 -07001648 /*
1649 * Long integer shift. This is different from the generic 32/64-bit
1650 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1651 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1652 * 6 bits.
1653 * On entry:
1654 * r0: low word
1655 * r1: high word
1656 * r2: shift count
1657 */
1658 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001659ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001660 and r2, r2, #63 @ r0<- r0 & 0x3f
1661 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1662 rsb r3, r2, #32 @ r3<- 32 - r2
1663 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1664 subs ip, r2, #32 @ ip<- r2 - 32
1665 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1666 mov r1, r1, asr r2 @ r1<- r1 >> r2
1667 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001668END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001669
buzbee54330722011-08-23 16:46:55 -07001670 /*
1671 * Long integer shift. This is different from the generic 32/64-bit
1672 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1673 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1674 * 6 bits.
1675 * On entry:
1676 * r0: low word
1677 * r1: high word
1678 * r2: shift count
1679 */
1680 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001681ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001682 and r2, r2, #63 @ r0<- r0 & 0x3f
1683 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1684 rsb r3, r2, #32 @ r3<- 32 - r2
1685 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1686 subs ip, r2, #32 @ ip<- r2 - 32
1687 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1688 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1689 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001690END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001691
buzbeefc9e6fa2012-03-23 15:14:29 -07001692 /*
1693 * String's indexOf.
1694 *
1695 * On entry:
1696 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001697 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001698 * r2: Starting offset in string data
1699 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001700ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001701 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001702 .cfi_adjust_cfa_offset 16
1703 .cfi_rel_offset r4, 0
1704 .cfi_rel_offset r10, 4
1705 .cfi_rel_offset r11, 8
1706 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001707 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001708 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001709
1710 /* Clamp start to [0..count] */
1711 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001712 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001713 movlt r2, #0
1714 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001715 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001716 movgt r2, r3
1717
buzbeefc9e6fa2012-03-23 15:14:29 -07001718 /* Save a copy in r12 to later compute result */
1719 mov r12, r0
1720
1721 /* Build pointer to start of data to compare and pre-bias */
1722 add r0, r0, r2, lsl #1
1723 sub r0, #2
1724
1725 /* Compute iteration count */
1726 sub r2, r3, r2
1727
1728 /*
1729 * At this point we have:
1730 * r0: start of data to test
1731 * r1: char to compare
1732 * r2: iteration count
1733 * r12: original start of string data
1734 * r3, r4, r10, r11 available for loading string data
1735 */
1736
1737 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001738 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001739
Ian Rogers5d885c82014-02-21 20:06:23 -08001740.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001741 ldrh r3, [r0, #2]!
1742 ldrh r4, [r0, #2]!
1743 ldrh r10, [r0, #2]!
1744 ldrh r11, [r0, #2]!
1745 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001746 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001747 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001748 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001749 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001750 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001751 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001752 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001753 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001754 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001755
Ian Rogers5d885c82014-02-21 20:06:23 -08001756.Lindexof_remainder:
1757 adds r2, #4
1758 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001759
Ian Rogers5d885c82014-02-21 20:06:23 -08001760.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001761 ldrh r3, [r0, #2]!
1762 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001763 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001764 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001765 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001766
Ian Rogers5d885c82014-02-21 20:06:23 -08001767.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001768 mov r0, #-1
1769 pop {r4, r10-r11, pc}
1770
Ian Rogers5d885c82014-02-21 20:06:23 -08001771.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001772 sub r0, #6
1773 sub r0, r12
1774 asr r0, r0, #1
1775 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001776.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001777 sub r0, #4
1778 sub r0, r12
1779 asr r0, r0, #1
1780 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001781.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001782 sub r0, #2
1783 sub r0, r12
1784 asr r0, r0, #1
1785 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001786.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001787 sub r0, r12
1788 asr r0, r0, #1
1789 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001790END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001791
Zheng Xu5667fdb2014-10-23 18:29:55 +08001792 /* Assembly routines used to handle ABI differences. */
1793
1794 /* double fmod(double a, double b) */
1795 .extern fmod
1796ENTRY art_quick_fmod
1797 push {lr}
1798 .cfi_adjust_cfa_offset 4
1799 .cfi_rel_offset lr, 0
1800 sub sp, #4
1801 .cfi_adjust_cfa_offset 4
1802 vmov r0, r1, d0
1803 vmov r2, r3, d1
1804 bl fmod
1805 vmov d0, r0, r1
1806 add sp, #4
1807 .cfi_adjust_cfa_offset -4
1808 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001809END art_quick_fmod
1810
1811 /* float fmodf(float a, float b) */
1812 .extern fmodf
1813ENTRY art_quick_fmodf
1814 push {lr}
1815 .cfi_adjust_cfa_offset 4
1816 .cfi_rel_offset lr, 0
1817 sub sp, #4
1818 .cfi_adjust_cfa_offset 4
1819 vmov r0, r1, d0
1820 bl fmodf
1821 vmov s0, r0
1822 add sp, #4
1823 .cfi_adjust_cfa_offset -4
1824 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001825END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001826
1827 /* int64_t art_d2l(double d) */
1828 .extern art_d2l
1829ENTRY art_quick_d2l
1830 vmov r0, r1, d0
1831 b art_d2l
1832END art_quick_d2l
1833
1834 /* int64_t art_f2l(float f) */
1835 .extern art_f2l
1836ENTRY art_quick_f2l
1837 vmov r0, s0
1838 b art_f2l
1839END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001840
1841 /* float art_l2f(int64_t l) */
1842 .extern art_l2f
1843ENTRY art_quick_l2f
1844 push {lr}
1845 .cfi_adjust_cfa_offset 4
1846 .cfi_rel_offset lr, 0
1847 sub sp, #4
1848 .cfi_adjust_cfa_offset 4
1849 bl art_l2f
1850 vmov s0, r0
1851 add sp, #4
1852 .cfi_adjust_cfa_offset -4
1853 pop {pc}
1854END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001855
Mathieu Chartier36c22712016-08-12 13:19:44 -07001856.macro CONDITIONAL_CBZ reg, reg_if, dest
1857.ifc \reg, \reg_if
1858 cbz \reg, \dest
1859.endif
1860.endm
1861
1862.macro CONDITIONAL_CMPBZ reg, reg_if, dest
1863.ifc \reg, \reg_if
1864 cmp \reg, #0
1865 beq \dest
1866.endif
1867.endm
1868
1869// Use CBZ if the register is in {r0, r7} otherwise compare and branch.
1870.macro SMART_CBZ reg, dest
1871 CONDITIONAL_CBZ \reg, r0, \dest
1872 CONDITIONAL_CBZ \reg, r1, \dest
1873 CONDITIONAL_CBZ \reg, r2, \dest
1874 CONDITIONAL_CBZ \reg, r3, \dest
1875 CONDITIONAL_CBZ \reg, r4, \dest
1876 CONDITIONAL_CBZ \reg, r5, \dest
1877 CONDITIONAL_CBZ \reg, r6, \dest
1878 CONDITIONAL_CBZ \reg, r7, \dest
1879 CONDITIONAL_CMPBZ \reg, r8, \dest
1880 CONDITIONAL_CMPBZ \reg, r9, \dest
1881 CONDITIONAL_CMPBZ \reg, r10, \dest
1882 CONDITIONAL_CMPBZ \reg, r11, \dest
1883 CONDITIONAL_CMPBZ \reg, r12, \dest
1884 CONDITIONAL_CMPBZ \reg, r13, \dest
1885 CONDITIONAL_CMPBZ \reg, r14, \dest
1886 CONDITIONAL_CMPBZ \reg, r15, \dest
1887.endm
1888
Roland Levillain02b75802016-07-13 11:54:35 +01001889 /*
1890 * Create a function `name` calling the ReadBarrier::Mark routine,
1891 * getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001892 * `reg`, saving and restoring all caller-save registers.
1893 *
1894 * If `reg` is different from `r0`, the generated function follows a
1895 * non-standard runtime calling convention:
1896 * - register `reg` is used to pass the (sole) argument of this
1897 * function (instead of R0);
1898 * - register `reg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001899 * (instead of R0);
Roland Levillain02b75802016-07-13 11:54:35 +01001900 * - R0 is treated like a normal (non-argument) caller-save register;
1901 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001902 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001903 */
1904.macro READ_BARRIER_MARK_REG name, reg
1905ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001906 // Null check so that we can load the lock word.
Mathieu Chartier36c22712016-08-12 13:19:44 -07001907 SMART_CBZ \reg, .Lret_rb_\name
1908 // Check lock word for mark bit, if marked return. Use IP for scratch since it is blocked.
1909 ldr ip, [\reg, MIRROR_OBJECT_LOCK_WORD_OFFSET]
1910 ands ip, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
1911 beq .Lslow_rb_\name
1912 // Already marked, return right away.
1913 bx lr
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001914
1915.Lslow_rb_\name:
Mathieu Chartier36c22712016-08-12 13:19:44 -07001916 push {r0-r5, r9, lr} @ save return address and core caller-save registers
1917 @ also save callee save r5 for 16 byte alignment
Roland Levillain4359e612016-07-20 11:32:19 +01001918 .cfi_adjust_cfa_offset 32
1919 .cfi_rel_offset r0, 0
1920 .cfi_rel_offset r1, 4
1921 .cfi_rel_offset r2, 8
1922 .cfi_rel_offset r3, 12
1923 .cfi_rel_offset r4, 16
Mathieu Chartier36c22712016-08-12 13:19:44 -07001924 .cfi_rel_offset r5, 20
1925 .cfi_rel_offset r9, 24
Roland Levillain4359e612016-07-20 11:32:19 +01001926 .cfi_rel_offset lr, 28
1927 vpush {s0-s15} @ save floating-point caller-save registers
1928 .cfi_adjust_cfa_offset 64
1929
1930 .ifnc \reg, r0
1931 mov r0, \reg @ pass arg1 - obj from `reg`
1932 .endif
1933 bl artReadBarrierMark @ r0 <- artReadBarrierMark(obj)
Mathieu Chartier36c22712016-08-12 13:19:44 -07001934 mov ip, r0 @ Save result in IP
Roland Levillain4359e612016-07-20 11:32:19 +01001935 vpop {s0-s15} @ restore floating-point registers
1936 .cfi_adjust_cfa_offset -64
Mathieu Chartier36c22712016-08-12 13:19:44 -07001937 pop {r0-r5, r9, lr} @ restore caller-save registers
1938 mov \reg, ip @ copy result to reg
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001939.Lret_rb_\name:
1940 bx lr
Roland Levillain02b75802016-07-13 11:54:35 +01001941END \name
1942.endm
1943
Roland Levillain4359e612016-07-20 11:32:19 +01001944READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, r0
Roland Levillain02b75802016-07-13 11:54:35 +01001945READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1946READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1947READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1948READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1949READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1950READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1951READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1952READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1953READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1954READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1955READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11