blob: 0797def8e8e0ebfb3541041132b94c3efb9cce3b [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
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010091 // Ugly compile-time check, but we only have the preprocessor.
92#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 28 + 4)
93#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM) size not as expected."
94#endif
95.endm
96
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070097.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070098 add sp, #4 @ bottom word holds Method*
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -070099 .cfi_adjust_cfa_offset -4
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700100 pop {r5-r8, r10-r11, lr} @ 7 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -0800101 .cfi_restore r5
102 .cfi_restore r6
103 .cfi_restore r7
104 .cfi_restore r8
105 .cfi_restore r10
106 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700107 .cfi_restore lr
108 .cfi_adjust_cfa_offset -28
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700109.endm
110
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700111.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu5667fdb2014-10-23 18:29:55 +0800112 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700113 bx lr @ return
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700114.endm
115
116 /*
117 * Macro that sets up the callee save frame to conform with
Mathieu Chartier19841522013-10-22 11:29:00 -0700118 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700119 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800120.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
121 push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves and args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800122 .cfi_adjust_cfa_offset 40
Jeff Hao5d917302013-02-27 17:57:33 -0800123 .cfi_rel_offset r1, 0
124 .cfi_rel_offset r2, 4
125 .cfi_rel_offset r3, 8
126 .cfi_rel_offset r5, 12
127 .cfi_rel_offset r6, 16
128 .cfi_rel_offset r7, 20
129 .cfi_rel_offset r8, 24
130 .cfi_rel_offset r10, 28
131 .cfi_rel_offset r11, 32
132 .cfi_rel_offset lr, 36
Zheng Xu5667fdb2014-10-23 18:29:55 +0800133 vpush {s0-s15} @ 16 words of float args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800134 .cfi_adjust_cfa_offset 64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700135 sub sp, #8 @ 2 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -0800136 .cfi_adjust_cfa_offset 8
Zheng Xu5667fdb2014-10-23 18:29:55 +0800137 // Ugly compile-time check, but we only have the preprocessor.
138#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 40 + 64 + 8)
139#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM) size not as expected."
140#endif
141.endm
142
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100143.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME rTemp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800144 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100145 RUNTIME_CURRENT3 \rTemp @ Load Runtime::Current into rTemp.
146 @ rTemp is kRefsAndArgs Method*.
147 ldr \rTemp, [\rTemp, #RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET]
148 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700149 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700150.endm
151
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700152.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Zheng Xu5667fdb2014-10-23 18:29:55 +0800153 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 str r0, [sp, #0] @ Store ArtMethod* to bottom of stack.
155 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
156.endm
157
158.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700159 add sp, #8 @ rewind sp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800160 .cfi_adjust_cfa_offset -8
161 vpop {s0-s15}
162 .cfi_adjust_cfa_offset -64
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700163 pop {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -0800164 .cfi_restore r1
165 .cfi_restore r2
166 .cfi_restore r3
167 .cfi_restore r5
168 .cfi_restore r6
169 .cfi_restore r7
170 .cfi_restore r8
171 .cfi_restore r10
172 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700173 .cfi_restore lr
Zheng Xu5667fdb2014-10-23 18:29:55 +0800174 .cfi_adjust_cfa_offset -40
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700175.endm
176
Ian Rogers637859c2013-08-27 14:35:54 -0700177.macro RETURN_IF_RESULT_IS_ZERO
178 cbnz r0, 1f @ result non-zero branch over
179 bx lr @ return
1801:
181.endm
182
183.macro RETURN_IF_RESULT_IS_NON_ZERO
184 cbz r0, 1f @ result zero branch over
185 bx lr @ return
1861:
187.endm
188
Ian Rogersce9eca62011-10-07 17:11:03 -0700189 /*
190 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
191 * exception is Thread::Current()->exception_
192 */
193.macro DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -0800194 .fnend
195 .fnstart
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100196 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ save callee saves for throw
Ian Rogersce9eca62011-10-07 17:11:03 -0700197 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700198 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700199.endm
200
Ian Rogers57b86d42012-03-27 16:05:41 -0700201.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700202 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800203ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100204 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700205 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700206 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800207END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700208.endm
buzbee44b412b2012-02-04 08:50:53 -0800209
Ian Rogers57b86d42012-03-27 16:05:41 -0700210.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700211 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800212ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100213 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r1 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700214 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700215 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800216END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700217.endm
Ian Rogers9651f422011-09-19 20:26:07 -0700218
Ian Rogers57b86d42012-03-27 16:05:41 -0700219.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700220 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800221ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100222 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700223 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700224 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800225END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700226.endm
Ian Rogersbdb03912011-09-14 00:55:44 -0700227
Fred Shih37f05ef2014-07-16 18:38:08 -0700228.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
229 ldr \reg, [r9, #THREAD_EXCEPTION_OFFSET] // Get exception field.
230 cbnz \reg, 1f
231 bx lr
2321:
233 DELIVER_PENDING_EXCEPTION
234.endm
235
236.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
237 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r1
238.endm
239
240.macro RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
241 RETURN_IF_RESULT_IS_ZERO
242 DELIVER_PENDING_EXCEPTION
243.endm
244
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800245.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
246 RETURN_IF_RESULT_IS_NON_ZERO
247 DELIVER_PENDING_EXCEPTION
248.endm
249
Fred Shih37f05ef2014-07-16 18:38:08 -0700250// Macros taking opportunity of code similarities for downcalls with referrer for non-wide fields.
251.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
252 .extern \entrypoint
253ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100254 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700255 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700256 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700257 bl \entrypoint @ (uint32_t field_idx, const Method* referrer, Thread*)
258 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700259 \return
260END \name
261.endm
262
263.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
264 .extern \entrypoint
265ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100266 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700267 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700268 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700269 bl \entrypoint @ (field_idx, Object*, referrer, Thread*)
270 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700271 \return
272END \name
273.endm
274
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800275.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
Fred Shih37f05ef2014-07-16 18:38:08 -0700276 .extern \entrypoint
277ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100278 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700279 ldr r3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
280 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700281 .cfi_adjust_cfa_offset 16
282 bl \entrypoint @ (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700283 add sp, #16 @ release out args
284 .cfi_adjust_cfa_offset -16
Roland Levillainf969a202016-03-09 16:14:00 +0000285 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Fred Shih37f05ef2014-07-16 18:38:08 -0700286 \return
287END \name
288.endm
289
Ian Rogers57b86d42012-03-27 16:05:41 -0700290 /*
291 * Called by managed code, saves callee saves and then calls artThrowException
292 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
293 */
Ian Rogers468532e2013-08-05 10:56:33 -0700294ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Ian Rogers932746a2011-09-22 18:57:50 -0700295
Ian Rogers57b86d42012-03-27 16:05:41 -0700296 /*
297 * Called by managed code to create and deliver a NullPointerException.
298 */
Ian Rogers468532e2013-08-05 10:56:33 -0700299NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700300
Ian Rogers57b86d42012-03-27 16:05:41 -0700301 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100302 * Call installed by a signal handler to create and deliver a NullPointerException.
303 */
304ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
305
306 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700307 * Called by managed code to create and deliver an ArithmeticException.
308 */
Ian Rogers468532e2013-08-05 10:56:33 -0700309NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700310
Ian Rogers57b86d42012-03-27 16:05:41 -0700311 /*
312 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
313 * index, arg2 holds limit.
314 */
Ian Rogers468532e2013-08-05 10:56:33 -0700315TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700316
317 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100318 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
319 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
320 */
321TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
322
323 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700324 * Called by managed code to create and deliver a StackOverflowError.
325 */
Ian Rogers468532e2013-08-05 10:56:33 -0700326NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700327
328 /*
329 * Called by managed code to create and deliver a NoSuchMethodError.
330 */
Ian Rogers468532e2013-08-05 10:56:33 -0700331ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700332
333 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800334 * All generated callsites for interface invokes and invocation slow paths will load arguments
335 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100336 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700337 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700338 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800339 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
340 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700341 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700342 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800343 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700344 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700345 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
346 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700347 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700348.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800349 .extern \cxx_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100350 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100351 mov r2, r9 @ pass Thread::Current
352 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700353 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700354 mov r12, r1 @ save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700355 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700356 cbz r0, 1f @ did we find the target? if not go to exception delivery
357 bx r12 @ tail call to target
3581:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800359 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700360.endm
361.macro INVOKE_TRAMPOLINE c_name, cxx_name
362ENTRY \c_name
363 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800364END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800365.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800366
Logan Chien8dbb7082013-01-25 20:31:17 +0800367INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800368
Logan Chien8dbb7082013-01-25 20:31:17 +0800369INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
370INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
371INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
372INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700373
Ian Rogers57b86d42012-03-27 16:05:41 -0700374 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800375 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700376 * On entry:
377 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700378 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700379 * r2 = size of argument array in bytes
380 * r3 = (managed) thread pointer
381 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800382 * [sp + 4] = result_in_float
383 * [sp + 8] = core register argument array
384 * [sp + 12] = fp register argument array
385 * +-------------------------+
386 * | uint32_t* fp_reg_args |
387 * | uint32_t* core_reg_args |
388 * | result_in_float | <- Caller frame
389 * | Jvalue* result |
390 * +-------------------------+
391 * | lr |
392 * | r11 |
393 * | r9 |
394 * | r4 | <- r11
395 * +-------------------------+
396 * | uint32_t out[n-1] |
397 * | : : | Outs
398 * | uint32_t out[0] |
399 * | StackRef<ArtMethod> | <- SP value=null
400 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800401 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800402ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700403 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800404 mov r11, sp @ save the stack pointer
405 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800406
Jeff Hao5d917302013-02-27 17:57:33 -0800407 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800408
409 add r4, r2, #4 @ create space for method pointer in frame
410 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
411 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
412 mov sp, r4 @ 16B alignment ourselves.
413
414 mov r4, r0 @ save method*
415 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
416 bl memcpy @ memcpy (dest, src, bytes)
417 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700418 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800419
Nicolas Geoffray48088462014-12-12 10:29:38 +0000420 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800421 vldm ip, {s0-s15} @ copy s0 - s15
422
Nicolas Geoffray48088462014-12-12 10:29:38 +0000423 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800424 mov r0, r4 @ restore method*
425 add ip, ip, #4 @ skip r0
426 ldm ip, {r1-r3} @ copy r1 - r3
427
Wei Jin04f4d8a2014-05-29 18:04:29 -0700428#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800429 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700430#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700431
Mathieu Chartiere401d142015-04-22 13:56:20 -0700432 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800433 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800434
Jeff Hao6474d192013-03-26 14:08:09 -0700435 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800436 .cfi_def_cfa_register sp
437
Nicolas Geoffray48088462014-12-12 10:29:38 +0000438 ldr r4, [sp, #40] @ load result_is_float
439 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800440 cmp r4, #0
441 ite eq
442 strdeq r0, [r9] @ store r0/r1 into result pointer
443 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
444
Nicolas Geoffray48088462014-12-12 10:29:38 +0000445 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800446END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700447
Jeff Hao5d917302013-02-27 17:57:33 -0800448 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000449 * On stack replacement stub.
450 * On entry:
451 * r0 = stack to copy
452 * r1 = size of stack
453 * r2 = pc to call
454 * r3 = JValue* result
455 * [sp] = shorty
456 * [sp + 4] = thread
457 */
458ENTRY art_quick_osr_stub
459 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
460 mov r11, sp @ Save the stack pointer
461 mov r10, r1 @ Save size of stack
462 ldr r9, [r11, #40] @ Move managed thread pointer into r9
463 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000464 sub r7, sp, #12 @ Reserve space for stack pointer,
465 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000466 and r7, #0xFFFFFFF0 @ Align stack pointer
467 mov sp, r7 @ Update stack pointer
468 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000469 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000470 mov ip, #0
471 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
472 sub sp, sp, r1 @ Reserve space for callee stack
473 mov r2, r1
474 mov r1, r0
475 mov r0, sp
476 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
477 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000478 ldr r10, [sp, #8] @ Restore JValue* result
479 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000480 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000481 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000482 cmp r4, #68 @ Test if result type char == 'D'.
483 beq .Losr_fp_result
484 cmp r4, #70 @ Test if result type char == 'F'.
485 beq .Losr_fp_result
486 strd r0, [r10] @ Store r0/r1 into result pointer
487 b .Losr_exit
488.Losr_fp_result:
489 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
490.Losr_exit:
491 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
492.Losr_entry:
493 sub r10, r10, #4
494 str lr, [sp, r10] @ Store link register per the compiler ABI
495 bx r8
496END art_quick_osr_stub
497
498 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700499 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
500 */
Ian Rogers637859c2013-08-27 14:35:54 -0700501ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700502 vldm r1, {s0-s31} @ load all fprs from argument fprs_
503 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700504 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700505 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700506 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700507 ldr r0, [r0, #-12] @ load r0 value
508 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700509 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800510END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700511
Ian Rogers60db5ab2012-02-20 17:02:00 -0800512 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700513 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
514 * failure.
515 */
Ian Rogers832336b2014-10-08 15:35:22 -0700516TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700517
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700518 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700519 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
520 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700521 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800522 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700523ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800524 cbz r0, .Lslow_lock
525.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700526 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700527 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800528 mov r3, r1
529 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
530 cbnz r3, .Lnot_unlocked @ already thin locked
531 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
532 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700533 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800534 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700535 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700536 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800537.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
538 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800539 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700540 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
541 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800542 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700543 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800544 mov r3, r1 @ copy the lock word to check count overflow.
545 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits.
546 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
547 lsr r3, r2, LOCK_WORD_READ_BARRIER_STATE_SHIFT @ if either of the upper two bits (28-29) are set, we overflowed.
548 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
549 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
550 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
551 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700552 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800553.Llock_strex_fail:
554 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800555.Lslow_lock:
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100556 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700557 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700558 bl artLockObjectFromCode @ (Object* obj, Thread*)
559 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700560 RETURN_IF_RESULT_IS_ZERO
561 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700562END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700563
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700564ENTRY art_quick_lock_object_no_inline
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100565 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700566 mov r1, r9 @ pass Thread::Current
567 bl artLockObjectFromCode @ (Object* obj, Thread*)
568 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
569 RETURN_IF_RESULT_IS_ZERO
570 DELIVER_PENDING_EXCEPTION
571END art_quick_lock_object_no_inline
572
Ian Rogersff1ed472011-09-20 13:46:24 -0700573 /*
574 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700575 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700576 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800577 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700578ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800579 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800580.Lretry_unlock:
581#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700582 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800583#else
584 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
585#endif
586 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800587 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700588 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800589 mov r3, r1 @ copy lock word to check thread id equality
590 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
591 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700592 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800593 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800594 mov r3, r1 @ copy lock word to detect transition to unlocked
595 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
596 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800597 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800598 @ transition to unlocked
599 mov r3, r1
600 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK @ r3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700601 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800602#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700603 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800604#else
605 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
606 cbnz r2, .Lunlock_strex_fail @ store failed, retry
607#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700608 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800609.Lrecursive_thin_unlock: @ r1: original lock word
610 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
611#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700612 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800613#else
614 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
615 cbnz r2, .Lunlock_strex_fail @ store failed, retry
616#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700617 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800618.Lunlock_strex_fail:
619 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800620.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700621 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100622 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700623 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700624 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
625 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700626 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700627 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700628END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700629
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700630ENTRY art_quick_unlock_object_no_inline
631 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100632 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700633 mov r1, r9 @ pass Thread::Current
634 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
635 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
636 RETURN_IF_RESULT_IS_ZERO
637 DELIVER_PENDING_EXCEPTION
638END art_quick_unlock_object_no_inline
639
Ian Rogersff1ed472011-09-20 13:46:24 -0700640 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700641 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
642 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700643 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700644 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700645ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700646 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700647 .cfi_adjust_cfa_offset 12
648 .cfi_rel_offset r0, 0
649 .cfi_rel_offset r1, 4
650 .cfi_rel_offset lr, 8
651 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700652 .cfi_adjust_cfa_offset 4
653 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800654 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700655 add sp, #4
656 .cfi_adjust_cfa_offset -4
657 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700658 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800659.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700660 add sp, #4
661 .cfi_adjust_cfa_offset -4
662 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700663 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800664 .cfi_restore r0
665 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700666 .cfi_restore lr
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100667 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700668 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700669 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700670 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700671END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700672
Man Cao1aee9002015-07-14 22:31:42 -0700673// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
674.macro POP_REG_NE rReg, offset, rExclude
675 .ifnc \rReg, \rExclude
676 ldr \rReg, [sp, #\offset] @ restore rReg
677 .cfi_restore \rReg
678 .endif
679.endm
680
681 /*
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]
1051 // Push the new object onto the thread
1052 // local allocation stack and
1053 // increment the thread local
1054 // allocation stack top.
1055 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1056 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1057 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1058 // Decrement the size of the free list
1059 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1060 sub r1, #1
1061 // TODO: consider combining this store
1062 // and the list head store above using
1063 // strd.
1064 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1065 // Fence. This is "ish" not "ishst" so
1066 // that the code after this allocation
1067 // site will see the right values in
1068 // the fields of the class.
1069 // Alternatively we could use "ishst"
1070 // if we use load-acquire for the
1071 // class status load.)
1072 dmb ish
1073 mov r0, r3 // Set the return value and return.
1074 bx lr
1075
1076.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001077 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001078 mov r2, r9 @ pass Thread::Current
1079 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1080 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1081 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1082END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001083
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001084// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1085//
1086// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1087// Need to preserve r0 and r1 to the slow path.
1088.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1089 cbz r2, \slowPathLabel // Check null class
1090 // Check class status.
1091 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1092 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1093 bne \slowPathLabel
1094 // Add a fake dependence from the
1095 // following access flag and size
1096 // loads to the status load.
1097 // This is to prevent those loads
1098 // from being reordered above the
1099 // status load and reading wrong
1100 // values (an alternative is to use
1101 // a load-acquire for the status).
1102 eor r3, r3, r3
1103 add r2, r2, r3
1104 // Check access flags has
1105 // kAccClassIsFinalizable.
1106 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1107 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1108 bne \slowPathLabel
1109 // Load thread_local_pos (r12) and
1110 // thread_local_end (r3) with ldrd.
1111 // Check constraints for ldrd.
1112#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1113#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1114#endif
1115 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1116 sub r12, r3, r12 // Compute the remaining buf size.
1117 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
1118 cmp r3, r12 // Check if it fits. OK to do this
1119 // before rounding up the object size
1120 // assuming the buf size alignment.
1121 bhi \slowPathLabel
1122 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1123 // Round up the object size by the
1124 // object alignment. (addr + 7) & ~7.
1125 add r3, r3, #OBJECT_ALIGNMENT_MASK
1126 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1127 // Reload old thread_local_pos (r0)
1128 // for the return value.
1129 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1130 add r1, r0, r3
1131 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1132 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1133 add r1, r1, #1
1134 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1135 POISON_HEAP_REF r2
1136 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1137 // Fence. This is "ish" not "ishst" so
1138 // that the code after this allocation
1139 // site will see the right values in
1140 // the fields of the class.
1141 // Alternatively we could use "ishst"
1142 // if we use load-acquire for the
1143 // class status load.)
1144 dmb ish
1145 bx lr
1146.endm
1147
1148// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1149ENTRY art_quick_alloc_object_tlab
1150 // Fast path tlab allocation.
1151 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1152 // r2, r3, r12: free.
1153#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001154 mvn r0, #0 // Read barrier not supported here.
1155 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001156#endif
1157 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1158 // Load the class (r2)
1159 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1160 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1161.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001162 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001163 mov r2, r9 // Pass Thread::Current.
1164 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1165 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1166 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1167END art_quick_alloc_object_tlab
1168
1169// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1170ENTRY art_quick_alloc_object_region_tlab
1171 // Fast path tlab allocation.
1172 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1173#if !defined(USE_READ_BARRIER)
1174 eor r0, r0, r0 // Read barrier must be enabled here.
1175 sub r0, r0, #1 // Return -1.
1176 bx lr
1177#endif
1178 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1179 // Load the class (r2)
1180 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1181 // Read barrier for class load.
1182 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
1183 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1184.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1185 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1186.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1187 // The read barrier slow path. Mark
1188 // the class.
1189 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1190 // to align sp by 16 bytes.
1191 mov r0, r2 // Pass the class as the first param.
1192 bl artReadBarrierMark
1193 mov r2, r0 // Get the (marked) class back.
1194 pop {r0, r1, r3, lr}
1195 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1196.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001197 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001198 mov r2, r9 // Pass Thread::Current.
1199 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1200 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1201 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1202END art_quick_alloc_object_region_tlab
1203
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001204 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001205 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001206 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001207 .extern artTestSuspendFromCode
1208ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001209#ifdef ARM_R4_SUSPEND_FLAG
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001210 ldrh r0, [rSELF, #THREAD_FLAGS_OFFSET]
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001211 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Ian Rogers637859c2013-08-27 14:35:54 -07001212 cbnz r0, 1f @ check Thread::Current()->suspend_count_ == 0
1213 bx lr @ return if suspend_count_ == 0
12141:
Wei Jin04f4d8a2014-05-29 18:04:29 -07001215#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001216 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001217 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for GC stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001218 @ TODO: save FPRs to enable access in the debugger?
1219 bl artTestSuspendFromCode @ (Thread*)
1220 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogers9329bbb2013-02-08 19:56:30 -08001221END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001222
Dave Allison83252962014-04-03 16:33:48 -07001223ENTRY art_quick_implicit_suspend
1224 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001225 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001226 bl artTestSuspendFromCode @ (Thread*)
1227 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001228END art_quick_implicit_suspend
1229
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001230 /*
1231 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001232 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1233 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001234 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001235 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001236ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001237 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001238 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001239 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001240 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001241 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001242 // Tear down the callee-save frame. Skip arg registers.
1243 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1244 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001245 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001246 cbnz r2, 1f @ success if no exception is pending
1247 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001248 bx lr @ return on success
12491:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001250 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001251END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001252
Jeff Hao88474b42013-10-23 16:24:40 -07001253 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001254 * Called to resolve an imt conflict.
1255 * r0 is the conflict ArtMethod.
1256 * r12 is a hidden argument that holds the target interface method's dex method index.
1257 *
1258 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001259 */
1260ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001261 ldr r4, [sp, #0] // Load referrer
1262 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1263 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1264 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1265 ldr r4, [r0] // Load first entry in ImtConflictTable.
1266.Limt_table_iterate:
1267 cmp r4, r12
1268 // Branch if found. Benchmarks have shown doing a branch here is better.
1269 beq .Limt_table_found
1270 // If the entry is null, the interface method is not in the ImtConflictTable.
1271 cbz r4, .Lconflict_trampoline
1272 // Iterate over the entries of the ImtConflictTable.
1273 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1274 b .Limt_table_iterate
1275.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001276 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001277 // and jump to it.
1278 ldr r0, [r0, #__SIZEOF_POINTER__]
1279 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1280.Lconflict_trampoline:
1281 // Call the runtime stub to populate the ImtConflictTable and jump to the
1282 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001283 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001284END art_quick_imt_conflict_trampoline
1285
Ian Rogers468532e2013-08-05 10:56:33 -07001286 .extern artQuickResolutionTrampoline
1287ENTRY art_quick_resolution_trampoline
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001288 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001289 mov r2, r9 @ pass Thread::Current
1290 mov r3, sp @ pass SP
1291 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001292 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001293 mov r12, r0
1294 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001295 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001296 bx r12 @ tail-call into actual code
12971:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001298 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001299 DELIVER_PENDING_EXCEPTION
1300END art_quick_resolution_trampoline
1301
Andreas Gampec200a4a2014-06-16 18:39:09 -07001302 /*
1303 * Called to do a generic JNI down-call
1304 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001305ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001306 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001307
1308 // Save rSELF
1309 mov r11, rSELF
1310 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1311 mov r10, sp
1312 .cfi_def_cfa_register r10
1313
1314 sub sp, sp, #5120
1315
1316 // prepare for artQuickGenericJniTrampoline call
1317 // (Thread*, SP)
1318 // r0 r1 <= C calling convention
1319 // rSELF r10 <= where they are
1320
1321 mov r0, rSELF // Thread*
1322 mov r1, r10
1323 blx artQuickGenericJniTrampoline // (Thread*, sp)
1324
1325 // The C call will have registered the complete save-frame on success.
1326 // The result of the call is:
1327 // r0: pointer to native code, 0 on error.
1328 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1329
1330 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001331 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001332
1333 // Release part of the alloca.
1334 mov sp, r1
1335
1336 // Save the code pointer
1337 mov r12, r0
1338
1339 // Load parameters from frame into registers.
1340 pop {r0-r3}
1341
1342 // Softfloat.
1343 // TODO: Change to hardfloat when supported.
1344
1345 blx r12 // native call.
1346
1347 // result sign extension is handled in C code
1348 // prepare for artQuickGenericJniEndTrampoline call
1349 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001350 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001351 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001352 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001353
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001354 push {r0-r1}
1355 mov r3, r1
1356 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001357 mov r0, r11
1358
1359 blx artQuickGenericJniEndTrampoline
1360
Andreas Gampec200a4a2014-06-16 18:39:09 -07001361 // Restore self pointer.
1362 mov r9, r11
1363
1364 // Pending exceptions possible.
1365 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1366 cbnz r2, .Lexception_in_native
1367
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001368 // Tear down the alloca.
1369 mov sp, r10
1370 .cfi_def_cfa_register sp
1371
Zheng Xu5667fdb2014-10-23 18:29:55 +08001372 // Tear down the callee-save frame. Skip arg registers.
1373 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1374 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1375 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001376
Zheng Xu5667fdb2014-10-23 18:29:55 +08001377 // store into fpr, for when it's a fpr return...
1378 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001379 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001380 // Undo the unwinding information from above since it doesn't apply below.
1381 .cfi_def_cfa_register r10
1382 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001383
Andreas Gampec200a4a2014-06-16 18:39:09 -07001384.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001385 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1386 .cfi_def_cfa_register sp
1387 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001388 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001389END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001390
Ian Rogers468532e2013-08-05 10:56:33 -07001391 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001392ENTRY art_quick_to_interpreter_bridge
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001393 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001394 mov r1, r9 @ pass Thread::Current
1395 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001396 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001397 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001398 // Tear down the callee-save frame. Skip arg registers.
1399 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1400 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001401 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001402 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001403 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1404 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014051:
Ian Rogers7db619b2013-01-16 18:35:48 -08001406 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001407END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001408
jeffhaoe343b762011-12-05 16:36:44 -08001409 /*
jeffhao0791adc2012-04-04 11:14:32 -07001410 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001411 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001412 .extern artInstrumentationMethodEntryFromCode
1413 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001414ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001415 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001416 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001417 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1418 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001419 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001420 mov r3, lr @ pass LR
1421 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001422 mov r12, r0 @ r12 holds reference to code
1423 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001424 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001425 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001426@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001427 .type art_quick_instrumentation_exit, #function
1428 .global art_quick_instrumentation_exit
1429art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001430 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001431 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 -08001432 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001433 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001434 .cfi_adjust_cfa_offset 8
1435 .cfi_rel_offset r0, 0
1436 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001437 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001438 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001439 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1440 @ need to align by 16.
1441 .cfi_adjust_cfa_offset 8
1442 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001443 mov r2, r0 @ pass return value as gpr_res
1444 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001445 mov r0, r9 @ pass Thread::Current
1446 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001447 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001448 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001449 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001450
Ian Rogers306057f2012-11-26 12:45:53 -08001451 mov r2, r0 @ link register saved by instrumentation
1452 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001453 vpop {d0} @ restore fp return value
1454 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001455 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001456 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001457 .cfi_restore r0
1458 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001459 add sp, #32 @ remove callee save frame
1460 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001461 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001462END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001463
Ian Rogers306057f2012-11-26 12:45:53 -08001464 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001465 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1466 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001467 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001468 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001469ENTRY art_quick_deoptimize
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001470 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001471 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001472 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001473END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001474
Ian Rogers324e1902012-09-09 12:17:52 -07001475 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001476 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001477 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001478 */
1479 .extern artDeoptimizeFromCompiledCode
1480ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001481 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001482 mov r0, r9 @ Set up args.
1483 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1484END art_quick_deoptimize_from_compiled_code
1485
1486 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001487 * Signed 64-bit integer multiply.
1488 *
1489 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1490 * WX
1491 * x YZ
1492 * --------
1493 * ZW ZX
1494 * YW YX
1495 *
1496 * The low word of the result holds ZX, the high word holds
1497 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1498 * it doesn't fit in the low 64 bits.
1499 *
1500 * Unlike most ARM math operations, multiply instructions have
1501 * restrictions on using the same register more than once (Rd and Rm
1502 * cannot be the same).
1503 */
1504 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001505ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001506 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001507 .cfi_adjust_cfa_offset 8
1508 .cfi_rel_offset r9, 0
1509 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001510 mul ip, r2, r1 @ ip<- ZxW
1511 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1512 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1513 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1514 mov r0,r9
1515 mov r1,r10
1516 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001517 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001518 .cfi_restore r9
1519 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001520 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001521END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001522
buzbee54330722011-08-23 16:46:55 -07001523 /*
1524 * Long integer shift. This is different from the generic 32/64-bit
1525 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1526 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1527 * 6 bits.
1528 * On entry:
1529 * r0: low word
1530 * r1: high word
1531 * r2: shift count
1532 */
1533 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001534ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001535 and r2, r2, #63 @ r2<- r2 & 0x3f
1536 mov r1, r1, asl r2 @ r1<- r1 << r2
1537 rsb r3, r2, #32 @ r3<- 32 - r2
1538 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1539 subs ip, r2, #32 @ ip<- r2 - 32
1540 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1541 mov r0, r0, asl r2 @ r0<- r0 << r2
1542 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001543END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001544
buzbee54330722011-08-23 16:46:55 -07001545 /*
1546 * Long integer shift. This is different from the generic 32/64-bit
1547 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1548 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1549 * 6 bits.
1550 * On entry:
1551 * r0: low word
1552 * r1: high word
1553 * r2: shift count
1554 */
1555 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001556ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001557 and r2, r2, #63 @ r0<- r0 & 0x3f
1558 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1559 rsb r3, r2, #32 @ r3<- 32 - r2
1560 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1561 subs ip, r2, #32 @ ip<- r2 - 32
1562 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1563 mov r1, r1, asr r2 @ r1<- r1 >> r2
1564 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001565END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001566
buzbee54330722011-08-23 16:46:55 -07001567 /*
1568 * Long integer shift. This is different from the generic 32/64-bit
1569 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1570 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1571 * 6 bits.
1572 * On entry:
1573 * r0: low word
1574 * r1: high word
1575 * r2: shift count
1576 */
1577 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001578ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001579 and r2, r2, #63 @ r0<- r0 & 0x3f
1580 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1581 rsb r3, r2, #32 @ r3<- 32 - r2
1582 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1583 subs ip, r2, #32 @ ip<- r2 - 32
1584 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1585 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1586 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001587END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001588
buzbeefc9e6fa2012-03-23 15:14:29 -07001589 /*
1590 * String's indexOf.
1591 *
1592 * On entry:
1593 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001594 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001595 * r2: Starting offset in string data
1596 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001597ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001598 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001599 .cfi_adjust_cfa_offset 16
1600 .cfi_rel_offset r4, 0
1601 .cfi_rel_offset r10, 4
1602 .cfi_rel_offset r11, 8
1603 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001604 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001605 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001606
1607 /* Clamp start to [0..count] */
1608 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001609 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001610 movlt r2, #0
1611 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001612 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001613 movgt r2, r3
1614
buzbeefc9e6fa2012-03-23 15:14:29 -07001615 /* Save a copy in r12 to later compute result */
1616 mov r12, r0
1617
1618 /* Build pointer to start of data to compare and pre-bias */
1619 add r0, r0, r2, lsl #1
1620 sub r0, #2
1621
1622 /* Compute iteration count */
1623 sub r2, r3, r2
1624
1625 /*
1626 * At this point we have:
1627 * r0: start of data to test
1628 * r1: char to compare
1629 * r2: iteration count
1630 * r12: original start of string data
1631 * r3, r4, r10, r11 available for loading string data
1632 */
1633
1634 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001635 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001636
Ian Rogers5d885c82014-02-21 20:06:23 -08001637.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001638 ldrh r3, [r0, #2]!
1639 ldrh r4, [r0, #2]!
1640 ldrh r10, [r0, #2]!
1641 ldrh r11, [r0, #2]!
1642 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001643 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001644 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001645 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001646 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001647 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001648 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001649 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001650 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001651 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001652
Ian Rogers5d885c82014-02-21 20:06:23 -08001653.Lindexof_remainder:
1654 adds r2, #4
1655 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001656
Ian Rogers5d885c82014-02-21 20:06:23 -08001657.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001658 ldrh r3, [r0, #2]!
1659 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001660 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001661 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001662 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001663
Ian Rogers5d885c82014-02-21 20:06:23 -08001664.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001665 mov r0, #-1
1666 pop {r4, r10-r11, pc}
1667
Ian Rogers5d885c82014-02-21 20:06:23 -08001668.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001669 sub r0, #6
1670 sub r0, r12
1671 asr r0, r0, #1
1672 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001673.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001674 sub r0, #4
1675 sub r0, r12
1676 asr r0, r0, #1
1677 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001678.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001679 sub r0, #2
1680 sub r0, r12
1681 asr r0, r0, #1
1682 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001683.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001684 sub r0, r12
1685 asr r0, r0, #1
1686 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001687END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001688
Zheng Xu5667fdb2014-10-23 18:29:55 +08001689 /* Assembly routines used to handle ABI differences. */
1690
1691 /* double fmod(double a, double b) */
1692 .extern fmod
1693ENTRY art_quick_fmod
1694 push {lr}
1695 .cfi_adjust_cfa_offset 4
1696 .cfi_rel_offset lr, 0
1697 sub sp, #4
1698 .cfi_adjust_cfa_offset 4
1699 vmov r0, r1, d0
1700 vmov r2, r3, d1
1701 bl fmod
1702 vmov d0, r0, r1
1703 add sp, #4
1704 .cfi_adjust_cfa_offset -4
1705 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001706END art_quick_fmod
1707
1708 /* float fmodf(float a, float b) */
1709 .extern fmodf
1710ENTRY art_quick_fmodf
1711 push {lr}
1712 .cfi_adjust_cfa_offset 4
1713 .cfi_rel_offset lr, 0
1714 sub sp, #4
1715 .cfi_adjust_cfa_offset 4
1716 vmov r0, r1, d0
1717 bl fmodf
1718 vmov s0, r0
1719 add sp, #4
1720 .cfi_adjust_cfa_offset -4
1721 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001722END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001723
1724 /* int64_t art_d2l(double d) */
1725 .extern art_d2l
1726ENTRY art_quick_d2l
1727 vmov r0, r1, d0
1728 b art_d2l
1729END art_quick_d2l
1730
1731 /* int64_t art_f2l(float f) */
1732 .extern art_f2l
1733ENTRY art_quick_f2l
1734 vmov r0, s0
1735 b art_f2l
1736END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001737
1738 /* float art_l2f(int64_t l) */
1739 .extern art_l2f
1740ENTRY art_quick_l2f
1741 push {lr}
1742 .cfi_adjust_cfa_offset 4
1743 .cfi_rel_offset lr, 0
1744 sub sp, #4
1745 .cfi_adjust_cfa_offset 4
1746 bl art_l2f
1747 vmov s0, r0
1748 add sp, #4
1749 .cfi_adjust_cfa_offset -4
1750 pop {pc}
1751END art_quick_l2f