blob: f33eebed948f56e1246425588eac8c1bfe782044 [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
45 * Runtime::CreateCalleeSaveMethod(kSaveAll)
46 */
47.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME rTemp1, rTemp2
48 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
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070053 RUNTIME_CURRENT1 \rTemp1, \rTemp2 @ Load Runtime::Current into rTemp1.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070054 ldr \rTemp1, [\rTemp1, #RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET] @ rTemp1 is kSaveAll Method*.
55 str \rTemp1, [sp, #0] @ Place Method* at bottom of stack.
56 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070057
58 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xu5667fdb2014-10-23 18:29:55 +080059#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 36 + 64 + 12)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070060#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM) size not as expected."
61#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070062.endm
63
64 /*
65 * Macro that sets up the callee save frame to conform with
Mathieu Chartier19841522013-10-22 11:29:00 -070066 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
Ian Rogers4f0d07c2011-10-06 23:38:47 -070067 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070068.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME rTemp1, rTemp2
69 push {r5-r8, r10-r11, lr} @ 7 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -080070 .cfi_adjust_cfa_offset 28
71 .cfi_rel_offset r5, 0
72 .cfi_rel_offset r6, 4
73 .cfi_rel_offset r7, 8
74 .cfi_rel_offset r8, 12
75 .cfi_rel_offset r10, 16
76 .cfi_rel_offset r11, 20
77 .cfi_rel_offset lr, 24
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070078 sub sp, #4 @ bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080079 .cfi_adjust_cfa_offset 4
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070080 RUNTIME_CURRENT2 \rTemp1, \rTemp2 @ Load Runtime::Current into rTemp1.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070081 ldr \rTemp1, [\rTemp1, #RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET] @ rTemp1 is kRefsOnly Method*.
82 str \rTemp1, [sp, #0] @ Place Method* at bottom of stack.
83 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070084
85 // Ugly compile-time check, but we only have the preprocessor.
86#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 28 + 4)
87#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM) size not as expected."
88#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070089.endm
90
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070091.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070092 add sp, #4 @ bottom word holds Method*
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -070093 .cfi_adjust_cfa_offset -4
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070094 pop {r5-r8, r10-r11, lr} @ 7 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080095 .cfi_restore r5
96 .cfi_restore r6
97 .cfi_restore r7
98 .cfi_restore r8
99 .cfi_restore r10
100 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700101 .cfi_restore lr
102 .cfi_adjust_cfa_offset -28
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700103.endm
104
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu5667fdb2014-10-23 18:29:55 +0800106 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700107 bx lr @ return
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700108.endm
109
110 /*
111 * Macro that sets up the callee save frame to conform with
Mathieu Chartier19841522013-10-22 11:29:00 -0700112 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700113 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800114.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
115 push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves and args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800116 .cfi_adjust_cfa_offset 40
Jeff Hao5d917302013-02-27 17:57:33 -0800117 .cfi_rel_offset r1, 0
118 .cfi_rel_offset r2, 4
119 .cfi_rel_offset r3, 8
120 .cfi_rel_offset r5, 12
121 .cfi_rel_offset r6, 16
122 .cfi_rel_offset r7, 20
123 .cfi_rel_offset r8, 24
124 .cfi_rel_offset r10, 28
125 .cfi_rel_offset r11, 32
126 .cfi_rel_offset lr, 36
Zheng Xu5667fdb2014-10-23 18:29:55 +0800127 vpush {s0-s15} @ 16 words of float args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800128 .cfi_adjust_cfa_offset 64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700129 sub sp, #8 @ 2 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -0800130 .cfi_adjust_cfa_offset 8
Zheng Xu5667fdb2014-10-23 18:29:55 +0800131 // Ugly compile-time check, but we only have the preprocessor.
132#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 40 + 64 + 8)
133#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM) size not as expected."
134#endif
135.endm
136
137.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME rTemp1, rTemp2
138 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700139 RUNTIME_CURRENT3 \rTemp1, \rTemp2 @ Load Runtime::Current into rTemp1.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700140 @ rTemp1 is kRefsAndArgs Method*.
141 ldr \rTemp1, [\rTemp1, #RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET]
142 str \rTemp1, [sp, #0] @ Place Method* at bottom of stack.
143 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700144.endm
145
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700146.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Zheng Xu5667fdb2014-10-23 18:29:55 +0800147 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700148 str r0, [sp, #0] @ Store ArtMethod* to bottom of stack.
149 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
150.endm
151
152.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700153 add sp, #8 @ rewind sp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800154 .cfi_adjust_cfa_offset -8
155 vpop {s0-s15}
156 .cfi_adjust_cfa_offset -64
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700157 pop {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -0800158 .cfi_restore r1
159 .cfi_restore r2
160 .cfi_restore r3
161 .cfi_restore r5
162 .cfi_restore r6
163 .cfi_restore r7
164 .cfi_restore r8
165 .cfi_restore r10
166 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700167 .cfi_restore lr
Zheng Xu5667fdb2014-10-23 18:29:55 +0800168 .cfi_adjust_cfa_offset -40
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700169.endm
170
Ian Rogers637859c2013-08-27 14:35:54 -0700171.macro RETURN_IF_RESULT_IS_ZERO
172 cbnz r0, 1f @ result non-zero branch over
173 bx lr @ return
1741:
175.endm
176
177.macro RETURN_IF_RESULT_IS_NON_ZERO
178 cbz r0, 1f @ result zero branch over
179 bx lr @ return
1801:
181.endm
182
Ian Rogersce9eca62011-10-07 17:11:03 -0700183 /*
184 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
185 * exception is Thread::Current()->exception_
186 */
187.macro DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -0800188 .fnend
189 .fnstart
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700190 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0, r1 @ save callee saves for throw
Ian Rogersce9eca62011-10-07 17:11:03 -0700191 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700192 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700193.endm
194
Ian Rogers57b86d42012-03-27 16:05:41 -0700195.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700196 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800197ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700198 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0, r1 // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700199 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700200 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800201END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700202.endm
buzbee44b412b2012-02-04 08:50:53 -0800203
Ian Rogers57b86d42012-03-27 16:05:41 -0700204.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700205 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800206ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700207 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r1, r2 // save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700208 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700209 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800210END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700211.endm
Ian Rogers9651f422011-09-19 20:26:07 -0700212
Ian Rogers57b86d42012-03-27 16:05:41 -0700213.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700214 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800215ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700216 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2, r3 // save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700217 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700218 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800219END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700220.endm
Ian Rogersbdb03912011-09-14 00:55:44 -0700221
Fred Shih37f05ef2014-07-16 18:38:08 -0700222.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
223 ldr \reg, [r9, #THREAD_EXCEPTION_OFFSET] // Get exception field.
224 cbnz \reg, 1f
225 bx lr
2261:
227 DELIVER_PENDING_EXCEPTION
228.endm
229
230.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
231 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r1
232.endm
233
234.macro RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
235 RETURN_IF_RESULT_IS_ZERO
236 DELIVER_PENDING_EXCEPTION
237.endm
238
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800239.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
240 RETURN_IF_RESULT_IS_NON_ZERO
241 DELIVER_PENDING_EXCEPTION
242.endm
243
Fred Shih37f05ef2014-07-16 18:38:08 -0700244// Macros taking opportunity of code similarities for downcalls with referrer for non-wide fields.
245.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
246 .extern \entrypoint
247ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700248 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2 @ save callee saves in case of GC
249 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700250 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700251 bl \entrypoint @ (uint32_t field_idx, const Method* referrer, Thread*)
252 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700253 \return
254END \name
255.endm
256
257.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
258 .extern \entrypoint
259ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700260 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case of GC
261 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700262 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700263 bl \entrypoint @ (field_idx, Object*, referrer, Thread*)
264 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700265 \return
266END \name
267.endm
268
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800269.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
Fred Shih37f05ef2014-07-16 18:38:08 -0700270 .extern \entrypoint
271ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700272 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3, r12 @ save callee saves in case of GC
273 ldr r3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
274 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700275 .cfi_adjust_cfa_offset 16
276 bl \entrypoint @ (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700277 add sp, #16 @ release out args
278 .cfi_adjust_cfa_offset -16
Roland Levillainf969a202016-03-09 16:14:00 +0000279 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Fred Shih37f05ef2014-07-16 18:38:08 -0700280 \return
281END \name
282.endm
283
Ian Rogers57b86d42012-03-27 16:05:41 -0700284 /*
285 * Called by managed code, saves callee saves and then calls artThrowException
286 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
287 */
Ian Rogers468532e2013-08-05 10:56:33 -0700288ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Ian Rogers932746a2011-09-22 18:57:50 -0700289
Ian Rogers57b86d42012-03-27 16:05:41 -0700290 /*
291 * Called by managed code to create and deliver a NullPointerException.
292 */
Ian Rogers468532e2013-08-05 10:56:33 -0700293NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700294
Ian Rogers57b86d42012-03-27 16:05:41 -0700295 /*
296 * Called by managed code to create and deliver an ArithmeticException.
297 */
Ian Rogers468532e2013-08-05 10:56:33 -0700298NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700299
Ian Rogers57b86d42012-03-27 16:05:41 -0700300 /*
301 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
302 * index, arg2 holds limit.
303 */
Ian Rogers468532e2013-08-05 10:56:33 -0700304TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700305
306 /*
307 * Called by managed code to create and deliver a StackOverflowError.
308 */
Ian Rogers468532e2013-08-05 10:56:33 -0700309NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700310
311 /*
312 * Called by managed code to create and deliver a NoSuchMethodError.
313 */
Ian Rogers468532e2013-08-05 10:56:33 -0700314ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700315
316 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800317 * All generated callsites for interface invokes and invocation slow paths will load arguments
318 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100319 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700320 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700321 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800322 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
323 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700324 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700325 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800326 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700327 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700328 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
329 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700330 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700331.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800332 .extern \cxx_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700333 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100334 mov r2, r9 @ pass Thread::Current
335 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700336 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700337 mov r12, r1 @ save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700338 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700339 cbz r0, 1f @ did we find the target? if not go to exception delivery
340 bx r12 @ tail call to target
3411:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800342 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700343.endm
344.macro INVOKE_TRAMPOLINE c_name, cxx_name
345ENTRY \c_name
346 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800347END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800348.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800349
Logan Chien8dbb7082013-01-25 20:31:17 +0800350INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800351
Logan Chien8dbb7082013-01-25 20:31:17 +0800352INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
353INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
354INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
355INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700356
Ian Rogers57b86d42012-03-27 16:05:41 -0700357 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800358 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700359 * On entry:
360 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700361 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700362 * r2 = size of argument array in bytes
363 * r3 = (managed) thread pointer
364 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800365 * [sp + 4] = result_in_float
366 * [sp + 8] = core register argument array
367 * [sp + 12] = fp register argument array
368 * +-------------------------+
369 * | uint32_t* fp_reg_args |
370 * | uint32_t* core_reg_args |
371 * | result_in_float | <- Caller frame
372 * | Jvalue* result |
373 * +-------------------------+
374 * | lr |
375 * | r11 |
376 * | r9 |
377 * | r4 | <- r11
378 * +-------------------------+
379 * | uint32_t out[n-1] |
380 * | : : | Outs
381 * | uint32_t out[0] |
382 * | StackRef<ArtMethod> | <- SP value=null
383 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800384 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800385ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700386 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800387 mov r11, sp @ save the stack pointer
388 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800389
Jeff Hao5d917302013-02-27 17:57:33 -0800390 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800391
392 add r4, r2, #4 @ create space for method pointer in frame
393 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
394 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
395 mov sp, r4 @ 16B alignment ourselves.
396
397 mov r4, r0 @ save method*
398 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
399 bl memcpy @ memcpy (dest, src, bytes)
400 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700401 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800402
Nicolas Geoffray48088462014-12-12 10:29:38 +0000403 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800404 vldm ip, {s0-s15} @ copy s0 - s15
405
Nicolas Geoffray48088462014-12-12 10:29:38 +0000406 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800407 mov r0, r4 @ restore method*
408 add ip, ip, #4 @ skip r0
409 ldm ip, {r1-r3} @ copy r1 - r3
410
Wei Jin04f4d8a2014-05-29 18:04:29 -0700411#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800412 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700413#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700414
Mathieu Chartiere401d142015-04-22 13:56:20 -0700415 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800416 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800417
Jeff Hao6474d192013-03-26 14:08:09 -0700418 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800419 .cfi_def_cfa_register sp
420
Nicolas Geoffray48088462014-12-12 10:29:38 +0000421 ldr r4, [sp, #40] @ load result_is_float
422 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800423 cmp r4, #0
424 ite eq
425 strdeq r0, [r9] @ store r0/r1 into result pointer
426 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
427
Nicolas Geoffray48088462014-12-12 10:29:38 +0000428 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800429END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700430
Jeff Hao5d917302013-02-27 17:57:33 -0800431 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000432 * On stack replacement stub.
433 * On entry:
434 * r0 = stack to copy
435 * r1 = size of stack
436 * r2 = pc to call
437 * r3 = JValue* result
438 * [sp] = shorty
439 * [sp + 4] = thread
440 */
441ENTRY art_quick_osr_stub
442 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
443 mov r11, sp @ Save the stack pointer
444 mov r10, r1 @ Save size of stack
445 ldr r9, [r11, #40] @ Move managed thread pointer into r9
446 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000447 sub r7, sp, #12 @ Reserve space for stack pointer,
448 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000449 and r7, #0xFFFFFFF0 @ Align stack pointer
450 mov sp, r7 @ Update stack pointer
451 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000452 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000453 mov ip, #0
454 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
455 sub sp, sp, r1 @ Reserve space for callee stack
456 mov r2, r1
457 mov r1, r0
458 mov r0, sp
459 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
460 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000461 ldr r10, [sp, #8] @ Restore JValue* result
462 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000463 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000464 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000465 cmp r4, #68 @ Test if result type char == 'D'.
466 beq .Losr_fp_result
467 cmp r4, #70 @ Test if result type char == 'F'.
468 beq .Losr_fp_result
469 strd r0, [r10] @ Store r0/r1 into result pointer
470 b .Losr_exit
471.Losr_fp_result:
472 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
473.Losr_exit:
474 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
475.Losr_entry:
476 sub r10, r10, #4
477 str lr, [sp, r10] @ Store link register per the compiler ABI
478 bx r8
479END art_quick_osr_stub
480
481 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700482 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
483 */
Ian Rogers637859c2013-08-27 14:35:54 -0700484ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700485 vldm r1, {s0-s31} @ load all fprs from argument fprs_
486 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700487 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700488 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700489 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700490 ldr r0, [r0, #-12] @ load r0 value
491 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700492 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800493END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700494
Ian Rogers60db5ab2012-02-20 17:02:00 -0800495 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700496 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
497 * failure.
498 */
Ian Rogers832336b2014-10-08 15:35:22 -0700499TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700500
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700501 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700502 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
503 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700504 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800505 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700506ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800507 cbz r0, .Lslow_lock
508.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700509 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700510 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800511 mov r3, r1
512 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
513 cbnz r3, .Lnot_unlocked @ already thin locked
514 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
515 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700516 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800517 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700518 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700519 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800520.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
521 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800522 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700523 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
524 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800525 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700526 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800527 mov r3, r1 @ copy the lock word to check count overflow.
528 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits.
529 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
530 lsr r3, r2, LOCK_WORD_READ_BARRIER_STATE_SHIFT @ if either of the upper two bits (28-29) are set, we overflowed.
531 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
532 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
533 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
534 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700535 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800536.Llock_strex_fail:
537 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800538.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700539 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700540 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700541 bl artLockObjectFromCode @ (Object* obj, Thread*)
542 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700543 RETURN_IF_RESULT_IS_ZERO
544 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700545END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700546
Ian Rogersff1ed472011-09-20 13:46:24 -0700547 /*
548 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700549 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700550 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800551 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700552ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800553 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800554.Lretry_unlock:
555#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700556 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800557#else
558 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
559#endif
560 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800561 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700562 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800563 mov r3, r1 @ copy lock word to check thread id equality
564 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
565 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700566 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800567 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800568 mov r3, r1 @ copy lock word to detect transition to unlocked
569 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
570 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800571 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800572 @ transition to unlocked
573 mov r3, r1
574 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK @ r3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700575 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800576#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700577 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800578#else
579 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
580 cbnz r2, .Lunlock_strex_fail @ store failed, retry
581#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700582 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800583.Lrecursive_thin_unlock: @ r1: original lock word
584 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
585#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700586 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800587#else
588 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
589 cbnz r2, .Lunlock_strex_fail @ store failed, retry
590#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700591 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800592.Lunlock_strex_fail:
593 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800594.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700595 @ save callee saves in case exception allocation triggers GC
596 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2
Ian Rogers637859c2013-08-27 14:35:54 -0700597 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700598 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
599 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700600 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700601 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700602END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700603
Ian Rogersff1ed472011-09-20 13:46:24 -0700604 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700605 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
606 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700607 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700608 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700609ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700610 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700611 .cfi_adjust_cfa_offset 12
612 .cfi_rel_offset r0, 0
613 .cfi_rel_offset r1, 4
614 .cfi_rel_offset lr, 8
615 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700616 .cfi_adjust_cfa_offset 4
617 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800618 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700619 add sp, #4
620 .cfi_adjust_cfa_offset -4
621 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700622 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800623.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700624 add sp, #4
625 .cfi_adjust_cfa_offset -4
626 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700627 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800628 .cfi_restore r0
629 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700630 .cfi_restore lr
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700631 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2, r3 // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700632 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700633 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700634 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700635END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700636
Man Cao1aee9002015-07-14 22:31:42 -0700637// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
638.macro POP_REG_NE rReg, offset, rExclude
639 .ifnc \rReg, \rExclude
640 ldr \rReg, [sp, #\offset] @ restore rReg
641 .cfi_restore \rReg
642 .endif
643.endm
644
645 /*
646 * Macro to insert read barrier, only used in art_quick_aput_obj.
647 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
648 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
649 */
650.macro READ_BARRIER rDest, rObj, offset
651#ifdef USE_READ_BARRIER
652 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
653 .cfi_adjust_cfa_offset 24
654 .cfi_rel_offset r0, 0
655 .cfi_rel_offset r1, 4
656 .cfi_rel_offset r2, 8
657 .cfi_rel_offset r3, 12
658 .cfi_rel_offset ip, 16
659 .cfi_rel_offset lr, 20
660 sub sp, #8 @ push padding
661 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700662 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700663 .ifnc \rObj, r1
664 mov r1, \rObj @ pass rObj
665 .endif
666 mov r2, #\offset @ pass offset
667 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
668 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
669 .ifnc \rDest, r0
670 mov \rDest, r0 @ save return value in rDest
671 .endif
672 add sp, #8 @ pop padding
673 .cfi_adjust_cfa_offset -8
674 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
675 POP_REG_NE r1, 4, \rDest
676 POP_REG_NE r2, 8, \rDest
677 POP_REG_NE r3, 12, \rDest
678 POP_REG_NE ip, 16, \rDest
679 add sp, #20
680 .cfi_adjust_cfa_offset -20
681 pop {lr} @ restore lr
682 .cfi_adjust_cfa_offset -4
683 .cfi_restore lr
684#else
685 ldr \rDest, [\rObj, #\offset]
686 UNPOISON_HEAP_REF \rDest
687#endif // USE_READ_BARRIER
688.endm
689
Ian Rogerse51a5112011-09-23 14:16:35 -0700690 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700691 * Entry from managed code for array put operations of objects where the value being stored
692 * needs to be checked for compatibility.
693 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700694 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700695ENTRY art_quick_aput_obj_with_null_and_bound_check
696 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700697 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700698 b art_quick_throw_null_pointer_exception
699END art_quick_aput_obj_with_null_and_bound_check
700
Dan Albert58bea4a2014-08-09 18:08:07 -0700701 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700702ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700703 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700704 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700705 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700706 mov r0, r1
707 mov r1, r3
708 b art_quick_throw_array_bounds
709END art_quick_aput_obj_with_bound_check
710
Man Cao1aee9002015-07-14 22:31:42 -0700711#ifdef USE_READ_BARRIER
712 .extern artReadBarrierSlow
713#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700714 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700715ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700716#ifdef USE_READ_BARRIER
717 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
718 tst r2, r2
719 beq .Ldo_aput_null
720#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800721 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700722#endif // USE_READ_BARRIER
723 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
724 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
725 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700726 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800727 bne .Lcheck_assignability
728.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700729 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700730 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700731 str r2, [r3, r1, lsl #2]
732 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
733 lsr r0, r0, #7
734 strb r3, [r3, r0]
735 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800736.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700737 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700738 str r2, [r3, r1, lsl #2]
739 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800740.Lcheck_assignability:
741 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700742 .cfi_adjust_cfa_offset 16
743 .cfi_rel_offset r0, 0
744 .cfi_rel_offset r1, 4
745 .cfi_rel_offset r2, 8
746 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700747 mov r1, ip
748 mov r0, r3
749 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800750 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700751 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700752 .cfi_restore r0
753 .cfi_restore r1
754 .cfi_restore r2
755 .cfi_restore lr
756 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700757 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700758 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700759 str r2, [r3, r1, lsl #2]
760 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
761 lsr r0, r0, #7
762 strb r3, [r3, r0]
763 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800764.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700765 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700766 /* No need to repeat restore cfi directives, the ones above apply here. */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700767 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r3, ip
Ian Rogersa9a82542013-10-04 11:17:26 -0700768 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700769 mov r2, r9 @ pass Thread::Current
770 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
771 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700772END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700773
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800774// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100775.macro ONE_ARG_DOWNCALL name, entrypoint, return
776 .extern \entrypoint
777ENTRY \name
778 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2 @ save callee saves in case of GC
779 mov r1, r9 @ pass Thread::Current
780 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
781 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
782 \return
783END \name
784.endm
785
786// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800787.macro TWO_ARG_DOWNCALL name, entrypoint, return
788 .extern \entrypoint
789ENTRY \name
790 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case of GC
791 mov r2, r9 @ pass Thread::Current
792 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700793 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800794 \return
795END \name
796.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700797
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800798// Macro to facilitate adding new array allocation entrypoints.
799.macro THREE_ARG_DOWNCALL name, entrypoint, return
800 .extern \entrypoint
801ENTRY \name
802 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3, r12 @ save callee saves in case of GC
803 mov r3, r9 @ pass Thread::Current
804 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
805 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700806 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800807 \return
808END \name
809.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700810
Jeff Hao848f70a2014-01-15 13:49:50 -0800811// Macro to facilitate adding new allocation entrypoints.
812.macro FOUR_ARG_DOWNCALL name, entrypoint, return
813 .extern \entrypoint
814ENTRY \name
Roland Levillainf969a202016-03-09 16:14:00 +0000815 sub sp, #12 @ alignment padding
816 .cfi_adjust_cfa_offset 12
817 push {r3} @ Save r3 as is it used as a temp register in the
818 .cfi_adjust_cfa_offset 4 @ expansion of the SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
819 .cfi_rel_offset r3, 0 @ macro below, which clobbers its arguments.
Jeff Hao848f70a2014-01-15 13:49:50 -0800820 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3, r12 @ save callee saves in case of GC
Roland Levillainf969a202016-03-09 16:14:00 +0000821 ldr r3, [sp, 32] @ restore r3
822 .cfi_restore r3
823
Jeff Hao848f70a2014-01-15 13:49:50 -0800824 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800825 .cfi_adjust_cfa_offset 16
826 bl \entrypoint
827 add sp, #16 @ strip the extra frame
828 .cfi_adjust_cfa_offset -16
829 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Roland Levillainf969a202016-03-09 16:14:00 +0000830 add sp, #16 @ pop r3 + padding
831 .cfi_adjust_cfa_offset -16
Jeff Hao848f70a2014-01-15 13:49:50 -0800832 \return
833END \name
834.endm
835
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100836ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
837ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
838ONE_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 -0700839
Ian Rogersce9eca62011-10-07 17:11:03 -0700840 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700841 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700842 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700843ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
844ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
845ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
846ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
847ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
848ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700849 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700850 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700851 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800852 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700853ENTRY art_quick_get64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700854 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case of GC
855 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700856 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700857 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700858 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700859 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700860 cbnz r2, 1f @ success if no exception pending
861 bx lr @ return on success
8621:
Ian Rogersce9eca62011-10-07 17:11:03 -0700863 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700864END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700865
Ian Rogersce9eca62011-10-07 17:11:03 -0700866 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700867 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700868 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700869TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
870TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
871TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
872TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
873TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
874TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800875 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700876 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800877 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800878 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700879ENTRY art_quick_get64_instance
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700880 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case of GC
881 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -0800882 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700883 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700884 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700885 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700886 cbnz r2, 1f @ success if no exception pending
887 bx lr @ return on success
8881:
Ian Rogers1bddec32012-02-04 12:27:34 -0800889 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700890END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800891
Ian Rogers1bddec32012-02-04 12:27:34 -0800892 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700893 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800894 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700895TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
896TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
897TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
898TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -0700899 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700900 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100901 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -0700902 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800903 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700904ENTRY art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +0100905 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r12 @ save callee saves in case of GC
906 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700907 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
908 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700909 .cfi_adjust_cfa_offset 16
910 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700911 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -0800912 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700913 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700914 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700915 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700916END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700917
Ian Rogersce9eca62011-10-07 17:11:03 -0700918 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700919 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700920 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700921THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
922THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
923THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
924THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -0800925 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700926 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800927 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700928 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700929ENTRY art_quick_set64_instance
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700930 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12, lr @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100931 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700932 ldr r12, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
933 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700934 .cfi_adjust_cfa_offset 12
935 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700936 .cfi_adjust_cfa_offset 4
937 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -0800938 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -0800939 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700940 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700941 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -0800942 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700943END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800944
Ian Rogers1bddec32012-02-04 12:27:34 -0800945 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -0700946 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100947 * exception on error. On success the String is returned. R0 holds the string index. The fast
948 * path check for hit in strings cache has already been performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700949 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100950ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb886da82011-09-23 16:27:54 -0700951
Mathieu Chartier7410f292013-11-24 13:17:35 -0800952// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700953GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -0800954
955// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
956ENTRY art_quick_alloc_object_tlab
957 // Fast path tlab allocation.
958 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
959 // r2, r3, r12: free.
960#if defined(USE_READ_BARRIER)
961 eor r0, r0, r0 // Read barrier not supported here.
962 sub r0, r0, #1 // Return -1.
963 bx lr
964#endif
965 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
966 // Load the class (r2)
967 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
968 cbz r2, .Lart_quick_alloc_object_tlab_slow_path // Check null class
969 // Check class status.
970 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
971 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
972 bne .Lart_quick_alloc_object_tlab_slow_path
973 // Add a fake dependence from the
974 // following access flag and size
975 // loads to the status load.
976 // This is to prevent those loads
977 // from being reordered above the
978 // status load and reading wrong
979 // values (an alternative is to use
980 // a load-acquire for the status).
981 eor r3, r3, r3
982 add r2, r2, r3
983 // Check access flags has
984 // kAccClassIsFinalizable.
985 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
986 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
987 bne .Lart_quick_alloc_object_tlab_slow_path
988 // Load thread_local_pos (r12) and
989 // thread_local_end (r3) with ldrd.
990 // Check constraints for ldrd.
991#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
992#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
993#endif
994 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
995 sub r12, r3, r12 // Compute the remaining buf size.
996 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
997 cmp r3, r12 // Check if it fits. OK to do this
998 // before rounding up the object size
999 // assuming the buf size alignment.
1000 bhi .Lart_quick_alloc_object_tlab_slow_path
1001 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1002 // Round up the object size by the
1003 // object alignment. (addr + 7) & ~7.
1004 add r3, r3, #OBJECT_ALIGNMENT_MASK
1005 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1006 // Reload old thread_local_pos (r0)
1007 // for the return value.
1008 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1009 add r1, r0, r3
1010 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1011 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1012 add r1, r1, #1
1013 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1014 POISON_HEAP_REF r2
1015 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1016 // Fence. This is "ish" not "ishst" so
1017 // that the code after this allocation
1018 // site will see the right values in
1019 // the fields of the class.
1020 // Alternatively we could use "ishst"
1021 // if we use load-acquire for the
1022 // class status load.)
1023 dmb ish
1024 bx lr
1025.Lart_quick_alloc_object_tlab_slow_path:
1026 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 // Save callee saves in case of GC.
1027 mov r2, r9 // Pass Thread::Current.
1028 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1029 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1030 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1031END art_quick_alloc_object_tlab
1032
1033
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001034// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1035ENTRY art_quick_alloc_object_rosalloc
1036 // Fast path rosalloc allocation.
1037 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1038 // r2, r3, r12: free.
1039 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1040 // Load the class (r2)
1041 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1042 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
1043 // Check class status.
1044 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1045 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1046 bne .Lart_quick_alloc_object_rosalloc_slow_path
1047 // Add a fake dependence from the
1048 // following access flag and size
1049 // loads to the status load.
1050 // This is to prevent those loads
1051 // from being reordered above the
1052 // status load and reading wrong
1053 // values (an alternative is to use
1054 // a load-acquire for the status).
1055 eor r3, r3, r3
1056 add r2, r2, r3
1057 // Check access flags has
1058 // kAccClassIsFinalizable
1059 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1060 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1061 bne .Lart_quick_alloc_object_rosalloc_slow_path
1062
1063 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1064 // allocation stack has room.
1065 // TODO: consider using ldrd.
1066 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1067 cmp r3, r12
1068 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1069
1070 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3)
1071 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1072 // local allocation
1073 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1074 // Compute the rosalloc bracket index
1075 // from the size.
1076 // Align up the size by the rosalloc
1077 // bracket quantum size and divide
1078 // by the quantum size and subtract
1079 // by 1. This code is a shorter but
1080 // equivalent version.
1081 sub r3, r3, #1
1082 lsr r3, r3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1083 // Load the rosalloc run (r12)
1084 add r12, r9, r3, lsl #POINTER_SIZE_SHIFT
1085 ldr r12, [r12, #THREAD_ROSALLOC_RUNS_OFFSET]
1086 // Load the free list head (r3). This
1087 // will be the return val.
1088 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1089 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1090 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1091 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1092 // and update the list head with the
1093 // next pointer.
1094 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1095 // Store the class pointer in the
1096 // header. This also overwrites the
1097 // next pointer. The offsets are
1098 // asserted to match.
1099#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1100#error "Class pointer needs to overwrite next pointer."
1101#endif
1102 POISON_HEAP_REF r2
1103 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
1104 // Push the new object onto the thread
1105 // local allocation stack and
1106 // increment the thread local
1107 // allocation stack top.
1108 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1109 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1110 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1111 // Decrement the size of the free list
1112 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1113 sub r1, #1
1114 // TODO: consider combining this store
1115 // and the list head store above using
1116 // strd.
1117 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1118 // Fence. This is "ish" not "ishst" so
1119 // that the code after this allocation
1120 // site will see the right values in
1121 // the fields of the class.
1122 // Alternatively we could use "ishst"
1123 // if we use load-acquire for the
1124 // class status load.)
1125 dmb ish
1126 mov r0, r3 // Set the return value and return.
1127 bx lr
1128
1129.Lart_quick_alloc_object_rosalloc_slow_path:
1130 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ save callee saves in case of GC
1131 mov r2, r9 @ pass Thread::Current
1132 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1133 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1134 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1135END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001136
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001137 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001138 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001139 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001140 .extern artTestSuspendFromCode
1141ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001142#ifdef ARM_R4_SUSPEND_FLAG
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001143 ldrh r0, [rSELF, #THREAD_FLAGS_OFFSET]
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001144 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Ian Rogers637859c2013-08-27 14:35:54 -07001145 cbnz r0, 1f @ check Thread::Current()->suspend_count_ == 0
1146 bx lr @ return if suspend_count_ == 0
11471:
Wei Jin04f4d8a2014-05-29 18:04:29 -07001148#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001149 mov r0, rSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001150 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2 @ save callee saves for GC stack crawl
1151 @ TODO: save FPRs to enable access in the debugger?
1152 bl artTestSuspendFromCode @ (Thread*)
1153 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogers9329bbb2013-02-08 19:56:30 -08001154END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001155
Dave Allison83252962014-04-03 16:33:48 -07001156ENTRY art_quick_implicit_suspend
1157 mov r0, rSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001158 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1, r2 @ save callee saves for stack crawl
1159 bl artTestSuspendFromCode @ (Thread*)
1160 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001161END art_quick_implicit_suspend
1162
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001163 /*
1164 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001165 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1166 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001167 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001168 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001169ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001170 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001171 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001172 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001173 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001174 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001175 // Tear down the callee-save frame. Skip arg registers.
1176 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1177 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001178 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001179 cbnz r2, 1f @ success if no exception is pending
1180 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001181 bx lr @ return on success
11821:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001183 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001184END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001185
Jeff Hao88474b42013-10-23 16:24:40 -07001186 /*
1187 * Called to resolve an imt conflict. r12 is a hidden argument that holds the target method's
1188 * dex method index.
1189 */
1190ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001191 mov r0, r12
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001192 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001193END art_quick_imt_conflict_trampoline
1194
Ian Rogers468532e2013-08-05 10:56:33 -07001195 .extern artQuickResolutionTrampoline
1196ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001197 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2, r3
Ian Rogers468532e2013-08-05 10:56:33 -07001198 mov r2, r9 @ pass Thread::Current
1199 mov r3, sp @ pass SP
1200 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001201 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001202 mov r12, r0
1203 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001204 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001205 bx r12 @ tail-call into actual code
12061:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001207 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001208 DELIVER_PENDING_EXCEPTION
1209END art_quick_resolution_trampoline
1210
Andreas Gampec200a4a2014-06-16 18:39:09 -07001211 /*
1212 * Called to do a generic JNI down-call
1213 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001214ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001215 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001216
1217 // Save rSELF
1218 mov r11, rSELF
1219 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1220 mov r10, sp
1221 .cfi_def_cfa_register r10
1222
1223 sub sp, sp, #5120
1224
1225 // prepare for artQuickGenericJniTrampoline call
1226 // (Thread*, SP)
1227 // r0 r1 <= C calling convention
1228 // rSELF r10 <= where they are
1229
1230 mov r0, rSELF // Thread*
1231 mov r1, r10
1232 blx artQuickGenericJniTrampoline // (Thread*, sp)
1233
1234 // The C call will have registered the complete save-frame on success.
1235 // The result of the call is:
1236 // r0: pointer to native code, 0 on error.
1237 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1238
1239 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001240 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001241
1242 // Release part of the alloca.
1243 mov sp, r1
1244
1245 // Save the code pointer
1246 mov r12, r0
1247
1248 // Load parameters from frame into registers.
1249 pop {r0-r3}
1250
1251 // Softfloat.
1252 // TODO: Change to hardfloat when supported.
1253
1254 blx r12 // native call.
1255
1256 // result sign extension is handled in C code
1257 // prepare for artQuickGenericJniEndTrampoline call
1258 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001259 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001260 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001261 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001262
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001263 push {r0-r1}
1264 mov r3, r1
1265 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001266 mov r0, r11
1267
1268 blx artQuickGenericJniEndTrampoline
1269
Andreas Gampec200a4a2014-06-16 18:39:09 -07001270 // Restore self pointer.
1271 mov r9, r11
1272
1273 // Pending exceptions possible.
1274 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1275 cbnz r2, .Lexception_in_native
1276
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001277 // Tear down the alloca.
1278 mov sp, r10
1279 .cfi_def_cfa_register sp
1280
Zheng Xu5667fdb2014-10-23 18:29:55 +08001281 // Tear down the callee-save frame. Skip arg registers.
1282 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1283 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1284 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001285
Zheng Xu5667fdb2014-10-23 18:29:55 +08001286 // store into fpr, for when it's a fpr return...
1287 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001288 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001289 // Undo the unwinding information from above since it doesn't apply below.
1290 .cfi_def_cfa_register r10
1291 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001292
Andreas Gampec200a4a2014-06-16 18:39:09 -07001293.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001294 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1295 .cfi_def_cfa_register sp
1296 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001297 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001298END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001299
Ian Rogers468532e2013-08-05 10:56:33 -07001300 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001301ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001302 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1, r2
Ian Rogers7db619b2013-01-16 18:35:48 -08001303 mov r1, r9 @ pass Thread::Current
1304 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001305 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001306 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001307 // Tear down the callee-save frame. Skip arg registers.
1308 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1309 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001310 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001311 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001312 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1313 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070013141:
Ian Rogers7db619b2013-01-16 18:35:48 -08001315 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001316END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001317
jeffhaoe343b762011-12-05 16:36:44 -08001318 /*
jeffhao0791adc2012-04-04 11:14:32 -07001319 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001320 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001321 .extern artInstrumentationMethodEntryFromCode
1322 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001323ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001324 @ Make stack crawlable and clobber r2 and r3 (post saving)
1325 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2, r3
1326 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1327 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001328 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001329 mov r3, lr @ pass LR
1330 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001331 mov r12, r0 @ r12 holds reference to code
1332 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001333 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001334 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001335@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001336 .type art_quick_instrumentation_exit, #function
1337 .global art_quick_instrumentation_exit
1338art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001339 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001340 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2, r3 @ set up frame knowing r2 and r3 must be dead on exit
Ian Rogers306057f2012-11-26 12:45:53 -08001341 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001342 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001343 .cfi_adjust_cfa_offset 8
1344 .cfi_rel_offset r0, 0
1345 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001346 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001347 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001348 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1349 @ need to align by 16.
1350 .cfi_adjust_cfa_offset 8
1351 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001352 mov r2, r0 @ pass return value as gpr_res
1353 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001354 mov r0, r9 @ pass Thread::Current
1355 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001356 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001357 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001358 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001359
Ian Rogers306057f2012-11-26 12:45:53 -08001360 mov r2, r0 @ link register saved by instrumentation
1361 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001362 vpop {d0} @ restore fp return value
1363 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001364 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001365 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001366 .cfi_restore r0
1367 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001368 add sp, #32 @ remove callee save frame
1369 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001370 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001371END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001372
Ian Rogers306057f2012-11-26 12:45:53 -08001373 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001374 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1375 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001376 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001377 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001378ENTRY art_quick_deoptimize
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001379 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0, r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001380 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001381 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001382END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001383
Ian Rogers324e1902012-09-09 12:17:52 -07001384 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001385 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001386 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001387 */
1388 .extern artDeoptimizeFromCompiledCode
1389ENTRY art_quick_deoptimize_from_compiled_code
1390 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0, r1
1391 mov r0, r9 @ Set up args.
1392 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1393END art_quick_deoptimize_from_compiled_code
1394
1395 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001396 * Signed 64-bit integer multiply.
1397 *
1398 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1399 * WX
1400 * x YZ
1401 * --------
1402 * ZW ZX
1403 * YW YX
1404 *
1405 * The low word of the result holds ZX, the high word holds
1406 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1407 * it doesn't fit in the low 64 bits.
1408 *
1409 * Unlike most ARM math operations, multiply instructions have
1410 * restrictions on using the same register more than once (Rd and Rm
1411 * cannot be the same).
1412 */
1413 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001414ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001415 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001416 .cfi_adjust_cfa_offset 8
1417 .cfi_rel_offset r9, 0
1418 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001419 mul ip, r2, r1 @ ip<- ZxW
1420 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1421 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1422 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1423 mov r0,r9
1424 mov r1,r10
1425 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001426 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001427 .cfi_restore r9
1428 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001429 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001430END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001431
buzbee54330722011-08-23 16:46:55 -07001432 /*
1433 * Long integer shift. This is different from the generic 32/64-bit
1434 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1435 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1436 * 6 bits.
1437 * On entry:
1438 * r0: low word
1439 * r1: high word
1440 * r2: shift count
1441 */
1442 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001443ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001444 and r2, r2, #63 @ r2<- r2 & 0x3f
1445 mov r1, r1, asl r2 @ r1<- r1 << r2
1446 rsb r3, r2, #32 @ r3<- 32 - r2
1447 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1448 subs ip, r2, #32 @ ip<- r2 - 32
1449 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1450 mov r0, r0, asl r2 @ r0<- r0 << r2
1451 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001452END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001453
buzbee54330722011-08-23 16:46:55 -07001454 /*
1455 * Long integer shift. This is different from the generic 32/64-bit
1456 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1457 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1458 * 6 bits.
1459 * On entry:
1460 * r0: low word
1461 * r1: high word
1462 * r2: shift count
1463 */
1464 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001465ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001466 and r2, r2, #63 @ r0<- r0 & 0x3f
1467 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1468 rsb r3, r2, #32 @ r3<- 32 - r2
1469 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1470 subs ip, r2, #32 @ ip<- r2 - 32
1471 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1472 mov r1, r1, asr r2 @ r1<- r1 >> r2
1473 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001474END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001475
buzbee54330722011-08-23 16:46:55 -07001476 /*
1477 * Long integer shift. This is different from the generic 32/64-bit
1478 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1479 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1480 * 6 bits.
1481 * On entry:
1482 * r0: low word
1483 * r1: high word
1484 * r2: shift count
1485 */
1486 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001487ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001488 and r2, r2, #63 @ r0<- r0 & 0x3f
1489 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1490 rsb r3, r2, #32 @ r3<- 32 - r2
1491 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1492 subs ip, r2, #32 @ ip<- r2 - 32
1493 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1494 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1495 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001496END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001497
buzbeefc9e6fa2012-03-23 15:14:29 -07001498 /*
1499 * String's indexOf.
1500 *
1501 * On entry:
1502 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001503 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001504 * r2: Starting offset in string data
1505 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001506ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001507 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001508 .cfi_adjust_cfa_offset 16
1509 .cfi_rel_offset r4, 0
1510 .cfi_rel_offset r10, 4
1511 .cfi_rel_offset r11, 8
1512 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001513 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001514 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001515
1516 /* Clamp start to [0..count] */
1517 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001518 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001519 movlt r2, #0
1520 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001521 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001522 movgt r2, r3
1523
buzbeefc9e6fa2012-03-23 15:14:29 -07001524 /* Save a copy in r12 to later compute result */
1525 mov r12, r0
1526
1527 /* Build pointer to start of data to compare and pre-bias */
1528 add r0, r0, r2, lsl #1
1529 sub r0, #2
1530
1531 /* Compute iteration count */
1532 sub r2, r3, r2
1533
1534 /*
1535 * At this point we have:
1536 * r0: start of data to test
1537 * r1: char to compare
1538 * r2: iteration count
1539 * r12: original start of string data
1540 * r3, r4, r10, r11 available for loading string data
1541 */
1542
1543 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001544 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001545
Ian Rogers5d885c82014-02-21 20:06:23 -08001546.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001547 ldrh r3, [r0, #2]!
1548 ldrh r4, [r0, #2]!
1549 ldrh r10, [r0, #2]!
1550 ldrh r11, [r0, #2]!
1551 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001552 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001553 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001554 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001555 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001556 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001557 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001558 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001559 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001560 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001561
Ian Rogers5d885c82014-02-21 20:06:23 -08001562.Lindexof_remainder:
1563 adds r2, #4
1564 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001565
Ian Rogers5d885c82014-02-21 20:06:23 -08001566.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001567 ldrh r3, [r0, #2]!
1568 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001569 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001570 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001571 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001572
Ian Rogers5d885c82014-02-21 20:06:23 -08001573.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001574 mov r0, #-1
1575 pop {r4, r10-r11, pc}
1576
Ian Rogers5d885c82014-02-21 20:06:23 -08001577.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001578 sub r0, #6
1579 sub r0, r12
1580 asr r0, r0, #1
1581 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001582.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001583 sub r0, #4
1584 sub r0, r12
1585 asr r0, r0, #1
1586 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001587.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001588 sub r0, #2
1589 sub r0, r12
1590 asr r0, r0, #1
1591 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001592.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001593 sub r0, r12
1594 asr r0, r0, #1
1595 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001596END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001597
1598 /*
1599 * String's compareTo.
1600 *
1601 * Requires rARG0/rARG1 to have been previously checked for null. Will
1602 * return negative if this's string is < comp, 0 if they are the
1603 * same and positive if >.
1604 *
1605 * On entry:
1606 * r0: this object pointer
1607 * r1: comp object pointer
1608 *
1609 */
buzbeefc9e6fa2012-03-23 15:14:29 -07001610 .extern __memcmp16
Ian Rogers9329bbb2013-02-08 19:56:30 -08001611ENTRY art_quick_string_compareto
buzbeefc9e6fa2012-03-23 15:14:29 -07001612 mov r2, r0 @ this to r2, opening up r0 for return value
Ian Rogers637859c2013-08-27 14:35:54 -07001613 sub r0, r2, r1 @ Same?
1614 cbnz r0,1f
1615 bx lr
16161: @ Same strings, return.
buzbeefc9e6fa2012-03-23 15:14:29 -07001617
1618 push {r4, r7-r12, lr} @ 8 words - keep alignment
Ian Rogers9329bbb2013-02-08 19:56:30 -08001619 .cfi_adjust_cfa_offset 32
1620 .cfi_rel_offset r4, 0
1621 .cfi_rel_offset r7, 4
1622 .cfi_rel_offset r8, 8
1623 .cfi_rel_offset r9, 12
1624 .cfi_rel_offset r10, 16
1625 .cfi_rel_offset r11, 20
1626 .cfi_rel_offset r12, 24
1627 .cfi_rel_offset lr, 28
buzbeefc9e6fa2012-03-23 15:14:29 -07001628
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001629 ldr r7, [r2, #MIRROR_STRING_COUNT_OFFSET]
1630 ldr r10, [r1, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001631 add r2, #MIRROR_STRING_VALUE_OFFSET
1632 add r1, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001633
1634 /*
1635 * At this point, we have:
1636 * value: r2/r1
1637 * offset: r4/r9
1638 * count: r7/r10
1639 * We're going to compute
1640 * r11 <- countDiff
1641 * r10 <- minCount
1642 */
1643 subs r11, r7, r10
Ian Rogers637859c2013-08-27 14:35:54 -07001644 it ls
buzbeefc9e6fa2012-03-23 15:14:29 -07001645 movls r10, r7
1646
buzbeefc9e6fa2012-03-23 15:14:29 -07001647 /*
1648 * Note: data pointers point to previous element so we can use pre-index
1649 * mode with base writeback.
1650 */
Jeff Hao848f70a2014-01-15 13:49:50 -08001651 subs r2, #2 @ offset to contents[-1]
1652 subs r1, #2 @ offset to contents[-1]
buzbeefc9e6fa2012-03-23 15:14:29 -07001653
1654 /*
1655 * At this point we have:
1656 * r2: *this string data
1657 * r1: *comp string data
1658 * r10: iteration count for comparison
1659 * r11: value to return if the first part of the string is equal
1660 * r0: reserved for result
1661 * r3, r4, r7, r8, r9, r12 available for loading string data
1662 */
1663
1664 subs r10, #2
Ian Rogers5d885c82014-02-21 20:06:23 -08001665 blt .Ldo_remainder2
buzbeefc9e6fa2012-03-23 15:14:29 -07001666
1667 /*
1668 * Unroll the first two checks so we can quickly catch early mismatch
1669 * on long strings (but preserve incoming alignment)
1670 */
1671
1672 ldrh r3, [r2, #2]!
1673 ldrh r4, [r1, #2]!
1674 ldrh r7, [r2, #2]!
1675 ldrh r8, [r1, #2]!
1676 subs r0, r3, r4
Ian Rogers637859c2013-08-27 14:35:54 -07001677 it eq
1678 subseq r0, r7, r8
Ian Rogers5d885c82014-02-21 20:06:23 -08001679 bne .Ldone
buzbeefc9e6fa2012-03-23 15:14:29 -07001680 cmp r10, #28
Ian Rogers5d885c82014-02-21 20:06:23 -08001681 bgt .Ldo_memcmp16
buzbeefc9e6fa2012-03-23 15:14:29 -07001682 subs r10, #3
Ian Rogers5d885c82014-02-21 20:06:23 -08001683 blt .Ldo_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001684
Ian Rogers5d885c82014-02-21 20:06:23 -08001685.Lloopback_triple:
buzbeefc9e6fa2012-03-23 15:14:29 -07001686 ldrh r3, [r2, #2]!
1687 ldrh r4, [r1, #2]!
1688 ldrh r7, [r2, #2]!
1689 ldrh r8, [r1, #2]!
1690 ldrh r9, [r2, #2]!
1691 ldrh r12,[r1, #2]!
1692 subs r0, r3, r4
Ian Rogers637859c2013-08-27 14:35:54 -07001693 it eq
1694 subseq r0, r7, r8
1695 it eq
1696 subseq r0, r9, r12
Ian Rogers5d885c82014-02-21 20:06:23 -08001697 bne .Ldone
buzbeefc9e6fa2012-03-23 15:14:29 -07001698 subs r10, #3
Ian Rogers5d885c82014-02-21 20:06:23 -08001699 bge .Lloopback_triple
buzbeefc9e6fa2012-03-23 15:14:29 -07001700
Ian Rogers5d885c82014-02-21 20:06:23 -08001701.Ldo_remainder:
buzbeefc9e6fa2012-03-23 15:14:29 -07001702 adds r10, #3
Ian Rogers5d885c82014-02-21 20:06:23 -08001703 beq .Lreturn_diff
buzbeefc9e6fa2012-03-23 15:14:29 -07001704
Ian Rogers5d885c82014-02-21 20:06:23 -08001705.Lloopback_single:
buzbeefc9e6fa2012-03-23 15:14:29 -07001706 ldrh r3, [r2, #2]!
1707 ldrh r4, [r1, #2]!
1708 subs r0, r3, r4
Ian Rogers5d885c82014-02-21 20:06:23 -08001709 bne .Ldone
buzbeefc9e6fa2012-03-23 15:14:29 -07001710 subs r10, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001711 bne .Lloopback_single
buzbeefc9e6fa2012-03-23 15:14:29 -07001712
Ian Rogers5d885c82014-02-21 20:06:23 -08001713.Lreturn_diff:
buzbeefc9e6fa2012-03-23 15:14:29 -07001714 mov r0, r11
1715 pop {r4, r7-r12, pc}
1716
Ian Rogers5d885c82014-02-21 20:06:23 -08001717.Ldo_remainder2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001718 adds r10, #2
Ian Rogers5d885c82014-02-21 20:06:23 -08001719 bne .Lloopback_single
buzbeefc9e6fa2012-03-23 15:14:29 -07001720 mov r0, r11
1721 pop {r4, r7-r12, pc}
1722
1723 /* Long string case */
Ian Rogers5d885c82014-02-21 20:06:23 -08001724.Ldo_memcmp16:
buzbeefc9e6fa2012-03-23 15:14:29 -07001725 mov r7, r11
1726 add r0, r2, #2
1727 add r1, r1, #2
1728 mov r2, r10
1729 bl __memcmp16
1730 cmp r0, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001731 it eq
buzbeefc9e6fa2012-03-23 15:14:29 -07001732 moveq r0, r7
Ian Rogers5d885c82014-02-21 20:06:23 -08001733.Ldone:
buzbeefc9e6fa2012-03-23 15:14:29 -07001734 pop {r4, r7-r12, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001735END art_quick_string_compareto
Zheng Xu5667fdb2014-10-23 18:29:55 +08001736
1737 /* Assembly routines used to handle ABI differences. */
1738
1739 /* double fmod(double a, double b) */
1740 .extern fmod
1741ENTRY art_quick_fmod
1742 push {lr}
1743 .cfi_adjust_cfa_offset 4
1744 .cfi_rel_offset lr, 0
1745 sub sp, #4
1746 .cfi_adjust_cfa_offset 4
1747 vmov r0, r1, d0
1748 vmov r2, r3, d1
1749 bl fmod
1750 vmov d0, r0, r1
1751 add sp, #4
1752 .cfi_adjust_cfa_offset -4
1753 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001754END art_quick_fmod
1755
1756 /* float fmodf(float a, float b) */
1757 .extern fmodf
1758ENTRY art_quick_fmodf
1759 push {lr}
1760 .cfi_adjust_cfa_offset 4
1761 .cfi_rel_offset lr, 0
1762 sub sp, #4
1763 .cfi_adjust_cfa_offset 4
1764 vmov r0, r1, d0
1765 bl fmodf
1766 vmov s0, r0
1767 add sp, #4
1768 .cfi_adjust_cfa_offset -4
1769 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001770END art_quick_fmod
1771
1772 /* int64_t art_d2l(double d) */
1773 .extern art_d2l
1774ENTRY art_quick_d2l
1775 vmov r0, r1, d0
1776 b art_d2l
1777END art_quick_d2l
1778
1779 /* int64_t art_f2l(float f) */
1780 .extern art_f2l
1781ENTRY art_quick_f2l
1782 vmov r0, s0
1783 b art_f2l
1784END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001785
1786 /* float art_l2f(int64_t l) */
1787 .extern art_l2f
1788ENTRY art_quick_l2f
1789 push {lr}
1790 .cfi_adjust_cfa_offset 4
1791 .cfi_rel_offset lr, 0
1792 sub sp, #4
1793 .cfi_adjust_cfa_offset 4
1794 bl art_l2f
1795 vmov s0, r0
1796 add sp, #4
1797 .cfi_adjust_cfa_offset -4
1798 pop {pc}
1799END art_quick_l2f