blob: 34d3158c62f14092b3263566e5859275da34ffa0 [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
Roland Levillain4359e612016-07-20 11:32:19 +0100675// Save rReg's value to [sp, #offset].
676.macro PUSH_REG rReg, offset
677 str \rReg, [sp, #\offset] @ save rReg
678 .cfi_rel_offset \rReg, \offset
679.endm
680
Man Cao1aee9002015-07-14 22:31:42 -0700681 /*
682 * Macro to insert read barrier, only used in art_quick_aput_obj.
683 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
684 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
685 */
686.macro READ_BARRIER rDest, rObj, offset
687#ifdef USE_READ_BARRIER
688 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
689 .cfi_adjust_cfa_offset 24
690 .cfi_rel_offset r0, 0
691 .cfi_rel_offset r1, 4
692 .cfi_rel_offset r2, 8
693 .cfi_rel_offset r3, 12
694 .cfi_rel_offset ip, 16
695 .cfi_rel_offset lr, 20
696 sub sp, #8 @ push padding
697 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700698 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700699 .ifnc \rObj, r1
700 mov r1, \rObj @ pass rObj
701 .endif
702 mov r2, #\offset @ pass offset
703 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
704 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
705 .ifnc \rDest, r0
706 mov \rDest, r0 @ save return value in rDest
707 .endif
708 add sp, #8 @ pop padding
709 .cfi_adjust_cfa_offset -8
710 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
711 POP_REG_NE r1, 4, \rDest
712 POP_REG_NE r2, 8, \rDest
713 POP_REG_NE r3, 12, \rDest
714 POP_REG_NE ip, 16, \rDest
715 add sp, #20
716 .cfi_adjust_cfa_offset -20
717 pop {lr} @ restore lr
718 .cfi_adjust_cfa_offset -4
719 .cfi_restore lr
720#else
721 ldr \rDest, [\rObj, #\offset]
722 UNPOISON_HEAP_REF \rDest
723#endif // USE_READ_BARRIER
724.endm
725
Ian Rogerse51a5112011-09-23 14:16:35 -0700726 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700727 * Entry from managed code for array put operations of objects where the value being stored
728 * needs to be checked for compatibility.
729 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700730 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700731ENTRY art_quick_aput_obj_with_null_and_bound_check
732 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700733 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700734 b art_quick_throw_null_pointer_exception
735END art_quick_aput_obj_with_null_and_bound_check
736
Dan Albert58bea4a2014-08-09 18:08:07 -0700737 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700738ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700739 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700740 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700741 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700742 mov r0, r1
743 mov r1, r3
744 b art_quick_throw_array_bounds
745END art_quick_aput_obj_with_bound_check
746
Man Cao1aee9002015-07-14 22:31:42 -0700747#ifdef USE_READ_BARRIER
748 .extern artReadBarrierSlow
749#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700750 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700751ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700752#ifdef USE_READ_BARRIER
753 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
754 tst r2, r2
755 beq .Ldo_aput_null
756#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800757 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700758#endif // USE_READ_BARRIER
759 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
760 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
761 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700762 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800763 bne .Lcheck_assignability
764.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700765 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700766 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700767 str r2, [r3, r1, lsl #2]
768 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
769 lsr r0, r0, #7
770 strb r3, [r3, r0]
771 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800772.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700773 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700774 str r2, [r3, r1, lsl #2]
775 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800776.Lcheck_assignability:
777 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700778 .cfi_adjust_cfa_offset 16
779 .cfi_rel_offset r0, 0
780 .cfi_rel_offset r1, 4
781 .cfi_rel_offset r2, 8
782 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700783 mov r1, ip
784 mov r0, r3
785 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800786 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700787 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700788 .cfi_restore r0
789 .cfi_restore r1
790 .cfi_restore r2
791 .cfi_restore lr
792 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700793 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700794 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700795 str r2, [r3, r1, lsl #2]
796 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
797 lsr r0, r0, #7
798 strb r3, [r3, r0]
799 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800800.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700801 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700802 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100803 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700804 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700805 mov r2, r9 @ pass Thread::Current
806 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
807 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700808END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700809
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800810// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100811.macro ONE_ARG_DOWNCALL name, entrypoint, return
812 .extern \entrypoint
813ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100814 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100815 mov r1, r9 @ pass Thread::Current
816 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
817 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
818 \return
819END \name
820.endm
821
822// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800823.macro TWO_ARG_DOWNCALL name, entrypoint, return
824 .extern \entrypoint
825ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100826 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800827 mov r2, r9 @ pass Thread::Current
828 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700829 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800830 \return
831END \name
832.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700833
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800834// Macro to facilitate adding new array allocation entrypoints.
835.macro THREE_ARG_DOWNCALL name, entrypoint, return
836 .extern \entrypoint
837ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100838 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800839 mov r3, r9 @ pass Thread::Current
840 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
841 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700842 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800843 \return
844END \name
845.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700846
Jeff Hao848f70a2014-01-15 13:49:50 -0800847// Macro to facilitate adding new allocation entrypoints.
848.macro FOUR_ARG_DOWNCALL name, entrypoint, return
849 .extern \entrypoint
850ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100851 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800852 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800853 .cfi_adjust_cfa_offset 16
854 bl \entrypoint
855 add sp, #16 @ strip the extra frame
856 .cfi_adjust_cfa_offset -16
857 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
858 \return
859END \name
860.endm
861
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100862ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
863ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
864ONE_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 -0700865
Ian Rogersce9eca62011-10-07 17:11:03 -0700866 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700867 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700868 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700869ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
870ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
871ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
872ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
873ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
874ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700875 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700876 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700877 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800878 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700879ENTRY art_quick_get64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100880 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700881 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700882 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700883 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700884 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700885 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700886 cbnz r2, 1f @ success if no exception pending
887 bx lr @ return on success
8881:
Ian Rogersce9eca62011-10-07 17:11:03 -0700889 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700890END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700891
Ian Rogersce9eca62011-10-07 17:11:03 -0700892 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700893 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700894 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700895TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
896TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
897TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
898TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
899TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
900TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800901 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700902 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800903 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800904 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700905ENTRY art_quick_get64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100906 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700907 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -0800908 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700909 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700910 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700911 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700912 cbnz r2, 1f @ success if no exception pending
913 bx lr @ return on success
9141:
Ian Rogers1bddec32012-02-04 12:27:34 -0800915 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700916END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800917
Ian Rogers1bddec32012-02-04 12:27:34 -0800918 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700919 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800920 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700921TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
922TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
923TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
924TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -0700925 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700926 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100927 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -0700928 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800929 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700930ENTRY art_quick_set64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100931 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100932 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700933 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
934 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700935 .cfi_adjust_cfa_offset 16
936 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700937 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -0800938 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700939 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700940 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700941 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700942END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700943
Ian Rogersce9eca62011-10-07 17:11:03 -0700944 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700945 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700946 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700947THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
948THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
949THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
950THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -0800951 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700952 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800953 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700954 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700955ENTRY art_quick_set64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100956 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100957 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700958 ldr r12, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
959 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700960 .cfi_adjust_cfa_offset 12
961 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700962 .cfi_adjust_cfa_offset 4
963 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -0800964 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -0800965 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700966 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700967 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -0800968 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700969END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800970
Ian Rogers1bddec32012-02-04 12:27:34 -0800971 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -0700972 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100973 * exception on error. On success the String is returned. R0 holds the string index. The fast
974 * path check for hit in strings cache has already been performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700975 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100976ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb886da82011-09-23 16:27:54 -0700977
Mathieu Chartier7410f292013-11-24 13:17:35 -0800978// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700979GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -0800980
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700981// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
982ENTRY art_quick_alloc_object_rosalloc
983 // Fast path rosalloc allocation.
984 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
985 // r2, r3, r12: free.
986 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
987 // Load the class (r2)
988 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
989 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
990 // Check class status.
991 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
992 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
993 bne .Lart_quick_alloc_object_rosalloc_slow_path
994 // Add a fake dependence from the
995 // following access flag and size
996 // loads to the status load.
997 // This is to prevent those loads
998 // from being reordered above the
999 // status load and reading wrong
1000 // values (an alternative is to use
1001 // a load-acquire for the status).
1002 eor r3, r3, r3
1003 add r2, r2, r3
1004 // Check access flags has
1005 // kAccClassIsFinalizable
1006 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1007 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1008 bne .Lart_quick_alloc_object_rosalloc_slow_path
1009
1010 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1011 // allocation stack has room.
1012 // TODO: consider using ldrd.
1013 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1014 cmp r3, r12
1015 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1016
1017 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3)
1018 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1019 // local allocation
1020 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1021 // Compute the rosalloc bracket index
1022 // from the size.
1023 // Align up the size by the rosalloc
1024 // bracket quantum size and divide
1025 // by the quantum size and subtract
1026 // by 1. This code is a shorter but
1027 // equivalent version.
1028 sub r3, r3, #1
1029 lsr r3, r3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1030 // Load the rosalloc run (r12)
1031 add r12, r9, r3, lsl #POINTER_SIZE_SHIFT
1032 ldr r12, [r12, #THREAD_ROSALLOC_RUNS_OFFSET]
1033 // Load the free list head (r3). This
1034 // will be the return val.
1035 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1036 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1037 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1038 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1039 // and update the list head with the
1040 // next pointer.
1041 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1042 // Store the class pointer in the
1043 // header. This also overwrites the
1044 // next pointer. The offsets are
1045 // asserted to match.
1046#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1047#error "Class pointer needs to overwrite next pointer."
1048#endif
1049 POISON_HEAP_REF r2
1050 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001051 // Fence. This is "ish" not "ishst" so
1052 // that it also ensures ordering of
1053 // the class status load with respect
1054 // to later accesses to the class
1055 // object. Alternatively we could use
1056 // "ishst" if we use load-acquire for
1057 // the class status load.)
1058 // Needs to be done before pushing on
1059 // allocation since Heap::VisitObjects
1060 // relies on seeing the class pointer.
1061 // b/28790624
1062 dmb ish
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001063 // Push the new object onto the thread
1064 // local allocation stack and
1065 // increment the thread local
1066 // allocation stack top.
1067 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1068 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1069 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1070 // Decrement the size of the free list
1071 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1072 sub r1, #1
1073 // TODO: consider combining this store
1074 // and the list head store above using
1075 // strd.
1076 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001077
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001078 mov r0, r3 // Set the return value and return.
1079 bx lr
1080
1081.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001082 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001083 mov r2, r9 @ pass Thread::Current
1084 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1085 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1086 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1087END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001088
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001089// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1090//
1091// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1092// Need to preserve r0 and r1 to the slow path.
1093.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1094 cbz r2, \slowPathLabel // Check null class
1095 // Check class status.
1096 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1097 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1098 bne \slowPathLabel
1099 // Add a fake dependence from the
1100 // following access flag and size
1101 // loads to the status load.
1102 // This is to prevent those loads
1103 // from being reordered above the
1104 // status load and reading wrong
1105 // values (an alternative is to use
1106 // a load-acquire for the status).
1107 eor r3, r3, r3
1108 add r2, r2, r3
1109 // Check access flags has
1110 // kAccClassIsFinalizable.
1111 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1112 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1113 bne \slowPathLabel
1114 // Load thread_local_pos (r12) and
1115 // thread_local_end (r3) with ldrd.
1116 // Check constraints for ldrd.
1117#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1118#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1119#endif
1120 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1121 sub r12, r3, r12 // Compute the remaining buf size.
1122 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
1123 cmp r3, r12 // Check if it fits. OK to do this
1124 // before rounding up the object size
1125 // assuming the buf size alignment.
1126 bhi \slowPathLabel
1127 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1128 // Round up the object size by the
1129 // object alignment. (addr + 7) & ~7.
1130 add r3, r3, #OBJECT_ALIGNMENT_MASK
1131 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1132 // Reload old thread_local_pos (r0)
1133 // for the return value.
1134 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1135 add r1, r0, r3
1136 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1137 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1138 add r1, r1, #1
1139 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1140 POISON_HEAP_REF r2
1141 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1142 // Fence. This is "ish" not "ishst" so
1143 // that the code after this allocation
1144 // site will see the right values in
1145 // the fields of the class.
1146 // Alternatively we could use "ishst"
1147 // if we use load-acquire for the
1148 // class status load.)
1149 dmb ish
1150 bx lr
1151.endm
1152
1153// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1154ENTRY art_quick_alloc_object_tlab
1155 // Fast path tlab allocation.
1156 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1157 // r2, r3, r12: free.
1158#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001159 mvn r0, #0 // Read barrier not supported here.
1160 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001161#endif
1162 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1163 // Load the class (r2)
1164 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1165 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1166.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001167 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001168 mov r2, r9 // Pass Thread::Current.
1169 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1170 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1171 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1172END art_quick_alloc_object_tlab
1173
1174// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1175ENTRY art_quick_alloc_object_region_tlab
1176 // Fast path tlab allocation.
1177 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1178#if !defined(USE_READ_BARRIER)
1179 eor r0, r0, r0 // Read barrier must be enabled here.
1180 sub r0, r0, #1 // Return -1.
1181 bx lr
1182#endif
1183 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1184 // Load the class (r2)
1185 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1186 // Read barrier for class load.
1187 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
1188 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1189.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1190 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1191.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1192 // The read barrier slow path. Mark
1193 // the class.
1194 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1195 // to align sp by 16 bytes.
1196 mov r0, r2 // Pass the class as the first param.
1197 bl artReadBarrierMark
1198 mov r2, r0 // Get the (marked) class back.
1199 pop {r0, r1, r3, lr}
1200 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1201.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001202 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001203 mov r2, r9 // Pass Thread::Current.
1204 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1205 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1206 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1207END art_quick_alloc_object_region_tlab
1208
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001209 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001210 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001211 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001212 .extern artTestSuspendFromCode
1213ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001214#ifdef ARM_R4_SUSPEND_FLAG
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001215 ldrh r0, [rSELF, #THREAD_FLAGS_OFFSET]
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001216 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Ian Rogers637859c2013-08-27 14:35:54 -07001217 cbnz r0, 1f @ check Thread::Current()->suspend_count_ == 0
1218 bx lr @ return if suspend_count_ == 0
12191:
Wei Jin04f4d8a2014-05-29 18:04:29 -07001220#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001221 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001222 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for GC stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001223 @ TODO: save FPRs to enable access in the debugger?
1224 bl artTestSuspendFromCode @ (Thread*)
1225 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogers9329bbb2013-02-08 19:56:30 -08001226END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001227
Dave Allison83252962014-04-03 16:33:48 -07001228ENTRY art_quick_implicit_suspend
1229 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001230 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001231 bl artTestSuspendFromCode @ (Thread*)
1232 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001233END art_quick_implicit_suspend
1234
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001235 /*
1236 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001237 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1238 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001239 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001240 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001241ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001242 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001243 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001244 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001245 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001246 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001247 // Tear down the callee-save frame. Skip arg registers.
1248 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1249 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001250 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001251 cbnz r2, 1f @ success if no exception is pending
1252 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001253 bx lr @ return on success
12541:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001255 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001256END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001257
Jeff Hao88474b42013-10-23 16:24:40 -07001258 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001259 * Called to resolve an imt conflict.
1260 * r0 is the conflict ArtMethod.
1261 * r12 is a hidden argument that holds the target interface method's dex method index.
1262 *
1263 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001264 */
1265ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001266 ldr r4, [sp, #0] // Load referrer
1267 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1268 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1269 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1270 ldr r4, [r0] // Load first entry in ImtConflictTable.
1271.Limt_table_iterate:
1272 cmp r4, r12
1273 // Branch if found. Benchmarks have shown doing a branch here is better.
1274 beq .Limt_table_found
1275 // If the entry is null, the interface method is not in the ImtConflictTable.
1276 cbz r4, .Lconflict_trampoline
1277 // Iterate over the entries of the ImtConflictTable.
1278 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1279 b .Limt_table_iterate
1280.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001281 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001282 // and jump to it.
1283 ldr r0, [r0, #__SIZEOF_POINTER__]
1284 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1285.Lconflict_trampoline:
1286 // Call the runtime stub to populate the ImtConflictTable and jump to the
1287 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001288 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001289END art_quick_imt_conflict_trampoline
1290
Ian Rogers468532e2013-08-05 10:56:33 -07001291 .extern artQuickResolutionTrampoline
1292ENTRY art_quick_resolution_trampoline
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001293 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001294 mov r2, r9 @ pass Thread::Current
1295 mov r3, sp @ pass SP
1296 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001297 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001298 mov r12, r0
1299 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001300 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001301 bx r12 @ tail-call into actual code
13021:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001303 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001304 DELIVER_PENDING_EXCEPTION
1305END art_quick_resolution_trampoline
1306
Andreas Gampec200a4a2014-06-16 18:39:09 -07001307 /*
1308 * Called to do a generic JNI down-call
1309 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001310ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001311 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001312
1313 // Save rSELF
1314 mov r11, rSELF
1315 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1316 mov r10, sp
1317 .cfi_def_cfa_register r10
1318
1319 sub sp, sp, #5120
1320
1321 // prepare for artQuickGenericJniTrampoline call
1322 // (Thread*, SP)
1323 // r0 r1 <= C calling convention
1324 // rSELF r10 <= where they are
1325
1326 mov r0, rSELF // Thread*
1327 mov r1, r10
1328 blx artQuickGenericJniTrampoline // (Thread*, sp)
1329
1330 // The C call will have registered the complete save-frame on success.
1331 // The result of the call is:
1332 // r0: pointer to native code, 0 on error.
1333 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1334
1335 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001336 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001337
1338 // Release part of the alloca.
1339 mov sp, r1
1340
1341 // Save the code pointer
1342 mov r12, r0
1343
1344 // Load parameters from frame into registers.
1345 pop {r0-r3}
1346
1347 // Softfloat.
1348 // TODO: Change to hardfloat when supported.
1349
1350 blx r12 // native call.
1351
1352 // result sign extension is handled in C code
1353 // prepare for artQuickGenericJniEndTrampoline call
1354 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001355 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001356 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001357 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001358
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001359 push {r0-r1}
1360 mov r3, r1
1361 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001362 mov r0, r11
1363
1364 blx artQuickGenericJniEndTrampoline
1365
Andreas Gampec200a4a2014-06-16 18:39:09 -07001366 // Restore self pointer.
1367 mov r9, r11
1368
1369 // Pending exceptions possible.
1370 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1371 cbnz r2, .Lexception_in_native
1372
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001373 // Tear down the alloca.
1374 mov sp, r10
1375 .cfi_def_cfa_register sp
1376
Zheng Xu5667fdb2014-10-23 18:29:55 +08001377 // Tear down the callee-save frame. Skip arg registers.
1378 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1379 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1380 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001381
Zheng Xu5667fdb2014-10-23 18:29:55 +08001382 // store into fpr, for when it's a fpr return...
1383 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001384 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001385 // Undo the unwinding information from above since it doesn't apply below.
1386 .cfi_def_cfa_register r10
1387 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001388
Andreas Gampec200a4a2014-06-16 18:39:09 -07001389.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001390 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1391 .cfi_def_cfa_register sp
1392 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001393 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001394END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001395
Ian Rogers468532e2013-08-05 10:56:33 -07001396 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001397ENTRY art_quick_to_interpreter_bridge
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001398 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001399 mov r1, r9 @ pass Thread::Current
1400 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001401 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001402 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001403 // Tear down the callee-save frame. Skip arg registers.
1404 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1405 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001406 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001407 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001408 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1409 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014101:
Ian Rogers7db619b2013-01-16 18:35:48 -08001411 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001412END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001413
jeffhaoe343b762011-12-05 16:36:44 -08001414 /*
jeffhao0791adc2012-04-04 11:14:32 -07001415 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001416 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001417 .extern artInstrumentationMethodEntryFromCode
1418 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001419ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001420 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001421 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001422 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1423 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001424 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001425 mov r3, lr @ pass LR
1426 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001427 mov r12, r0 @ r12 holds reference to code
1428 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001429 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001430 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001431@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001432 .type art_quick_instrumentation_exit, #function
1433 .global art_quick_instrumentation_exit
1434art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001435 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001436 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 -08001437 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001438 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001439 .cfi_adjust_cfa_offset 8
1440 .cfi_rel_offset r0, 0
1441 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001442 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001443 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001444 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1445 @ need to align by 16.
1446 .cfi_adjust_cfa_offset 8
1447 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001448 mov r2, r0 @ pass return value as gpr_res
1449 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001450 mov r0, r9 @ pass Thread::Current
1451 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001452 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001453 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001454 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001455
Ian Rogers306057f2012-11-26 12:45:53 -08001456 mov r2, r0 @ link register saved by instrumentation
1457 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001458 vpop {d0} @ restore fp return value
1459 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001460 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001461 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001462 .cfi_restore r0
1463 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001464 add sp, #32 @ remove callee save frame
1465 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001466 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001467END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001468
Ian Rogers306057f2012-11-26 12:45:53 -08001469 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001470 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1471 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001472 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001473 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001474ENTRY art_quick_deoptimize
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001475 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001476 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001477 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001478END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001479
Ian Rogers324e1902012-09-09 12:17:52 -07001480 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001481 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001482 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001483 */
1484 .extern artDeoptimizeFromCompiledCode
1485ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001486 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001487 mov r0, r9 @ Set up args.
1488 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1489END art_quick_deoptimize_from_compiled_code
1490
1491 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001492 * Signed 64-bit integer multiply.
1493 *
1494 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1495 * WX
1496 * x YZ
1497 * --------
1498 * ZW ZX
1499 * YW YX
1500 *
1501 * The low word of the result holds ZX, the high word holds
1502 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1503 * it doesn't fit in the low 64 bits.
1504 *
1505 * Unlike most ARM math operations, multiply instructions have
1506 * restrictions on using the same register more than once (Rd and Rm
1507 * cannot be the same).
1508 */
1509 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001510ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001511 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001512 .cfi_adjust_cfa_offset 8
1513 .cfi_rel_offset r9, 0
1514 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001515 mul ip, r2, r1 @ ip<- ZxW
1516 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1517 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1518 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1519 mov r0,r9
1520 mov r1,r10
1521 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001522 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001523 .cfi_restore r9
1524 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001525 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001526END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001527
buzbee54330722011-08-23 16:46:55 -07001528 /*
1529 * Long integer shift. This is different from the generic 32/64-bit
1530 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1531 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1532 * 6 bits.
1533 * On entry:
1534 * r0: low word
1535 * r1: high word
1536 * r2: shift count
1537 */
1538 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001539ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001540 and r2, r2, #63 @ r2<- r2 & 0x3f
1541 mov r1, r1, asl r2 @ r1<- r1 << r2
1542 rsb r3, r2, #32 @ r3<- 32 - r2
1543 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1544 subs ip, r2, #32 @ ip<- r2 - 32
1545 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1546 mov r0, r0, asl r2 @ r0<- r0 << r2
1547 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001548END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001549
buzbee54330722011-08-23 16:46:55 -07001550 /*
1551 * Long integer shift. This is different from the generic 32/64-bit
1552 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1553 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1554 * 6 bits.
1555 * On entry:
1556 * r0: low word
1557 * r1: high word
1558 * r2: shift count
1559 */
1560 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001561ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001562 and r2, r2, #63 @ r0<- r0 & 0x3f
1563 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1564 rsb r3, r2, #32 @ r3<- 32 - r2
1565 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1566 subs ip, r2, #32 @ ip<- r2 - 32
1567 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1568 mov r1, r1, asr r2 @ r1<- r1 >> r2
1569 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001570END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001571
buzbee54330722011-08-23 16:46:55 -07001572 /*
1573 * Long integer shift. This is different from the generic 32/64-bit
1574 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1575 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1576 * 6 bits.
1577 * On entry:
1578 * r0: low word
1579 * r1: high word
1580 * r2: shift count
1581 */
1582 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001583ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001584 and r2, r2, #63 @ r0<- r0 & 0x3f
1585 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1586 rsb r3, r2, #32 @ r3<- 32 - r2
1587 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1588 subs ip, r2, #32 @ ip<- r2 - 32
1589 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1590 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1591 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001592END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001593
buzbeefc9e6fa2012-03-23 15:14:29 -07001594 /*
1595 * String's indexOf.
1596 *
1597 * On entry:
1598 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001599 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001600 * r2: Starting offset in string data
1601 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001602ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001603 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001604 .cfi_adjust_cfa_offset 16
1605 .cfi_rel_offset r4, 0
1606 .cfi_rel_offset r10, 4
1607 .cfi_rel_offset r11, 8
1608 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001609 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001610 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001611
1612 /* Clamp start to [0..count] */
1613 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001614 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001615 movlt r2, #0
1616 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001617 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001618 movgt r2, r3
1619
buzbeefc9e6fa2012-03-23 15:14:29 -07001620 /* Save a copy in r12 to later compute result */
1621 mov r12, r0
1622
1623 /* Build pointer to start of data to compare and pre-bias */
1624 add r0, r0, r2, lsl #1
1625 sub r0, #2
1626
1627 /* Compute iteration count */
1628 sub r2, r3, r2
1629
1630 /*
1631 * At this point we have:
1632 * r0: start of data to test
1633 * r1: char to compare
1634 * r2: iteration count
1635 * r12: original start of string data
1636 * r3, r4, r10, r11 available for loading string data
1637 */
1638
1639 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001640 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001641
Ian Rogers5d885c82014-02-21 20:06:23 -08001642.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001643 ldrh r3, [r0, #2]!
1644 ldrh r4, [r0, #2]!
1645 ldrh r10, [r0, #2]!
1646 ldrh r11, [r0, #2]!
1647 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001648 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001649 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001650 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001651 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001652 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001653 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001654 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001655 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001656 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001657
Ian Rogers5d885c82014-02-21 20:06:23 -08001658.Lindexof_remainder:
1659 adds r2, #4
1660 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001661
Ian Rogers5d885c82014-02-21 20:06:23 -08001662.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001663 ldrh r3, [r0, #2]!
1664 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001665 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001666 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001667 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001668
Ian Rogers5d885c82014-02-21 20:06:23 -08001669.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001670 mov r0, #-1
1671 pop {r4, r10-r11, pc}
1672
Ian Rogers5d885c82014-02-21 20:06:23 -08001673.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001674 sub r0, #6
1675 sub r0, r12
1676 asr r0, r0, #1
1677 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001678.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001679 sub r0, #4
1680 sub r0, r12
1681 asr r0, r0, #1
1682 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001683.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001684 sub r0, #2
1685 sub r0, r12
1686 asr r0, r0, #1
1687 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001688.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001689 sub r0, r12
1690 asr r0, r0, #1
1691 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001692END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001693
Zheng Xu5667fdb2014-10-23 18:29:55 +08001694 /* Assembly routines used to handle ABI differences. */
1695
1696 /* double fmod(double a, double b) */
1697 .extern fmod
1698ENTRY art_quick_fmod
1699 push {lr}
1700 .cfi_adjust_cfa_offset 4
1701 .cfi_rel_offset lr, 0
1702 sub sp, #4
1703 .cfi_adjust_cfa_offset 4
1704 vmov r0, r1, d0
1705 vmov r2, r3, d1
1706 bl fmod
1707 vmov d0, r0, r1
1708 add sp, #4
1709 .cfi_adjust_cfa_offset -4
1710 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001711END art_quick_fmod
1712
1713 /* float fmodf(float a, float b) */
1714 .extern fmodf
1715ENTRY art_quick_fmodf
1716 push {lr}
1717 .cfi_adjust_cfa_offset 4
1718 .cfi_rel_offset lr, 0
1719 sub sp, #4
1720 .cfi_adjust_cfa_offset 4
1721 vmov r0, r1, d0
1722 bl fmodf
1723 vmov s0, r0
1724 add sp, #4
1725 .cfi_adjust_cfa_offset -4
1726 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001727END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001728
1729 /* int64_t art_d2l(double d) */
1730 .extern art_d2l
1731ENTRY art_quick_d2l
1732 vmov r0, r1, d0
1733 b art_d2l
1734END art_quick_d2l
1735
1736 /* int64_t art_f2l(float f) */
1737 .extern art_f2l
1738ENTRY art_quick_f2l
1739 vmov r0, s0
1740 b art_f2l
1741END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001742
1743 /* float art_l2f(int64_t l) */
1744 .extern art_l2f
1745ENTRY art_quick_l2f
1746 push {lr}
1747 .cfi_adjust_cfa_offset 4
1748 .cfi_rel_offset lr, 0
1749 sub sp, #4
1750 .cfi_adjust_cfa_offset 4
1751 bl art_l2f
1752 vmov s0, r0
1753 add sp, #4
1754 .cfi_adjust_cfa_offset -4
1755 pop {pc}
1756END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001757
1758 /*
1759 * Create a function `name` calling the ReadBarrier::Mark routine,
1760 * getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001761 * `reg`, saving and restoring all caller-save registers.
1762 *
1763 * If `reg` is different from `r0`, the generated function follows a
1764 * non-standard runtime calling convention:
1765 * - register `reg` is used to pass the (sole) argument of this
1766 * function (instead of R0);
1767 * - register `reg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001768 * (instead of R0);
Roland Levillain02b75802016-07-13 11:54:35 +01001769 * - R0 is treated like a normal (non-argument) caller-save register;
1770 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001771 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001772 */
1773.macro READ_BARRIER_MARK_REG name, reg
1774ENTRY \name
Roland Levillain4359e612016-07-20 11:32:19 +01001775 push {r0-r4, r9, r12, lr} @ save return address and core caller-save registers
1776 .cfi_adjust_cfa_offset 32
1777 .cfi_rel_offset r0, 0
1778 .cfi_rel_offset r1, 4
1779 .cfi_rel_offset r2, 8
1780 .cfi_rel_offset r3, 12
1781 .cfi_rel_offset r4, 16
1782 .cfi_rel_offset r9, 20
1783 .cfi_rel_offset r12, 24
1784 .cfi_rel_offset lr, 28
1785 vpush {s0-s15} @ save floating-point caller-save registers
1786 .cfi_adjust_cfa_offset 64
1787
1788 .ifnc \reg, r0
1789 mov r0, \reg @ pass arg1 - obj from `reg`
1790 .endif
1791 bl artReadBarrierMark @ r0 <- artReadBarrierMark(obj)
1792
1793 vpop {s0-s15} @ restore floating-point registers
1794 .cfi_adjust_cfa_offset -64
1795 @ If `reg` is a caller-save register, save the result to its
1796 @ corresponding stack slot; it will be restored by the "pop"
1797 @ instruction below. Otherwise, move result into `reg`.
1798 @
1799 @ (Note that saving `reg` to its stack slot will overwrite the value
1800 @ previously stored by the "push" instruction above. That is
1801 @ alright, as in that case we know that `reg` is not a live
1802 @ register, as it is used to pass the argument and return the result
1803 @ of this function.)
1804 .ifc \reg, r0
1805 PUSH_REG r0, 0 @ copy result to r0's stack location
1806 .else
1807 .ifc \reg, r1
1808 PUSH_REG r0, 4 @ copy result to r1's stack location
1809 .else
1810 .ifc \reg, r2
1811 PUSH_REG r0, 8 @ copy result to r2's stack location
1812 .else
1813 .ifc \reg, r3
1814 PUSH_REG r0, 12 @ copy result to r3's stack location
1815 .else
1816 .ifc \reg, r4
1817 PUSH_REG r0, 16 @ copy result to r4's stack location
1818 .else
1819 .ifc \reg, r9
1820 PUSH_REG r0, 20 @ copy result to r9's stack location
1821 .else
1822 .ifc \reg, r12
1823 PUSH_REG r0, 24 @ copy result to r12's stack location
1824 .else
1825 mov \reg, r0 @ return result into `reg`
1826 .endif
1827 .endif
1828 .endif
1829 .endif
1830 .endif
1831 .endif
1832 .endif
1833 pop {r0-r4, r9, r12, pc} @ restore caller-save registers and return
Roland Levillain02b75802016-07-13 11:54:35 +01001834END \name
1835.endm
1836
Roland Levillain4359e612016-07-20 11:32:19 +01001837READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, r0
Roland Levillain02b75802016-07-13 11:54:35 +01001838READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1839READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1840READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1841READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1842READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1843READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1844READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1845READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1846READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1847READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1848READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11
1849READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, r12