blob: 82d64b90d7ac37f9d0240b78957d4ebb94edcda3 [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 */
Vladimir Marko3098c8c2016-06-14 17:43:17 +010047.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME rTemp
Andreas Gampe76914b02015-07-17 20:14:50 -070048 SPILL_ALL_CALLEE_SAVE_GPRS @ 9 words (36 bytes) of callee saves.
Zheng Xu5667fdb2014-10-23 18:29:55 +080049 vpush {s16-s31} @ 16 words (64 bytes) of floats.
Zheng Xu5667fdb2014-10-23 18:29:55 +080050 .cfi_adjust_cfa_offset 64
51 sub sp, #12 @ 3 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080052 .cfi_adjust_cfa_offset 12
Vladimir Marko3098c8c2016-06-14 17:43:17 +010053 RUNTIME_CURRENT1 \rTemp @ Load Runtime::Current into rTemp.
54 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET] @ rTemp is kSaveAll Method*.
55 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070056 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 */
Vladimir Marko3098c8c2016-06-14 17:43:17 +010068.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME rTemp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070069 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +010080 RUNTIME_CURRENT2 \rTemp @ Load Runtime::Current into rTemp.
81 ldr \rTemp, [\rTemp, #RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET] @ rTemp is kRefsOnly Method*.
82 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070083 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100137.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME rTemp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800138 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100139 RUNTIME_CURRENT3 \rTemp @ Load Runtime::Current into rTemp.
140 @ rTemp is kRefsAndArgs Method*.
141 ldr \rTemp, [\rTemp, #RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET]
142 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100190 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100198 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100207 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r1 @ 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100216 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100248 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700249 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100260 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700261 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
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100272 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700273 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 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100296 * Call installed by a signal handler to create and deliver a NullPointerException.
297 */
298ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
299
300 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700301 * Called by managed code to create and deliver an ArithmeticException.
302 */
Ian Rogers468532e2013-08-05 10:56:33 -0700303NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700304
Ian Rogers57b86d42012-03-27 16:05:41 -0700305 /*
306 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
307 * index, arg2 holds limit.
308 */
Ian Rogers468532e2013-08-05 10:56:33 -0700309TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700310
311 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100312 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
313 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
314 */
315TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
316
317 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700318 * Called by managed code to create and deliver a StackOverflowError.
319 */
Ian Rogers468532e2013-08-05 10:56:33 -0700320NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700321
322 /*
323 * Called by managed code to create and deliver a NoSuchMethodError.
324 */
Ian Rogers468532e2013-08-05 10:56:33 -0700325ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700326
327 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800328 * All generated callsites for interface invokes and invocation slow paths will load arguments
329 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100330 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700331 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700332 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800333 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
334 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700335 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700336 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800337 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700338 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700339 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
340 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700341 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700342.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800343 .extern \cxx_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100344 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100345 mov r2, r9 @ pass Thread::Current
346 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700347 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700348 mov r12, r1 @ save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700349 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700350 cbz r0, 1f @ did we find the target? if not go to exception delivery
351 bx r12 @ tail call to target
3521:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800353 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700354.endm
355.macro INVOKE_TRAMPOLINE c_name, cxx_name
356ENTRY \c_name
357 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800358END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800359.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800360
Logan Chien8dbb7082013-01-25 20:31:17 +0800361INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800362
Logan Chien8dbb7082013-01-25 20:31:17 +0800363INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
364INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
365INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
366INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700367
Ian Rogers57b86d42012-03-27 16:05:41 -0700368 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800369 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700370 * On entry:
371 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700372 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700373 * r2 = size of argument array in bytes
374 * r3 = (managed) thread pointer
375 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800376 * [sp + 4] = result_in_float
377 * [sp + 8] = core register argument array
378 * [sp + 12] = fp register argument array
379 * +-------------------------+
380 * | uint32_t* fp_reg_args |
381 * | uint32_t* core_reg_args |
382 * | result_in_float | <- Caller frame
383 * | Jvalue* result |
384 * +-------------------------+
385 * | lr |
386 * | r11 |
387 * | r9 |
388 * | r4 | <- r11
389 * +-------------------------+
390 * | uint32_t out[n-1] |
391 * | : : | Outs
392 * | uint32_t out[0] |
393 * | StackRef<ArtMethod> | <- SP value=null
394 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800395 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800396ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700397 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800398 mov r11, sp @ save the stack pointer
399 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800400
Jeff Hao5d917302013-02-27 17:57:33 -0800401 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800402
403 add r4, r2, #4 @ create space for method pointer in frame
404 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
405 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
406 mov sp, r4 @ 16B alignment ourselves.
407
408 mov r4, r0 @ save method*
409 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
410 bl memcpy @ memcpy (dest, src, bytes)
411 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700412 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800413
Nicolas Geoffray48088462014-12-12 10:29:38 +0000414 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800415 vldm ip, {s0-s15} @ copy s0 - s15
416
Nicolas Geoffray48088462014-12-12 10:29:38 +0000417 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800418 mov r0, r4 @ restore method*
419 add ip, ip, #4 @ skip r0
420 ldm ip, {r1-r3} @ copy r1 - r3
421
Wei Jin04f4d8a2014-05-29 18:04:29 -0700422#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800423 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700424#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700425
Mathieu Chartiere401d142015-04-22 13:56:20 -0700426 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800427 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800428
Jeff Hao6474d192013-03-26 14:08:09 -0700429 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800430 .cfi_def_cfa_register sp
431
Nicolas Geoffray48088462014-12-12 10:29:38 +0000432 ldr r4, [sp, #40] @ load result_is_float
433 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800434 cmp r4, #0
435 ite eq
436 strdeq r0, [r9] @ store r0/r1 into result pointer
437 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
438
Nicolas Geoffray48088462014-12-12 10:29:38 +0000439 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800440END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700441
Jeff Hao5d917302013-02-27 17:57:33 -0800442 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000443 * On stack replacement stub.
444 * On entry:
445 * r0 = stack to copy
446 * r1 = size of stack
447 * r2 = pc to call
448 * r3 = JValue* result
449 * [sp] = shorty
450 * [sp + 4] = thread
451 */
452ENTRY art_quick_osr_stub
453 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
454 mov r11, sp @ Save the stack pointer
455 mov r10, r1 @ Save size of stack
456 ldr r9, [r11, #40] @ Move managed thread pointer into r9
457 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000458 sub r7, sp, #12 @ Reserve space for stack pointer,
459 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000460 and r7, #0xFFFFFFF0 @ Align stack pointer
461 mov sp, r7 @ Update stack pointer
462 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000463 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000464 mov ip, #0
465 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
466 sub sp, sp, r1 @ Reserve space for callee stack
467 mov r2, r1
468 mov r1, r0
469 mov r0, sp
470 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
471 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000472 ldr r10, [sp, #8] @ Restore JValue* result
473 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000474 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000475 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000476 cmp r4, #68 @ Test if result type char == 'D'.
477 beq .Losr_fp_result
478 cmp r4, #70 @ Test if result type char == 'F'.
479 beq .Losr_fp_result
480 strd r0, [r10] @ Store r0/r1 into result pointer
481 b .Losr_exit
482.Losr_fp_result:
483 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
484.Losr_exit:
485 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
486.Losr_entry:
487 sub r10, r10, #4
488 str lr, [sp, r10] @ Store link register per the compiler ABI
489 bx r8
490END art_quick_osr_stub
491
492 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700493 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
494 */
Ian Rogers637859c2013-08-27 14:35:54 -0700495ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700496 vldm r1, {s0-s31} @ load all fprs from argument fprs_
497 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700498 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700499 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700500 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700501 ldr r0, [r0, #-12] @ load r0 value
502 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700503 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800504END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700505
Ian Rogers60db5ab2012-02-20 17:02:00 -0800506 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700507 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
508 * failure.
509 */
Ian Rogers832336b2014-10-08 15:35:22 -0700510TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700511
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700512 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700513 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
514 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700515 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800516 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700517ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800518 cbz r0, .Lslow_lock
519.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700520 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700521 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800522 mov r3, r1
523 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
524 cbnz r3, .Lnot_unlocked @ already thin locked
525 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
526 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700527 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800528 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700529 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700530 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800531.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
532 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800533 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700534 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
535 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800536 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700537 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800538 mov r3, r1 @ copy the lock word to check count overflow.
539 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits.
540 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
541 lsr r3, r2, LOCK_WORD_READ_BARRIER_STATE_SHIFT @ if either of the upper two bits (28-29) are set, we overflowed.
542 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
543 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
544 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
545 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700546 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800547.Llock_strex_fail:
548 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800549.Lslow_lock:
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100550 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700551 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700552 bl artLockObjectFromCode @ (Object* obj, Thread*)
553 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700554 RETURN_IF_RESULT_IS_ZERO
555 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700556END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700557
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700558ENTRY art_quick_lock_object_no_inline
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100559 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700560 mov r1, r9 @ pass Thread::Current
561 bl artLockObjectFromCode @ (Object* obj, Thread*)
562 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
563 RETURN_IF_RESULT_IS_ZERO
564 DELIVER_PENDING_EXCEPTION
565END art_quick_lock_object_no_inline
566
Ian Rogersff1ed472011-09-20 13:46:24 -0700567 /*
568 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700569 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700570 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800571 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700572ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800573 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800574.Lretry_unlock:
575#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700576 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800577#else
578 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
579#endif
580 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800581 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700582 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800583 mov r3, r1 @ copy lock word to check thread id equality
584 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
585 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700586 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800587 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800588 mov r3, r1 @ copy lock word to detect transition to unlocked
589 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
590 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800591 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800592 @ transition to unlocked
593 mov r3, r1
594 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK @ r3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700595 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800596#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700597 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800598#else
599 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
600 cbnz r2, .Lunlock_strex_fail @ store failed, retry
601#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700602 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800603.Lrecursive_thin_unlock: @ r1: original lock word
604 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
605#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700606 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800607#else
608 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
609 cbnz r2, .Lunlock_strex_fail @ store failed, retry
610#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700611 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800612.Lunlock_strex_fail:
613 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800614.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700615 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100616 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700617 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700618 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
619 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700620 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700621 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700622END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700623
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700624ENTRY art_quick_unlock_object_no_inline
625 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100626 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700627 mov r1, r9 @ pass Thread::Current
628 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
629 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
630 RETURN_IF_RESULT_IS_ZERO
631 DELIVER_PENDING_EXCEPTION
632END art_quick_unlock_object_no_inline
633
Ian Rogersff1ed472011-09-20 13:46:24 -0700634 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700635 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
636 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700637 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700638 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700639ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700640 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700641 .cfi_adjust_cfa_offset 12
642 .cfi_rel_offset r0, 0
643 .cfi_rel_offset r1, 4
644 .cfi_rel_offset lr, 8
645 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700646 .cfi_adjust_cfa_offset 4
647 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800648 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700649 add sp, #4
650 .cfi_adjust_cfa_offset -4
651 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700652 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800653.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700654 add sp, #4
655 .cfi_adjust_cfa_offset -4
656 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700657 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800658 .cfi_restore r0
659 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700660 .cfi_restore lr
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100661 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700662 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700663 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700664 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700665END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700666
Man Cao1aee9002015-07-14 22:31:42 -0700667// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
668.macro POP_REG_NE rReg, offset, rExclude
669 .ifnc \rReg, \rExclude
670 ldr \rReg, [sp, #\offset] @ restore rReg
671 .cfi_restore \rReg
672 .endif
673.endm
674
675 /*
676 * Macro to insert read barrier, only used in art_quick_aput_obj.
677 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
678 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
679 */
680.macro READ_BARRIER rDest, rObj, offset
681#ifdef USE_READ_BARRIER
682 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
683 .cfi_adjust_cfa_offset 24
684 .cfi_rel_offset r0, 0
685 .cfi_rel_offset r1, 4
686 .cfi_rel_offset r2, 8
687 .cfi_rel_offset r3, 12
688 .cfi_rel_offset ip, 16
689 .cfi_rel_offset lr, 20
690 sub sp, #8 @ push padding
691 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700692 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700693 .ifnc \rObj, r1
694 mov r1, \rObj @ pass rObj
695 .endif
696 mov r2, #\offset @ pass offset
697 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
698 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
699 .ifnc \rDest, r0
700 mov \rDest, r0 @ save return value in rDest
701 .endif
702 add sp, #8 @ pop padding
703 .cfi_adjust_cfa_offset -8
704 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
705 POP_REG_NE r1, 4, \rDest
706 POP_REG_NE r2, 8, \rDest
707 POP_REG_NE r3, 12, \rDest
708 POP_REG_NE ip, 16, \rDest
709 add sp, #20
710 .cfi_adjust_cfa_offset -20
711 pop {lr} @ restore lr
712 .cfi_adjust_cfa_offset -4
713 .cfi_restore lr
714#else
715 ldr \rDest, [\rObj, #\offset]
716 UNPOISON_HEAP_REF \rDest
717#endif // USE_READ_BARRIER
718.endm
719
Ian Rogerse51a5112011-09-23 14:16:35 -0700720 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700721 * Entry from managed code for array put operations of objects where the value being stored
722 * needs to be checked for compatibility.
723 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700724 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700725ENTRY art_quick_aput_obj_with_null_and_bound_check
726 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700727 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700728 b art_quick_throw_null_pointer_exception
729END art_quick_aput_obj_with_null_and_bound_check
730
Dan Albert58bea4a2014-08-09 18:08:07 -0700731 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700732ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700733 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700734 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700735 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700736 mov r0, r1
737 mov r1, r3
738 b art_quick_throw_array_bounds
739END art_quick_aput_obj_with_bound_check
740
Man Cao1aee9002015-07-14 22:31:42 -0700741#ifdef USE_READ_BARRIER
742 .extern artReadBarrierSlow
743#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700744 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700745ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700746#ifdef USE_READ_BARRIER
747 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
748 tst r2, r2
749 beq .Ldo_aput_null
750#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800751 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700752#endif // USE_READ_BARRIER
753 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
754 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
755 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700756 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800757 bne .Lcheck_assignability
758.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700759 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700760 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700761 str r2, [r3, r1, lsl #2]
762 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
763 lsr r0, r0, #7
764 strb r3, [r3, r0]
765 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800766.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700767 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700768 str r2, [r3, r1, lsl #2]
769 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800770.Lcheck_assignability:
771 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700772 .cfi_adjust_cfa_offset 16
773 .cfi_rel_offset r0, 0
774 .cfi_rel_offset r1, 4
775 .cfi_rel_offset r2, 8
776 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700777 mov r1, ip
778 mov r0, r3
779 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800780 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700781 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700782 .cfi_restore r0
783 .cfi_restore r1
784 .cfi_restore r2
785 .cfi_restore lr
786 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700787 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700788 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700789 str r2, [r3, r1, lsl #2]
790 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
791 lsr r0, r0, #7
792 strb r3, [r3, r0]
793 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800794.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700795 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700796 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100797 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700798 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700799 mov r2, r9 @ pass Thread::Current
800 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
801 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700802END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700803
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800804// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100805.macro ONE_ARG_DOWNCALL name, entrypoint, return
806 .extern \entrypoint
807ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100808 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100809 mov r1, r9 @ pass Thread::Current
810 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
811 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
812 \return
813END \name
814.endm
815
816// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800817.macro TWO_ARG_DOWNCALL name, entrypoint, return
818 .extern \entrypoint
819ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100820 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800821 mov r2, r9 @ pass Thread::Current
822 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700823 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800824 \return
825END \name
826.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700827
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800828// Macro to facilitate adding new array allocation entrypoints.
829.macro THREE_ARG_DOWNCALL name, entrypoint, return
830 .extern \entrypoint
831ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100832 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800833 mov r3, r9 @ pass Thread::Current
834 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
835 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700836 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800837 \return
838END \name
839.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700840
Jeff Hao848f70a2014-01-15 13:49:50 -0800841// Macro to facilitate adding new allocation entrypoints.
842.macro FOUR_ARG_DOWNCALL name, entrypoint, return
843 .extern \entrypoint
844ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100845 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800846 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800847 .cfi_adjust_cfa_offset 16
848 bl \entrypoint
849 add sp, #16 @ strip the extra frame
850 .cfi_adjust_cfa_offset -16
851 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
852 \return
853END \name
854.endm
855
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100856ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
857ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
858ONE_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 -0700859
Ian Rogersce9eca62011-10-07 17:11:03 -0700860 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700861 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700862 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700863ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
864ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
865ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
866ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
867ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
868ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700869 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700870 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700871 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800872 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700873ENTRY art_quick_get64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100874 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700875 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700876 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700877 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700878 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700879 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700880 cbnz r2, 1f @ success if no exception pending
881 bx lr @ return on success
8821:
Ian Rogersce9eca62011-10-07 17:11:03 -0700883 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700884END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700885
Ian Rogersce9eca62011-10-07 17:11:03 -0700886 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700887 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700888 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700889TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
890TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
891TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
892TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
893TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
894TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800895 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700896 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800897 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800898 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700899ENTRY art_quick_get64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100900 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700901 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -0800902 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700903 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700904 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700905 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700906 cbnz r2, 1f @ success if no exception pending
907 bx lr @ return on success
9081:
Ian Rogers1bddec32012-02-04 12:27:34 -0800909 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700910END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800911
Ian Rogers1bddec32012-02-04 12:27:34 -0800912 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700913 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800914 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700915TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
916TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
917TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
918TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -0700919 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700920 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100921 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -0700922 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800923 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700924ENTRY art_quick_set64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100925 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100926 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700927 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
928 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700929 .cfi_adjust_cfa_offset 16
930 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700931 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -0800932 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700933 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700934 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700935 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700936END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700937
Ian Rogersce9eca62011-10-07 17:11:03 -0700938 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700939 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700940 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700941THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
942THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
943THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
944THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -0800945 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700946 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800947 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700948 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700949ENTRY art_quick_set64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100950 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100951 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700952 ldr r12, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
953 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700954 .cfi_adjust_cfa_offset 12
955 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700956 .cfi_adjust_cfa_offset 4
957 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -0800958 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -0800959 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700960 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700961 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -0800962 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700963END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800964
Ian Rogers1bddec32012-02-04 12:27:34 -0800965 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -0700966 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100967 * exception on error. On success the String is returned. R0 holds the string index. The fast
968 * path check for hit in strings cache has already been performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700969 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100970ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb886da82011-09-23 16:27:54 -0700971
Mathieu Chartier7410f292013-11-24 13:17:35 -0800972// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700973GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -0800974
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700975// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
976ENTRY art_quick_alloc_object_rosalloc
977 // Fast path rosalloc allocation.
978 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
979 // r2, r3, r12: free.
980 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
981 // Load the class (r2)
982 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
983 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
984 // Check class status.
985 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
986 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
987 bne .Lart_quick_alloc_object_rosalloc_slow_path
988 // Add a fake dependence from the
989 // following access flag and size
990 // loads to the status load.
991 // This is to prevent those loads
992 // from being reordered above the
993 // status load and reading wrong
994 // values (an alternative is to use
995 // a load-acquire for the status).
996 eor r3, r3, r3
997 add r2, r2, r3
998 // Check access flags has
999 // kAccClassIsFinalizable
1000 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1001 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1002 bne .Lart_quick_alloc_object_rosalloc_slow_path
1003
1004 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1005 // allocation stack has room.
1006 // TODO: consider using ldrd.
1007 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1008 cmp r3, r12
1009 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1010
1011 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3)
1012 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1013 // local allocation
1014 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1015 // Compute the rosalloc bracket index
1016 // from the size.
1017 // Align up the size by the rosalloc
1018 // bracket quantum size and divide
1019 // by the quantum size and subtract
1020 // by 1. This code is a shorter but
1021 // equivalent version.
1022 sub r3, r3, #1
1023 lsr r3, r3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1024 // Load the rosalloc run (r12)
1025 add r12, r9, r3, lsl #POINTER_SIZE_SHIFT
1026 ldr r12, [r12, #THREAD_ROSALLOC_RUNS_OFFSET]
1027 // Load the free list head (r3). This
1028 // will be the return val.
1029 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1030 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1031 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1032 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1033 // and update the list head with the
1034 // next pointer.
1035 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1036 // Store the class pointer in the
1037 // header. This also overwrites the
1038 // next pointer. The offsets are
1039 // asserted to match.
1040#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1041#error "Class pointer needs to overwrite next pointer."
1042#endif
1043 POISON_HEAP_REF r2
1044 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
1045 // Push the new object onto the thread
1046 // local allocation stack and
1047 // increment the thread local
1048 // allocation stack top.
1049 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1050 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1051 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1052 // Decrement the size of the free list
1053 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1054 sub r1, #1
1055 // TODO: consider combining this store
1056 // and the list head store above using
1057 // strd.
1058 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1059 // Fence. This is "ish" not "ishst" so
1060 // that the code after this allocation
1061 // site will see the right values in
1062 // the fields of the class.
1063 // Alternatively we could use "ishst"
1064 // if we use load-acquire for the
1065 // class status load.)
1066 dmb ish
1067 mov r0, r3 // Set the return value and return.
1068 bx lr
1069
1070.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001071 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001072 mov r2, r9 @ pass Thread::Current
1073 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1074 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1075 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1076END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001077
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001078// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1079//
1080// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1081// Need to preserve r0 and r1 to the slow path.
1082.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1083 cbz r2, \slowPathLabel // Check null class
1084 // Check class status.
1085 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1086 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1087 bne \slowPathLabel
1088 // Add a fake dependence from the
1089 // following access flag and size
1090 // loads to the status load.
1091 // This is to prevent those loads
1092 // from being reordered above the
1093 // status load and reading wrong
1094 // values (an alternative is to use
1095 // a load-acquire for the status).
1096 eor r3, r3, r3
1097 add r2, r2, r3
1098 // Check access flags has
1099 // kAccClassIsFinalizable.
1100 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1101 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1102 bne \slowPathLabel
1103 // Load thread_local_pos (r12) and
1104 // thread_local_end (r3) with ldrd.
1105 // Check constraints for ldrd.
1106#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1107#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1108#endif
1109 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1110 sub r12, r3, r12 // Compute the remaining buf size.
1111 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
1112 cmp r3, r12 // Check if it fits. OK to do this
1113 // before rounding up the object size
1114 // assuming the buf size alignment.
1115 bhi \slowPathLabel
1116 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1117 // Round up the object size by the
1118 // object alignment. (addr + 7) & ~7.
1119 add r3, r3, #OBJECT_ALIGNMENT_MASK
1120 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1121 // Reload old thread_local_pos (r0)
1122 // for the return value.
1123 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1124 add r1, r0, r3
1125 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1126 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1127 add r1, r1, #1
1128 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1129 POISON_HEAP_REF r2
1130 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1131 // Fence. This is "ish" not "ishst" so
1132 // that the code after this allocation
1133 // site will see the right values in
1134 // the fields of the class.
1135 // Alternatively we could use "ishst"
1136 // if we use load-acquire for the
1137 // class status load.)
1138 dmb ish
1139 bx lr
1140.endm
1141
1142// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1143ENTRY art_quick_alloc_object_tlab
1144 // Fast path tlab allocation.
1145 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1146 // r2, r3, r12: free.
1147#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001148 mvn r0, #0 // Read barrier not supported here.
1149 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001150#endif
1151 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1152 // Load the class (r2)
1153 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1154 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1155.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001156 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001157 mov r2, r9 // Pass Thread::Current.
1158 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1159 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1160 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1161END art_quick_alloc_object_tlab
1162
1163// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1164ENTRY art_quick_alloc_object_region_tlab
1165 // Fast path tlab allocation.
1166 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1167#if !defined(USE_READ_BARRIER)
1168 eor r0, r0, r0 // Read barrier must be enabled here.
1169 sub r0, r0, #1 // Return -1.
1170 bx lr
1171#endif
1172 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1173 // Load the class (r2)
1174 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1175 // Read barrier for class load.
1176 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
1177 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1178.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1179 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1180.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1181 // The read barrier slow path. Mark
1182 // the class.
1183 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1184 // to align sp by 16 bytes.
1185 mov r0, r2 // Pass the class as the first param.
1186 bl artReadBarrierMark
1187 mov r2, r0 // Get the (marked) class back.
1188 pop {r0, r1, r3, lr}
1189 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1190.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001191 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001192 mov r2, r9 // Pass Thread::Current.
1193 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1194 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1195 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1196END art_quick_alloc_object_region_tlab
1197
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001198 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001199 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001200 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001201 .extern artTestSuspendFromCode
1202ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001203#ifdef ARM_R4_SUSPEND_FLAG
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001204 ldrh r0, [rSELF, #THREAD_FLAGS_OFFSET]
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001205 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Ian Rogers637859c2013-08-27 14:35:54 -07001206 cbnz r0, 1f @ check Thread::Current()->suspend_count_ == 0
1207 bx lr @ return if suspend_count_ == 0
12081:
Wei Jin04f4d8a2014-05-29 18:04:29 -07001209#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001210 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001211 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for GC stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001212 @ TODO: save FPRs to enable access in the debugger?
1213 bl artTestSuspendFromCode @ (Thread*)
1214 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogers9329bbb2013-02-08 19:56:30 -08001215END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001216
Dave Allison83252962014-04-03 16:33:48 -07001217ENTRY art_quick_implicit_suspend
1218 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001219 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001220 bl artTestSuspendFromCode @ (Thread*)
1221 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001222END art_quick_implicit_suspend
1223
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001224 /*
1225 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001226 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1227 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001228 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001229 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001230ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001231 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001232 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001233 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001234 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001235 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001236 // Tear down the callee-save frame. Skip arg registers.
1237 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1238 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001239 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001240 cbnz r2, 1f @ success if no exception is pending
1241 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001242 bx lr @ return on success
12431:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001244 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001245END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001246
Jeff Hao88474b42013-10-23 16:24:40 -07001247 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001248 * Called to resolve an imt conflict.
1249 * r0 is the conflict ArtMethod.
1250 * r12 is a hidden argument that holds the target interface method's dex method index.
1251 *
1252 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001253 */
1254ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001255 ldr r4, [sp, #0] // Load referrer
1256 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1257 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1258 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1259 ldr r4, [r0] // Load first entry in ImtConflictTable.
1260.Limt_table_iterate:
1261 cmp r4, r12
1262 // Branch if found. Benchmarks have shown doing a branch here is better.
1263 beq .Limt_table_found
1264 // If the entry is null, the interface method is not in the ImtConflictTable.
1265 cbz r4, .Lconflict_trampoline
1266 // Iterate over the entries of the ImtConflictTable.
1267 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1268 b .Limt_table_iterate
1269.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001270 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001271 // and jump to it.
1272 ldr r0, [r0, #__SIZEOF_POINTER__]
1273 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1274.Lconflict_trampoline:
1275 // Call the runtime stub to populate the ImtConflictTable and jump to the
1276 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001277 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001278END art_quick_imt_conflict_trampoline
1279
Ian Rogers468532e2013-08-05 10:56:33 -07001280 .extern artQuickResolutionTrampoline
1281ENTRY art_quick_resolution_trampoline
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001282 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001283 mov r2, r9 @ pass Thread::Current
1284 mov r3, sp @ pass SP
1285 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001286 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001287 mov r12, r0
1288 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001289 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001290 bx r12 @ tail-call into actual code
12911:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001292 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001293 DELIVER_PENDING_EXCEPTION
1294END art_quick_resolution_trampoline
1295
Andreas Gampec200a4a2014-06-16 18:39:09 -07001296 /*
1297 * Called to do a generic JNI down-call
1298 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001299ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001300 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001301
1302 // Save rSELF
1303 mov r11, rSELF
1304 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1305 mov r10, sp
1306 .cfi_def_cfa_register r10
1307
1308 sub sp, sp, #5120
1309
1310 // prepare for artQuickGenericJniTrampoline call
1311 // (Thread*, SP)
1312 // r0 r1 <= C calling convention
1313 // rSELF r10 <= where they are
1314
1315 mov r0, rSELF // Thread*
1316 mov r1, r10
1317 blx artQuickGenericJniTrampoline // (Thread*, sp)
1318
1319 // The C call will have registered the complete save-frame on success.
1320 // The result of the call is:
1321 // r0: pointer to native code, 0 on error.
1322 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1323
1324 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001325 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001326
1327 // Release part of the alloca.
1328 mov sp, r1
1329
1330 // Save the code pointer
1331 mov r12, r0
1332
1333 // Load parameters from frame into registers.
1334 pop {r0-r3}
1335
1336 // Softfloat.
1337 // TODO: Change to hardfloat when supported.
1338
1339 blx r12 // native call.
1340
1341 // result sign extension is handled in C code
1342 // prepare for artQuickGenericJniEndTrampoline call
1343 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001344 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001345 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001346 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001347
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001348 push {r0-r1}
1349 mov r3, r1
1350 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001351 mov r0, r11
1352
1353 blx artQuickGenericJniEndTrampoline
1354
Andreas Gampec200a4a2014-06-16 18:39:09 -07001355 // Restore self pointer.
1356 mov r9, r11
1357
1358 // Pending exceptions possible.
1359 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1360 cbnz r2, .Lexception_in_native
1361
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001362 // Tear down the alloca.
1363 mov sp, r10
1364 .cfi_def_cfa_register sp
1365
Zheng Xu5667fdb2014-10-23 18:29:55 +08001366 // Tear down the callee-save frame. Skip arg registers.
1367 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1368 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1369 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001370
Zheng Xu5667fdb2014-10-23 18:29:55 +08001371 // store into fpr, for when it's a fpr return...
1372 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001373 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001374 // Undo the unwinding information from above since it doesn't apply below.
1375 .cfi_def_cfa_register r10
1376 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001377
Andreas Gampec200a4a2014-06-16 18:39:09 -07001378.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001379 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1380 .cfi_def_cfa_register sp
1381 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001382 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001383END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001384
Ian Rogers468532e2013-08-05 10:56:33 -07001385 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001386ENTRY art_quick_to_interpreter_bridge
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001387 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001388 mov r1, r9 @ pass Thread::Current
1389 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001390 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001391 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001392 // Tear down the callee-save frame. Skip arg registers.
1393 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1394 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001395 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001396 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001397 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1398 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070013991:
Ian Rogers7db619b2013-01-16 18:35:48 -08001400 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001401END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001402
jeffhaoe343b762011-12-05 16:36:44 -08001403 /*
jeffhao0791adc2012-04-04 11:14:32 -07001404 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001405 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001406 .extern artInstrumentationMethodEntryFromCode
1407 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001408ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001409 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001410 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001411 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1412 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001413 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001414 mov r3, lr @ pass LR
1415 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001416 mov r12, r0 @ r12 holds reference to code
1417 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001418 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001419 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001420@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001421 .type art_quick_instrumentation_exit, #function
1422 .global art_quick_instrumentation_exit
1423art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001424 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001425 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ set up frame knowing r2 and r3 must be dead on exit
Ian Rogers306057f2012-11-26 12:45:53 -08001426 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001427 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001428 .cfi_adjust_cfa_offset 8
1429 .cfi_rel_offset r0, 0
1430 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001431 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001432 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001433 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1434 @ need to align by 16.
1435 .cfi_adjust_cfa_offset 8
1436 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001437 mov r2, r0 @ pass return value as gpr_res
1438 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001439 mov r0, r9 @ pass Thread::Current
1440 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001441 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001442 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001443 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001444
Ian Rogers306057f2012-11-26 12:45:53 -08001445 mov r2, r0 @ link register saved by instrumentation
1446 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001447 vpop {d0} @ restore fp return value
1448 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001449 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001450 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001451 .cfi_restore r0
1452 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001453 add sp, #32 @ remove callee save frame
1454 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001455 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001456END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001457
Ian Rogers306057f2012-11-26 12:45:53 -08001458 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001459 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1460 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001461 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001462 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001463ENTRY art_quick_deoptimize
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001464 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001465 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001466 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001467END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001468
Ian Rogers324e1902012-09-09 12:17:52 -07001469 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001470 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001471 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001472 */
1473 .extern artDeoptimizeFromCompiledCode
1474ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001475 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001476 mov r0, r9 @ Set up args.
1477 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1478END art_quick_deoptimize_from_compiled_code
1479
1480 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001481 * Signed 64-bit integer multiply.
1482 *
1483 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1484 * WX
1485 * x YZ
1486 * --------
1487 * ZW ZX
1488 * YW YX
1489 *
1490 * The low word of the result holds ZX, the high word holds
1491 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1492 * it doesn't fit in the low 64 bits.
1493 *
1494 * Unlike most ARM math operations, multiply instructions have
1495 * restrictions on using the same register more than once (Rd and Rm
1496 * cannot be the same).
1497 */
1498 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001499ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001500 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001501 .cfi_adjust_cfa_offset 8
1502 .cfi_rel_offset r9, 0
1503 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001504 mul ip, r2, r1 @ ip<- ZxW
1505 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1506 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1507 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1508 mov r0,r9
1509 mov r1,r10
1510 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001511 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001512 .cfi_restore r9
1513 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001514 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001515END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001516
buzbee54330722011-08-23 16:46:55 -07001517 /*
1518 * Long integer shift. This is different from the generic 32/64-bit
1519 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1520 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1521 * 6 bits.
1522 * On entry:
1523 * r0: low word
1524 * r1: high word
1525 * r2: shift count
1526 */
1527 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001528ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001529 and r2, r2, #63 @ r2<- r2 & 0x3f
1530 mov r1, r1, asl r2 @ r1<- r1 << r2
1531 rsb r3, r2, #32 @ r3<- 32 - r2
1532 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1533 subs ip, r2, #32 @ ip<- r2 - 32
1534 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1535 mov r0, r0, asl r2 @ r0<- r0 << r2
1536 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001537END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001538
buzbee54330722011-08-23 16:46:55 -07001539 /*
1540 * Long integer shift. This is different from the generic 32/64-bit
1541 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1542 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1543 * 6 bits.
1544 * On entry:
1545 * r0: low word
1546 * r1: high word
1547 * r2: shift count
1548 */
1549 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001550ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001551 and r2, r2, #63 @ r0<- r0 & 0x3f
1552 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1553 rsb r3, r2, #32 @ r3<- 32 - r2
1554 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1555 subs ip, r2, #32 @ ip<- r2 - 32
1556 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1557 mov r1, r1, asr r2 @ r1<- r1 >> r2
1558 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001559END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001560
buzbee54330722011-08-23 16:46:55 -07001561 /*
1562 * Long integer shift. This is different from the generic 32/64-bit
1563 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1564 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1565 * 6 bits.
1566 * On entry:
1567 * r0: low word
1568 * r1: high word
1569 * r2: shift count
1570 */
1571 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001572ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001573 and r2, r2, #63 @ r0<- r0 & 0x3f
1574 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1575 rsb r3, r2, #32 @ r3<- 32 - r2
1576 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1577 subs ip, r2, #32 @ ip<- r2 - 32
1578 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1579 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1580 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001581END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001582
buzbeefc9e6fa2012-03-23 15:14:29 -07001583 /*
1584 * String's indexOf.
1585 *
1586 * On entry:
1587 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001588 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001589 * r2: Starting offset in string data
1590 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001591ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001592 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001593 .cfi_adjust_cfa_offset 16
1594 .cfi_rel_offset r4, 0
1595 .cfi_rel_offset r10, 4
1596 .cfi_rel_offset r11, 8
1597 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001598 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001599 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001600
1601 /* Clamp start to [0..count] */
1602 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001603 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001604 movlt r2, #0
1605 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001606 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001607 movgt r2, r3
1608
buzbeefc9e6fa2012-03-23 15:14:29 -07001609 /* Save a copy in r12 to later compute result */
1610 mov r12, r0
1611
1612 /* Build pointer to start of data to compare and pre-bias */
1613 add r0, r0, r2, lsl #1
1614 sub r0, #2
1615
1616 /* Compute iteration count */
1617 sub r2, r3, r2
1618
1619 /*
1620 * At this point we have:
1621 * r0: start of data to test
1622 * r1: char to compare
1623 * r2: iteration count
1624 * r12: original start of string data
1625 * r3, r4, r10, r11 available for loading string data
1626 */
1627
1628 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001629 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001630
Ian Rogers5d885c82014-02-21 20:06:23 -08001631.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001632 ldrh r3, [r0, #2]!
1633 ldrh r4, [r0, #2]!
1634 ldrh r10, [r0, #2]!
1635 ldrh r11, [r0, #2]!
1636 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001637 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001638 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001639 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001640 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001641 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001642 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001643 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001644 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001645 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001646
Ian Rogers5d885c82014-02-21 20:06:23 -08001647.Lindexof_remainder:
1648 adds r2, #4
1649 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001650
Ian Rogers5d885c82014-02-21 20:06:23 -08001651.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001652 ldrh r3, [r0, #2]!
1653 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001654 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001655 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001656 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001657
Ian Rogers5d885c82014-02-21 20:06:23 -08001658.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001659 mov r0, #-1
1660 pop {r4, r10-r11, pc}
1661
Ian Rogers5d885c82014-02-21 20:06:23 -08001662.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001663 sub r0, #6
1664 sub r0, r12
1665 asr r0, r0, #1
1666 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001667.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001668 sub r0, #4
1669 sub r0, r12
1670 asr r0, r0, #1
1671 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001672.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001673 sub r0, #2
1674 sub r0, r12
1675 asr r0, r0, #1
1676 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001677.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001678 sub r0, r12
1679 asr r0, r0, #1
1680 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001681END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001682
Zheng Xu5667fdb2014-10-23 18:29:55 +08001683 /* Assembly routines used to handle ABI differences. */
1684
1685 /* double fmod(double a, double b) */
1686 .extern fmod
1687ENTRY art_quick_fmod
1688 push {lr}
1689 .cfi_adjust_cfa_offset 4
1690 .cfi_rel_offset lr, 0
1691 sub sp, #4
1692 .cfi_adjust_cfa_offset 4
1693 vmov r0, r1, d0
1694 vmov r2, r3, d1
1695 bl fmod
1696 vmov d0, r0, r1
1697 add sp, #4
1698 .cfi_adjust_cfa_offset -4
1699 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001700END art_quick_fmod
1701
1702 /* float fmodf(float a, float b) */
1703 .extern fmodf
1704ENTRY art_quick_fmodf
1705 push {lr}
1706 .cfi_adjust_cfa_offset 4
1707 .cfi_rel_offset lr, 0
1708 sub sp, #4
1709 .cfi_adjust_cfa_offset 4
1710 vmov r0, r1, d0
1711 bl fmodf
1712 vmov s0, r0
1713 add sp, #4
1714 .cfi_adjust_cfa_offset -4
1715 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001716END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001717
1718 /* int64_t art_d2l(double d) */
1719 .extern art_d2l
1720ENTRY art_quick_d2l
1721 vmov r0, r1, d0
1722 b art_d2l
1723END art_quick_d2l
1724
1725 /* int64_t art_f2l(float f) */
1726 .extern art_f2l
1727ENTRY art_quick_f2l
1728 vmov r0, s0
1729 b art_f2l
1730END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001731
1732 /* float art_l2f(int64_t l) */
1733 .extern art_l2f
1734ENTRY art_quick_l2f
1735 push {lr}
1736 .cfi_adjust_cfa_offset 4
1737 .cfi_rel_offset lr, 0
1738 sub sp, #4
1739 .cfi_adjust_cfa_offset 4
1740 bl art_l2f
1741 vmov s0, r0
1742 add sp, #4
1743 .cfi_adjust_cfa_offset -4
1744 pop {pc}
1745END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001746
1747 /*
1748 * Create a function `name` calling the ReadBarrier::Mark routine,
1749 * getting its argument and returning its result through register
1750 * `reg`, thus following a non-standard runtime calling convention:
1751 * - `reg` is used to pass the (sole) argument of this function
1752 * (instead of R0);
1753 * - `reg` is used to return the result of this function (instead of R0);
1754 * - R0 is treated like a normal (non-argument) caller-save register;
1755 * - everything else is the same as in the standard runtime calling
1756 * convention (e.g. same callee-save registers).
1757 */
1758.macro READ_BARRIER_MARK_REG name, reg
1759ENTRY \name
1760 push {lr} @ save return address
1761 .cfi_adjust_cfa_offset 4
1762 .cfi_rel_offset lr, 0
1763 sub sp, #4 @ push padding (native calling convention 8-byte alignment)
1764 .cfi_adjust_cfa_offset 4
1765 mov r0, \reg @ pass arg1 - obj from `reg`
1766 bl artReadBarrierMark @ artReadBarrierMark(obj)
1767 mov \reg, r0 @ return result into `reg`
1768 add sp, #4 @ pop padding
1769 .cfi_adjust_cfa_offset -4
1770 pop {pc} @ return
1771END \name
1772.endm
1773
1774READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1775READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1776READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1777READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1778READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1779READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1780READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1781READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1782READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1783READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1784READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11
1785READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, r12