blob: 27a41f09add6e7a9dad8bae55da388e08698399d [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 /*
302 * Called by managed code to create and deliver an ArithmeticException.
303 */
Ian Rogers468532e2013-08-05 10:56:33 -0700304NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700305
Ian Rogers57b86d42012-03-27 16:05:41 -0700306 /*
307 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
308 * index, arg2 holds limit.
309 */
Ian Rogers468532e2013-08-05 10:56:33 -0700310TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700311
312 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100313 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
314 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
315 */
316TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
317
318 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700319 * Called by managed code to create and deliver a StackOverflowError.
320 */
Ian Rogers468532e2013-08-05 10:56:33 -0700321NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700322
323 /*
324 * Called by managed code to create and deliver a NoSuchMethodError.
325 */
Ian Rogers468532e2013-08-05 10:56:33 -0700326ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700327
328 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800329 * All generated callsites for interface invokes and invocation slow paths will load arguments
330 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100331 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700332 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700333 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800334 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
335 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700336 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700337 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800338 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700339 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700340 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
341 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700342 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700343.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800344 .extern \cxx_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100345 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100346 mov r2, r9 @ pass Thread::Current
347 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700348 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700349 mov r12, r1 @ save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700350 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700351 cbz r0, 1f @ did we find the target? if not go to exception delivery
352 bx r12 @ tail call to target
3531:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800354 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700355.endm
356.macro INVOKE_TRAMPOLINE c_name, cxx_name
357ENTRY \c_name
358 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800359END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800360.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800361
Logan Chien8dbb7082013-01-25 20:31:17 +0800362INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800363
Logan Chien8dbb7082013-01-25 20:31:17 +0800364INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
365INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
366INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
367INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700368
Ian Rogers57b86d42012-03-27 16:05:41 -0700369 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800370 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700371 * On entry:
372 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700373 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700374 * r2 = size of argument array in bytes
375 * r3 = (managed) thread pointer
376 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800377 * [sp + 4] = result_in_float
378 * [sp + 8] = core register argument array
379 * [sp + 12] = fp register argument array
380 * +-------------------------+
381 * | uint32_t* fp_reg_args |
382 * | uint32_t* core_reg_args |
383 * | result_in_float | <- Caller frame
384 * | Jvalue* result |
385 * +-------------------------+
386 * | lr |
387 * | r11 |
388 * | r9 |
389 * | r4 | <- r11
390 * +-------------------------+
391 * | uint32_t out[n-1] |
392 * | : : | Outs
393 * | uint32_t out[0] |
394 * | StackRef<ArtMethod> | <- SP value=null
395 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800396 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800397ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700398 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800399 mov r11, sp @ save the stack pointer
400 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800401
Jeff Hao5d917302013-02-27 17:57:33 -0800402 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800403
404 add r4, r2, #4 @ create space for method pointer in frame
405 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
406 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
407 mov sp, r4 @ 16B alignment ourselves.
408
409 mov r4, r0 @ save method*
410 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
411 bl memcpy @ memcpy (dest, src, bytes)
412 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700413 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800414
Nicolas Geoffray48088462014-12-12 10:29:38 +0000415 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800416 vldm ip, {s0-s15} @ copy s0 - s15
417
Nicolas Geoffray48088462014-12-12 10:29:38 +0000418 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800419 mov r0, r4 @ restore method*
420 add ip, ip, #4 @ skip r0
421 ldm ip, {r1-r3} @ copy r1 - r3
422
Wei Jin04f4d8a2014-05-29 18:04:29 -0700423#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800424 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700425#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700426
Mathieu Chartiere401d142015-04-22 13:56:20 -0700427 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800428 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800429
Jeff Hao6474d192013-03-26 14:08:09 -0700430 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800431 .cfi_def_cfa_register sp
432
Nicolas Geoffray48088462014-12-12 10:29:38 +0000433 ldr r4, [sp, #40] @ load result_is_float
434 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800435 cmp r4, #0
436 ite eq
437 strdeq r0, [r9] @ store r0/r1 into result pointer
438 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
439
Nicolas Geoffray48088462014-12-12 10:29:38 +0000440 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800441END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700442
Jeff Hao5d917302013-02-27 17:57:33 -0800443 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000444 * On stack replacement stub.
445 * On entry:
446 * r0 = stack to copy
447 * r1 = size of stack
448 * r2 = pc to call
449 * r3 = JValue* result
450 * [sp] = shorty
451 * [sp + 4] = thread
452 */
453ENTRY art_quick_osr_stub
454 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
455 mov r11, sp @ Save the stack pointer
456 mov r10, r1 @ Save size of stack
457 ldr r9, [r11, #40] @ Move managed thread pointer into r9
458 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000459 sub r7, sp, #12 @ Reserve space for stack pointer,
460 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000461 and r7, #0xFFFFFFF0 @ Align stack pointer
462 mov sp, r7 @ Update stack pointer
463 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000464 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000465 mov ip, #0
466 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
467 sub sp, sp, r1 @ Reserve space for callee stack
468 mov r2, r1
469 mov r1, r0
470 mov r0, sp
471 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
472 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000473 ldr r10, [sp, #8] @ Restore JValue* result
474 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000475 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000476 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000477 cmp r4, #68 @ Test if result type char == 'D'.
478 beq .Losr_fp_result
479 cmp r4, #70 @ Test if result type char == 'F'.
480 beq .Losr_fp_result
481 strd r0, [r10] @ Store r0/r1 into result pointer
482 b .Losr_exit
483.Losr_fp_result:
484 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
485.Losr_exit:
486 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
487.Losr_entry:
488 sub r10, r10, #4
489 str lr, [sp, r10] @ Store link register per the compiler ABI
490 bx r8
491END art_quick_osr_stub
492
493 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700494 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
495 */
Ian Rogers637859c2013-08-27 14:35:54 -0700496ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700497 vldm r1, {s0-s31} @ load all fprs from argument fprs_
498 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700499 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700500 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700501 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700502 ldr r0, [r0, #-12] @ load r0 value
503 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700504 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800505END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700506
Ian Rogers60db5ab2012-02-20 17:02:00 -0800507 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700508 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
509 * failure.
510 */
Ian Rogers832336b2014-10-08 15:35:22 -0700511TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700512
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700513 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700514 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
515 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700516 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800517 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700518ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800519 cbz r0, .Lslow_lock
520.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700521 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700522 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800523 mov r3, r1
524 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
525 cbnz r3, .Lnot_unlocked @ already thin locked
526 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
527 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700528 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800529 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700530 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700531 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800532.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
533 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800534 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700535 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
536 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800537 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700538 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800539 mov r3, r1 @ copy the lock word to check count overflow.
540 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits.
541 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
542 lsr r3, r2, LOCK_WORD_READ_BARRIER_STATE_SHIFT @ if either of the upper two bits (28-29) are set, we overflowed.
543 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
544 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
545 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
546 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700547 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800548.Llock_strex_fail:
549 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800550.Lslow_lock:
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100551 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700552 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700553 bl artLockObjectFromCode @ (Object* obj, Thread*)
554 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700555 RETURN_IF_RESULT_IS_ZERO
556 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700557END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700558
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700559ENTRY art_quick_lock_object_no_inline
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100560 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700561 mov r1, r9 @ pass Thread::Current
562 bl artLockObjectFromCode @ (Object* obj, Thread*)
563 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
564 RETURN_IF_RESULT_IS_ZERO
565 DELIVER_PENDING_EXCEPTION
566END art_quick_lock_object_no_inline
567
Ian Rogersff1ed472011-09-20 13:46:24 -0700568 /*
569 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700570 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700571 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800572 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700573ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800574 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800575.Lretry_unlock:
576#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700577 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800578#else
579 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
580#endif
581 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800582 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700583 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800584 mov r3, r1 @ copy lock word to check thread id equality
585 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
586 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700587 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800588 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800589 mov r3, r1 @ copy lock word to detect transition to unlocked
590 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED @ zero the read barrier bits
591 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800592 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800593 @ transition to unlocked
594 mov r3, r1
595 and r3, #LOCK_WORD_READ_BARRIER_STATE_MASK @ r3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700596 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800597#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700598 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800599#else
600 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
601 cbnz r2, .Lunlock_strex_fail @ store failed, retry
602#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700603 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800604.Lrecursive_thin_unlock: @ r1: original lock word
605 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
606#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700607 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800608#else
609 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
610 cbnz r2, .Lunlock_strex_fail @ store failed, retry
611#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700612 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800613.Lunlock_strex_fail:
614 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800615.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700616 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100617 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700618 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700619 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
620 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700621 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700622 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700623END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700624
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700625ENTRY art_quick_unlock_object_no_inline
626 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100627 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700628 mov r1, r9 @ pass Thread::Current
629 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
630 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
631 RETURN_IF_RESULT_IS_ZERO
632 DELIVER_PENDING_EXCEPTION
633END art_quick_unlock_object_no_inline
634
Ian Rogersff1ed472011-09-20 13:46:24 -0700635 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700636 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
637 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700638 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700639 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700640ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700641 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700642 .cfi_adjust_cfa_offset 12
643 .cfi_rel_offset r0, 0
644 .cfi_rel_offset r1, 4
645 .cfi_rel_offset lr, 8
646 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700647 .cfi_adjust_cfa_offset 4
648 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800649 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700650 add sp, #4
651 .cfi_adjust_cfa_offset -4
652 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700653 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800654.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, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700658 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800659 .cfi_restore r0
660 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700661 .cfi_restore lr
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100662 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700663 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700664 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700665 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700666END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700667
Man Cao1aee9002015-07-14 22:31:42 -0700668// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
669.macro POP_REG_NE rReg, offset, rExclude
670 .ifnc \rReg, \rExclude
671 ldr \rReg, [sp, #\offset] @ restore rReg
672 .cfi_restore \rReg
673 .endif
674.endm
675
676 /*
677 * Macro to insert read barrier, only used in art_quick_aput_obj.
678 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
679 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
680 */
681.macro READ_BARRIER rDest, rObj, offset
682#ifdef USE_READ_BARRIER
683 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
684 .cfi_adjust_cfa_offset 24
685 .cfi_rel_offset r0, 0
686 .cfi_rel_offset r1, 4
687 .cfi_rel_offset r2, 8
688 .cfi_rel_offset r3, 12
689 .cfi_rel_offset ip, 16
690 .cfi_rel_offset lr, 20
691 sub sp, #8 @ push padding
692 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700693 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700694 .ifnc \rObj, r1
695 mov r1, \rObj @ pass rObj
696 .endif
697 mov r2, #\offset @ pass offset
698 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
699 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
700 .ifnc \rDest, r0
701 mov \rDest, r0 @ save return value in rDest
702 .endif
703 add sp, #8 @ pop padding
704 .cfi_adjust_cfa_offset -8
705 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
706 POP_REG_NE r1, 4, \rDest
707 POP_REG_NE r2, 8, \rDest
708 POP_REG_NE r3, 12, \rDest
709 POP_REG_NE ip, 16, \rDest
710 add sp, #20
711 .cfi_adjust_cfa_offset -20
712 pop {lr} @ restore lr
713 .cfi_adjust_cfa_offset -4
714 .cfi_restore lr
715#else
716 ldr \rDest, [\rObj, #\offset]
717 UNPOISON_HEAP_REF \rDest
718#endif // USE_READ_BARRIER
719.endm
720
Ian Rogerse51a5112011-09-23 14:16:35 -0700721 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700722 * Entry from managed code for array put operations of objects where the value being stored
723 * needs to be checked for compatibility.
724 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700725 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700726ENTRY art_quick_aput_obj_with_null_and_bound_check
727 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700728 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700729 b art_quick_throw_null_pointer_exception
730END art_quick_aput_obj_with_null_and_bound_check
731
Dan Albert58bea4a2014-08-09 18:08:07 -0700732 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700733ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700734 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700735 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700736 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700737 mov r0, r1
738 mov r1, r3
739 b art_quick_throw_array_bounds
740END art_quick_aput_obj_with_bound_check
741
Man Cao1aee9002015-07-14 22:31:42 -0700742#ifdef USE_READ_BARRIER
743 .extern artReadBarrierSlow
744#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700745 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700746ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700747#ifdef USE_READ_BARRIER
748 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
749 tst r2, r2
750 beq .Ldo_aput_null
751#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800752 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700753#endif // USE_READ_BARRIER
754 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
755 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
756 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700757 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800758 bne .Lcheck_assignability
759.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700760 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700761 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700762 str r2, [r3, r1, lsl #2]
763 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
764 lsr r0, r0, #7
765 strb r3, [r3, r0]
766 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800767.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700768 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700769 str r2, [r3, r1, lsl #2]
770 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800771.Lcheck_assignability:
772 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700773 .cfi_adjust_cfa_offset 16
774 .cfi_rel_offset r0, 0
775 .cfi_rel_offset r1, 4
776 .cfi_rel_offset r2, 8
777 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700778 mov r1, ip
779 mov r0, r3
780 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800781 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700782 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700783 .cfi_restore r0
784 .cfi_restore r1
785 .cfi_restore r2
786 .cfi_restore lr
787 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700788 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700789 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700790 str r2, [r3, r1, lsl #2]
791 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
792 lsr r0, r0, #7
793 strb r3, [r3, r0]
794 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800795.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700796 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700797 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100798 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700799 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700800 mov r2, r9 @ pass Thread::Current
801 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
802 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700803END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700804
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800805// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100806.macro ONE_ARG_DOWNCALL name, entrypoint, return
807 .extern \entrypoint
808ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100809 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100810 mov r1, r9 @ pass Thread::Current
811 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
812 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
813 \return
814END \name
815.endm
816
817// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800818.macro TWO_ARG_DOWNCALL name, entrypoint, return
819 .extern \entrypoint
820ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100821 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800822 mov r2, r9 @ pass Thread::Current
823 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700824 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800825 \return
826END \name
827.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700828
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800829// Macro to facilitate adding new array allocation entrypoints.
830.macro THREE_ARG_DOWNCALL name, entrypoint, return
831 .extern \entrypoint
832ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100833 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800834 mov r3, r9 @ pass Thread::Current
835 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
836 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700837 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800838 \return
839END \name
840.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700841
Jeff Hao848f70a2014-01-15 13:49:50 -0800842// Macro to facilitate adding new allocation entrypoints.
843.macro FOUR_ARG_DOWNCALL name, entrypoint, return
844 .extern \entrypoint
845ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100846 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800847 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800848 .cfi_adjust_cfa_offset 16
849 bl \entrypoint
850 add sp, #16 @ strip the extra frame
851 .cfi_adjust_cfa_offset -16
852 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
853 \return
854END \name
855.endm
856
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100857ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
858ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
859ONE_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 -0700860
Ian Rogersce9eca62011-10-07 17:11:03 -0700861 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700862 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700863 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700864ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
865ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
866ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
867ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
868ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
869ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700870 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700871 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700872 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800873 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700874ENTRY art_quick_get64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100875 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700876 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700877 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700878 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700879 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700880 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700881 cbnz r2, 1f @ success if no exception pending
882 bx lr @ return on success
8831:
Ian Rogersce9eca62011-10-07 17:11:03 -0700884 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700885END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700886
Ian Rogersce9eca62011-10-07 17:11:03 -0700887 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700888 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700889 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700890TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
891TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
892TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
893TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
894TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
895TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800896 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700897 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800898 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800899 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700900ENTRY art_quick_get64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100901 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700902 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -0800903 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700904 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700905 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700906 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700907 cbnz r2, 1f @ success if no exception pending
908 bx lr @ return on success
9091:
Ian Rogers1bddec32012-02-04 12:27:34 -0800910 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700911END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800912
Ian Rogers1bddec32012-02-04 12:27:34 -0800913 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700914 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800915 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700916TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
917TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
918TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
919TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -0700920 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700921 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100922 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -0700923 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800924 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700925ENTRY art_quick_set64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100926 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100927 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700928 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
929 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700930 .cfi_adjust_cfa_offset 16
931 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700932 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -0800933 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700934 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700935 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700936 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700937END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700938
Ian Rogersce9eca62011-10-07 17:11:03 -0700939 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700940 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700941 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700942THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
943THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
944THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
945THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -0800946 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700947 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800948 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700949 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700950ENTRY art_quick_set64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100951 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100952 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700953 ldr r12, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
954 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700955 .cfi_adjust_cfa_offset 12
956 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700957 .cfi_adjust_cfa_offset 4
958 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -0800959 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -0800960 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700961 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700962 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -0800963 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700964END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800965
Ian Rogers1bddec32012-02-04 12:27:34 -0800966 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -0700967 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100968 * exception on error. On success the String is returned. R0 holds the string index. The fast
969 * path check for hit in strings cache has already been performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700970 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100971ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb886da82011-09-23 16:27:54 -0700972
Mathieu Chartier7410f292013-11-24 13:17:35 -0800973// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700974GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -0800975
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -0700976// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
977ENTRY art_quick_alloc_object_rosalloc
978 // Fast path rosalloc allocation.
979 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
980 // r2, r3, r12: free.
981 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
982 // Load the class (r2)
983 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
984 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
985 // Check class status.
986 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
987 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
988 bne .Lart_quick_alloc_object_rosalloc_slow_path
989 // Add a fake dependence from the
990 // following access flag and size
991 // loads to the status load.
992 // This is to prevent those loads
993 // from being reordered above the
994 // status load and reading wrong
995 // values (an alternative is to use
996 // a load-acquire for the status).
997 eor r3, r3, r3
998 add r2, r2, r3
999 // Check access flags has
1000 // kAccClassIsFinalizable
1001 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1002 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1003 bne .Lart_quick_alloc_object_rosalloc_slow_path
1004
1005 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1006 // allocation stack has room.
1007 // TODO: consider using ldrd.
1008 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1009 cmp r3, r12
1010 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1011
1012 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3)
1013 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1014 // local allocation
1015 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1016 // Compute the rosalloc bracket index
1017 // from the size.
1018 // Align up the size by the rosalloc
1019 // bracket quantum size and divide
1020 // by the quantum size and subtract
1021 // by 1. This code is a shorter but
1022 // equivalent version.
1023 sub r3, r3, #1
1024 lsr r3, r3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1025 // Load the rosalloc run (r12)
1026 add r12, r9, r3, lsl #POINTER_SIZE_SHIFT
1027 ldr r12, [r12, #THREAD_ROSALLOC_RUNS_OFFSET]
1028 // Load the free list head (r3). This
1029 // will be the return val.
1030 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1031 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1032 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1033 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1034 // and update the list head with the
1035 // next pointer.
1036 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1037 // Store the class pointer in the
1038 // header. This also overwrites the
1039 // next pointer. The offsets are
1040 // asserted to match.
1041#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1042#error "Class pointer needs to overwrite next pointer."
1043#endif
1044 POISON_HEAP_REF r2
1045 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
1046 // Push the new object onto the thread
1047 // local allocation stack and
1048 // increment the thread local
1049 // allocation stack top.
1050 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1051 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1052 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1053 // Decrement the size of the free list
1054 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1055 sub r1, #1
1056 // TODO: consider combining this store
1057 // and the list head store above using
1058 // strd.
1059 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1060 // Fence. This is "ish" not "ishst" so
1061 // that the code after this allocation
1062 // site will see the right values in
1063 // the fields of the class.
1064 // Alternatively we could use "ishst"
1065 // if we use load-acquire for the
1066 // class status load.)
1067 dmb ish
1068 mov r0, r3 // Set the return value and return.
1069 bx lr
1070
1071.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001072 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001073 mov r2, r9 @ pass Thread::Current
1074 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1075 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1076 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1077END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001078
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001079// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1080//
1081// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1082// Need to preserve r0 and r1 to the slow path.
1083.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1084 cbz r2, \slowPathLabel // Check null class
1085 // Check class status.
1086 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1087 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1088 bne \slowPathLabel
1089 // Add a fake dependence from the
1090 // following access flag and size
1091 // loads to the status load.
1092 // This is to prevent those loads
1093 // from being reordered above the
1094 // status load and reading wrong
1095 // values (an alternative is to use
1096 // a load-acquire for the status).
1097 eor r3, r3, r3
1098 add r2, r2, r3
1099 // Check access flags has
1100 // kAccClassIsFinalizable.
1101 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1102 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1103 bne \slowPathLabel
1104 // Load thread_local_pos (r12) and
1105 // thread_local_end (r3) with ldrd.
1106 // Check constraints for ldrd.
1107#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1108#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1109#endif
1110 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1111 sub r12, r3, r12 // Compute the remaining buf size.
1112 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
1113 cmp r3, r12 // Check if it fits. OK to do this
1114 // before rounding up the object size
1115 // assuming the buf size alignment.
1116 bhi \slowPathLabel
1117 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1118 // Round up the object size by the
1119 // object alignment. (addr + 7) & ~7.
1120 add r3, r3, #OBJECT_ALIGNMENT_MASK
1121 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1122 // Reload old thread_local_pos (r0)
1123 // for the return value.
1124 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1125 add r1, r0, r3
1126 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1127 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1128 add r1, r1, #1
1129 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1130 POISON_HEAP_REF r2
1131 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1132 // Fence. This is "ish" not "ishst" so
1133 // that the code after this allocation
1134 // site will see the right values in
1135 // the fields of the class.
1136 // Alternatively we could use "ishst"
1137 // if we use load-acquire for the
1138 // class status load.)
1139 dmb ish
1140 bx lr
1141.endm
1142
1143// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1144ENTRY art_quick_alloc_object_tlab
1145 // Fast path tlab allocation.
1146 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1147 // r2, r3, r12: free.
1148#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001149 mvn r0, #0 // Read barrier not supported here.
1150 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001151#endif
1152 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1153 // Load the class (r2)
1154 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1155 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1156.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001157 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001158 mov r2, r9 // Pass Thread::Current.
1159 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1160 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1161 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1162END art_quick_alloc_object_tlab
1163
1164// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1165ENTRY art_quick_alloc_object_region_tlab
1166 // Fast path tlab allocation.
1167 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1168#if !defined(USE_READ_BARRIER)
1169 eor r0, r0, r0 // Read barrier must be enabled here.
1170 sub r0, r0, #1 // Return -1.
1171 bx lr
1172#endif
1173 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1174 // Load the class (r2)
1175 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1176 // Read barrier for class load.
1177 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
1178 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1179.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1180 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1181.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1182 // The read barrier slow path. Mark
1183 // the class.
1184 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1185 // to align sp by 16 bytes.
1186 mov r0, r2 // Pass the class as the first param.
1187 bl artReadBarrierMark
1188 mov r2, r0 // Get the (marked) class back.
1189 pop {r0, r1, r3, lr}
1190 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1191.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001192 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001193 mov r2, r9 // Pass Thread::Current.
1194 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1195 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1196 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1197END art_quick_alloc_object_region_tlab
1198
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001199 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001200 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001201 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001202 .extern artTestSuspendFromCode
1203ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001204#ifdef ARM_R4_SUSPEND_FLAG
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001205 ldrh r0, [rSELF, #THREAD_FLAGS_OFFSET]
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001206 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Ian Rogers637859c2013-08-27 14:35:54 -07001207 cbnz r0, 1f @ check Thread::Current()->suspend_count_ == 0
1208 bx lr @ return if suspend_count_ == 0
12091:
Wei Jin04f4d8a2014-05-29 18:04:29 -07001210#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001211 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001212 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for GC stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001213 @ TODO: save FPRs to enable access in the debugger?
1214 bl artTestSuspendFromCode @ (Thread*)
1215 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Ian Rogers9329bbb2013-02-08 19:56:30 -08001216END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001217
Dave Allison83252962014-04-03 16:33:48 -07001218ENTRY art_quick_implicit_suspend
1219 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001220 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001221 bl artTestSuspendFromCode @ (Thread*)
1222 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001223END art_quick_implicit_suspend
1224
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001225 /*
1226 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001227 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1228 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001229 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001230 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001231ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001232 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001233 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001234 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001235 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001236 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001237 // Tear down the callee-save frame. Skip arg registers.
1238 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1239 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001240 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001241 cbnz r2, 1f @ success if no exception is pending
1242 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001243 bx lr @ return on success
12441:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001245 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001246END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001247
Jeff Hao88474b42013-10-23 16:24:40 -07001248 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001249 * Called to resolve an imt conflict.
1250 * r0 is the conflict ArtMethod.
1251 * r12 is a hidden argument that holds the target interface method's dex method index.
1252 *
1253 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001254 */
1255ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001256 ldr r4, [sp, #0] // Load referrer
1257 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1258 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1259 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1260 ldr r4, [r0] // Load first entry in ImtConflictTable.
1261.Limt_table_iterate:
1262 cmp r4, r12
1263 // Branch if found. Benchmarks have shown doing a branch here is better.
1264 beq .Limt_table_found
1265 // If the entry is null, the interface method is not in the ImtConflictTable.
1266 cbz r4, .Lconflict_trampoline
1267 // Iterate over the entries of the ImtConflictTable.
1268 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1269 b .Limt_table_iterate
1270.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001271 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001272 // and jump to it.
1273 ldr r0, [r0, #__SIZEOF_POINTER__]
1274 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1275.Lconflict_trampoline:
1276 // Call the runtime stub to populate the ImtConflictTable and jump to the
1277 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001278 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001279END art_quick_imt_conflict_trampoline
1280
Ian Rogers468532e2013-08-05 10:56:33 -07001281 .extern artQuickResolutionTrampoline
1282ENTRY art_quick_resolution_trampoline
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001283 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001284 mov r2, r9 @ pass Thread::Current
1285 mov r3, sp @ pass SP
1286 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001287 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001288 mov r12, r0
1289 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001290 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001291 bx r12 @ tail-call into actual code
12921:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001293 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001294 DELIVER_PENDING_EXCEPTION
1295END art_quick_resolution_trampoline
1296
Andreas Gampec200a4a2014-06-16 18:39:09 -07001297 /*
1298 * Called to do a generic JNI down-call
1299 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001300ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001301 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001302
1303 // Save rSELF
1304 mov r11, rSELF
1305 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1306 mov r10, sp
1307 .cfi_def_cfa_register r10
1308
1309 sub sp, sp, #5120
1310
1311 // prepare for artQuickGenericJniTrampoline call
1312 // (Thread*, SP)
1313 // r0 r1 <= C calling convention
1314 // rSELF r10 <= where they are
1315
1316 mov r0, rSELF // Thread*
1317 mov r1, r10
1318 blx artQuickGenericJniTrampoline // (Thread*, sp)
1319
1320 // The C call will have registered the complete save-frame on success.
1321 // The result of the call is:
1322 // r0: pointer to native code, 0 on error.
1323 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1324
1325 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001326 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001327
1328 // Release part of the alloca.
1329 mov sp, r1
1330
1331 // Save the code pointer
1332 mov r12, r0
1333
1334 // Load parameters from frame into registers.
1335 pop {r0-r3}
1336
1337 // Softfloat.
1338 // TODO: Change to hardfloat when supported.
1339
1340 blx r12 // native call.
1341
1342 // result sign extension is handled in C code
1343 // prepare for artQuickGenericJniEndTrampoline call
1344 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001345 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001346 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001347 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001348
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001349 push {r0-r1}
1350 mov r3, r1
1351 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001352 mov r0, r11
1353
1354 blx artQuickGenericJniEndTrampoline
1355
Andreas Gampec200a4a2014-06-16 18:39:09 -07001356 // Restore self pointer.
1357 mov r9, r11
1358
1359 // Pending exceptions possible.
1360 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1361 cbnz r2, .Lexception_in_native
1362
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001363 // Tear down the alloca.
1364 mov sp, r10
1365 .cfi_def_cfa_register sp
1366
Zheng Xu5667fdb2014-10-23 18:29:55 +08001367 // Tear down the callee-save frame. Skip arg registers.
1368 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1369 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1370 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001371
Zheng Xu5667fdb2014-10-23 18:29:55 +08001372 // store into fpr, for when it's a fpr return...
1373 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001374 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001375 // Undo the unwinding information from above since it doesn't apply below.
1376 .cfi_def_cfa_register r10
1377 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001378
Andreas Gampec200a4a2014-06-16 18:39:09 -07001379.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001380 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1381 .cfi_def_cfa_register sp
1382 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001383 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001384END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001385
Ian Rogers468532e2013-08-05 10:56:33 -07001386 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001387ENTRY art_quick_to_interpreter_bridge
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001388 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001389 mov r1, r9 @ pass Thread::Current
1390 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001391 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001392 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001393 // Tear down the callee-save frame. Skip arg registers.
1394 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1395 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001396 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001397 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001398 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1399 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014001:
Ian Rogers7db619b2013-01-16 18:35:48 -08001401 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001402END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001403
jeffhaoe343b762011-12-05 16:36:44 -08001404 /*
jeffhao0791adc2012-04-04 11:14:32 -07001405 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001406 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001407 .extern artInstrumentationMethodEntryFromCode
1408 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001409ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001410 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001411 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001412 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1413 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001414 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001415 mov r3, lr @ pass LR
1416 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001417 mov r12, r0 @ r12 holds reference to code
1418 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001419 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001420 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001421@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001422 .type art_quick_instrumentation_exit, #function
1423 .global art_quick_instrumentation_exit
1424art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001425 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001426 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 -08001427 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001428 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001429 .cfi_adjust_cfa_offset 8
1430 .cfi_rel_offset r0, 0
1431 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001432 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001433 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001434 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1435 @ need to align by 16.
1436 .cfi_adjust_cfa_offset 8
1437 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001438 mov r2, r0 @ pass return value as gpr_res
1439 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001440 mov r0, r9 @ pass Thread::Current
1441 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001442 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001443 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001444 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001445
Ian Rogers306057f2012-11-26 12:45:53 -08001446 mov r2, r0 @ link register saved by instrumentation
1447 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001448 vpop {d0} @ restore fp return value
1449 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001450 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001451 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001452 .cfi_restore r0
1453 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001454 add sp, #32 @ remove callee save frame
1455 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001456 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001457END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001458
Ian Rogers306057f2012-11-26 12:45:53 -08001459 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001460 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1461 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001462 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001463 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001464ENTRY art_quick_deoptimize
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001465 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001466 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001467 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001468END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001469
Ian Rogers324e1902012-09-09 12:17:52 -07001470 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001471 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001472 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001473 */
1474 .extern artDeoptimizeFromCompiledCode
1475ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001476 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001477 mov r0, r9 @ Set up args.
1478 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1479END art_quick_deoptimize_from_compiled_code
1480
1481 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001482 * Signed 64-bit integer multiply.
1483 *
1484 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1485 * WX
1486 * x YZ
1487 * --------
1488 * ZW ZX
1489 * YW YX
1490 *
1491 * The low word of the result holds ZX, the high word holds
1492 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1493 * it doesn't fit in the low 64 bits.
1494 *
1495 * Unlike most ARM math operations, multiply instructions have
1496 * restrictions on using the same register more than once (Rd and Rm
1497 * cannot be the same).
1498 */
1499 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001500ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001501 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001502 .cfi_adjust_cfa_offset 8
1503 .cfi_rel_offset r9, 0
1504 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001505 mul ip, r2, r1 @ ip<- ZxW
1506 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1507 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1508 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1509 mov r0,r9
1510 mov r1,r10
1511 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001512 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001513 .cfi_restore r9
1514 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001515 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001516END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001517
buzbee54330722011-08-23 16:46:55 -07001518 /*
1519 * Long integer shift. This is different from the generic 32/64-bit
1520 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1521 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1522 * 6 bits.
1523 * On entry:
1524 * r0: low word
1525 * r1: high word
1526 * r2: shift count
1527 */
1528 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001529ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001530 and r2, r2, #63 @ r2<- r2 & 0x3f
1531 mov r1, r1, asl r2 @ r1<- r1 << r2
1532 rsb r3, r2, #32 @ r3<- 32 - r2
1533 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1534 subs ip, r2, #32 @ ip<- r2 - 32
1535 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1536 mov r0, r0, asl r2 @ r0<- r0 << r2
1537 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001538END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001539
buzbee54330722011-08-23 16:46:55 -07001540 /*
1541 * Long integer shift. This is different from the generic 32/64-bit
1542 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1543 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1544 * 6 bits.
1545 * On entry:
1546 * r0: low word
1547 * r1: high word
1548 * r2: shift count
1549 */
1550 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001551ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001552 and r2, r2, #63 @ r0<- r0 & 0x3f
1553 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1554 rsb r3, r2, #32 @ r3<- 32 - r2
1555 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1556 subs ip, r2, #32 @ ip<- r2 - 32
1557 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1558 mov r1, r1, asr r2 @ r1<- r1 >> r2
1559 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001560END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001561
buzbee54330722011-08-23 16:46:55 -07001562 /*
1563 * Long integer shift. This is different from the generic 32/64-bit
1564 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1565 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1566 * 6 bits.
1567 * On entry:
1568 * r0: low word
1569 * r1: high word
1570 * r2: shift count
1571 */
1572 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001573ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001574 and r2, r2, #63 @ r0<- r0 & 0x3f
1575 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1576 rsb r3, r2, #32 @ r3<- 32 - r2
1577 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1578 subs ip, r2, #32 @ ip<- r2 - 32
1579 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1580 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1581 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001582END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001583
buzbeefc9e6fa2012-03-23 15:14:29 -07001584 /*
1585 * String's indexOf.
1586 *
1587 * On entry:
1588 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001589 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001590 * r2: Starting offset in string data
1591 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001592ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001593 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001594 .cfi_adjust_cfa_offset 16
1595 .cfi_rel_offset r4, 0
1596 .cfi_rel_offset r10, 4
1597 .cfi_rel_offset r11, 8
1598 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001599 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001600 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001601
1602 /* Clamp start to [0..count] */
1603 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001604 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001605 movlt r2, #0
1606 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001607 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001608 movgt r2, r3
1609
buzbeefc9e6fa2012-03-23 15:14:29 -07001610 /* Save a copy in r12 to later compute result */
1611 mov r12, r0
1612
1613 /* Build pointer to start of data to compare and pre-bias */
1614 add r0, r0, r2, lsl #1
1615 sub r0, #2
1616
1617 /* Compute iteration count */
1618 sub r2, r3, r2
1619
1620 /*
1621 * At this point we have:
1622 * r0: start of data to test
1623 * r1: char to compare
1624 * r2: iteration count
1625 * r12: original start of string data
1626 * r3, r4, r10, r11 available for loading string data
1627 */
1628
1629 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001630 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001631
Ian Rogers5d885c82014-02-21 20:06:23 -08001632.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001633 ldrh r3, [r0, #2]!
1634 ldrh r4, [r0, #2]!
1635 ldrh r10, [r0, #2]!
1636 ldrh r11, [r0, #2]!
1637 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001638 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001639 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001640 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001641 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001642 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001643 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001644 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001645 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001646 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001647
Ian Rogers5d885c82014-02-21 20:06:23 -08001648.Lindexof_remainder:
1649 adds r2, #4
1650 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001651
Ian Rogers5d885c82014-02-21 20:06:23 -08001652.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001653 ldrh r3, [r0, #2]!
1654 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001655 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001656 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001657 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001658
Ian Rogers5d885c82014-02-21 20:06:23 -08001659.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001660 mov r0, #-1
1661 pop {r4, r10-r11, pc}
1662
Ian Rogers5d885c82014-02-21 20:06:23 -08001663.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001664 sub r0, #6
1665 sub r0, r12
1666 asr r0, r0, #1
1667 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001668.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001669 sub r0, #4
1670 sub r0, r12
1671 asr r0, r0, #1
1672 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001673.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001674 sub r0, #2
1675 sub r0, r12
1676 asr r0, r0, #1
1677 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001678.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001679 sub r0, r12
1680 asr r0, r0, #1
1681 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001682END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001683
Zheng Xu5667fdb2014-10-23 18:29:55 +08001684 /* Assembly routines used to handle ABI differences. */
1685
1686 /* double fmod(double a, double b) */
1687 .extern fmod
1688ENTRY art_quick_fmod
1689 push {lr}
1690 .cfi_adjust_cfa_offset 4
1691 .cfi_rel_offset lr, 0
1692 sub sp, #4
1693 .cfi_adjust_cfa_offset 4
1694 vmov r0, r1, d0
1695 vmov r2, r3, d1
1696 bl fmod
1697 vmov d0, r0, r1
1698 add sp, #4
1699 .cfi_adjust_cfa_offset -4
1700 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001701END art_quick_fmod
1702
1703 /* float fmodf(float a, float b) */
1704 .extern fmodf
1705ENTRY art_quick_fmodf
1706 push {lr}
1707 .cfi_adjust_cfa_offset 4
1708 .cfi_rel_offset lr, 0
1709 sub sp, #4
1710 .cfi_adjust_cfa_offset 4
1711 vmov r0, r1, d0
1712 bl fmodf
1713 vmov s0, r0
1714 add sp, #4
1715 .cfi_adjust_cfa_offset -4
1716 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001717END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001718
1719 /* int64_t art_d2l(double d) */
1720 .extern art_d2l
1721ENTRY art_quick_d2l
1722 vmov r0, r1, d0
1723 b art_d2l
1724END art_quick_d2l
1725
1726 /* int64_t art_f2l(float f) */
1727 .extern art_f2l
1728ENTRY art_quick_f2l
1729 vmov r0, s0
1730 b art_f2l
1731END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001732
1733 /* float art_l2f(int64_t l) */
1734 .extern art_l2f
1735ENTRY art_quick_l2f
1736 push {lr}
1737 .cfi_adjust_cfa_offset 4
1738 .cfi_rel_offset lr, 0
1739 sub sp, #4
1740 .cfi_adjust_cfa_offset 4
1741 bl art_l2f
1742 vmov s0, r0
1743 add sp, #4
1744 .cfi_adjust_cfa_offset -4
1745 pop {pc}
1746END art_quick_l2f