blob: 42418ad2ff0f81b15ef2fb2ac4fe857b64993035 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_arm.S"
Ian Rogers9651f422011-09-19 20:26:07 -070018
Mathieu Chartier7410f292013-11-24 13:17:35 -080019#include "arch/quick_alloc_entrypoints.S"
20
Ian Rogersff1ed472011-09-20 13:46:24 -070021 /* Deliver the given exception */
22 .extern artDeliverExceptionFromCode
23 /* Deliver an exception pending on a thread */
24 .extern artDeliverPendingException
25
Ian Rogers4f0d07c2011-10-06 23:38:47 -070026 /*
Andreas Gampe76914b02015-07-17 20:14:50 -070027 * Macro to spill the GPRs.
Ian Rogers4f0d07c2011-10-06 23:38:47 -070028 */
Andreas Gampe76914b02015-07-17 20:14:50 -070029.macro SPILL_ALL_CALLEE_SAVE_GPRS
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070030 push {r4-r11, lr} @ 9 words (36 bytes) of callee saves.
Ian Rogers9329bbb2013-02-08 19:56:30 -080031 .cfi_adjust_cfa_offset 36
32 .cfi_rel_offset r4, 0
33 .cfi_rel_offset r5, 4
34 .cfi_rel_offset r6, 8
35 .cfi_rel_offset r7, 12
36 .cfi_rel_offset r8, 16
37 .cfi_rel_offset r9, 20
38 .cfi_rel_offset r10, 24
39 .cfi_rel_offset r11, 28
40 .cfi_rel_offset lr, 32
Andreas Gampe76914b02015-07-17 20:14:50 -070041.endm
42
43 /*
44 * Macro that sets up the callee save frame to conform with
45 * Runtime::CreateCalleeSaveMethod(kSaveAll)
46 */
Vladimir Marko3098c8c2016-06-14 17:43:17 +010047.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME rTemp
Andreas Gampe76914b02015-07-17 20:14:50 -070048 SPILL_ALL_CALLEE_SAVE_GPRS @ 9 words (36 bytes) of callee saves.
Zheng Xu5667fdb2014-10-23 18:29:55 +080049 vpush {s16-s31} @ 16 words (64 bytes) of floats.
Zheng Xu5667fdb2014-10-23 18:29:55 +080050 .cfi_adjust_cfa_offset 64
51 sub sp, #12 @ 3 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080052 .cfi_adjust_cfa_offset 12
Vladimir Marko3098c8c2016-06-14 17:43:17 +010053 RUNTIME_CURRENT1 \rTemp @ Load Runtime::Current into rTemp.
54 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET] @ rTemp is kSaveAll Method*.
55 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070056 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070057
58 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xu5667fdb2014-10-23 18:29:55 +080059#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 36 + 64 + 12)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070060#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM) size not as expected."
61#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070062.endm
63
64 /*
65 * Macro that sets up the callee save frame to conform with
Mathieu Chartier19841522013-10-22 11:29:00 -070066 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
Ian Rogers4f0d07c2011-10-06 23:38:47 -070067 */
Vladimir Marko3098c8c2016-06-14 17:43:17 +010068.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME rTemp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070069 push {r5-r8, r10-r11, lr} @ 7 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -080070 .cfi_adjust_cfa_offset 28
71 .cfi_rel_offset r5, 0
72 .cfi_rel_offset r6, 4
73 .cfi_rel_offset r7, 8
74 .cfi_rel_offset r8, 12
75 .cfi_rel_offset r10, 16
76 .cfi_rel_offset r11, 20
77 .cfi_rel_offset lr, 24
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070078 sub sp, #4 @ bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -080079 .cfi_adjust_cfa_offset 4
Vladimir Marko3098c8c2016-06-14 17:43:17 +010080 RUNTIME_CURRENT2 \rTemp @ Load Runtime::Current into rTemp.
81 ldr \rTemp, [\rTemp, #RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET] @ rTemp is kRefsOnly Method*.
82 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070083 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070084
85 // Ugly compile-time check, but we only have the preprocessor.
86#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 28 + 4)
87#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM) size not as expected."
88#endif
Ian Rogers4f0d07c2011-10-06 23:38:47 -070089.endm
90
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070091.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070092 add sp, #4 @ bottom word holds Method*
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -070093 .cfi_adjust_cfa_offset -4
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070094 pop {r5-r8, r10-r11, lr} @ 7 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080095 .cfi_restore r5
96 .cfi_restore r6
97 .cfi_restore r7
98 .cfi_restore r8
99 .cfi_restore r10
100 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700101 .cfi_restore lr
102 .cfi_adjust_cfa_offset -28
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700103.endm
104
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu5667fdb2014-10-23 18:29:55 +0800106 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700107 bx lr @ return
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700108.endm
109
110 /*
111 * Macro that sets up the callee save frame to conform with
Mathieu Chartier19841522013-10-22 11:29:00 -0700112 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700113 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800114.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
115 push {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves and args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800116 .cfi_adjust_cfa_offset 40
Jeff Hao5d917302013-02-27 17:57:33 -0800117 .cfi_rel_offset r1, 0
118 .cfi_rel_offset r2, 4
119 .cfi_rel_offset r3, 8
120 .cfi_rel_offset r5, 12
121 .cfi_rel_offset r6, 16
122 .cfi_rel_offset r7, 20
123 .cfi_rel_offset r8, 24
124 .cfi_rel_offset r10, 28
125 .cfi_rel_offset r11, 32
126 .cfi_rel_offset lr, 36
Zheng Xu5667fdb2014-10-23 18:29:55 +0800127 vpush {s0-s15} @ 16 words of float args.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800128 .cfi_adjust_cfa_offset 64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700129 sub sp, #8 @ 2 words of space, bottom word will hold Method*
Ian Rogers9329bbb2013-02-08 19:56:30 -0800130 .cfi_adjust_cfa_offset 8
Zheng Xu5667fdb2014-10-23 18:29:55 +0800131 // Ugly compile-time check, but we only have the preprocessor.
132#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 40 + 64 + 8)
133#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM) size not as expected."
134#endif
135.endm
136
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100137.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME rTemp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800138 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100139 RUNTIME_CURRENT3 \rTemp @ Load Runtime::Current into rTemp.
140 @ rTemp is kRefsAndArgs Method*.
141 ldr \rTemp, [\rTemp, #RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET]
142 str \rTemp, [sp, #0] @ Place Method* at bottom of stack.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700144.endm
145
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700146.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Zheng Xu5667fdb2014-10-23 18:29:55 +0800147 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700148 str r0, [sp, #0] @ Store ArtMethod* to bottom of stack.
149 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
150.endm
151
152.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700153 add sp, #8 @ rewind sp
Zheng Xu5667fdb2014-10-23 18:29:55 +0800154 .cfi_adjust_cfa_offset -8
155 vpop {s0-s15}
156 .cfi_adjust_cfa_offset -64
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700157 pop {r1-r3, r5-r8, r10-r11, lr} @ 10 words of callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -0800158 .cfi_restore r1
159 .cfi_restore r2
160 .cfi_restore r3
161 .cfi_restore r5
162 .cfi_restore r6
163 .cfi_restore r7
164 .cfi_restore r8
165 .cfi_restore r10
166 .cfi_restore r11
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700167 .cfi_restore lr
Zheng Xu5667fdb2014-10-23 18:29:55 +0800168 .cfi_adjust_cfa_offset -40
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700169.endm
170
Vladimir Marko952dbb12016-07-28 12:01:51 +0100171 /*
172 * Macro that sets up the callee save frame to conform with
173 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
174 */
175.macro SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME rTemp
176 push {r0-r12, lr} @ 14 words of callee saves and args.
177 .cfi_adjust_cfa_offset 56
178 .cfi_rel_offset r0, 0
179 .cfi_rel_offset r1, 4
180 .cfi_rel_offset r2, 8
181 .cfi_rel_offset r3, 12
182 .cfi_rel_offset r4, 16
183 .cfi_rel_offset r5, 20
184 .cfi_rel_offset r6, 24
185 .cfi_rel_offset r7, 28
186 .cfi_rel_offset r8, 32
187 .cfi_rel_offset r9, 36
188 .cfi_rel_offset r10, 40
189 .cfi_rel_offset r11, 44
190 .cfi_rel_offset ip, 48
191 .cfi_rel_offset lr, 52
192 vpush {s0-s31} @ 32 words of float args.
193 .cfi_adjust_cfa_offset 128
194 sub sp, #8 @ 2 words of space, alignment padding and Method*
195 .cfi_adjust_cfa_offset 8
196 RUNTIME_CURRENT1 \rTemp @ Load Runtime::Current into rTemp.
197 @ Load kSaveEverything Method* to rTemp.
198 ldr \rTemp, [\rTemp, #RUNTIME_SAVE_EVERYTHING_CALLEE_SAVE_FRAME_OFFSET]
199 str \rTemp, [sp, #0] @ Store kSaveEverything Method* to the bottom of the stack.
200 str sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET] @ Place sp in Thread::Current()->top_quick_frame.
201
202 // Ugly compile-time check, but we only have the preprocessor.
203#if (FRAME_SIZE_SAVE_EVERYTHING_CALLEE_SAVE != 56 + 128 + 8)
204#error "SAVE_EVERYTHING_CALLEE_SAVE_FRAME(ARM) size not as expected."
205#endif
206.endm
207
208.macro RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME
209 add sp, #8 @ rewind sp
210 .cfi_adjust_cfa_offset -8
211 vpop {s0-s31}
212 .cfi_adjust_cfa_offset -128
213 pop {r0-r12, lr} @ 14 words of callee saves
214 .cfi_restore r0
215 .cfi_restore r1
216 .cfi_restore r2
217 .cfi_restore r3
218 .cfi_restore r5
219 .cfi_restore r6
220 .cfi_restore r7
221 .cfi_restore r8
222 .cfi_restore r9
223 .cfi_restore r10
224 .cfi_restore r11
225 .cfi_restore r12
226 .cfi_restore lr
227 .cfi_adjust_cfa_offset -56
228.endm
229
Ian Rogers637859c2013-08-27 14:35:54 -0700230.macro RETURN_IF_RESULT_IS_ZERO
231 cbnz r0, 1f @ result non-zero branch over
232 bx lr @ return
2331:
234.endm
235
236.macro RETURN_IF_RESULT_IS_NON_ZERO
237 cbz r0, 1f @ result zero branch over
238 bx lr @ return
2391:
240.endm
241
Ian Rogersce9eca62011-10-07 17:11:03 -0700242 /*
243 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
244 * exception is Thread::Current()->exception_
245 */
246.macro DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -0800247 .fnend
248 .fnstart
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100249 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ save callee saves for throw
Ian Rogersce9eca62011-10-07 17:11:03 -0700250 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700251 b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700252.endm
253
Ian Rogers57b86d42012-03-27 16:05:41 -0700254.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700255 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800256ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100257 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0 @ save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700258 mov r0, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700259 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800260END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700261.endm
buzbee44b412b2012-02-04 08:50:53 -0800262
Ian Rogers57b86d42012-03-27 16:05:41 -0700263.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700264 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800265ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100266 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r1 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700267 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700268 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800269END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700270.endm
Ian Rogers9651f422011-09-19 20:26:07 -0700271
Ian Rogers57b86d42012-03-27 16:05:41 -0700272.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700273 .extern \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800274ENTRY \c_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100275 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersff1ed472011-09-20 13:46:24 -0700276 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700277 b \cxx_name @ \cxx_name(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -0800278END \c_name
Ian Rogers57b86d42012-03-27 16:05:41 -0700279.endm
Ian Rogersbdb03912011-09-14 00:55:44 -0700280
Fred Shih37f05ef2014-07-16 18:38:08 -0700281.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
282 ldr \reg, [r9, #THREAD_EXCEPTION_OFFSET] // Get exception field.
283 cbnz \reg, 1f
284 bx lr
2851:
286 DELIVER_PENDING_EXCEPTION
287.endm
288
289.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
290 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG r1
291.endm
292
293.macro RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
294 RETURN_IF_RESULT_IS_ZERO
295 DELIVER_PENDING_EXCEPTION
296.endm
297
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800298.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
299 RETURN_IF_RESULT_IS_NON_ZERO
300 DELIVER_PENDING_EXCEPTION
301.endm
302
Fred Shih37f05ef2014-07-16 18:38:08 -0700303// Macros taking opportunity of code similarities for downcalls with referrer for non-wide fields.
304.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
305 .extern \entrypoint
306ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100307 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700308 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700309 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700310 bl \entrypoint @ (uint32_t field_idx, const Method* referrer, Thread*)
311 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700312 \return
313END \name
314.endm
315
316.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
317 .extern \entrypoint
318ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100319 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700320 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Fred Shih37f05ef2014-07-16 18:38:08 -0700321 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700322 bl \entrypoint @ (field_idx, Object*, referrer, Thread*)
323 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Fred Shih37f05ef2014-07-16 18:38:08 -0700324 \return
325END \name
326.endm
327
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800328.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
Fred Shih37f05ef2014-07-16 18:38:08 -0700329 .extern \entrypoint
330ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100331 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700332 ldr r3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
333 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700334 .cfi_adjust_cfa_offset 16
335 bl \entrypoint @ (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700336 add sp, #16 @ release out args
337 .cfi_adjust_cfa_offset -16
Roland Levillainf969a202016-03-09 16:14:00 +0000338 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Fred Shih37f05ef2014-07-16 18:38:08 -0700339 \return
340END \name
341.endm
342
Ian Rogers57b86d42012-03-27 16:05:41 -0700343 /*
344 * Called by managed code, saves callee saves and then calls artThrowException
345 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
346 */
Ian Rogers468532e2013-08-05 10:56:33 -0700347ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Ian Rogers932746a2011-09-22 18:57:50 -0700348
Ian Rogers57b86d42012-03-27 16:05:41 -0700349 /*
350 * Called by managed code to create and deliver a NullPointerException.
351 */
Ian Rogers468532e2013-08-05 10:56:33 -0700352NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700353
Ian Rogers57b86d42012-03-27 16:05:41 -0700354 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100355 * Call installed by a signal handler to create and deliver a NullPointerException.
356 */
357ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
358
359 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700360 * Called by managed code to create and deliver an ArithmeticException.
361 */
Ian Rogers468532e2013-08-05 10:56:33 -0700362NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogersc0c8dc82011-09-24 18:15:59 -0700363
Ian Rogers57b86d42012-03-27 16:05:41 -0700364 /*
365 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
366 * index, arg2 holds limit.
367 */
Ian Rogers468532e2013-08-05 10:56:33 -0700368TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700369
370 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100371 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
372 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
373 */
374TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
375
376 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700377 * Called by managed code to create and deliver a StackOverflowError.
378 */
Ian Rogers468532e2013-08-05 10:56:33 -0700379NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700380
381 /*
382 * Called by managed code to create and deliver a NoSuchMethodError.
383 */
Ian Rogers468532e2013-08-05 10:56:33 -0700384ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700385
386 /*
Ian Rogersc8b306f2012-02-17 21:34:44 -0800387 * All generated callsites for interface invokes and invocation slow paths will load arguments
388 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100389 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700390 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
buzbee4a3164f2011-09-03 11:25:10 -0700391 *
Ian Rogersc8b306f2012-02-17 21:34:44 -0800392 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
393 * of the target Method* in r0 and method->code_ in r1.
buzbee4a3164f2011-09-03 11:25:10 -0700394 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700395 * If unsuccessful, the helper will return null/null. There will bea pending exception in the
Ian Rogersc8b306f2012-02-17 21:34:44 -0800396 * thread and we branch to another stub to deliver it.
buzbee4a3164f2011-09-03 11:25:10 -0700397 *
Ian Rogersff1ed472011-09-20 13:46:24 -0700398 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
399 * pointing back to the original caller.
buzbee4a3164f2011-09-03 11:25:10 -0700400 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700401.macro INVOKE_TRAMPOLINE_BODY cxx_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800402 .extern \cxx_name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100403 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2 @ save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100404 mov r2, r9 @ pass Thread::Current
405 mov r3, sp
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700406 bl \cxx_name @ (method_idx, this, Thread*, SP)
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700407 mov r12, r1 @ save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700408 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700409 cbz r0, 1f @ did we find the target? if not go to exception delivery
410 bx r12 @ tail call to target
4111:
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800412 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700413.endm
414.macro INVOKE_TRAMPOLINE c_name, cxx_name
415ENTRY \c_name
416 INVOKE_TRAMPOLINE_BODY \cxx_name
Ian Rogers9329bbb2013-02-08 19:56:30 -0800417END \c_name
Ian Rogersc8b306f2012-02-17 21:34:44 -0800418.endm
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800419
Logan Chien8dbb7082013-01-25 20:31:17 +0800420INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogersa32a6fd2012-02-06 20:18:44 -0800421
Logan Chien8dbb7082013-01-25 20:31:17 +0800422INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
423INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
424INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
425INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogersff1ed472011-09-20 13:46:24 -0700426
Ian Rogers57b86d42012-03-27 16:05:41 -0700427 /*
Zheng Xu5667fdb2014-10-23 18:29:55 +0800428 * Quick invocation stub internal.
Jeff Hao6474d192013-03-26 14:08:09 -0700429 * On entry:
430 * r0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700431 * r1 = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700432 * r2 = size of argument array in bytes
433 * r3 = (managed) thread pointer
434 * [sp] = JValue* result
Zheng Xu5667fdb2014-10-23 18:29:55 +0800435 * [sp + 4] = result_in_float
436 * [sp + 8] = core register argument array
437 * [sp + 12] = fp register argument array
438 * +-------------------------+
439 * | uint32_t* fp_reg_args |
440 * | uint32_t* core_reg_args |
441 * | result_in_float | <- Caller frame
442 * | Jvalue* result |
443 * +-------------------------+
444 * | lr |
445 * | r11 |
446 * | r9 |
447 * | r4 | <- r11
448 * +-------------------------+
449 * | uint32_t out[n-1] |
450 * | : : | Outs
451 * | uint32_t out[0] |
452 * | StackRef<ArtMethod> | <- SP value=null
453 * +-------------------------+
Jeff Hao5d917302013-02-27 17:57:33 -0800454 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800455ENTRY art_quick_invoke_stub_internal
Andreas Gampe76914b02015-07-17 20:14:50 -0700456 SPILL_ALL_CALLEE_SAVE_GPRS @ spill regs (9)
Jeff Hao5d917302013-02-27 17:57:33 -0800457 mov r11, sp @ save the stack pointer
458 .cfi_def_cfa_register r11
Zheng Xu5667fdb2014-10-23 18:29:55 +0800459
Jeff Hao5d917302013-02-27 17:57:33 -0800460 mov r9, r3 @ move managed thread pointer into r9
Zheng Xu5667fdb2014-10-23 18:29:55 +0800461
462 add r4, r2, #4 @ create space for method pointer in frame
463 sub r4, sp, r4 @ reserve & align *stack* to 16 bytes: native calling
464 and r4, #0xFFFFFFF0 @ convention only aligns to 8B, so we have to ensure ART
465 mov sp, r4 @ 16B alignment ourselves.
466
467 mov r4, r0 @ save method*
468 add r0, sp, #4 @ pass stack pointer + method ptr as dest for memcpy
469 bl memcpy @ memcpy (dest, src, bytes)
470 mov ip, #0 @ set ip to 0
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700471 str ip, [sp] @ store null for method* at bottom of frame
Zheng Xu5667fdb2014-10-23 18:29:55 +0800472
Nicolas Geoffray48088462014-12-12 10:29:38 +0000473 ldr ip, [r11, #48] @ load fp register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800474 vldm ip, {s0-s15} @ copy s0 - s15
475
Nicolas Geoffray48088462014-12-12 10:29:38 +0000476 ldr ip, [r11, #44] @ load core register argument array pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800477 mov r0, r4 @ restore method*
478 add ip, ip, #4 @ skip r0
479 ldm ip, {r1-r3} @ copy r1 - r3
480
Wei Jin04f4d8a2014-05-29 18:04:29 -0700481#ifdef ARM_R4_SUSPEND_FLAG
Jeff Hao5d917302013-02-27 17:57:33 -0800482 mov r4, #SUSPEND_CHECK_INTERVAL @ reset r4 to suspend check interval
Wei Jin04f4d8a2014-05-29 18:04:29 -0700483#endif
Andreas Gampe6e498692014-08-18 16:43:12 -0700484
Mathieu Chartiere401d142015-04-22 13:56:20 -0700485 ldr ip, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32] @ get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800486 blx ip @ call the method
Zheng Xu5667fdb2014-10-23 18:29:55 +0800487
Jeff Hao6474d192013-03-26 14:08:09 -0700488 mov sp, r11 @ restore the stack pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800489 .cfi_def_cfa_register sp
490
Nicolas Geoffray48088462014-12-12 10:29:38 +0000491 ldr r4, [sp, #40] @ load result_is_float
492 ldr r9, [sp, #36] @ load the result pointer
Zheng Xu5667fdb2014-10-23 18:29:55 +0800493 cmp r4, #0
494 ite eq
495 strdeq r0, [r9] @ store r0/r1 into result pointer
496 vstrne d0, [r9] @ store s0-s1/d0 into result pointer
497
Nicolas Geoffray48088462014-12-12 10:29:38 +0000498 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc} @ restore spill regs
Zheng Xu5667fdb2014-10-23 18:29:55 +0800499END art_quick_invoke_stub_internal
Jeff Hao6474d192013-03-26 14:08:09 -0700500
Jeff Hao5d917302013-02-27 17:57:33 -0800501 /*
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000502 * On stack replacement stub.
503 * On entry:
504 * r0 = stack to copy
505 * r1 = size of stack
506 * r2 = pc to call
507 * r3 = JValue* result
508 * [sp] = shorty
509 * [sp + 4] = thread
510 */
511ENTRY art_quick_osr_stub
512 SPILL_ALL_CALLEE_SAVE_GPRS @ Spill regs (9)
513 mov r11, sp @ Save the stack pointer
514 mov r10, r1 @ Save size of stack
515 ldr r9, [r11, #40] @ Move managed thread pointer into r9
516 mov r8, r2 @ Save the pc to call
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000517 sub r7, sp, #12 @ Reserve space for stack pointer,
518 @ JValue* result, and ArtMethod* slot.
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000519 and r7, #0xFFFFFFF0 @ Align stack pointer
520 mov sp, r7 @ Update stack pointer
521 str r11, [sp, #4] @ Save old stack pointer
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000522 str r3, [sp, #8] @ Save JValue* result
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000523 mov ip, #0
524 str ip, [sp] @ Store null for ArtMethod* at bottom of frame
525 sub sp, sp, r1 @ Reserve space for callee stack
526 mov r2, r1
527 mov r1, r0
528 mov r0, sp
529 bl memcpy @ memcpy (dest r0, src r1, bytes r2)
530 bl .Losr_entry @ Call the method
Nicolas Geoffrayd9994f02016-02-11 17:35:55 +0000531 ldr r10, [sp, #8] @ Restore JValue* result
532 ldr sp, [sp, #4] @ Restore saved stack pointer
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000533 ldr r4, [sp, #36] @ load shorty
Nicolas Geoffrayd9bc4332016-02-05 23:32:25 +0000534 ldrb r4, [r4, #0] @ load return type
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000535 cmp r4, #68 @ Test if result type char == 'D'.
536 beq .Losr_fp_result
537 cmp r4, #70 @ Test if result type char == 'F'.
538 beq .Losr_fp_result
539 strd r0, [r10] @ Store r0/r1 into result pointer
540 b .Losr_exit
541.Losr_fp_result:
542 vstr d0, [r10] @ Store s0-s1/d0 into result pointer
543.Losr_exit:
544 pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
545.Losr_entry:
546 sub r10, r10, #4
547 str lr, [sp, r10] @ Store link register per the compiler ABI
548 bx r8
549END art_quick_osr_stub
550
551 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700552 * On entry r0 is uint32_t* gprs_ and r1 is uint32_t* fprs_
553 */
Ian Rogers637859c2013-08-27 14:35:54 -0700554ARM_ENTRY art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700555 vldm r1, {s0-s31} @ load all fprs from argument fprs_
556 ldr r2, [r0, #60] @ r2 = r15 (PC from gprs_ 60=4*15)
Jeff Hao467f8162014-08-05 18:59:16 -0700557 ldr r14, [r0, #56] @ (LR from gprs_ 56=4*14)
Ian Rogers57b86d42012-03-27 16:05:41 -0700558 add r0, r0, #12 @ increment r0 to skip gprs_[0..2] 12=4*3
Jeff Hao467f8162014-08-05 18:59:16 -0700559 ldm r0, {r3-r13} @ load remaining gprs from argument gprs_
Andreas Gampe639bdd12015-06-03 11:22:45 -0700560 ldr r0, [r0, #-12] @ load r0 value
561 mov r1, #0 @ clear result register r1
Ian Rogers57b86d42012-03-27 16:05:41 -0700562 bx r2 @ do long jump
Ian Rogers9329bbb2013-02-08 19:56:30 -0800563END art_quick_do_long_jump
Ian Rogers57b86d42012-03-27 16:05:41 -0700564
Ian Rogers60db5ab2012-02-20 17:02:00 -0800565 /*
Ian Rogersff1ed472011-09-20 13:46:24 -0700566 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
567 * failure.
568 */
Ian Rogers832336b2014-10-08 15:35:22 -0700569TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700570
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700571 /*
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700572 * Entry from managed code that calls artLockObjectFromCode, may block for GC. r0 holds the
573 * possibly null object to lock.
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700574 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800575 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700576ENTRY art_quick_lock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800577 cbz r0, .Lslow_lock
578.Lretry_lock:
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700579 ldr r2, [r9, #THREAD_ID_OFFSET]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700580 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800581 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700582 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800583 cbnz r3, .Lnot_unlocked @ already thin locked
584 @ unlocked case - r1: original lock word that's zero except for the read barrier bits.
585 orr r2, r1, r2 @ r2 holds thread id with count of 0 with preserved read barrier bits
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700586 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800587 cbnz r3, .Llock_strex_fail @ store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700588 dmb ish @ full (LoadLoad|LoadStore) memory barrier
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700589 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800590.Lnot_unlocked: @ r1: original lock word, r2: thread_id with count of 0 and zero read barrier bits
591 lsr r3, r1, LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800592 cbnz r3, .Lslow_lock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700593 eor r2, r1, r2 @ lock_word.ThreadId() ^ self->ThreadId()
594 uxth r2, r2 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800595 cbnz r2, .Lslow_lock @ lock word and self thread id's match -> recursive lock
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700596 @ else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800597 mov r3, r1 @ copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700598 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800599 add r2, r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count in lock word placing in r2 to check overflow
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700600 lsr r3, r2, #LOCK_WORD_GC_STATE_SHIFT @ if the first gc state bit is set, we overflowed.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800601 cbnz r3, .Lslow_lock @ if we overflow the count go slow path
602 add r2, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ increment count for real
603 strex r3, r2, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
604 cbnz r3, .Llock_strex_fail @ strex failed, retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700605 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800606.Llock_strex_fail:
607 b .Lretry_lock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800608.Lslow_lock:
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100609 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700610 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700611 bl artLockObjectFromCode @ (Object* obj, Thread*)
612 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700613 RETURN_IF_RESULT_IS_ZERO
614 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700615END art_quick_lock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700616
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700617ENTRY art_quick_lock_object_no_inline
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100618 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700619 mov r1, r9 @ pass Thread::Current
620 bl artLockObjectFromCode @ (Object* obj, Thread*)
621 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
622 RETURN_IF_RESULT_IS_ZERO
623 DELIVER_PENDING_EXCEPTION
624END art_quick_lock_object_no_inline
625
Ian Rogersff1ed472011-09-20 13:46:24 -0700626 /*
627 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700628 * r0 holds the possibly null object to lock.
Ian Rogersff1ed472011-09-20 13:46:24 -0700629 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800630 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700631ENTRY art_quick_unlock_object
Ian Rogers5d885c82014-02-21 20:06:23 -0800632 cbz r0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800633.Lretry_unlock:
634#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700635 ldr r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800636#else
637 ldrex r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ Need to use atomic instructions for read barrier
638#endif
639 lsr r2, r1, #LOCK_WORD_STATE_SHIFT
Ian Rogers5d885c82014-02-21 20:06:23 -0800640 cbnz r2, .Lslow_unlock @ if either of the top two bits are set, go slow path
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700641 ldr r2, [r9, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800642 mov r3, r1 @ copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700643 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800644 eor r3, r3, r2 @ lock_word.ThreadId() ^ self->ThreadId()
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700645 uxth r3, r3 @ zero top 16 bits
Ian Rogers5d885c82014-02-21 20:06:23 -0800646 cbnz r3, .Lslow_unlock @ do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800647 mov r3, r1 @ copy lock word to detect transition to unlocked
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700648 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED @ zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800649 cmp r3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Ian Rogers5d885c82014-02-21 20:06:23 -0800650 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800651 @ transition to unlocked
652 mov r3, r1
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700653 and r3, #LOCK_WORD_GC_STATE_MASK_SHIFTED @ r3: zero except for the preserved gc bits
Andreas Gampe675967d2014-05-14 16:28:34 -0700654 dmb ish @ full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800655#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700656 str r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800657#else
658 strex r2, r3, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
659 cbnz r2, .Lunlock_strex_fail @ store failed, retry
660#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700661 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800662.Lrecursive_thin_unlock: @ r1: original lock word
663 sub r1, r1, #LOCK_WORD_THIN_LOCK_COUNT_ONE @ decrement count
664#ifndef USE_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700665 str r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800666#else
667 strex r2, r1, [r0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] @ strex necessary for read barrier bits
668 cbnz r2, .Lunlock_strex_fail @ store failed, retry
669#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700670 bx lr
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800671.Lunlock_strex_fail:
672 b .Lretry_unlock @ retry
Ian Rogers5d885c82014-02-21 20:06:23 -0800673.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700674 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100675 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Ian Rogers637859c2013-08-27 14:35:54 -0700676 mov r1, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700677 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
678 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700679 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -0700680 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700681END art_quick_unlock_object
Ian Rogersff1ed472011-09-20 13:46:24 -0700682
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700683ENTRY art_quick_unlock_object_no_inline
684 @ save callee saves in case exception allocation triggers GC
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100685 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700686 mov r1, r9 @ pass Thread::Current
687 bl artUnlockObjectFromCode @ (Object* obj, Thread*)
688 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
689 RETURN_IF_RESULT_IS_ZERO
690 DELIVER_PENDING_EXCEPTION
691END art_quick_unlock_object_no_inline
692
Ian Rogersff1ed472011-09-20 13:46:24 -0700693 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700694 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
695 * artThrowClassCastException.
Ian Rogersff1ed472011-09-20 13:46:24 -0700696 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700697 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700698ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700699 push {r0-r1, lr} @ save arguments, link register and pad
Ian Rogersa9a82542013-10-04 11:17:26 -0700700 .cfi_adjust_cfa_offset 12
701 .cfi_rel_offset r0, 0
702 .cfi_rel_offset r1, 4
703 .cfi_rel_offset lr, 8
704 sub sp, #4
Ian Rogersa9a82542013-10-04 11:17:26 -0700705 .cfi_adjust_cfa_offset 4
706 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800707 cbz r0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700708 add sp, #4
709 .cfi_adjust_cfa_offset -4
710 pop {r0-r1, pc}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700711 .cfi_adjust_cfa_offset 4 @ Reset unwind info so following code unwinds.
Ian Rogers5d885c82014-02-21 20:06:23 -0800712.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700713 add sp, #4
714 .cfi_adjust_cfa_offset -4
715 pop {r0-r1, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700716 .cfi_adjust_cfa_offset -12
Dave Allisonbbb32c22013-11-05 18:25:18 -0800717 .cfi_restore r0
718 .cfi_restore r1
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700719 .cfi_restore lr
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100720 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r2 @ save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -0700721 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700722 b artThrowClassCastException @ (Class*, Class*, Thread*)
Ian Rogersa9a82542013-10-04 11:17:26 -0700723 bkpt
Ian Rogers468532e2013-08-05 10:56:33 -0700724END art_quick_check_cast
buzbee4a3164f2011-09-03 11:25:10 -0700725
Man Cao1aee9002015-07-14 22:31:42 -0700726// Restore rReg's value from [sp, #offset] if rReg is not the same as rExclude.
727.macro POP_REG_NE rReg, offset, rExclude
728 .ifnc \rReg, \rExclude
729 ldr \rReg, [sp, #\offset] @ restore rReg
730 .cfi_restore \rReg
731 .endif
732.endm
733
Roland Levillain4359e612016-07-20 11:32:19 +0100734// Save rReg's value to [sp, #offset].
735.macro PUSH_REG rReg, offset
736 str \rReg, [sp, #\offset] @ save rReg
737 .cfi_rel_offset \rReg, \offset
738.endm
739
Man Cao1aee9002015-07-14 22:31:42 -0700740 /*
741 * Macro to insert read barrier, only used in art_quick_aput_obj.
742 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
743 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
744 */
745.macro READ_BARRIER rDest, rObj, offset
746#ifdef USE_READ_BARRIER
747 push {r0-r3, ip, lr} @ 6 words for saved registers (used in art_quick_aput_obj)
748 .cfi_adjust_cfa_offset 24
749 .cfi_rel_offset r0, 0
750 .cfi_rel_offset r1, 4
751 .cfi_rel_offset r2, 8
752 .cfi_rel_offset r3, 12
753 .cfi_rel_offset ip, 16
754 .cfi_rel_offset lr, 20
755 sub sp, #8 @ push padding
756 .cfi_adjust_cfa_offset 8
Man Cao63069212015-08-21 15:51:39 -0700757 @ mov r0, \rRef @ pass ref in r0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -0700758 .ifnc \rObj, r1
759 mov r1, \rObj @ pass rObj
760 .endif
761 mov r2, #\offset @ pass offset
762 bl artReadBarrierSlow @ artReadBarrierSlow(ref, rObj, offset)
763 @ No need to unpoison return value in r0, artReadBarrierSlow() would do the unpoisoning.
764 .ifnc \rDest, r0
765 mov \rDest, r0 @ save return value in rDest
766 .endif
767 add sp, #8 @ pop padding
768 .cfi_adjust_cfa_offset -8
769 POP_REG_NE r0, 0, \rDest @ conditionally restore saved registers
770 POP_REG_NE r1, 4, \rDest
771 POP_REG_NE r2, 8, \rDest
772 POP_REG_NE r3, 12, \rDest
773 POP_REG_NE ip, 16, \rDest
774 add sp, #20
775 .cfi_adjust_cfa_offset -20
776 pop {lr} @ restore lr
777 .cfi_adjust_cfa_offset -4
778 .cfi_restore lr
779#else
780 ldr \rDest, [\rObj, #\offset]
781 UNPOISON_HEAP_REF \rDest
782#endif // USE_READ_BARRIER
783.endm
784
Ian Rogerse51a5112011-09-23 14:16:35 -0700785 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700786 * Entry from managed code for array put operations of objects where the value being stored
787 * needs to be checked for compatibility.
788 * r0 = array, r1 = index, r2 = value
Ian Rogerse51a5112011-09-23 14:16:35 -0700789 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700790ENTRY art_quick_aput_obj_with_null_and_bound_check
791 tst r0, r0
Dan Albertd8426482014-08-07 17:40:03 -0700792 bne art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700793 b art_quick_throw_null_pointer_exception
794END art_quick_aput_obj_with_null_and_bound_check
795
Dan Albert58bea4a2014-08-09 18:08:07 -0700796 .hidden art_quick_aput_obj_with_bound_check
Ian Rogersa9a82542013-10-04 11:17:26 -0700797ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700798 ldr r3, [r0, #MIRROR_ARRAY_LENGTH_OFFSET]
Ian Rogersa9a82542013-10-04 11:17:26 -0700799 cmp r3, r1
Dan Albertd8426482014-08-07 17:40:03 -0700800 bhi art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700801 mov r0, r1
802 mov r1, r3
803 b art_quick_throw_array_bounds
804END art_quick_aput_obj_with_bound_check
805
Man Cao1aee9002015-07-14 22:31:42 -0700806#ifdef USE_READ_BARRIER
807 .extern artReadBarrierSlow
808#endif
Dan Albert58bea4a2014-08-09 18:08:07 -0700809 .hidden art_quick_aput_obj
Ian Rogersa9a82542013-10-04 11:17:26 -0700810ENTRY art_quick_aput_obj
Man Cao1aee9002015-07-14 22:31:42 -0700811#ifdef USE_READ_BARRIER
812 @ The offset to .Ldo_aput_null is too large to use cbz due to expansion from READ_BARRIER macro.
813 tst r2, r2
814 beq .Ldo_aput_null
815#else
Ian Rogers5d885c82014-02-21 20:06:23 -0800816 cbz r2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -0700817#endif // USE_READ_BARRIER
818 READ_BARRIER r3, r0, MIRROR_OBJECT_CLASS_OFFSET
819 READ_BARRIER ip, r2, MIRROR_OBJECT_CLASS_OFFSET
820 READ_BARRIER r3, r3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700821 cmp r3, ip @ value's type == array's component type - trivial assignability
Ian Rogers5d885c82014-02-21 20:06:23 -0800822 bne .Lcheck_assignability
823.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700824 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700825 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700826 str r2, [r3, r1, lsl #2]
827 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
828 lsr r0, r0, #7
829 strb r3, [r3, r0]
830 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800831.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700832 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Ian Rogersa9a82542013-10-04 11:17:26 -0700833 str r2, [r3, r1, lsl #2]
834 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800835.Lcheck_assignability:
836 push {r0-r2, lr} @ save arguments
Andreas Gampe525cde22014-04-22 15:44:50 -0700837 .cfi_adjust_cfa_offset 16
838 .cfi_rel_offset r0, 0
839 .cfi_rel_offset r1, 4
840 .cfi_rel_offset r2, 8
841 .cfi_rel_offset lr, 12
Ian Rogersa9a82542013-10-04 11:17:26 -0700842 mov r1, ip
843 mov r0, r3
844 bl artIsAssignableFromCode
Ian Rogers5d885c82014-02-21 20:06:23 -0800845 cbz r0, .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700846 pop {r0-r2, lr}
Andreas Gampe525cde22014-04-22 15:44:50 -0700847 .cfi_restore r0
848 .cfi_restore r1
849 .cfi_restore r2
850 .cfi_restore lr
851 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700852 add r3, r0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700853 POISON_HEAP_REF r2
Ian Rogersa9a82542013-10-04 11:17:26 -0700854 str r2, [r3, r1, lsl #2]
855 ldr r3, [r9, #THREAD_CARD_TABLE_OFFSET]
856 lsr r0, r0, #7
857 strb r3, [r3, r0]
858 blx lr
Ian Rogers5d885c82014-02-21 20:06:23 -0800859.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700860 pop {r0-r2, lr}
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -0700861 /* No need to repeat restore cfi directives, the ones above apply here. */
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100862 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r3
Ian Rogersa9a82542013-10-04 11:17:26 -0700863 mov r1, r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700864 mov r2, r9 @ pass Thread::Current
865 b artThrowArrayStoreException @ (Class*, Class*, Thread*)
866 bkpt @ unreached
Ian Rogersa9a82542013-10-04 11:17:26 -0700867END art_quick_aput_obj
Ian Rogerse51a5112011-09-23 14:16:35 -0700868
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800869// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100870.macro ONE_ARG_DOWNCALL name, entrypoint, return
871 .extern \entrypoint
872ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100873 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100874 mov r1, r9 @ pass Thread::Current
875 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
876 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
877 \return
878END \name
879.endm
880
881// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800882.macro TWO_ARG_DOWNCALL name, entrypoint, return
883 .extern \entrypoint
884ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100885 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800886 mov r2, r9 @ pass Thread::Current
887 bl \entrypoint @ (uint32_t type_idx, Method* method, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700888 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800889 \return
890END \name
891.endm
Ian Rogersce9eca62011-10-07 17:11:03 -0700892
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800893// Macro to facilitate adding new array allocation entrypoints.
894.macro THREE_ARG_DOWNCALL name, entrypoint, return
895 .extern \entrypoint
896ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100897 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r3 @ save callee saves in case of GC
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800898 mov r3, r9 @ pass Thread::Current
899 @ (uint32_t type_idx, Method* method, int32_t component_count, Thread*)
900 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700901 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800902 \return
903END \name
904.endm
Ian Rogers28ad40d2011-10-27 15:19:26 -0700905
Jeff Hao848f70a2014-01-15 13:49:50 -0800906// Macro to facilitate adding new allocation entrypoints.
907.macro FOUR_ARG_DOWNCALL name, entrypoint, return
908 .extern \entrypoint
909ENTRY \name
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100910 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -0800911 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -0800912 .cfi_adjust_cfa_offset 16
913 bl \entrypoint
914 add sp, #16 @ strip the extra frame
915 .cfi_adjust_cfa_offset -16
916 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
917 \return
918END \name
919.endm
920
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100921ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
922ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
923ONE_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 -0700924
Ian Rogersce9eca62011-10-07 17:11:03 -0700925 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700926 * Called by managed code to resolve a static field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700927 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700928ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
929ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
930ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
931ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
932ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
933ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogersce9eca62011-10-07 17:11:03 -0700934 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700935 * Called by managed code to resolve a static field and load a 64-bit primitive value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700936 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800937 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700938ENTRY art_quick_get64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100939 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700940 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogersce9eca62011-10-07 17:11:03 -0700941 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700942 bl artGet64StaticFromCode @ (uint32_t field_idx, const Method* referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700943 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700944 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700945 cbnz r2, 1f @ success if no exception pending
946 bx lr @ return on success
9471:
Ian Rogersce9eca62011-10-07 17:11:03 -0700948 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700949END art_quick_get64_static
Ian Rogersce9eca62011-10-07 17:11:03 -0700950
Ian Rogersce9eca62011-10-07 17:11:03 -0700951 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700952 * Called by managed code to resolve an instance field and load a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -0700953 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700954TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
955TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
956TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
957TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
958TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
959TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_R1
Ian Rogers1bddec32012-02-04 12:27:34 -0800960 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700961 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800962 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800963 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700964ENTRY art_quick_get64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100965 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700966 ldr r2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
Ian Rogers1bddec32012-02-04 12:27:34 -0800967 mov r3, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700968 bl artGet64InstanceFromCode @ (field_idx, Object*, referrer, Thread*)
Ian Rogers637859c2013-08-27 14:35:54 -0700969 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700970 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers637859c2013-08-27 14:35:54 -0700971 cbnz r2, 1f @ success if no exception pending
972 bx lr @ return on success
9731:
Ian Rogers1bddec32012-02-04 12:27:34 -0800974 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700975END art_quick_get64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -0800976
Ian Rogers1bddec32012-02-04 12:27:34 -0800977 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700978 * Called by managed code to resolve a static field and store a non-wide value.
Ian Rogers1bddec32012-02-04 12:27:34 -0800979 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700980TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
981TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
982TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
983TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogersce9eca62011-10-07 17:11:03 -0700984 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700985 * Called by managed code to resolve a static field and store a 64-bit primitive value.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100986 * On entry r0 holds field index, r2:r3 hold new_val
Ian Rogersce9eca62011-10-07 17:11:03 -0700987 */
Ian Rogers9329bbb2013-02-08 19:56:30 -0800988 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700989ENTRY art_quick_set64_static
Vladimir Marko3098c8c2016-06-14 17:43:17 +0100990 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +0100991 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700992 ldr r1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
993 str r9, [sp, #-16]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700994 .cfi_adjust_cfa_offset 16
995 bl artSet64StaticFromCode @ (field_idx, referrer, new_val, Thread*)
Ian Rogersce9eca62011-10-07 17:11:03 -0700996 add sp, #16 @ release out args
Dave Allisonbbb32c22013-11-05 18:25:18 -0800997 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700998 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -0700999 RETURN_IF_RESULT_IS_ZERO
Ian Rogersce9eca62011-10-07 17:11:03 -07001000 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001001END art_quick_set64_static
Ian Rogersce9eca62011-10-07 17:11:03 -07001002
Ian Rogersce9eca62011-10-07 17:11:03 -07001003 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001004 * Called by managed code to resolve an instance field and store a non-wide value.
Ian Rogersce9eca62011-10-07 17:11:03 -07001005 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001006THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1007THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1008THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
1009THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_RESULT_IS_ZERO_OR_DELIVER
Ian Rogers1bddec32012-02-04 12:27:34 -08001010 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001011 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
Ian Rogers1bddec32012-02-04 12:27:34 -08001012 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001013 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001014ENTRY art_quick_set64_instance
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001015 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r12 @ save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001016 @ r2:r3 contain the wide argument
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001017 ldr r12, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] @ pass referrer
1018 str r9, [sp, #-12]! @ expand the frame and pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001019 .cfi_adjust_cfa_offset 12
1020 str r12, [sp, #-4]! @ expand the frame and pass the referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001021 .cfi_adjust_cfa_offset 4
1022 bl artSet64InstanceFromCode @ (field_idx, Object*, new_val, Method* referrer, Thread*)
Ian Rogers1bddec32012-02-04 12:27:34 -08001023 add sp, #16 @ release out args
Ian Rogers9329bbb2013-02-08 19:56:30 -08001024 .cfi_adjust_cfa_offset -16
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001025 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME @ TODO: we can clearly save an add here
Ian Rogers637859c2013-08-27 14:35:54 -07001026 RETURN_IF_RESULT_IS_ZERO
Ian Rogers1bddec32012-02-04 12:27:34 -08001027 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001028END art_quick_set64_instance
Ian Rogers1bddec32012-02-04 12:27:34 -08001029
Ian Rogers1bddec32012-02-04 12:27:34 -08001030 /*
Ian Rogerscaab8c42011-10-12 12:11:18 -07001031 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001032 * exception on error. On success the String is returned. R0 holds the string index. The fast
1033 * path check for hit in strings cache has already been performed.
Brian Carlstromaded5f72011-10-07 17:15:04 -07001034 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001035ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersb886da82011-09-23 16:27:54 -07001036
Mathieu Chartier7410f292013-11-24 13:17:35 -08001037// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001038GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi7e1ce282015-12-11 15:46:19 -08001039
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001040// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1041ENTRY art_quick_alloc_object_rosalloc
1042 // Fast path rosalloc allocation.
1043 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1044 // r2, r3, r12: free.
1045 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1046 // Load the class (r2)
1047 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1048 cbz r2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
1049 // Check class status.
1050 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1051 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1052 bne .Lart_quick_alloc_object_rosalloc_slow_path
1053 // Add a fake dependence from the
1054 // following access flag and size
1055 // loads to the status load.
1056 // This is to prevent those loads
1057 // from being reordered above the
1058 // status load and reading wrong
1059 // values (an alternative is to use
1060 // a load-acquire for the status).
1061 eor r3, r3, r3
1062 add r2, r2, r3
1063 // Check access flags has
1064 // kAccClassIsFinalizable
1065 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1066 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1067 bne .Lart_quick_alloc_object_rosalloc_slow_path
1068
1069 ldr r3, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1070 // allocation stack has room.
1071 // TODO: consider using ldrd.
1072 ldr r12, [r9, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1073 cmp r3, r12
1074 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1075
1076 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3)
1077 cmp r3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1078 // local allocation
1079 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1080 // Compute the rosalloc bracket index
1081 // from the size.
1082 // Align up the size by the rosalloc
1083 // bracket quantum size and divide
1084 // by the quantum size and subtract
1085 // by 1. This code is a shorter but
1086 // equivalent version.
1087 sub r3, r3, #1
1088 lsr r3, r3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1089 // Load the rosalloc run (r12)
1090 add r12, r9, r3, lsl #POINTER_SIZE_SHIFT
1091 ldr r12, [r12, #THREAD_ROSALLOC_RUNS_OFFSET]
1092 // Load the free list head (r3). This
1093 // will be the return val.
1094 ldr r3, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1095 cbz r3, .Lart_quick_alloc_object_rosalloc_slow_path
1096 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1097 ldr r1, [r3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1098 // and update the list head with the
1099 // next pointer.
1100 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1101 // Store the class pointer in the
1102 // header. This also overwrites the
1103 // next pointer. The offsets are
1104 // asserted to match.
1105#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1106#error "Class pointer needs to overwrite next pointer."
1107#endif
1108 POISON_HEAP_REF r2
1109 str r2, [r3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001110 // Fence. This is "ish" not "ishst" so
1111 // that it also ensures ordering of
1112 // the class status load with respect
1113 // to later accesses to the class
1114 // object. Alternatively we could use
1115 // "ishst" if we use load-acquire for
1116 // the class status load.)
1117 // Needs to be done before pushing on
1118 // allocation since Heap::VisitObjects
1119 // relies on seeing the class pointer.
1120 // b/28790624
1121 dmb ish
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001122 // Push the new object onto the thread
1123 // local allocation stack and
1124 // increment the thread local
1125 // allocation stack top.
1126 ldr r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1127 str r3, [r1], #COMPRESSED_REFERENCE_SIZE // (Increment r1 as a side effect.)
1128 str r1, [r9, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1129 // Decrement the size of the free list
1130 ldr r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1131 sub r1, #1
1132 // TODO: consider combining this store
1133 // and the list head store above using
1134 // strd.
1135 str r1, [r12, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001136
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001137 mov r0, r3 // Set the return value and return.
1138 bx lr
1139
1140.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001141 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 @ save callee saves in case of GC
Hiroshi Yamauchidc412b62015-10-15 12:26:57 -07001142 mov r2, r9 @ pass Thread::Current
1143 bl artAllocObjectFromCodeRosAlloc @ (uint32_t type_idx, Method* method, Thread*)
1144 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1145 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1146END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001147
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001148// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1149//
1150// r0: type_idx/return value, r1: ArtMethod*, r2: class, r9: Thread::Current, r3, r12: free.
1151// Need to preserve r0 and r1 to the slow path.
1152.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1153 cbz r2, \slowPathLabel // Check null class
1154 // Check class status.
1155 ldr r3, [r2, #MIRROR_CLASS_STATUS_OFFSET]
1156 cmp r3, #MIRROR_CLASS_STATUS_INITIALIZED
1157 bne \slowPathLabel
1158 // Add a fake dependence from the
1159 // following access flag and size
1160 // loads to the status load.
1161 // This is to prevent those loads
1162 // from being reordered above the
1163 // status load and reading wrong
1164 // values (an alternative is to use
1165 // a load-acquire for the status).
1166 eor r3, r3, r3
1167 add r2, r2, r3
1168 // Check access flags has
1169 // kAccClassIsFinalizable.
1170 ldr r3, [r2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1171 tst r3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1172 bne \slowPathLabel
1173 // Load thread_local_pos (r12) and
1174 // thread_local_end (r3) with ldrd.
1175 // Check constraints for ldrd.
1176#if !((THREAD_LOCAL_POS_OFFSET + 4 == THREAD_LOCAL_END_OFFSET) && (THREAD_LOCAL_POS_OFFSET % 8 == 0))
1177#error "Thread::thread_local_pos/end must be consecutive and are 8 byte aligned for performance"
1178#endif
1179 ldrd r12, r3, [r9, #THREAD_LOCAL_POS_OFFSET]
1180 sub r12, r3, r12 // Compute the remaining buf size.
1181 ldr r3, [r2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (r3).
1182 cmp r3, r12 // Check if it fits. OK to do this
1183 // before rounding up the object size
1184 // assuming the buf size alignment.
1185 bhi \slowPathLabel
1186 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber r0 and r1.
1187 // Round up the object size by the
1188 // object alignment. (addr + 7) & ~7.
1189 add r3, r3, #OBJECT_ALIGNMENT_MASK
1190 and r3, r3, #OBJECT_ALIGNMENT_MASK_TOGGLED
1191 // Reload old thread_local_pos (r0)
1192 // for the return value.
1193 ldr r0, [r9, #THREAD_LOCAL_POS_OFFSET]
1194 add r1, r0, r3
1195 str r1, [r9, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1196 ldr r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1197 add r1, r1, #1
1198 str r1, [r9, #THREAD_LOCAL_OBJECTS_OFFSET]
1199 POISON_HEAP_REF r2
1200 str r2, [r0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1201 // Fence. This is "ish" not "ishst" so
1202 // that the code after this allocation
1203 // site will see the right values in
1204 // the fields of the class.
1205 // Alternatively we could use "ishst"
1206 // if we use load-acquire for the
1207 // class status load.)
1208 dmb ish
1209 bx lr
1210.endm
1211
1212// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1213ENTRY art_quick_alloc_object_tlab
1214 // Fast path tlab allocation.
1215 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current
1216 // r2, r3, r12: free.
1217#if defined(USE_READ_BARRIER)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001218 mvn r0, #0 // Read barrier not supported here.
1219 bx lr // Return -1.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001220#endif
1221 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1222 // Load the class (r2)
1223 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1224 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1225.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001226 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001227 mov r2, r9 // Pass Thread::Current.
1228 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1229 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1230 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1231END art_quick_alloc_object_tlab
1232
1233// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1234ENTRY art_quick_alloc_object_region_tlab
1235 // Fast path tlab allocation.
1236 // r0: type_idx/return value, r1: ArtMethod*, r9: Thread::Current, r2, r3, r12: free.
1237#if !defined(USE_READ_BARRIER)
1238 eor r0, r0, r0 // Read barrier must be enabled here.
1239 sub r0, r0, #1 // Return -1.
1240 bx lr
1241#endif
1242 ldr r2, [r1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_32] // Load dex cache resolved types array
1243 // Load the class (r2)
1244 ldr r2, [r2, r0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1245 // Read barrier for class load.
1246 ldr r3, [r9, #THREAD_IS_GC_MARKING_OFFSET]
1247 cbnz r3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1248.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1249 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1250.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1251 // The read barrier slow path. Mark
1252 // the class.
1253 push {r0, r1, r3, lr} // Save registers. r3 is pushed only
1254 // to align sp by 16 bytes.
1255 mov r0, r2 // Pass the class as the first param.
1256 bl artReadBarrierMark
1257 mov r2, r0 // Get the (marked) class back.
1258 pop {r0, r1, r3, lr}
1259 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1260.Lart_quick_alloc_object_region_tlab_slow_path:
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001261 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r2 // Save callee saves in case of GC.
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001262 mov r2, r9 // Pass Thread::Current.
1263 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1264 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1265 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1266END art_quick_alloc_object_region_tlab
1267
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001268 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001269 * Called by managed code when the value in rSUSPEND has been decremented to 0.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001270 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001271 .extern artTestSuspendFromCode
1272ENTRY art_quick_test_suspend
Wei Jin04f4d8a2014-05-29 18:04:29 -07001273#ifdef ARM_R4_SUSPEND_FLAG
Vladimir Marko952dbb12016-07-28 12:01:51 +01001274 ldrh rSUSPEND, [rSELF, #THREAD_FLAGS_OFFSET]
1275 cbnz rSUSPEND, 1f @ check Thread::Current()->suspend_count_ == 0
1276 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1277 bx lr @ return if suspend_count_ == 0
Ian Rogers637859c2013-08-27 14:35:54 -070012781:
Vladimir Marko952dbb12016-07-28 12:01:51 +01001279 mov rSUSPEND, #SUSPEND_CHECK_INTERVAL @ reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Wei Jin04f4d8a2014-05-29 18:04:29 -07001280#endif
Vladimir Marko952dbb12016-07-28 12:01:51 +01001281 SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME r0 @ save everything for GC stack crawl
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001282 mov r0, rSELF
Vladimir Marko952dbb12016-07-28 12:01:51 +01001283 bl artTestSuspendFromCode @ (Thread*)
1284 RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME
1285 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001286END art_quick_test_suspend
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001287
Dave Allison83252962014-04-03 16:33:48 -07001288ENTRY art_quick_implicit_suspend
1289 mov r0, rSELF
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001290 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME r1 @ save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001291 bl artTestSuspendFromCode @ (Thread*)
1292 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Dave Allison83252962014-04-03 16:33:48 -07001293END art_quick_implicit_suspend
1294
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001295 /*
1296 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001297 * r0 holds the proxy method and r1 holds the receiver; r2 and r3 may contain arguments. The
1298 * frame size of the invoked proxy method agrees with a ref and args callee save frame.
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001299 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001300 .extern artQuickProxyInvokeHandler
Ian Rogers9329bbb2013-02-08 19:56:30 -08001301ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001302 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001303 mov r2, r9 @ pass Thread::Current
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001304 mov r3, sp @ pass SP
Jeff Hao5fa60c32013-04-04 17:57:01 -07001305 blx artQuickProxyInvokeHandler @ (Method* proxy method, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001306 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001307 // Tear down the callee-save frame. Skip arg registers.
1308 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1309 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001310 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu5667fdb2014-10-23 18:29:55 +08001311 cbnz r2, 1f @ success if no exception is pending
1312 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
Ian Rogers637859c2013-08-27 14:35:54 -07001313 bx lr @ return on success
13141:
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001315 DELIVER_PENDING_EXCEPTION
Ian Rogers9329bbb2013-02-08 19:56:30 -08001316END art_quick_proxy_invoke_handler
Ian Rogersdfcdf1a2011-10-10 17:50:35 -07001317
Jeff Hao88474b42013-10-23 16:24:40 -07001318 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001319 * Called to resolve an imt conflict.
1320 * r0 is the conflict ArtMethod.
1321 * r12 is a hidden argument that holds the target interface method's dex method index.
1322 *
1323 * Note that this stub writes to r0, r4, and r12.
Jeff Hao88474b42013-10-23 16:24:40 -07001324 */
1325ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001326 ldr r4, [sp, #0] // Load referrer
1327 ldr r4, [r4, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_32] // Load dex cache methods array
1328 ldr r12, [r4, r12, lsl #POINTER_SIZE_SHIFT] // Load interface method
1329 ldr r0, [r0, #ART_METHOD_JNI_OFFSET_32] // Load ImtConflictTable
1330 ldr r4, [r0] // Load first entry in ImtConflictTable.
1331.Limt_table_iterate:
1332 cmp r4, r12
1333 // Branch if found. Benchmarks have shown doing a branch here is better.
1334 beq .Limt_table_found
1335 // If the entry is null, the interface method is not in the ImtConflictTable.
1336 cbz r4, .Lconflict_trampoline
1337 // Iterate over the entries of the ImtConflictTable.
1338 ldr r4, [r0, #(2 * __SIZEOF_POINTER__)]!
1339 b .Limt_table_iterate
1340.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001341 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001342 // and jump to it.
1343 ldr r0, [r0, #__SIZEOF_POINTER__]
1344 ldr pc, [r0, #ART_METHOD_QUICK_CODE_OFFSET_32]
1345.Lconflict_trampoline:
1346 // Call the runtime stub to populate the ImtConflictTable and jump to the
1347 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001348 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001349END art_quick_imt_conflict_trampoline
1350
Ian Rogers468532e2013-08-05 10:56:33 -07001351 .extern artQuickResolutionTrampoline
1352ENTRY art_quick_resolution_trampoline
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001353 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers468532e2013-08-05 10:56:33 -07001354 mov r2, r9 @ pass Thread::Current
1355 mov r3, sp @ pass SP
1356 blx artQuickResolutionTrampoline @ (Method* called, receiver, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001357 cbz r0, 1f @ is code pointer null? goto exception
Ian Rogers468532e2013-08-05 10:56:33 -07001358 mov r12, r0
1359 ldr r0, [sp, #0] @ load resolved method in r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001360 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001361 bx r12 @ tail-call into actual code
13621:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001363 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001364 DELIVER_PENDING_EXCEPTION
1365END art_quick_resolution_trampoline
1366
Andreas Gampec200a4a2014-06-16 18:39:09 -07001367 /*
1368 * Called to do a generic JNI down-call
1369 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001370ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001371 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_R0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001372
1373 // Save rSELF
1374 mov r11, rSELF
1375 // Save SP , so we can have static CFI info. r10 is saved in ref_and_args.
1376 mov r10, sp
1377 .cfi_def_cfa_register r10
1378
1379 sub sp, sp, #5120
1380
1381 // prepare for artQuickGenericJniTrampoline call
1382 // (Thread*, SP)
1383 // r0 r1 <= C calling convention
1384 // rSELF r10 <= where they are
1385
1386 mov r0, rSELF // Thread*
1387 mov r1, r10
1388 blx artQuickGenericJniTrampoline // (Thread*, sp)
1389
1390 // The C call will have registered the complete save-frame on success.
1391 // The result of the call is:
1392 // r0: pointer to native code, 0 on error.
1393 // r1: pointer to the bottom of the used area of the alloca, can restore stack till there.
1394
1395 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001396 cbz r0, .Lexception_in_native
Andreas Gampec200a4a2014-06-16 18:39:09 -07001397
1398 // Release part of the alloca.
1399 mov sp, r1
1400
1401 // Save the code pointer
1402 mov r12, r0
1403
1404 // Load parameters from frame into registers.
1405 pop {r0-r3}
1406
1407 // Softfloat.
1408 // TODO: Change to hardfloat when supported.
1409
1410 blx r12 // native call.
1411
1412 // result sign extension is handled in C code
1413 // prepare for artQuickGenericJniEndTrampoline call
1414 // (Thread*, result, result_f)
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001415 // r0 r2,r3 stack <= C calling convention
Andreas Gampec200a4a2014-06-16 18:39:09 -07001416 // r11 r0,r1 r0,r1 <= where they are
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001417 sub sp, sp, #8 // Stack alignment.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001418
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001419 push {r0-r1}
1420 mov r3, r1
1421 mov r2, r0
Andreas Gampec200a4a2014-06-16 18:39:09 -07001422 mov r0, r11
1423
1424 blx artQuickGenericJniEndTrampoline
1425
Andreas Gampec200a4a2014-06-16 18:39:09 -07001426 // Restore self pointer.
1427 mov r9, r11
1428
1429 // Pending exceptions possible.
1430 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
1431 cbnz r2, .Lexception_in_native
1432
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001433 // Tear down the alloca.
1434 mov sp, r10
1435 .cfi_def_cfa_register sp
1436
Zheng Xu5667fdb2014-10-23 18:29:55 +08001437 // Tear down the callee-save frame. Skip arg registers.
1438 add sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
1439 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1440 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampec200a4a2014-06-16 18:39:09 -07001441
Zheng Xu5667fdb2014-10-23 18:29:55 +08001442 // store into fpr, for when it's a fpr return...
1443 vmov d0, r0, r1
Andreas Gampec200a4a2014-06-16 18:39:09 -07001444 bx lr // ret
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001445 // Undo the unwinding information from above since it doesn't apply below.
1446 .cfi_def_cfa_register r10
1447 .cfi_adjust_cfa_offset FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Andreas Gampec200a4a2014-06-16 18:39:09 -07001448
Andreas Gampec200a4a2014-06-16 18:39:09 -07001449.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001450 ldr sp, [r9, #THREAD_TOP_QUICK_FRAME_OFFSET]
1451 .cfi_def_cfa_register sp
1452 # This will create a new save-all frame, required by the runtime.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001453 DELIVER_PENDING_EXCEPTION
Andreas Gampec200a4a2014-06-16 18:39:09 -07001454END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001455
Ian Rogers468532e2013-08-05 10:56:33 -07001456 .extern artQuickToInterpreterBridge
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001457ENTRY art_quick_to_interpreter_bridge
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001458 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r1
Ian Rogers7db619b2013-01-16 18:35:48 -08001459 mov r1, r9 @ pass Thread::Current
1460 mov r2, sp @ pass SP
Ian Rogers468532e2013-08-05 10:56:33 -07001461 blx artQuickToInterpreterBridge @ (Method* method, Thread*, SP)
Ian Rogers637859c2013-08-27 14:35:54 -07001462 ldr r2, [r9, #THREAD_EXCEPTION_OFFSET] @ load Thread::Current()->exception_
Zheng Xu5667fdb2014-10-23 18:29:55 +08001463 // Tear down the callee-save frame. Skip arg registers.
1464 add sp, #(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1465 .cfi_adjust_cfa_offset -(FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001466 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Mathieu Chartier590fee92013-09-13 13:46:47 -07001467 cbnz r2, 1f @ success if no exception is pending
Zheng Xu5667fdb2014-10-23 18:29:55 +08001468 vmov d0, r0, r1 @ store into fpr, for when it's a fpr return...
1469 bx lr @ return on success
Ian Rogers637859c2013-08-27 14:35:54 -070014701:
Ian Rogers7db619b2013-01-16 18:35:48 -08001471 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001472END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001473
jeffhaoe343b762011-12-05 16:36:44 -08001474 /*
jeffhao0791adc2012-04-04 11:14:32 -07001475 * Routine that intercepts method calls and returns.
jeffhaoe343b762011-12-05 16:36:44 -08001476 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001477 .extern artInstrumentationMethodEntryFromCode
1478 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001479ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001480 @ Make stack crawlable and clobber r2 and r3 (post saving)
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001481 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME r2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001482 @ preserve r0 (not normally an arg) knowing there is a spare slot in kRefsAndArgs.
1483 str r0, [sp, #4]
Ian Rogers62d6c772013-02-27 08:32:07 -08001484 mov r2, r9 @ pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001485 mov r3, lr @ pass LR
1486 blx artInstrumentationMethodEntryFromCode @ (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001487 mov r12, r0 @ r12 holds reference to code
1488 ldr r0, [sp, #4] @ restore r0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001489 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001490 blx r12 @ call method with lr set to art_quick_instrumentation_exit
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001491@ Deliberate fall-through into art_quick_instrumentation_exit.
Ian Rogers468532e2013-08-05 10:56:33 -07001492 .type art_quick_instrumentation_exit, #function
1493 .global art_quick_instrumentation_exit
1494art_quick_instrumentation_exit:
Ian Rogers62d6c772013-02-27 08:32:07 -08001495 mov lr, #0 @ link register is to here, so clobber with 0 for later checks
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001496 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 -08001497 mov r12, sp @ remember bottom of caller's frame
jeffhaoe343b762011-12-05 16:36:44 -08001498 push {r0-r1} @ save return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001499 .cfi_adjust_cfa_offset 8
1500 .cfi_rel_offset r0, 0
1501 .cfi_rel_offset r1, 4
Andreas Gampec89b0472015-06-23 23:28:59 -07001502 vpush {d0} @ save fp return value
Ian Rogers9329bbb2013-02-08 19:56:30 -08001503 .cfi_adjust_cfa_offset 8
Andreas Gampec89b0472015-06-23 23:28:59 -07001504 sub sp, #8 @ space for return value argument. Note: AAPCS stack alignment is 8B, no
1505 @ need to align by 16.
1506 .cfi_adjust_cfa_offset 8
1507 vstr d0, [sp] @ d0 -> [sp] for fpr_res
Ian Rogers62d6c772013-02-27 08:32:07 -08001508 mov r2, r0 @ pass return value as gpr_res
1509 mov r3, r1
Ian Rogers306057f2012-11-26 12:45:53 -08001510 mov r0, r9 @ pass Thread::Current
1511 mov r1, r12 @ pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08001512 blx artInstrumentationMethodExitFromCode @ (Thread*, SP, gpr_res, fpr_res)
Ian Rogers306057f2012-11-26 12:45:53 -08001513 add sp, #8
Ian Rogers9329bbb2013-02-08 19:56:30 -08001514 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001515
Ian Rogers306057f2012-11-26 12:45:53 -08001516 mov r2, r0 @ link register saved by instrumentation
1517 mov lr, r1 @ r1 is holding link register if we're to bounce to deoptimize
Andreas Gampec89b0472015-06-23 23:28:59 -07001518 vpop {d0} @ restore fp return value
1519 .cfi_adjust_cfa_offset -8
jeffhaoe343b762011-12-05 16:36:44 -08001520 pop {r0, r1} @ restore return value
Christopher Ferrisd0a0b3e2014-10-30 19:04:13 -07001521 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001522 .cfi_restore r0
1523 .cfi_restore r1
Ian Rogers62d6c772013-02-27 08:32:07 -08001524 add sp, #32 @ remove callee save frame
1525 .cfi_adjust_cfa_offset -32
Ian Rogers306057f2012-11-26 12:45:53 -08001526 bx r2 @ return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001527END art_quick_instrumentation_entry
Ian Rogers306057f2012-11-26 12:45:53 -08001528
Ian Rogers306057f2012-11-26 12:45:53 -08001529 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001530 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1531 * will long jump to the upcall with a special exception of -1.
Ian Rogers306057f2012-11-26 12:45:53 -08001532 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001533 .extern artDeoptimize
Ian Rogers9329bbb2013-02-08 19:56:30 -08001534ENTRY art_quick_deoptimize
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001535 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Ian Rogers62d6c772013-02-27 08:32:07 -08001536 mov r0, r9 @ Set up args.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001537 blx artDeoptimize @ artDeoptimize(Thread*)
Ian Rogers9329bbb2013-02-08 19:56:30 -08001538END art_quick_deoptimize
jeffhaoe343b762011-12-05 16:36:44 -08001539
Ian Rogers324e1902012-09-09 12:17:52 -07001540 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001541 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001542 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001543 */
1544 .extern artDeoptimizeFromCompiledCode
1545ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko3098c8c2016-06-14 17:43:17 +01001546 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME r0
Sebastien Hertz07474662015-08-25 15:12:33 +00001547 mov r0, r9 @ Set up args.
1548 blx artDeoptimizeFromCompiledCode @ artDeoptimizeFromCompiledCode(Thread*)
1549END art_quick_deoptimize_from_compiled_code
1550
1551 /*
Ian Rogers324e1902012-09-09 12:17:52 -07001552 * Signed 64-bit integer multiply.
1553 *
1554 * Consider WXxYZ (r1r0 x r3r2) with a long multiply:
1555 * WX
1556 * x YZ
1557 * --------
1558 * ZW ZX
1559 * YW YX
1560 *
1561 * The low word of the result holds ZX, the high word holds
1562 * (ZW+YX) + (the high overflow from ZX). YW doesn't matter because
1563 * it doesn't fit in the low 64 bits.
1564 *
1565 * Unlike most ARM math operations, multiply instructions have
1566 * restrictions on using the same register more than once (Rd and Rm
1567 * cannot be the same).
1568 */
1569 /* mul-long vAA, vBB, vCC */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001570ENTRY art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001571 push {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001572 .cfi_adjust_cfa_offset 8
1573 .cfi_rel_offset r9, 0
1574 .cfi_rel_offset r10, 4
Ian Rogers324e1902012-09-09 12:17:52 -07001575 mul ip, r2, r1 @ ip<- ZxW
1576 umull r9, r10, r2, r0 @ r9/r10 <- ZxX
1577 mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
1578 add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
1579 mov r0,r9
1580 mov r1,r10
1581 pop {r9 - r10}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001582 .cfi_adjust_cfa_offset -8
Dave Allisonbbb32c22013-11-05 18:25:18 -08001583 .cfi_restore r9
1584 .cfi_restore r10
Ian Rogers324e1902012-09-09 12:17:52 -07001585 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001586END art_quick_mul_long
Ian Rogers324e1902012-09-09 12:17:52 -07001587
buzbee54330722011-08-23 16:46:55 -07001588 /*
1589 * Long integer shift. This is different from the generic 32/64-bit
1590 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1591 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1592 * 6 bits.
1593 * On entry:
1594 * r0: low word
1595 * r1: high word
1596 * r2: shift count
1597 */
1598 /* shl-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001599ARM_ENTRY art_quick_shl_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001600 and r2, r2, #63 @ r2<- r2 & 0x3f
1601 mov r1, r1, asl r2 @ r1<- r1 << r2
1602 rsb r3, r2, #32 @ r3<- 32 - r2
1603 orr r1, r1, r0, lsr r3 @ r1<- r1 | (r0 << (32-r2))
1604 subs ip, r2, #32 @ ip<- r2 - 32
1605 movpl r1, r0, asl ip @ if r2 >= 32, r1<- r0 << (r2-32)
1606 mov r0, r0, asl r2 @ r0<- r0 << r2
1607 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001608END art_quick_shl_long
buzbee54330722011-08-23 16:46:55 -07001609
buzbee54330722011-08-23 16:46:55 -07001610 /*
1611 * Long integer shift. This is different from the generic 32/64-bit
1612 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1613 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1614 * 6 bits.
1615 * On entry:
1616 * r0: low word
1617 * r1: high word
1618 * r2: shift count
1619 */
1620 /* shr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001621ARM_ENTRY art_quick_shr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001622 and r2, r2, #63 @ r0<- r0 & 0x3f
1623 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1624 rsb r3, r2, #32 @ r3<- 32 - r2
1625 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1626 subs ip, r2, #32 @ ip<- r2 - 32
1627 movpl r0, r1, asr ip @ if r2 >= 32, r0<-r1 >> (r2-32)
1628 mov r1, r1, asr r2 @ r1<- r1 >> r2
1629 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001630END art_quick_shr_long
buzbee54330722011-08-23 16:46:55 -07001631
buzbee54330722011-08-23 16:46:55 -07001632 /*
1633 * Long integer shift. This is different from the generic 32/64-bit
1634 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1635 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1636 * 6 bits.
1637 * On entry:
1638 * r0: low word
1639 * r1: high word
1640 * r2: shift count
1641 */
1642 /* ushr-long vAA, vBB, vCC */
Ian Rogers637859c2013-08-27 14:35:54 -07001643ARM_ENTRY art_quick_ushr_long @ ARM code as thumb code requires spills
buzbee54330722011-08-23 16:46:55 -07001644 and r2, r2, #63 @ r0<- r0 & 0x3f
1645 mov r0, r0, lsr r2 @ r0<- r2 >> r2
1646 rsb r3, r2, #32 @ r3<- 32 - r2
1647 orr r0, r0, r1, asl r3 @ r0<- r0 | (r1 << (32-r2))
1648 subs ip, r2, #32 @ ip<- r2 - 32
1649 movpl r0, r1, lsr ip @ if r2 >= 32, r0<-r1 >>> (r2-32)
1650 mov r1, r1, lsr r2 @ r1<- r1 >>> r2
1651 bx lr
Ian Rogers9329bbb2013-02-08 19:56:30 -08001652END art_quick_ushr_long
buzbeefc9e6fa2012-03-23 15:14:29 -07001653
buzbeefc9e6fa2012-03-23 15:14:29 -07001654 /*
1655 * String's indexOf.
1656 *
1657 * On entry:
1658 * r0: string object (known non-null)
jeffhao86e46712012-08-08 17:30:59 -07001659 * r1: char to match (known <= 0xFFFF)
buzbeefc9e6fa2012-03-23 15:14:29 -07001660 * r2: Starting offset in string data
1661 */
Ian Rogers9329bbb2013-02-08 19:56:30 -08001662ENTRY art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001663 push {r4, r10-r11, lr} @ 4 words of callee saves
Ian Rogers9329bbb2013-02-08 19:56:30 -08001664 .cfi_adjust_cfa_offset 16
1665 .cfi_rel_offset r4, 0
1666 .cfi_rel_offset r10, 4
1667 .cfi_rel_offset r11, 8
1668 .cfi_rel_offset lr, 12
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001669 ldr r3, [r0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001670 add r0, #MIRROR_STRING_VALUE_OFFSET
buzbeefc9e6fa2012-03-23 15:14:29 -07001671
1672 /* Clamp start to [0..count] */
1673 cmp r2, #0
Ian Rogers637859c2013-08-27 14:35:54 -07001674 it lt
buzbeefc9e6fa2012-03-23 15:14:29 -07001675 movlt r2, #0
1676 cmp r2, r3
Ian Rogers637859c2013-08-27 14:35:54 -07001677 it gt
buzbeefc9e6fa2012-03-23 15:14:29 -07001678 movgt r2, r3
1679
buzbeefc9e6fa2012-03-23 15:14:29 -07001680 /* Save a copy in r12 to later compute result */
1681 mov r12, r0
1682
1683 /* Build pointer to start of data to compare and pre-bias */
1684 add r0, r0, r2, lsl #1
1685 sub r0, #2
1686
1687 /* Compute iteration count */
1688 sub r2, r3, r2
1689
1690 /*
1691 * At this point we have:
1692 * r0: start of data to test
1693 * r1: char to compare
1694 * r2: iteration count
1695 * r12: original start of string data
1696 * r3, r4, r10, r11 available for loading string data
1697 */
1698
1699 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001700 blt .Lindexof_remainder
buzbeefc9e6fa2012-03-23 15:14:29 -07001701
Ian Rogers5d885c82014-02-21 20:06:23 -08001702.Lindexof_loop4:
buzbeefc9e6fa2012-03-23 15:14:29 -07001703 ldrh r3, [r0, #2]!
1704 ldrh r4, [r0, #2]!
1705 ldrh r10, [r0, #2]!
1706 ldrh r11, [r0, #2]!
1707 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001708 beq .Lmatch_0
buzbeefc9e6fa2012-03-23 15:14:29 -07001709 cmp r4, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001710 beq .Lmatch_1
buzbeefc9e6fa2012-03-23 15:14:29 -07001711 cmp r10, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001712 beq .Lmatch_2
buzbeefc9e6fa2012-03-23 15:14:29 -07001713 cmp r11, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001714 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001715 subs r2, #4
Ian Rogers5d885c82014-02-21 20:06:23 -08001716 bge .Lindexof_loop4
buzbeefc9e6fa2012-03-23 15:14:29 -07001717
Ian Rogers5d885c82014-02-21 20:06:23 -08001718.Lindexof_remainder:
1719 adds r2, #4
1720 beq .Lindexof_nomatch
buzbeefc9e6fa2012-03-23 15:14:29 -07001721
Ian Rogers5d885c82014-02-21 20:06:23 -08001722.Lindexof_loop1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001723 ldrh r3, [r0, #2]!
1724 cmp r3, r1
Ian Rogers5d885c82014-02-21 20:06:23 -08001725 beq .Lmatch_3
buzbeefc9e6fa2012-03-23 15:14:29 -07001726 subs r2, #1
Ian Rogers5d885c82014-02-21 20:06:23 -08001727 bne .Lindexof_loop1
buzbeefc9e6fa2012-03-23 15:14:29 -07001728
Ian Rogers5d885c82014-02-21 20:06:23 -08001729.Lindexof_nomatch:
buzbeefc9e6fa2012-03-23 15:14:29 -07001730 mov r0, #-1
1731 pop {r4, r10-r11, pc}
1732
Ian Rogers5d885c82014-02-21 20:06:23 -08001733.Lmatch_0:
buzbeefc9e6fa2012-03-23 15:14:29 -07001734 sub r0, #6
1735 sub r0, r12
1736 asr r0, r0, #1
1737 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001738.Lmatch_1:
buzbeefc9e6fa2012-03-23 15:14:29 -07001739 sub r0, #4
1740 sub r0, r12
1741 asr r0, r0, #1
1742 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001743.Lmatch_2:
buzbeefc9e6fa2012-03-23 15:14:29 -07001744 sub r0, #2
1745 sub r0, r12
1746 asr r0, r0, #1
1747 pop {r4, r10-r11, pc}
Ian Rogers5d885c82014-02-21 20:06:23 -08001748.Lmatch_3:
buzbeefc9e6fa2012-03-23 15:14:29 -07001749 sub r0, r12
1750 asr r0, r0, #1
1751 pop {r4, r10-r11, pc}
Ian Rogers9329bbb2013-02-08 19:56:30 -08001752END art_quick_indexof
buzbeefc9e6fa2012-03-23 15:14:29 -07001753
Zheng Xu5667fdb2014-10-23 18:29:55 +08001754 /* Assembly routines used to handle ABI differences. */
1755
1756 /* double fmod(double a, double b) */
1757 .extern fmod
1758ENTRY art_quick_fmod
1759 push {lr}
1760 .cfi_adjust_cfa_offset 4
1761 .cfi_rel_offset lr, 0
1762 sub sp, #4
1763 .cfi_adjust_cfa_offset 4
1764 vmov r0, r1, d0
1765 vmov r2, r3, d1
1766 bl fmod
1767 vmov d0, r0, r1
1768 add sp, #4
1769 .cfi_adjust_cfa_offset -4
1770 pop {pc}
Zheng Xu5667fdb2014-10-23 18:29:55 +08001771END art_quick_fmod
1772
1773 /* float fmodf(float a, float b) */
1774 .extern fmodf
1775ENTRY art_quick_fmodf
1776 push {lr}
1777 .cfi_adjust_cfa_offset 4
1778 .cfi_rel_offset lr, 0
1779 sub sp, #4
1780 .cfi_adjust_cfa_offset 4
1781 vmov r0, r1, d0
1782 bl fmodf
1783 vmov s0, r0
1784 add sp, #4
1785 .cfi_adjust_cfa_offset -4
1786 pop {pc}
Goran Jakovljevicab4c64b2016-04-14 11:46:58 +02001787END art_quick_fmodf
Zheng Xu5667fdb2014-10-23 18:29:55 +08001788
1789 /* int64_t art_d2l(double d) */
1790 .extern art_d2l
1791ENTRY art_quick_d2l
1792 vmov r0, r1, d0
1793 b art_d2l
1794END art_quick_d2l
1795
1796 /* int64_t art_f2l(float f) */
1797 .extern art_f2l
1798ENTRY art_quick_f2l
1799 vmov r0, s0
1800 b art_f2l
1801END art_quick_f2l
Roland Levillain5b3ee562015-04-14 16:02:41 +01001802
1803 /* float art_l2f(int64_t l) */
1804 .extern art_l2f
1805ENTRY art_quick_l2f
1806 push {lr}
1807 .cfi_adjust_cfa_offset 4
1808 .cfi_rel_offset lr, 0
1809 sub sp, #4
1810 .cfi_adjust_cfa_offset 4
1811 bl art_l2f
1812 vmov s0, r0
1813 add sp, #4
1814 .cfi_adjust_cfa_offset -4
1815 pop {pc}
1816END art_quick_l2f
Roland Levillain02b75802016-07-13 11:54:35 +01001817
1818 /*
1819 * Create a function `name` calling the ReadBarrier::Mark routine,
1820 * getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001821 * `reg`, saving and restoring all caller-save registers.
1822 *
1823 * If `reg` is different from `r0`, the generated function follows a
1824 * non-standard runtime calling convention:
1825 * - register `reg` is used to pass the (sole) argument of this
1826 * function (instead of R0);
1827 * - register `reg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001828 * (instead of R0);
Roland Levillain02b75802016-07-13 11:54:35 +01001829 * - R0 is treated like a normal (non-argument) caller-save register;
1830 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001831 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001832 */
1833.macro READ_BARRIER_MARK_REG name, reg
1834ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001835 // Null check so that we can load the lock word.
1836 cmp \reg, #0
1837 beq .Lret_rb_\name
1838 // Check lock word for mark bit, if marked return.
1839 push {r0}
1840 ldr r0, [\reg, MIRROR_OBJECT_LOCK_WORD_OFFSET]
1841 and r0, #LOCK_WORD_MARK_BIT_MASK_SHIFTED
1842 cbz r0, .Lslow_rb_\name
1843 // Restore LR and return.
1844 pop {r0}
1845 bx lr
1846
1847.Lslow_rb_\name:
1848 pop {r0}
Roland Levillain4359e612016-07-20 11:32:19 +01001849 push {r0-r4, r9, r12, lr} @ save return address and core caller-save registers
1850 .cfi_adjust_cfa_offset 32
1851 .cfi_rel_offset r0, 0
1852 .cfi_rel_offset r1, 4
1853 .cfi_rel_offset r2, 8
1854 .cfi_rel_offset r3, 12
1855 .cfi_rel_offset r4, 16
1856 .cfi_rel_offset r9, 20
1857 .cfi_rel_offset r12, 24
1858 .cfi_rel_offset lr, 28
1859 vpush {s0-s15} @ save floating-point caller-save registers
1860 .cfi_adjust_cfa_offset 64
1861
1862 .ifnc \reg, r0
1863 mov r0, \reg @ pass arg1 - obj from `reg`
1864 .endif
1865 bl artReadBarrierMark @ r0 <- artReadBarrierMark(obj)
1866
1867 vpop {s0-s15} @ restore floating-point registers
1868 .cfi_adjust_cfa_offset -64
1869 @ If `reg` is a caller-save register, save the result to its
1870 @ corresponding stack slot; it will be restored by the "pop"
1871 @ instruction below. Otherwise, move result into `reg`.
1872 @
1873 @ (Note that saving `reg` to its stack slot will overwrite the value
1874 @ previously stored by the "push" instruction above. That is
1875 @ alright, as in that case we know that `reg` is not a live
1876 @ register, as it is used to pass the argument and return the result
1877 @ of this function.)
1878 .ifc \reg, r0
1879 PUSH_REG r0, 0 @ copy result to r0's stack location
1880 .else
1881 .ifc \reg, r1
1882 PUSH_REG r0, 4 @ copy result to r1's stack location
1883 .else
1884 .ifc \reg, r2
1885 PUSH_REG r0, 8 @ copy result to r2's stack location
1886 .else
1887 .ifc \reg, r3
1888 PUSH_REG r0, 12 @ copy result to r3's stack location
1889 .else
1890 .ifc \reg, r4
1891 PUSH_REG r0, 16 @ copy result to r4's stack location
1892 .else
1893 .ifc \reg, r9
1894 PUSH_REG r0, 20 @ copy result to r9's stack location
1895 .else
1896 .ifc \reg, r12
1897 PUSH_REG r0, 24 @ copy result to r12's stack location
1898 .else
1899 mov \reg, r0 @ return result into `reg`
1900 .endif
1901 .endif
1902 .endif
1903 .endif
1904 .endif
1905 .endif
1906 .endif
1907 pop {r0-r4, r9, r12, pc} @ restore caller-save registers and return
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001908.Lret_rb_\name:
1909 bx lr
Roland Levillain02b75802016-07-13 11:54:35 +01001910END \name
1911.endm
1912
Roland Levillain4359e612016-07-20 11:32:19 +01001913READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, r0
Roland Levillain02b75802016-07-13 11:54:35 +01001914READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, r1
1915READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, r2
1916READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, r3
1917READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, r4
1918READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, r5
1919READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, r6
1920READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, r7
1921READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, r8
1922READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, r9
1923READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, r10
1924READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, r11
1925READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, r12