blob: f6204bd8b63f1f6c4fffab9a28937f90899e1188 [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_mips.S"
buzbee5bc5a7b2012-03-07 15:52:59 -080018
Mathieu Chartier7410f292013-11-24 13:17:35 -080019#include "arch/quick_alloc_entrypoints.S"
20
jeffhao07030602012-09-26 14:33:14 -070021 .set noreorder
buzbee5bc5a7b2012-03-07 15:52:59 -080022 .balign 4
23
24 /* Deliver the given exception */
25 .extern artDeliverExceptionFromCode
26 /* Deliver an exception pending on a thread */
jeffhao8161c032012-10-31 15:50:00 -070027 .extern artDeliverPendingExceptionFromCode
buzbee5bc5a7b2012-03-07 15:52:59 -080028
Douglas Leung735b8552014-10-31 12:21:40 -070029#define ARG_SLOT_SIZE 32 // space for a0-a3 plus 4 more words
30
buzbee5bc5a7b2012-03-07 15:52:59 -080031 /*
32 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010033 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Douglas Leung735b8552014-10-31 12:21:40 -070034 * Callee-save: $s0-$s8 + $gp + $ra, 11 total + 1 word for Method*
35 * Clobbers $t0 and $sp
36 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010037 * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVES + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080038 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010039.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gampea4e0e672015-05-27 18:31:42 -070040 addiu $sp, $sp, -96
41 .cfi_adjust_cfa_offset 96
Andreas Gampe5c1e4352014-04-21 19:28:24 -070042
43 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 96)
45#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070046#endif
47
Andreas Gampea4e0e672015-05-27 18:31:42 -070048 sw $ra, 92($sp)
49 .cfi_rel_offset 31, 92
50 sw $s8, 88($sp)
51 .cfi_rel_offset 30, 88
52 sw $gp, 84($sp)
53 .cfi_rel_offset 28, 84
54 sw $s7, 80($sp)
55 .cfi_rel_offset 23, 80
56 sw $s6, 76($sp)
57 .cfi_rel_offset 22, 76
58 sw $s5, 72($sp)
59 .cfi_rel_offset 21, 72
60 sw $s4, 68($sp)
61 .cfi_rel_offset 20, 68
62 sw $s3, 64($sp)
63 .cfi_rel_offset 19, 64
64 sw $s2, 60($sp)
65 .cfi_rel_offset 18, 60
66 sw $s1, 56($sp)
67 .cfi_rel_offset 17, 56
68 sw $s0, 52($sp)
69 .cfi_rel_offset 16, 52
70
71 SDu $f30, $f31, 44, $sp, $t1
72 SDu $f28, $f29, 36, $sp, $t1
73 SDu $f26, $f27, 28, $sp, $t1
74 SDu $f24, $f25, 20, $sp, $t1
75 SDu $f22, $f23, 12, $sp, $t1
76 SDu $f20, $f21, 4, $sp, $t1
77
Douglas Leung735b8552014-10-31 12:21:40 -070078 # 1 word for holding Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070079
Douglas Leung4af77b72014-10-22 16:32:28 -070080 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
81 lw $t0, 0($t0)
Vladimir Markofd36f1f2016-08-03 18:49:58 +010082 lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070083 sw $t0, 0($sp) # Place Method* at bottom of stack.
84 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -070085 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
86 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -080087.endm
88
89 /*
90 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010091 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly). Restoration assumes non-moving GC.
buzbee5bc5a7b2012-03-07 15:52:59 -080092 * Does not include rSUSPEND or rSELF
Douglas Leung735b8552014-10-31 12:21:40 -070093 * callee-save: $s2-$s8 + $gp + $ra, 9 total + 2 words padding + 1 word to hold Method*
94 * Clobbers $t0 and $sp
95 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010096 * Reserves FRAME_SIZE_SAVE_REFS_ONLY + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080097 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010098.macro SETUP_SAVE_REFS_ONLY_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -070099 addiu $sp, $sp, -48
100 .cfi_adjust_cfa_offset 48
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700101
102 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100103#if (FRAME_SIZE_SAVE_REFS_ONLY != 48)
104#error "FRAME_SIZE_SAVE_REFS_ONLY(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700105#endif
106
Douglas Leung735b8552014-10-31 12:21:40 -0700107 sw $ra, 44($sp)
108 .cfi_rel_offset 31, 44
109 sw $s8, 40($sp)
110 .cfi_rel_offset 30, 40
111 sw $gp, 36($sp)
112 .cfi_rel_offset 28, 36
113 sw $s7, 32($sp)
114 .cfi_rel_offset 23, 32
115 sw $s6, 28($sp)
116 .cfi_rel_offset 22, 28
117 sw $s5, 24($sp)
118 .cfi_rel_offset 21, 24
119 sw $s4, 20($sp)
120 .cfi_rel_offset 20, 20
121 sw $s3, 16($sp)
122 .cfi_rel_offset 19, 16
123 sw $s2, 12($sp)
124 .cfi_rel_offset 18, 12
125 # 2 words for alignment and bottom word will hold Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700126
Douglas Leung4af77b72014-10-22 16:32:28 -0700127 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
128 lw $t0, 0($t0)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100129 lw $t0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700130 sw $t0, 0($sp) # Place Method* at bottom of stack.
131 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700132 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
133 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800134.endm
135
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100136.macro RESTORE_SAVE_REFS_ONLY_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -0700137 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
138 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
139 lw $ra, 44($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800140 .cfi_restore 31
Douglas Leung735b8552014-10-31 12:21:40 -0700141 lw $s8, 40($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800142 .cfi_restore 30
Douglas Leung735b8552014-10-31 12:21:40 -0700143 lw $gp, 36($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800144 .cfi_restore 28
Douglas Leung735b8552014-10-31 12:21:40 -0700145 lw $s7, 32($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800146 .cfi_restore 23
Douglas Leung735b8552014-10-31 12:21:40 -0700147 lw $s6, 28($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800148 .cfi_restore 22
Douglas Leung735b8552014-10-31 12:21:40 -0700149 lw $s5, 24($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800150 .cfi_restore 21
Douglas Leung735b8552014-10-31 12:21:40 -0700151 lw $s4, 20($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800152 .cfi_restore 20
Douglas Leung735b8552014-10-31 12:21:40 -0700153 lw $s3, 16($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800154 .cfi_restore 19
Douglas Leung735b8552014-10-31 12:21:40 -0700155 lw $s2, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800156 .cfi_restore 18
Douglas Leung735b8552014-10-31 12:21:40 -0700157 addiu $sp, $sp, 48
158 .cfi_adjust_cfa_offset -48
buzbee5bc5a7b2012-03-07 15:52:59 -0800159.endm
160
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100161.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
162 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe8d365912015-01-13 11:32:32 -0800163 jalr $zero, $ra
Douglas Leung735b8552014-10-31 12:21:40 -0700164 nop
buzbee5bc5a7b2012-03-07 15:52:59 -0800165.endm
166
167 /*
Alexey Frunze279cfba2017-07-22 00:24:43 -0700168 * Individually usable part of macro SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY.
169 */
170.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_S4_THRU_S8
171 sw $s8, 104($sp)
172 .cfi_rel_offset 30, 104
173 sw $s7, 96($sp)
174 .cfi_rel_offset 23, 96
175 sw $s6, 92($sp)
176 .cfi_rel_offset 22, 92
177 sw $s5, 88($sp)
178 .cfi_rel_offset 21, 88
179 sw $s4, 84($sp)
180 .cfi_rel_offset 20, 84
181.endm
182
183 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800184 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100185 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800186 * callee-save: $a1-$a3, $t0-$t1, $s2-$s8, $gp, $ra, $f8-$f19
187 * (26 total + 1 word padding + method*)
buzbee5bc5a7b2012-03-07 15:52:59 -0800188 */
Alexey Frunze279cfba2017-07-22 00:24:43 -0700189.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY save_s4_thru_s8=1
190 addiu $sp, $sp, -112
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800191 .cfi_adjust_cfa_offset 112
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700192
193 // Ugly compile-time check, but we only have the preprocessor.
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800194#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 112)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100195#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700196#endif
197
Alexey Frunze279cfba2017-07-22 00:24:43 -0700198 sw $ra, 108($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800199 .cfi_rel_offset 31, 108
Alexey Frunze279cfba2017-07-22 00:24:43 -0700200 sw $gp, 100($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800201 .cfi_rel_offset 28, 100
Alexey Frunze279cfba2017-07-22 00:24:43 -0700202 .if \save_s4_thru_s8
203 SETUP_SAVE_REFS_AND_ARGS_FRAME_S4_THRU_S8
204 .endif
205 sw $s3, 80($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800206 .cfi_rel_offset 19, 80
Alexey Frunze279cfba2017-07-22 00:24:43 -0700207 sw $s2, 76($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800208 .cfi_rel_offset 18, 76
Alexey Frunze279cfba2017-07-22 00:24:43 -0700209 sw $t1, 72($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800210 .cfi_rel_offset 9, 72
Alexey Frunze279cfba2017-07-22 00:24:43 -0700211 sw $t0, 68($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800212 .cfi_rel_offset 8, 68
Alexey Frunze279cfba2017-07-22 00:24:43 -0700213 sw $a3, 64($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800214 .cfi_rel_offset 7, 64
Alexey Frunze279cfba2017-07-22 00:24:43 -0700215 sw $a2, 60($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800216 .cfi_rel_offset 6, 60
Alexey Frunze279cfba2017-07-22 00:24:43 -0700217 sw $a1, 56($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800218 .cfi_rel_offset 5, 56
Alexey Frunze279cfba2017-07-22 00:24:43 -0700219 SDu $f18, $f19, 48, $sp, $t8
220 SDu $f16, $f17, 40, $sp, $t8
221 SDu $f14, $f15, 32, $sp, $t8
222 SDu $f12, $f13, 24, $sp, $t8
223 SDu $f10, $f11, 16, $sp, $t8
224 SDu $f8, $f9, 8, $sp, $t8
jeffhaofa147e22012-10-12 17:03:32 -0700225 # bottom will hold Method*
Douglas Leung735b8552014-10-31 12:21:40 -0700226.endm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700227
Douglas Leung735b8552014-10-31 12:21:40 -0700228 /*
229 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100230 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes non-moving GC.
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800231 * callee-save: $a1-$a3, $t0-$t1, $s2-$s8, $gp, $ra, $f8-$f19
232 * (26 total + 1 word padding + method*)
Douglas Leung735b8552014-10-31 12:21:40 -0700233 * Clobbers $t0 and $sp
234 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100235 * Reserves FRAME_SIZE_SAVE_REFS_AND_ARGS + ARG_SLOT_SIZE bytes on the stack
Douglas Leung735b8552014-10-31 12:21:40 -0700236 */
Alexey Frunze279cfba2017-07-22 00:24:43 -0700237.macro SETUP_SAVE_REFS_AND_ARGS_FRAME save_s4_thru_s8_only=0
238 .if \save_s4_thru_s8_only
239 // It is expected that `SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY /* save_s4_thru_s8 */ 0`
240 // has been done prior to `SETUP_SAVE_REFS_AND_ARGS_FRAME /* save_s4_thru_s8_only */ 1`.
241 SETUP_SAVE_REFS_AND_ARGS_FRAME_S4_THRU_S8
242 .else
243 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
244 .endif
Douglas Leung4af77b72014-10-22 16:32:28 -0700245 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
246 lw $t0, 0($t0)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100247 lw $t0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700248 sw $t0, 0($sp) # Place Method* at bottom of stack.
249 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700250 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
251 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
252.endm
253
254 /*
255 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100256 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes non-moving GC.
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800257 * callee-save: $a1-$a3, $t0-$t1, $s2-$s8, $gp, $ra, $f8-$f19
258 * (26 total + 1 word padding + method*)
Douglas Leung735b8552014-10-31 12:21:40 -0700259 * Clobbers $sp
260 * Use $a0 as the Method* and loads it into bottom of stack.
261 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100262 * Reserves FRAME_SIZE_SAVE_REFS_AND_ARGS + ARG_SLOT_SIZE bytes on the stack
Douglas Leung735b8552014-10-31 12:21:40 -0700263 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100264.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
265 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Douglas Leung735b8552014-10-31 12:21:40 -0700266 sw $a0, 0($sp) # Place Method* at bottom of stack.
267 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
268 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
269 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800270.endm
271
Alexey Frunze279cfba2017-07-22 00:24:43 -0700272 /*
273 * Individually usable part of macro RESTORE_SAVE_REFS_AND_ARGS_FRAME.
274 */
275.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME_GP
276 lw $gp, 100($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800277 .cfi_restore 28
Alexey Frunze279cfba2017-07-22 00:24:43 -0700278.endm
279
280 /*
281 * Individually usable part of macro RESTORE_SAVE_REFS_AND_ARGS_FRAME.
282 */
283.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME_A1
284 lw $a1, 56($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800285 .cfi_restore 5
Alexey Frunze279cfba2017-07-22 00:24:43 -0700286.endm
287
288.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME restore_s4_thru_s8=1, remove_arg_slots=1
289 .if \remove_arg_slots
290 addiu $sp, $sp, ARG_SLOT_SIZE # Remove argument slots from the stack.
291 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
292 .endif
293 lw $ra, 108($sp)
294 .cfi_restore 31
295 .if \restore_s4_thru_s8
296 lw $s8, 104($sp)
297 .cfi_restore 30
298 .endif
299 RESTORE_SAVE_REFS_AND_ARGS_FRAME_GP
300 .if \restore_s4_thru_s8
301 lw $s7, 96($sp)
302 .cfi_restore 23
303 lw $s6, 92($sp)
304 .cfi_restore 22
305 lw $s5, 88($sp)
306 .cfi_restore 21
307 lw $s4, 84($sp)
308 .cfi_restore 20
309 .endif
310 lw $s3, 80($sp)
311 .cfi_restore 19
312 lw $s2, 76($sp)
313 .cfi_restore 18
314 lw $t1, 72($sp)
315 .cfi_restore 9
316 lw $t0, 68($sp)
317 .cfi_restore 8
318 lw $a3, 64($sp)
319 .cfi_restore 7
320 lw $a2, 60($sp)
321 .cfi_restore 6
322 RESTORE_SAVE_REFS_AND_ARGS_FRAME_A1
323 LDu $f18, $f19, 48, $sp, $t8
324 LDu $f16, $f17, 40, $sp, $t8
325 LDu $f14, $f15, 32, $sp, $t8
326 LDu $f12, $f13, 24, $sp, $t8
327 LDu $f10, $f11, 16, $sp, $t8
328 LDu $f8, $f9, 8, $sp, $t8
329 addiu $sp, $sp, 112 # Pop frame.
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800330 .cfi_adjust_cfa_offset -112
buzbee5bc5a7b2012-03-07 15:52:59 -0800331.endm
332
333 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100334 * Macro that sets up the callee save frame to conform with
335 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000336 * when the $sp has already been decremented by FRAME_SIZE_SAVE_EVERYTHING.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100337 * Callee-save: $at, $v0-$v1, $a0-$a3, $t0-$t7, $s0-$s7, $t8-$t9, $gp, $fp $ra, $f0-$f31;
338 * 28(GPR)+ 32(FPR) + 3 words for padding and 1 word for Method*
339 * Clobbers $t0 and $t1.
340 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100341 * Reserves FRAME_SIZE_SAVE_EVERYTHING + ARG_SLOT_SIZE bytes on the stack.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100342 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
343 */
Alexey Frunze19428ad2017-08-03 10:36:46 -0700344.macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Marko952dbb12016-07-28 12:01:51 +0100345 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100346#if (FRAME_SIZE_SAVE_EVERYTHING != 256)
347#error "FRAME_SIZE_SAVE_EVERYTHING(MIPS) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100348#endif
349
350 sw $ra, 252($sp)
351 .cfi_rel_offset 31, 252
352 sw $fp, 248($sp)
353 .cfi_rel_offset 30, 248
354 sw $gp, 244($sp)
355 .cfi_rel_offset 28, 244
356 sw $t9, 240($sp)
357 .cfi_rel_offset 25, 240
358 sw $t8, 236($sp)
359 .cfi_rel_offset 24, 236
360 sw $s7, 232($sp)
361 .cfi_rel_offset 23, 232
362 sw $s6, 228($sp)
363 .cfi_rel_offset 22, 228
364 sw $s5, 224($sp)
365 .cfi_rel_offset 21, 224
366 sw $s4, 220($sp)
367 .cfi_rel_offset 20, 220
368 sw $s3, 216($sp)
369 .cfi_rel_offset 19, 216
370 sw $s2, 212($sp)
371 .cfi_rel_offset 18, 212
372 sw $s1, 208($sp)
373 .cfi_rel_offset 17, 208
374 sw $s0, 204($sp)
375 .cfi_rel_offset 16, 204
376 sw $t7, 200($sp)
377 .cfi_rel_offset 15, 200
378 sw $t6, 196($sp)
379 .cfi_rel_offset 14, 196
380 sw $t5, 192($sp)
381 .cfi_rel_offset 13, 192
382 sw $t4, 188($sp)
383 .cfi_rel_offset 12, 188
384 sw $t3, 184($sp)
385 .cfi_rel_offset 11, 184
386 sw $t2, 180($sp)
387 .cfi_rel_offset 10, 180
388 sw $t1, 176($sp)
389 .cfi_rel_offset 9, 176
390 sw $t0, 172($sp)
391 .cfi_rel_offset 8, 172
392 sw $a3, 168($sp)
393 .cfi_rel_offset 7, 168
394 sw $a2, 164($sp)
395 .cfi_rel_offset 6, 164
396 sw $a1, 160($sp)
397 .cfi_rel_offset 5, 160
398 sw $a0, 156($sp)
399 .cfi_rel_offset 4, 156
400 sw $v1, 152($sp)
401 .cfi_rel_offset 3, 152
402 sw $v0, 148($sp)
403 .cfi_rel_offset 2, 148
404
405 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
406 bal 1f
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200407 .set push
408 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100409 sw $at, 144($sp)
410 .cfi_rel_offset 1, 144
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200411 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +01004121:
413 .cpload $ra
414
415 SDu $f30, $f31, 136, $sp, $t1
416 SDu $f28, $f29, 128, $sp, $t1
417 SDu $f26, $f27, 120, $sp, $t1
418 SDu $f24, $f25, 112, $sp, $t1
419 SDu $f22, $f23, 104, $sp, $t1
420 SDu $f20, $f21, 96, $sp, $t1
421 SDu $f18, $f19, 88, $sp, $t1
422 SDu $f16, $f17, 80, $sp, $t1
423 SDu $f14, $f15, 72, $sp, $t1
424 SDu $f12, $f13, 64, $sp, $t1
425 SDu $f10, $f11, 56, $sp, $t1
426 SDu $f8, $f9, 48, $sp, $t1
427 SDu $f6, $f7, 40, $sp, $t1
428 SDu $f4, $f5, 32, $sp, $t1
429 SDu $f2, $f3, 24, $sp, $t1
430 SDu $f0, $f1, 16, $sp, $t1
431
432 # 3 words padding and 1 word for holding Method*
433
434 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
435 lw $t0, 0($t0)
Alexey Frunze19428ad2017-08-03 10:36:46 -0700436 lw $t0, \runtime_method_offset($t0)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100437 sw $t0, 0($sp) # Place Method* at bottom of stack.
438 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
439 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
440 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
441.endm
442
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000443 /*
444 * Macro that sets up the callee save frame to conform with
445 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
446 * Callee-save: $at, $v0-$v1, $a0-$a3, $t0-$t7, $s0-$s7, $t8-$t9, $gp, $fp $ra, $f0-$f31;
447 * 28(GPR)+ 32(FPR) + 3 words for padding and 1 word for Method*
448 * Clobbers $t0 and $t1.
449 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
450 * Reserves FRAME_SIZE_SAVE_EVERYTHING + ARG_SLOT_SIZE bytes on the stack.
451 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
452 */
Alexey Frunze19428ad2017-08-03 10:36:46 -0700453.macro SETUP_SAVE_EVERYTHING_FRAME runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000454 addiu $sp, $sp, -(FRAME_SIZE_SAVE_EVERYTHING)
455 .cfi_adjust_cfa_offset (FRAME_SIZE_SAVE_EVERYTHING)
Alexey Frunze19428ad2017-08-03 10:36:46 -0700456 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP \runtime_method_offset
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000457.endm
458
Alexey Frunzec61c0762017-04-10 13:54:23 -0700459.macro RESTORE_SAVE_EVERYTHING_FRAME restore_a0=1
Vladimir Marko952dbb12016-07-28 12:01:51 +0100460 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
461 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
462
463 LDu $f30, $f31, 136, $sp, $t1
464 LDu $f28, $f29, 128, $sp, $t1
465 LDu $f26, $f27, 120, $sp, $t1
466 LDu $f24, $f25, 112, $sp, $t1
467 LDu $f22, $f23, 104, $sp, $t1
468 LDu $f20, $f21, 96, $sp, $t1
469 LDu $f18, $f19, 88, $sp, $t1
470 LDu $f16, $f17, 80, $sp, $t1
471 LDu $f14, $f15, 72, $sp, $t1
472 LDu $f12, $f13, 64, $sp, $t1
473 LDu $f10, $f11, 56, $sp, $t1
474 LDu $f8, $f9, 48, $sp, $t1
475 LDu $f6, $f7, 40, $sp, $t1
476 LDu $f4, $f5, 32, $sp, $t1
477 LDu $f2, $f3, 24, $sp, $t1
478 LDu $f0, $f1, 16, $sp, $t1
479
480 lw $ra, 252($sp)
481 .cfi_restore 31
482 lw $fp, 248($sp)
483 .cfi_restore 30
484 lw $gp, 244($sp)
485 .cfi_restore 28
486 lw $t9, 240($sp)
487 .cfi_restore 25
488 lw $t8, 236($sp)
489 .cfi_restore 24
490 lw $s7, 232($sp)
491 .cfi_restore 23
492 lw $s6, 228($sp)
493 .cfi_restore 22
494 lw $s5, 224($sp)
495 .cfi_restore 21
496 lw $s4, 220($sp)
497 .cfi_restore 20
498 lw $s3, 216($sp)
499 .cfi_restore 19
500 lw $s2, 212($sp)
501 .cfi_restore 18
502 lw $s1, 208($sp)
503 .cfi_restore 17
504 lw $s0, 204($sp)
505 .cfi_restore 16
506 lw $t7, 200($sp)
507 .cfi_restore 15
508 lw $t6, 196($sp)
509 .cfi_restore 14
510 lw $t5, 192($sp)
511 .cfi_restore 13
512 lw $t4, 188($sp)
513 .cfi_restore 12
514 lw $t3, 184($sp)
515 .cfi_restore 11
516 lw $t2, 180($sp)
517 .cfi_restore 10
518 lw $t1, 176($sp)
519 .cfi_restore 9
520 lw $t0, 172($sp)
521 .cfi_restore 8
522 lw $a3, 168($sp)
523 .cfi_restore 7
524 lw $a2, 164($sp)
525 .cfi_restore 6
526 lw $a1, 160($sp)
527 .cfi_restore 5
Alexey Frunzec61c0762017-04-10 13:54:23 -0700528 .if \restore_a0
Vladimir Marko952dbb12016-07-28 12:01:51 +0100529 lw $a0, 156($sp)
530 .cfi_restore 4
Alexey Frunzec61c0762017-04-10 13:54:23 -0700531 .endif
Vladimir Marko952dbb12016-07-28 12:01:51 +0100532 lw $v1, 152($sp)
533 .cfi_restore 3
534 lw $v0, 148($sp)
535 .cfi_restore 2
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200536 .set push
537 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100538 lw $at, 144($sp)
539 .cfi_restore 1
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200540 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +0100541
542 addiu $sp, $sp, 256 # pop frame
543 .cfi_adjust_cfa_offset -256
544.endm
545
546 /*
Alexey Frunzec61c0762017-04-10 13:54:23 -0700547 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
548 * exception is Thread::Current()->exception_ when the runtime method frame is ready.
549 * Requires $gp properly set up.
buzbee5bc5a7b2012-03-07 15:52:59 -0800550 */
Alexey Frunzec61c0762017-04-10 13:54:23 -0700551.macro DELIVER_PENDING_EXCEPTION_FRAME_READY
jeffhao8161c032012-10-31 15:50:00 -0700552 la $t9, artDeliverPendingExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800553 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700554 move $a0, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800555.endm
556
Alexey Frunzec61c0762017-04-10 13:54:23 -0700557 /*
558 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
559 * exception is Thread::Current()->exception_.
560 * Requires $gp properly set up.
561 */
562.macro DELIVER_PENDING_EXCEPTION
563 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME # save callee saves for throw
564 DELIVER_PENDING_EXCEPTION_FRAME_READY
565.endm
566
buzbee5bc5a7b2012-03-07 15:52:59 -0800567.macro RETURN_IF_NO_EXCEPTION
jeffhao7fbee072012-08-24 17:56:54 -0700568 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100569 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700570 bnez $t0, 1f # success if no exception is pending
buzbee5bc5a7b2012-03-07 15:52:59 -0800571 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800572 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -0800573 nop
5741:
575 DELIVER_PENDING_EXCEPTION
576.endm
577
578.macro RETURN_IF_ZERO
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100579 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700580 bnez $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800581 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800582 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800583 nop
5841:
585 DELIVER_PENDING_EXCEPTION
586.endm
587
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800588.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100589 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700590 beqz $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800591 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800592 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800593 nop
5941:
595 DELIVER_PENDING_EXCEPTION
596.endm
597
buzbee5bc5a7b2012-03-07 15:52:59 -0800598 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100599 * On stack replacement stub.
600 * On entry:
601 * a0 = stack to copy
602 * a1 = size of stack
603 * a2 = pc to call
604 * a3 = JValue* result
605 * [sp + 16] = shorty
606 * [sp + 20] = thread
607 */
608ENTRY art_quick_osr_stub
609 // Save callee general purpose registers, RA and GP.
610 addiu $sp, $sp, -48
611 .cfi_adjust_cfa_offset 48
612 sw $ra, 44($sp)
613 .cfi_rel_offset 31, 44
614 sw $s8, 40($sp)
615 .cfi_rel_offset 30, 40
616 sw $gp, 36($sp)
617 .cfi_rel_offset 28, 36
618 sw $s7, 32($sp)
619 .cfi_rel_offset 23, 32
620 sw $s6, 28($sp)
621 .cfi_rel_offset 22, 28
622 sw $s5, 24($sp)
623 .cfi_rel_offset 21, 24
624 sw $s4, 20($sp)
625 .cfi_rel_offset 20, 20
626 sw $s3, 16($sp)
627 .cfi_rel_offset 19, 16
628 sw $s2, 12($sp)
629 .cfi_rel_offset 18, 12
630 sw $s1, 8($sp)
631 .cfi_rel_offset 17, 8
632 sw $s0, 4($sp)
633 .cfi_rel_offset 16, 4
634
635 move $s8, $sp # Save the stack pointer
636 move $s7, $a1 # Save size of stack
637 move $s6, $a2 # Save the pc to call
638 lw rSELF, 48+20($sp) # Save managed thread pointer into rSELF
639 addiu $t0, $sp, -12 # Reserve space for stack pointer,
640 # JValue* result, and ArtMethod* slot.
641 srl $t0, $t0, 4 # Align stack pointer to 16 bytes
642 sll $sp, $t0, 4 # Update stack pointer
643 sw $s8, 4($sp) # Save old stack pointer
644 sw $a3, 8($sp) # Save JValue* result
645 sw $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
646 subu $sp, $a1 # Reserve space for callee stack
647 move $a2, $a1
648 move $a1, $a0
649 move $a0, $sp
650 la $t9, memcpy
651 jalr $t9 # memcpy (dest a0, src a1, bytes a2)
652 addiu $sp, $sp, -16 # make space for argument slots for memcpy
653 bal .Losr_entry # Call the method
654 addiu $sp, $sp, 16 # restore stack after memcpy
655 lw $a2, 8($sp) # Restore JValue* result
656 lw $sp, 4($sp) # Restore saved stack pointer
657 lw $a0, 48+16($sp) # load shorty
658 lbu $a0, 0($a0) # load return type
659 li $a1, 'D' # put char 'D' into a1
660 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'D'
661 li $a1, 'F' # put char 'F' into a1
662 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'F'
663 nop
664 sw $v0, 0($a2)
665 b .Losr_exit
666 sw $v1, 4($a2) # store v0/v1 into result
667.Losr_fp_result:
668 SDu $f0, $f1, 0, $a2, $t0 # store f0/f1 into result
669.Losr_exit:
670 lw $ra, 44($sp)
671 .cfi_restore 31
672 lw $s8, 40($sp)
673 .cfi_restore 30
674 lw $gp, 36($sp)
675 .cfi_restore 28
676 lw $s7, 32($sp)
677 .cfi_restore 23
678 lw $s6, 28($sp)
679 .cfi_restore 22
680 lw $s5, 24($sp)
681 .cfi_restore 21
682 lw $s4, 20($sp)
683 .cfi_restore 20
684 lw $s3, 16($sp)
685 .cfi_restore 19
686 lw $s2, 12($sp)
687 .cfi_restore 18
688 lw $s1, 8($sp)
689 .cfi_restore 17
690 lw $s0, 4($sp)
691 .cfi_restore 16
692 jalr $zero, $ra
693 addiu $sp, $sp, 48
694 .cfi_adjust_cfa_offset -48
695.Losr_entry:
696 addiu $s7, $s7, -4
697 addu $t0, $s7, $sp
698 move $t9, $s6
699 jalr $zero, $t9
700 sw $ra, 0($t0) # Store RA per the compiler ABI
701END art_quick_osr_stub
702
703 /*
jeffhao7fbee072012-08-24 17:56:54 -0700704 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
buzbee5bc5a7b2012-03-07 15:52:59 -0800705 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
706 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800707ENTRY art_quick_do_long_jump
Duane Sande34652f2014-11-04 11:09:36 -0800708 LDu $f0, $f1, 0*8, $a1, $t1
709 LDu $f2, $f3, 1*8, $a1, $t1
710 LDu $f4, $f5, 2*8, $a1, $t1
711 LDu $f6, $f7, 3*8, $a1, $t1
712 LDu $f8, $f9, 4*8, $a1, $t1
713 LDu $f10, $f11, 5*8, $a1, $t1
714 LDu $f12, $f13, 6*8, $a1, $t1
715 LDu $f14, $f15, 7*8, $a1, $t1
716 LDu $f16, $f17, 8*8, $a1, $t1
717 LDu $f18, $f19, 9*8, $a1, $t1
718 LDu $f20, $f21, 10*8, $a1, $t1
719 LDu $f22, $f23, 11*8, $a1, $t1
720 LDu $f24, $f25, 12*8, $a1, $t1
721 LDu $f26, $f27, 13*8, $a1, $t1
722 LDu $f28, $f29, 14*8, $a1, $t1
723 LDu $f30, $f31, 15*8, $a1, $t1
724
Chris Dearman748dd952014-05-23 10:47:01 -0700725 .set push
726 .set nomacro
727 .set noat
jeffhao7fbee072012-08-24 17:56:54 -0700728 lw $at, 4($a0)
Chris Dearman748dd952014-05-23 10:47:01 -0700729 .set pop
jeffhao7fbee072012-08-24 17:56:54 -0700730 lw $v0, 8($a0)
731 lw $v1, 12($a0)
732 lw $a1, 20($a0)
733 lw $a2, 24($a0)
734 lw $a3, 28($a0)
735 lw $t0, 32($a0)
736 lw $t1, 36($a0)
737 lw $t2, 40($a0)
738 lw $t3, 44($a0)
739 lw $t4, 48($a0)
740 lw $t5, 52($a0)
741 lw $t6, 56($a0)
742 lw $t7, 60($a0)
743 lw $s0, 64($a0)
744 lw $s1, 68($a0)
745 lw $s2, 72($a0)
746 lw $s3, 76($a0)
747 lw $s4, 80($a0)
748 lw $s5, 84($a0)
749 lw $s6, 88($a0)
750 lw $s7, 92($a0)
751 lw $t8, 96($a0)
752 lw $t9, 100($a0)
jeffhao7fbee072012-08-24 17:56:54 -0700753 lw $gp, 112($a0)
754 lw $sp, 116($a0)
755 lw $fp, 120($a0)
756 lw $ra, 124($a0)
757 lw $a0, 16($a0)
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100758 move $v0, $zero # clear result registers v0 and v1 (in branch delay slot)
Goran Jakovljevic75969962015-10-27 12:29:07 +0100759 jalr $zero, $t9 # do long jump
jeffhao7fbee072012-08-24 17:56:54 -0700760 move $v1, $zero
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800761END art_quick_do_long_jump
buzbee5bc5a7b2012-03-07 15:52:59 -0800762
buzbee5bc5a7b2012-03-07 15:52:59 -0800763 /*
764 * Called by managed code, saves most registers (forms basis of long jump context) and passes
765 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200766 * the bottom of the thread. On entry a0 holds Throwable*
buzbee5bc5a7b2012-03-07 15:52:59 -0800767 */
Ian Rogers468532e2013-08-05 10:56:33 -0700768ENTRY art_quick_deliver_exception
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100769 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700770 la $t9, artDeliverExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800771 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700772 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700773END art_quick_deliver_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800774
buzbee5bc5a7b2012-03-07 15:52:59 -0800775 /*
776 * Called by managed code to create and deliver a NullPointerException
777 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800778 .extern artThrowNullPointerExceptionFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100779ENTRY_NO_GP art_quick_throw_null_pointer_exception
780 // Note that setting up $gp does not rely on $t9 here, so branching here directly is OK,
781 // even after clobbering any registers we don't need to preserve, such as $gp or $t0.
782 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700783 la $t9, artThrowNullPointerExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800784 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700785 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700786END art_quick_throw_null_pointer_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800787
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100788
789 /*
790 * Call installed by a signal handler to create and deliver a NullPointerException.
791 */
792 .extern artThrowNullPointerExceptionFromSignal
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000793ENTRY_NO_GP_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, FRAME_SIZE_SAVE_EVERYTHING
794 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
795 # Retrieve the fault address from the padding where the signal handler stores it.
796 lw $a0, (ARG_SLOT_SIZE + __SIZEOF_POINTER__)($sp)
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100797 la $t9, artThrowNullPointerExceptionFromSignal
798 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uintptr_t, Thread*)
799 move $a1, rSELF # pass Thread::Current
800END art_quick_throw_null_pointer_exception_from_signal
801
buzbee5bc5a7b2012-03-07 15:52:59 -0800802 /*
803 * Called by managed code to create and deliver an ArithmeticException
804 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800805 .extern artThrowDivZeroFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100806ENTRY_NO_GP art_quick_throw_div_zero
807 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700808 la $t9, artThrowDivZeroFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800809 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700810 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700811END art_quick_throw_div_zero
buzbee5bc5a7b2012-03-07 15:52:59 -0800812
buzbee5bc5a7b2012-03-07 15:52:59 -0800813 /*
814 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
815 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800816 .extern artThrowArrayBoundsFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100817ENTRY_NO_GP art_quick_throw_array_bounds
818 // Note that setting up $gp does not rely on $t9 here, so branching here directly is OK,
819 // even after clobbering any registers we don't need to preserve, such as $gp or $t0.
820 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700821 la $t9, artThrowArrayBoundsFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800822 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700823 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700824END art_quick_throw_array_bounds
buzbee5bc5a7b2012-03-07 15:52:59 -0800825
Ian Rogers57b86d42012-03-27 16:05:41 -0700826 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100827 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
828 * as if thrown from a call to String.charAt().
829 */
830 .extern artThrowStringBoundsFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100831ENTRY_NO_GP art_quick_throw_string_bounds
832 SETUP_SAVE_EVERYTHING_FRAME
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100833 la $t9, artThrowStringBoundsFromCode
834 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
835 move $a2, rSELF # pass Thread::Current
836END art_quick_throw_string_bounds
837
838 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700839 * Called by managed code to create and deliver a StackOverflowError.
840 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800841 .extern artThrowStackOverflowFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700842ENTRY art_quick_throw_stack_overflow
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100843 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700844 la $t9, artThrowStackOverflowFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800845 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700846 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700847END art_quick_throw_stack_overflow
buzbee5bc5a7b2012-03-07 15:52:59 -0800848
Ian Rogers57b86d42012-03-27 16:05:41 -0700849 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800850 * All generated callsites for interface invokes and invocation slow paths will load arguments
jeffhao7fbee072012-08-24 17:56:54 -0700851 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100852 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
jeffhao7fbee072012-08-24 17:56:54 -0700853 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800854 *
jeffhao7fbee072012-08-24 17:56:54 -0700855 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
856 * of the target Method* in $v0 and method->code_ in $v1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800857 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700858 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
buzbee5bc5a7b2012-03-07 15:52:59 -0800859 * thread and we branch to another stub to deliver it.
860 *
861 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
862 * pointing back to the original caller.
863 */
Alexey Frunze279cfba2017-07-22 00:24:43 -0700864.macro INVOKE_TRAMPOLINE_BODY cxx_name, save_s4_thru_s8_only=0
buzbee5bc5a7b2012-03-07 15:52:59 -0800865 .extern \cxx_name
Alexey Frunze279cfba2017-07-22 00:24:43 -0700866 SETUP_SAVE_REFS_AND_ARGS_FRAME \save_s4_thru_s8_only # save callee saves in case
867 # allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100868 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100869 la $t9, \cxx_name
870 jalr $t9 # (method_idx, this, Thread*, $sp)
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100871 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
872 move $a0, $v0 # save target Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100873 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhaofa147e22012-10-12 17:03:32 -0700874 beqz $v0, 1f
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100875 move $t9, $v1 # save $v0->code_
Andreas Gampe8d365912015-01-13 11:32:32 -0800876 jalr $zero, $t9
buzbee5bc5a7b2012-03-07 15:52:59 -0800877 nop
8781:
879 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700880.endm
881.macro INVOKE_TRAMPOLINE c_name, cxx_name
882ENTRY \c_name
883 INVOKE_TRAMPOLINE_BODY \cxx_name
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800884END \c_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800885.endm
886
Logan Chien8dbb7082013-01-25 20:31:17 +0800887INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800888
Logan Chien8dbb7082013-01-25 20:31:17 +0800889INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
890INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
891INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
892INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800893
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800894// Each of the following macros expands into four instructions or 16 bytes.
895// They are used to build indexable "tables" of code.
896
897.macro LOAD_WORD_TO_REG reg, next_arg, index_reg, label
Goran Jakovljevicff734982015-08-24 12:58:55 +0000898 lw $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
899 b \label
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800900 addiu $\index_reg, 16
901 .balign 16
Goran Jakovljevicff734982015-08-24 12:58:55 +0000902.endm
903
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800904.macro LOAD_LONG_TO_REG reg1, reg2, next_arg, index_reg, next_index, label
Goran Jakovljevicff734982015-08-24 12:58:55 +0000905 lw $\reg1, -8($\next_arg) # next_arg points to argument after the current one (offset is 8)
906 lw $\reg2, -4($\next_arg)
907 b \label
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800908 li $\index_reg, \next_index
909 .balign 16
Goran Jakovljevicff734982015-08-24 12:58:55 +0000910.endm
911
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800912.macro LOAD_FLOAT_TO_REG reg, next_arg, index_reg, label
Goran Jakovljevicff734982015-08-24 12:58:55 +0000913 lwc1 $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
914 b \label
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800915 addiu $\index_reg, 16
916 .balign 16
Goran Jakovljevicff734982015-08-24 12:58:55 +0000917.endm
918
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800919#if defined(__mips_isa_rev) && __mips_isa_rev > 2
920// LDu expands into 3 instructions for 64-bit FPU, so index_reg cannot be updated here.
921.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index_reg, tmp, label
922 .set reorder # force use of the branch delay slot
Goran Jakovljevicff734982015-08-24 12:58:55 +0000923 LDu $\reg1, $\reg2, -8, $\next_arg, $\tmp # next_arg points to argument after the current one
924 # (offset is 8)
925 b \label
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800926 .set noreorder
927 .balign 16
928.endm
929#else
930// LDu expands into 2 instructions for 32-bit FPU, so index_reg is updated here.
931.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index_reg, tmp, label
932 LDu $\reg1, $\reg2, -8, $\next_arg, $\tmp # next_arg points to argument after the current one
933 # (offset is 8)
934 b \label
935 addiu $\index_reg, 16
936 .balign 16
937.endm
938#endif
939
940.macro LOAD_END index_reg, next_index, label
941 b \label
942 li $\index_reg, \next_index
943 .balign 16
Goran Jakovljevicff734982015-08-24 12:58:55 +0000944.endm
945
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100946#define SPILL_SIZE 32
947
Jeff Hao79fe5392013-04-24 18:41:58 -0700948 /*
Ian Rogersef7d42f2014-01-06 12:55:46 -0800949 * Invocation stub for quick code.
Jeff Hao5d917302013-02-27 17:57:33 -0800950 * On entry:
951 * a0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700952 * a1 = argument array or null for no argument methods
Jeff Hao5d917302013-02-27 17:57:33 -0800953 * a2 = size of argument array in bytes
954 * a3 = (managed) thread pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700955 * [sp + 16] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800956 * [sp + 20] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800957 */
958ENTRY art_quick_invoke_stub
Jeff Hao5d917302013-02-27 17:57:33 -0800959 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100960 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
961 .cfi_adjust_cfa_offset SPILL_SIZE
962 sw $gp, 16($sp)
Jeff Hao5d917302013-02-27 17:57:33 -0800963 sw $ra, 12($sp)
964 .cfi_rel_offset 31, 12
965 sw $fp, 8($sp)
966 .cfi_rel_offset 30, 8
967 sw $s1, 4($sp)
968 .cfi_rel_offset 17, 4
969 sw $s0, 0($sp)
970 .cfi_rel_offset 16, 0
971 move $fp, $sp # save sp in fp
972 .cfi_def_cfa_register 30
973 move $s1, $a3 # move managed thread pointer into s1
Goran Jakovljevicff734982015-08-24 12:58:55 +0000974 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700975 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
Goran Jakovljevicff734982015-08-24 12:58:55 +0000976 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
977 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
978 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100979 la $t9, memcpy
980 jalr $t9 # (dest, src, bytes)
Jeff Hao5d917302013-02-27 17:57:33 -0800981 addiu $sp, $sp, -16 # make space for argument slots for memcpy
982 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100983 lw $gp, 16($fp) # restore $gp
984 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000985 lw $a1, 4($sp) # a1 = this*
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800986 addiu $t8, $sp, 8 # t8 = pointer to the current argument (skip ArtMethod* and this*)
987 li $t6, 0 # t6 = gpr_index = 0 (corresponds to A2; A0 and A1 are skipped)
988 li $t7, 0 # t7 = fp_index = 0
989 lw $t9, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100990 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800991 addiu $t9, 1 # t9 = shorty + 1 (skip 1 for return type)
992
993 // Load the base addresses of tabInt ... tabDouble.
994 // We will use the register indices (gpr_index, fp_index) to branch.
995 // Note that the indices are scaled by 16, so they can be added to the bases directly.
996#if defined(__mips_isa_rev) && __mips_isa_rev >= 6
997 lapc $t2, tabInt
998 lapc $t3, tabLong
999 lapc $t4, tabSingle
1000 lapc $t5, tabDouble
1001#else
1002 bltzal $zero, tabBase # nal
1003 addiu $t2, $ra, %lo(tabInt - tabBase)
1004tabBase:
1005 addiu $t3, $ra, %lo(tabLong - tabBase)
1006 addiu $t4, $ra, %lo(tabSingle - tabBase)
1007 addiu $t5, $ra, %lo(tabDouble - tabBase)
1008#endif
1009
Goran Jakovljevicff734982015-08-24 12:58:55 +00001010loop:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001011 lbu $ra, 0($t9) # ra = shorty[i]
1012 beqz $ra, loopEnd # finish getting args when shorty[i] == '\0'
1013 addiu $t9, 1
Goran Jakovljevicff734982015-08-24 12:58:55 +00001014
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001015 addiu $ra, -'J'
1016 beqz $ra, isLong # branch if result type char == 'J'
1017 addiu $ra, 'J' - 'D'
1018 beqz $ra, isDouble # branch if result type char == 'D'
1019 addiu $ra, 'D' - 'F'
1020 beqz $ra, isSingle # branch if result type char == 'F'
Goran Jakovljevicff734982015-08-24 12:58:55 +00001021
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001022 addu $ra, $t2, $t6
1023 jalr $zero, $ra
1024 addiu $t8, 4 # next_arg = curr_arg + 4
Goran Jakovljevicff734982015-08-24 12:58:55 +00001025
1026isLong:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001027 addu $ra, $t3, $t6
1028 jalr $zero, $ra
1029 addiu $t8, 8 # next_arg = curr_arg + 8
Goran Jakovljevicff734982015-08-24 12:58:55 +00001030
1031isSingle:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001032 addu $ra, $t4, $t7
1033 jalr $zero, $ra
1034 addiu $t8, 4 # next_arg = curr_arg + 4
1035
1036isDouble:
1037 addu $ra, $t5, $t7
1038#if defined(__mips_isa_rev) && __mips_isa_rev > 2
1039 addiu $t7, 16 # fp_index += 16 didn't fit into LOAD_DOUBLE_TO_REG
1040#endif
1041 jalr $zero, $ra
1042 addiu $t8, 8 # next_arg = curr_arg + 8
Goran Jakovljevicff734982015-08-24 12:58:55 +00001043
1044loopEnd:
Mathieu Chartiere401d142015-04-22 13:56:20 -07001045 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -08001046 jalr $t9 # call the method
Goran Jakovljevicff734982015-08-24 12:58:55 +00001047 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
Jeff Hao5d917302013-02-27 17:57:33 -08001048 move $sp, $fp # restore the stack
1049 lw $s0, 0($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -08001050 .cfi_restore 16
Jeff Hao5d917302013-02-27 17:57:33 -08001051 lw $s1, 4($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -08001052 .cfi_restore 17
Jeff Hao5d917302013-02-27 17:57:33 -08001053 lw $fp, 8($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -08001054 .cfi_restore 30
Jeff Hao5d917302013-02-27 17:57:33 -08001055 lw $ra, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -08001056 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001057 addiu $sp, $sp, SPILL_SIZE
1058 .cfi_adjust_cfa_offset -SPILL_SIZE
Jeff Hao5d917302013-02-27 17:57:33 -08001059 lw $t0, 16($sp) # get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -08001060 lw $t1, 20($sp) # get shorty
1061 lb $t1, 0($t1) # get result type char
Goran Jakovljevicff734982015-08-24 12:58:55 +00001062 li $t2, 'D' # put char 'D' into t2
1063 beq $t1, $t2, 5f # branch if result type char == 'D'
1064 li $t3, 'F' # put char 'F' into t3
1065 beq $t1, $t3, 5f # branch if result type char == 'F'
Jeff Hao5d917302013-02-27 17:57:33 -08001066 sw $v0, 0($t0) # store the result
Andreas Gampe8d365912015-01-13 11:32:32 -08001067 jalr $zero, $ra
Jeff Hao5d917302013-02-27 17:57:33 -08001068 sw $v1, 4($t0) # store the other half of the result
Goran Jakovljevicff734982015-08-24 12:58:55 +000010695:
Duane Sande34652f2014-11-04 11:09:36 -08001070 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
Andreas Gampe8d365912015-01-13 11:32:32 -08001071 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001072 nop
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001073
1074 // Note that gpr_index is kept within the range of tabInt and tabLong
1075 // and fp_index is kept within the range of tabSingle and tabDouble.
1076 .balign 16
1077tabInt:
1078 LOAD_WORD_TO_REG a2, t8, t6, loop # a2 = current argument, gpr_index += 16
1079 LOAD_WORD_TO_REG a3, t8, t6, loop # a3 = current argument, gpr_index += 16
1080 LOAD_WORD_TO_REG t0, t8, t6, loop # t0 = current argument, gpr_index += 16
1081 LOAD_WORD_TO_REG t1, t8, t6, loop # t1 = current argument, gpr_index += 16
1082 LOAD_END t6, 4*16, loop # no more GPR args, gpr_index = 4*16
1083tabLong:
1084 LOAD_LONG_TO_REG a2, a3, t8, t6, 2*16, loop # a2_a3 = curr_arg, gpr_index = 2*16
1085 LOAD_LONG_TO_REG t0, t1, t8, t6, 4*16, loop # t0_t1 = curr_arg, gpr_index = 4*16
1086 LOAD_LONG_TO_REG t0, t1, t8, t6, 4*16, loop # t0_t1 = curr_arg, gpr_index = 4*16
1087 LOAD_END t6, 4*16, loop # no more GPR args, gpr_index = 4*16
1088 LOAD_END t6, 4*16, loop # no more GPR args, gpr_index = 4*16
1089tabSingle:
1090 LOAD_FLOAT_TO_REG f8, t8, t7, loop # f8 = curr_arg, fp_index += 16
1091 LOAD_FLOAT_TO_REG f10, t8, t7, loop # f10 = curr_arg, fp_index += 16
1092 LOAD_FLOAT_TO_REG f12, t8, t7, loop # f12 = curr_arg, fp_index += 16
1093 LOAD_FLOAT_TO_REG f14, t8, t7, loop # f14 = curr_arg, fp_index += 16
1094 LOAD_FLOAT_TO_REG f16, t8, t7, loop # f16 = curr_arg, fp_index += 16
1095 LOAD_FLOAT_TO_REG f18, t8, t7, loop # f18 = curr_arg, fp_index += 16
1096 LOAD_END t7, 6*16, loop # no more FPR args, fp_index = 6*16
1097tabDouble:
1098 LOAD_DOUBLE_TO_REG f8, f9, t8, t7, ra, loop # f8_f9 = curr_arg; if FPU32, fp_index += 16
1099 LOAD_DOUBLE_TO_REG f10, f11, t8, t7, ra, loop # f10_f11 = curr_arg; if FPU32, fp_index += 16
1100 LOAD_DOUBLE_TO_REG f12, f13, t8, t7, ra, loop # f12_f13 = curr_arg; if FPU32, fp_index += 16
1101 LOAD_DOUBLE_TO_REG f14, f15, t8, t7, ra, loop # f14_f15 = curr_arg; if FPU32, fp_index += 16
1102 LOAD_DOUBLE_TO_REG f16, f17, t8, t7, ra, loop # f16_f17 = curr_arg; if FPU32, fp_index += 16
1103 LOAD_DOUBLE_TO_REG f18, f19, t8, t7, ra, loop # f18_f19 = curr_arg; if FPU32, fp_index += 16
1104 LOAD_END t7, 6*16, loop # no more FPR args, fp_index = 6*16
Jeff Hao5d917302013-02-27 17:57:33 -08001105END art_quick_invoke_stub
1106
1107 /*
Goran Jakovljevicff734982015-08-24 12:58:55 +00001108 * Invocation static stub for quick code.
1109 * On entry:
1110 * a0 = method pointer
1111 * a1 = argument array or null for no argument methods
1112 * a2 = size of argument array in bytes
1113 * a3 = (managed) thread pointer
1114 * [sp + 16] = JValue* result
1115 * [sp + 20] = shorty
1116 */
1117ENTRY art_quick_invoke_static_stub
1118 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001119 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
1120 .cfi_adjust_cfa_offset SPILL_SIZE
1121 sw $gp, 16($sp)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001122 sw $ra, 12($sp)
1123 .cfi_rel_offset 31, 12
1124 sw $fp, 8($sp)
1125 .cfi_rel_offset 30, 8
1126 sw $s1, 4($sp)
1127 .cfi_rel_offset 17, 4
1128 sw $s0, 0($sp)
1129 .cfi_rel_offset 16, 0
1130 move $fp, $sp # save sp in fp
1131 .cfi_def_cfa_register 30
1132 move $s1, $a3 # move managed thread pointer into s1
Goran Jakovljevicff734982015-08-24 12:58:55 +00001133 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
1134 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
1135 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
1136 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
1137 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001138 la $t9, memcpy
1139 jalr $t9 # (dest, src, bytes)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001140 addiu $sp, $sp, -16 # make space for argument slots for memcpy
1141 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001142 lw $gp, 16($fp) # restore $gp
1143 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001144 addiu $t8, $sp, 4 # t8 = pointer to the current argument (skip ArtMethod*)
1145 li $t6, 0 # t6 = gpr_index = 0 (corresponds to A1; A0 is skipped)
1146 li $t7, 0 # t7 = fp_index = 0
1147 lw $t9, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001148 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001149 addiu $t9, 1 # t9 = shorty + 1 (skip 1 for return type)
1150
1151 // Load the base addresses of tabIntS ... tabDoubleS.
1152 // We will use the register indices (gpr_index, fp_index) to branch.
1153 // Note that the indices are scaled by 16, so they can be added to the bases directly.
1154#if defined(__mips_isa_rev) && __mips_isa_rev >= 6
1155 lapc $t2, tabIntS
1156 lapc $t3, tabLongS
1157 lapc $t4, tabSingleS
1158 lapc $t5, tabDoubleS
1159#else
1160 bltzal $zero, tabBaseS # nal
1161 addiu $t2, $ra, %lo(tabIntS - tabBaseS)
1162tabBaseS:
1163 addiu $t3, $ra, %lo(tabLongS - tabBaseS)
1164 addiu $t4, $ra, %lo(tabSingleS - tabBaseS)
1165 addiu $t5, $ra, %lo(tabDoubleS - tabBaseS)
1166#endif
1167
Goran Jakovljevicff734982015-08-24 12:58:55 +00001168loopS:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001169 lbu $ra, 0($t9) # ra = shorty[i]
1170 beqz $ra, loopEndS # finish getting args when shorty[i] == '\0'
1171 addiu $t9, 1
Goran Jakovljevicff734982015-08-24 12:58:55 +00001172
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001173 addiu $ra, -'J'
1174 beqz $ra, isLongS # branch if result type char == 'J'
1175 addiu $ra, 'J' - 'D'
1176 beqz $ra, isDoubleS # branch if result type char == 'D'
1177 addiu $ra, 'D' - 'F'
1178 beqz $ra, isSingleS # branch if result type char == 'F'
Goran Jakovljevicff734982015-08-24 12:58:55 +00001179
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001180 addu $ra, $t2, $t6
1181 jalr $zero, $ra
1182 addiu $t8, 4 # next_arg = curr_arg + 4
Goran Jakovljevicff734982015-08-24 12:58:55 +00001183
1184isLongS:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001185 addu $ra, $t3, $t6
1186 jalr $zero, $ra
1187 addiu $t8, 8 # next_arg = curr_arg + 8
Goran Jakovljevicff734982015-08-24 12:58:55 +00001188
1189isSingleS:
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001190 addu $ra, $t4, $t7
1191 jalr $zero, $ra
1192 addiu $t8, 4 # next_arg = curr_arg + 4
1193
1194isDoubleS:
1195 addu $ra, $t5, $t7
1196#if defined(__mips_isa_rev) && __mips_isa_rev > 2
1197 addiu $t7, 16 # fp_index += 16 didn't fit into LOAD_DOUBLE_TO_REG
1198#endif
1199 jalr $zero, $ra
1200 addiu $t8, 8 # next_arg = curr_arg + 8
Goran Jakovljevicff734982015-08-24 12:58:55 +00001201
1202loopEndS:
1203 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
1204 jalr $t9 # call the method
1205 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1206 move $sp, $fp # restore the stack
1207 lw $s0, 0($sp)
1208 .cfi_restore 16
1209 lw $s1, 4($sp)
1210 .cfi_restore 17
1211 lw $fp, 8($sp)
1212 .cfi_restore 30
1213 lw $ra, 12($sp)
1214 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001215 addiu $sp, $sp, SPILL_SIZE
1216 .cfi_adjust_cfa_offset -SPILL_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +00001217 lw $t0, 16($sp) # get result pointer
1218 lw $t1, 20($sp) # get shorty
1219 lb $t1, 0($t1) # get result type char
1220 li $t2, 'D' # put char 'D' into t2
1221 beq $t1, $t2, 6f # branch if result type char == 'D'
1222 li $t3, 'F' # put char 'F' into t3
1223 beq $t1, $t3, 6f # branch if result type char == 'F'
1224 sw $v0, 0($t0) # store the result
1225 jalr $zero, $ra
1226 sw $v1, 4($t0) # store the other half of the result
12276:
1228 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
1229 jalr $zero, $ra
1230 nop
Alexey Frunze1b8464d2016-11-12 17:22:05 -08001231
1232 // Note that gpr_index is kept within the range of tabIntS and tabLongS
1233 // and fp_index is kept within the range of tabSingleS and tabDoubleS.
1234 .balign 16
1235tabIntS:
1236 LOAD_WORD_TO_REG a1, t8, t6, loopS # a1 = current argument, gpr_index += 16
1237 LOAD_WORD_TO_REG a2, t8, t6, loopS # a2 = current argument, gpr_index += 16
1238 LOAD_WORD_TO_REG a3, t8, t6, loopS # a3 = current argument, gpr_index += 16
1239 LOAD_WORD_TO_REG t0, t8, t6, loopS # t0 = current argument, gpr_index += 16
1240 LOAD_WORD_TO_REG t1, t8, t6, loopS # t1 = current argument, gpr_index += 16
1241 LOAD_END t6, 5*16, loopS # no more GPR args, gpr_index = 5*16
1242tabLongS:
1243 LOAD_LONG_TO_REG a2, a3, t8, t6, 3*16, loopS # a2_a3 = curr_arg, gpr_index = 3*16
1244 LOAD_LONG_TO_REG a2, a3, t8, t6, 3*16, loopS # a2_a3 = curr_arg, gpr_index = 3*16
1245 LOAD_LONG_TO_REG t0, t1, t8, t6, 5*16, loopS # t0_t1 = curr_arg, gpr_index = 5*16
1246 LOAD_LONG_TO_REG t0, t1, t8, t6, 5*16, loopS # t0_t1 = curr_arg, gpr_index = 5*16
1247 LOAD_END t6, 5*16, loopS # no more GPR args, gpr_index = 5*16
1248 LOAD_END t6, 5*16, loopS # no more GPR args, gpr_index = 5*16
1249tabSingleS:
1250 LOAD_FLOAT_TO_REG f8, t8, t7, loopS # f8 = curr_arg, fp_index += 16
1251 LOAD_FLOAT_TO_REG f10, t8, t7, loopS # f10 = curr_arg, fp_index += 16
1252 LOAD_FLOAT_TO_REG f12, t8, t7, loopS # f12 = curr_arg, fp_index += 16
1253 LOAD_FLOAT_TO_REG f14, t8, t7, loopS # f14 = curr_arg, fp_index += 16
1254 LOAD_FLOAT_TO_REG f16, t8, t7, loopS # f16 = curr_arg, fp_index += 16
1255 LOAD_FLOAT_TO_REG f18, t8, t7, loopS # f18 = curr_arg, fp_index += 16
1256 LOAD_END t7, 6*16, loopS # no more FPR args, fp_index = 6*16
1257tabDoubleS:
1258 LOAD_DOUBLE_TO_REG f8, f9, t8, t7, ra, loopS # f8_f9 = curr_arg; if FPU32, fp_index += 16
1259 LOAD_DOUBLE_TO_REG f10, f11, t8, t7, ra, loopS # f10_f11 = curr_arg; if FPU32, fp_index += 16
1260 LOAD_DOUBLE_TO_REG f12, f13, t8, t7, ra, loopS # f12_f13 = curr_arg; if FPU32, fp_index += 16
1261 LOAD_DOUBLE_TO_REG f14, f15, t8, t7, ra, loopS # f14_f15 = curr_arg; if FPU32, fp_index += 16
1262 LOAD_DOUBLE_TO_REG f16, f17, t8, t7, ra, loopS # f16_f17 = curr_arg; if FPU32, fp_index += 16
1263 LOAD_DOUBLE_TO_REG f18, f19, t8, t7, ra, loopS # f18_f19 = curr_arg; if FPU32, fp_index += 16
1264 LOAD_END t7, 6*16, loopS # no more FPR args, fp_index = 6*16
Goran Jakovljevicff734982015-08-24 12:58:55 +00001265END art_quick_invoke_static_stub
1266
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001267#undef SPILL_SIZE
1268
Goran Jakovljevicff734982015-08-24 12:58:55 +00001269 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08001270 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1271 * failure.
1272 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001273 .extern artHandleFillArrayDataFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001274ENTRY art_quick_handle_fill_data
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001275 lw $a2, 0($sp) # pass referrer's Method*
1276 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001277 la $t9, artHandleFillArrayDataFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001278 jalr $t9 # (payload offset, Array*, method, Thread*)
1279 move $a3, rSELF # pass Thread::Current
jeffhaofc6a30e2012-10-18 18:24:15 -07001280 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001281END art_quick_handle_fill_data
buzbee5bc5a7b2012-03-07 15:52:59 -08001282
buzbee5bc5a7b2012-03-07 15:52:59 -08001283 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001284 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
buzbee5bc5a7b2012-03-07 15:52:59 -08001285 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001286 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001287ENTRY art_quick_lock_object
Vladimir Marko804b03f2016-09-14 16:26:36 +01001288 beqz $a0, art_quick_throw_null_pointer_exception
Alexey Frunzead63fe52017-05-08 22:10:00 -07001289 li $t8, LOCK_WORD_THIN_LOCK_COUNT_ONE
1290 li $t3, LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED
1291.Lretry_lock:
1292 lw $t0, THREAD_ID_OFFSET(rSELF) # TODO: Can the thread ID really change during the loop?
1293 ll $t1, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1294 and $t2, $t1, $t3 # zero the gc bits
1295 bnez $t2, .Lnot_unlocked # already thin locked
1296 # Unlocked case - $t1: original lock word that's zero except for the read barrier bits.
1297 or $t2, $t1, $t0 # $t2 holds thread id with count of 0 with preserved read barrier bits
1298 sc $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1299 beqz $t2, .Lretry_lock # store failed, retry
Ian Rogersa9a82542013-10-04 11:17:26 -07001300 nop
Alexey Frunzead63fe52017-05-08 22:10:00 -07001301 jalr $zero, $ra
1302 sync # full (LoadLoad|LoadStore) memory barrier
1303.Lnot_unlocked:
1304 # $t1: original lock word, $t0: thread_id with count of 0 and zero read barrier bits
1305 srl $t2, $t1, LOCK_WORD_STATE_SHIFT
1306 bnez $t2, .Lslow_lock # if either of the top two bits are set, go slow path
1307 xor $t2, $t1, $t0 # lock_word.ThreadId() ^ self->ThreadId()
1308 andi $t2, $t2, 0xFFFF # zero top 16 bits
1309 bnez $t2, .Lslow_lock # lock word and self thread id's match -> recursive lock
1310 # otherwise contention, go to slow path
1311 and $t2, $t1, $t3 # zero the gc bits
1312 addu $t2, $t2, $t8 # increment count in lock word
1313 srl $t2, $t2, LOCK_WORD_STATE_SHIFT # if the first gc state bit is set, we overflowed.
1314 bnez $t2, .Lslow_lock # if we overflow the count go slow path
1315 addu $t2, $t1, $t8 # increment count for real
1316 sc $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1317 beqz $t2, .Lretry_lock # store failed, retry
1318 nop
1319 jalr $zero, $ra
1320 nop
1321.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001322 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001323 la $t9, artLockObjectFromCode
1324 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001325 move $a1, rSELF # pass Thread::Current
Ian Rogers6bcd1632013-10-08 18:50:47 -07001326 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001327END art_quick_lock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001328
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001329ENTRY art_quick_lock_object_no_inline
Vladimir Marko804b03f2016-09-14 16:26:36 +01001330 beqz $a0, art_quick_throw_null_pointer_exception
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001331 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001332 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001333 la $t9, artLockObjectFromCode
1334 jalr $t9 # (Object* obj, Thread*)
1335 move $a1, rSELF # pass Thread::Current
1336 RETURN_IF_ZERO
1337END art_quick_lock_object_no_inline
1338
buzbee5bc5a7b2012-03-07 15:52:59 -08001339 /*
1340 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1341 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001342 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001343ENTRY art_quick_unlock_object
Vladimir Marko804b03f2016-09-14 16:26:36 +01001344 beqz $a0, art_quick_throw_null_pointer_exception
Alexey Frunzead63fe52017-05-08 22:10:00 -07001345 li $t8, LOCK_WORD_THIN_LOCK_COUNT_ONE
1346 li $t3, LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED
1347.Lretry_unlock:
1348#ifndef USE_READ_BARRIER
1349 lw $t1, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1350#else
1351 ll $t1, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0) # Need to use atomic read-modify-write for read barrier
1352#endif
1353 srl $t2, $t1, LOCK_WORD_STATE_SHIFT
1354 bnez $t2, .Lslow_unlock # if either of the top two bits are set, go slow path
1355 lw $t0, THREAD_ID_OFFSET(rSELF)
1356 and $t2, $t1, $t3 # zero the gc bits
1357 xor $t2, $t2, $t0 # lock_word.ThreadId() ^ self->ThreadId()
1358 andi $t2, $t2, 0xFFFF # zero top 16 bits
1359 bnez $t2, .Lslow_unlock # do lock word and self thread id's match?
1360 and $t2, $t1, $t3 # zero the gc bits
1361 bgeu $t2, $t8, .Lrecursive_thin_unlock
1362 # transition to unlocked
1363 nor $t2, $zero, $t3 # $t2 = LOCK_WORD_GC_STATE_MASK_SHIFTED
1364 and $t2, $t1, $t2 # $t2: zero except for the preserved gc bits
1365 sync # full (LoadStore|StoreStore) memory barrier
1366#ifndef USE_READ_BARRIER
1367 jalr $zero, $ra
1368 sw $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1369#else
1370 sc $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1371 beqz $t2, .Lretry_unlock # store failed, retry
Ian Rogersa9a82542013-10-04 11:17:26 -07001372 nop
Alexey Frunzead63fe52017-05-08 22:10:00 -07001373 jalr $zero, $ra
1374 nop
1375#endif
1376.Lrecursive_thin_unlock:
1377 # t1: original lock word
1378 subu $t2, $t1, $t8 # decrement count
1379#ifndef USE_READ_BARRIER
1380 jalr $zero, $ra
1381 sw $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1382#else
1383 sc $t2, MIRROR_OBJECT_LOCK_WORD_OFFSET($a0)
1384 beqz $t2, .Lretry_unlock # store failed, retry
1385 nop
1386 jalr $zero, $ra
1387 nop
1388#endif
1389.Lslow_unlock:
1390 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001391 la $t9, artUnlockObjectFromCode
Alexey Frunzead63fe52017-05-08 22:10:00 -07001392 jalr $t9 # (Object* obj, Thread*)
1393 move $a1, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001394 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001395END art_quick_unlock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001396
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001397ENTRY art_quick_unlock_object_no_inline
Vladimir Marko804b03f2016-09-14 16:26:36 +01001398 beqz $a0, art_quick_throw_null_pointer_exception
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001399 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001400 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001401 la $t9, artUnlockObjectFromCode
1402 jalr $t9 # (Object* obj, Thread*)
1403 move $a1, rSELF # pass Thread::Current
1404 RETURN_IF_ZERO
1405END art_quick_unlock_object_no_inline
1406
buzbee5bc5a7b2012-03-07 15:52:59 -08001407 /*
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001408 * Entry from managed code that calls artInstanceOfFromCode and delivers exception on failure.
buzbee5bc5a7b2012-03-07 15:52:59 -08001409 */
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001410 .extern artInstanceOfFromCode
1411 .extern artThrowClassCastExceptionForObject
1412ENTRY art_quick_check_instance_of
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001413 addiu $sp, $sp, -32
1414 .cfi_adjust_cfa_offset 32
1415 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001416 sw $ra, 12($sp)
1417 .cfi_rel_offset 31, 12
1418 sw $t9, 8($sp)
1419 sw $a1, 4($sp)
1420 sw $a0, 0($sp)
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001421 la $t9, artInstanceOfFromCode
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001422 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07001423 addiu $sp, $sp, -16 # reserve argument slots on the stack
1424 addiu $sp, $sp, 16
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001425 lw $gp, 16($sp)
Ian Rogers86bcdc22014-02-21 22:06:38 -08001426 beqz $v0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001427 lw $ra, 12($sp)
Andreas Gampe8d365912015-01-13 11:32:32 -08001428 jalr $zero, $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001429 addiu $sp, $sp, 32
1430 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001431.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001432 lw $t9, 8($sp)
1433 lw $a1, 4($sp)
1434 lw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001435 addiu $sp, $sp, 32
1436 .cfi_adjust_cfa_offset -32
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001437 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001438 la $t9, artThrowClassCastExceptionForObject
1439 jalr $zero, $t9 # artThrowClassCastException (Object*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001440 move $a2, rSELF # pass Thread::Current
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001441END art_quick_check_instance_of
buzbee5bc5a7b2012-03-07 15:52:59 -08001442
buzbee5bc5a7b2012-03-07 15:52:59 -08001443 /*
Man Cao1aee9002015-07-14 22:31:42 -07001444 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1445 * nReg is the register number for rReg.
1446 */
1447.macro POP_REG_NE rReg, nReg, offset, rExclude
1448 .ifnc \rReg, \rExclude
1449 lw \rReg, \offset($sp) # restore rReg
1450 .cfi_restore \nReg
1451 .endif
1452.endm
1453
1454 /*
1455 * Macro to insert read barrier, only used in art_quick_aput_obj.
1456 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1457 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1458 */
1459.macro READ_BARRIER rDest, rObj, offset
1460#ifdef USE_READ_BARRIER
1461 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
1462 addiu $sp, $sp, -32
1463 .cfi_adjust_cfa_offset 32
1464 sw $ra, 28($sp)
1465 .cfi_rel_offset 31, 28
1466 sw $t9, 24($sp)
1467 .cfi_rel_offset 25, 24
1468 sw $t1, 20($sp)
1469 .cfi_rel_offset 9, 20
1470 sw $t0, 16($sp)
1471 .cfi_rel_offset 8, 16
1472 sw $a2, 8($sp) # padding slot at offset 12 (padding can be any slot in the 32B)
1473 .cfi_rel_offset 6, 8
1474 sw $a1, 4($sp)
1475 .cfi_rel_offset 5, 4
1476 sw $a0, 0($sp)
1477 .cfi_rel_offset 4, 0
1478
Man Cao63069212015-08-21 15:51:39 -07001479 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001480 .ifnc \rObj, $a1
1481 move $a1, \rObj # pass rObj
1482 .endif
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001483 addiu $a2, $zero, \offset # pass offset
1484 la $t9, artReadBarrierSlow
1485 jalr $t9 # artReadBarrierSlow(ref, rObj, offset)
Man Cao1aee9002015-07-14 22:31:42 -07001486 addiu $sp, $sp, -16 # Use branch delay slot to reserve argument slots on the stack
1487 # before the call to artReadBarrierSlow.
1488 addiu $sp, $sp, 16 # restore stack after call to artReadBarrierSlow
1489 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1490 move \rDest, $v0 # save return value in rDest
1491 # (rDest cannot be v0 in art_quick_aput_obj)
1492
1493 lw $a0, 0($sp) # restore registers except rDest
1494 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1495 .cfi_restore 4
1496 lw $a1, 4($sp)
1497 .cfi_restore 5
1498 lw $a2, 8($sp)
1499 .cfi_restore 6
1500 POP_REG_NE $t0, 8, 16, \rDest
1501 POP_REG_NE $t1, 9, 20, \rDest
1502 lw $t9, 24($sp)
1503 .cfi_restore 25
1504 lw $ra, 28($sp) # restore $ra
1505 .cfi_restore 31
1506 addiu $sp, $sp, 32
1507 .cfi_adjust_cfa_offset -32
1508#else
1509 lw \rDest, \offset(\rObj)
1510 UNPOISON_HEAP_REF \rDest
1511#endif // USE_READ_BARRIER
1512.endm
1513
Man Cao1aee9002015-07-14 22:31:42 -07001514#ifdef USE_READ_BARRIER
1515 .extern artReadBarrierSlow
1516#endif
Ian Rogersa9a82542013-10-04 11:17:26 -07001517ENTRY art_quick_aput_obj
Ian Rogers86bcdc22014-02-21 22:06:38 -08001518 beqz $a2, .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -07001519 nop
Man Cao1aee9002015-07-14 22:31:42 -07001520 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1521 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1522 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogers86bcdc22014-02-21 22:06:38 -08001523 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
Ian Rogersa9a82542013-10-04 11:17:26 -07001524 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001525.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -07001526 sll $a1, $a1, 2
1527 add $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001528 POISON_HEAP_REF $a2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001529 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001530 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001531 srl $t1, $a0, CARD_TABLE_CARD_SHIFT
Ian Rogersa9a82542013-10-04 11:17:26 -07001532 add $t1, $t1, $t0
1533 sb $t0, ($t1)
Andreas Gampe8d365912015-01-13 11:32:32 -08001534 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001535 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001536.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -07001537 sll $a1, $a1, 2
1538 add $t0, $a0, $a1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001539 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Andreas Gampe8d365912015-01-13 11:32:32 -08001540 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001541 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001542.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -07001543 addiu $sp, $sp, -32
1544 .cfi_adjust_cfa_offset 32
1545 sw $ra, 28($sp)
1546 .cfi_rel_offset 31, 28
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001547 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001548 sw $t9, 12($sp)
1549 sw $a2, 8($sp)
1550 sw $a1, 4($sp)
1551 sw $a0, 0($sp)
1552 move $a1, $t1
1553 move $a0, $t0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001554 la $t9, artIsAssignableFromCode
1555 jalr $t9 # (Class*, Class*)
1556 addiu $sp, $sp, -16 # reserve argument slots on the stack
1557 addiu $sp, $sp, 16
Ian Rogersa9a82542013-10-04 11:17:26 -07001558 lw $ra, 28($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001559 lw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001560 lw $t9, 12($sp)
1561 lw $a2, 8($sp)
1562 lw $a1, 4($sp)
1563 lw $a0, 0($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001564 addiu $sp, 32
Ian Rogersa9a82542013-10-04 11:17:26 -07001565 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001566 bnez $v0, .Ldo_aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001567 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001568 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -07001569 move $a1, $a2
Ian Rogersa9a82542013-10-04 11:17:26 -07001570 la $t9, artThrowArrayStoreException
Andreas Gampe8d365912015-01-13 11:32:32 -08001571 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001572 move $a2, rSELF # pass Thread::Current
Ian Rogersa9a82542013-10-04 11:17:26 -07001573END art_quick_aput_obj
buzbee5bc5a7b2012-03-07 15:52:59 -08001574
Alexey Frunze0cb12422017-01-25 19:30:18 -08001575// Macros taking opportunity of code similarities for downcalls.
1576.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1577 .extern \entrypoint
1578ENTRY \name
1579 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1580 la $t9, \entrypoint
1581 jalr $t9 # (field_idx, Thread*)
1582 move $a1, rSELF # pass Thread::Current
1583 \return # RETURN_IF_NO_EXCEPTION or RETURN_IF_ZERO
1584END \name
1585.endm
1586
1587.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1588 .extern \entrypoint
1589ENTRY \name
1590 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1591 la $t9, \entrypoint
1592 jalr $t9 # (field_idx, Object*, Thread*) or
1593 # (field_idx, new_val, Thread*)
1594 move $a2, rSELF # pass Thread::Current
1595 \return # RETURN_IF_NO_EXCEPTION or RETURN_IF_ZERO
1596END \name
1597.endm
1598
1599.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1600 .extern \entrypoint
1601ENTRY \name
1602 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1603 la $t9, \entrypoint
1604 jalr $t9 # (field_idx, Object*, new_val, Thread*)
1605 move $a3, rSELF # pass Thread::Current
1606 \return # RETURN_IF_NO_EXCEPTION or RETURN_IF_ZERO
1607END \name
1608.endm
1609
1610.macro FOUR_ARG_REF_DOWNCALL name, entrypoint, return
1611 .extern \entrypoint
1612ENTRY \name
1613 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1614 la $t9, \entrypoint
1615 jalr $t9 # (field_idx, Object*, 64-bit new_val, Thread*) or
1616 # (field_idx, 64-bit new_val, Thread*)
1617 # Note that a 64-bit new_val needs to be aligned with
1618 # an even-numbered register, hence A1 may be skipped
1619 # for new_val to reside in A2-A3.
1620 sw rSELF, 16($sp) # pass Thread::Current
1621 \return # RETURN_IF_NO_EXCEPTION or RETURN_IF_ZERO
1622END \name
1623.endm
Fred Shih37f05ef2014-07-16 18:38:08 -07001624
1625 /*
Alexey Frunze0cb12422017-01-25 19:30:18 -08001626 * Called by managed code to resolve a static/instance field and load/store a value.
Fred Shih37f05ef2014-07-16 18:38:08 -07001627 */
Alexey Frunze0cb12422017-01-25 19:30:18 -08001628ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1629ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1630ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1631ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1632ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1633ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1634ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCompiledCode, RETURN_IF_NO_EXCEPTION
1635TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1636TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1637TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1638TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1639TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1640TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1641TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCompiledCode, RETURN_IF_NO_EXCEPTION
1642TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_ZERO
1643TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_ZERO
1644TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_ZERO
1645TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_ZERO
1646FOUR_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_ZERO
1647THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_ZERO
1648THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_ZERO
1649THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_ZERO
1650THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_ZERO
1651FOUR_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCompiledCode, RETURN_IF_ZERO
buzbee5bc5a7b2012-03-07 15:52:59 -08001652
Vladimir Markoa3c38272015-04-28 12:37:09 +01001653// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001654.macro ONE_ARG_DOWNCALL name, entrypoint, return
1655 .extern \entrypoint
1656ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001657 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001658 la $t9, \entrypoint
1659 jalr $t9
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001660 move $a1, rSELF # pass Thread::Current
1661 \return
1662END \name
1663.endm
1664
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001665.macro TWO_ARG_DOWNCALL name, entrypoint, return
1666 .extern \entrypoint
1667ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001668 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001669 la $t9, \entrypoint
1670 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001671 move $a2, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001672 \return
1673END \name
1674.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001675
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001676.macro THREE_ARG_DOWNCALL name, entrypoint, return
1677 .extern \entrypoint
1678ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001679 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001680 la $t9, \entrypoint
1681 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001682 move $a3, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001683 \return
1684END \name
1685.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001686
Jeff Hao848f70a2014-01-15 13:49:50 -08001687.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1688 .extern \entrypoint
1689ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001690 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001691 la $t9, \entrypoint
1692 jalr $t9
Vladimir Markoa3c38272015-04-28 12:37:09 +01001693 sw rSELF, 16($sp) # pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -08001694 \return
1695END \name
1696.endm
1697
Mathieu Chartier7410f292013-11-24 13:17:35 -08001698// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic854df412017-06-27 14:41:39 +02001699GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
1700// Comment out allocators that have mips specific asm.
1701// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1702// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1703GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1704// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
1705// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
1706// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
1707// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
1708// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
1709GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1710GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1711GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
1712
1713// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
1714// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
1715GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
1716// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
1717// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_tlab, TLAB)
1718// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_tlab, TLAB)
1719// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_tlab, TLAB)
1720// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_tlab, TLAB)
1721GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_tlab, TLAB)
1722GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_tlab, TLAB)
1723GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_tlab, TLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001724
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001725// A hand-written override for:
1726// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc, RosAlloc)
1727// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc, RosAlloc)
Goran Jakovljevic854df412017-06-27 14:41:39 +02001728.macro ART_QUICK_ALLOC_OBJECT_ROSALLOC c_name, cxx_name, isInitialized
1729ENTRY_NO_GP \c_name
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001730 # Fast path rosalloc allocation
1731 # a0: type
1732 # s1: Thread::Current
1733 # -----------------------------
1734 # t1: object size
1735 # t2: rosalloc run
1736 # t3: thread stack top offset
1737 # t4: thread stack bottom offset
1738 # v0: free list head
1739 #
1740 # t5, t6 : temps
1741 lw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation
1742 lw $t4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # stack has any room left.
1743 bgeu $t3, $t4, .Lslow_path_\c_name
Pavle Batuta712c59d2015-12-02 18:39:01 +01001744
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001745 lw $t1, MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET($a0) # Load object size (t1).
1746 li $t5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1747 # allocation. Also does the
1748 # initialized and finalizable checks.
Goran Jakovljevic854df412017-06-27 14:41:39 +02001749 # When isInitialized == 0, then the class is potentially not yet initialized.
1750 # If the class is not yet initialized, the object size will be very large to force the branch
1751 # below to be taken.
1752 #
1753 # See InitializeClassVisitors in class-inl.h for more details.
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001754 bgtu $t1, $t5, .Lslow_path_\c_name
1755
1756 # Compute the rosalloc bracket index from the size. Since the size is already aligned we can
1757 # combine the two shifts together.
1758 srl $t1, $t1, (ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1759
1760 addu $t2, $t1, $s1
1761 lw $t2, (THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)($t2) # Load rosalloc run (t2).
1762
1763 # Load the free list head (v0).
1764 # NOTE: this will be the return val.
1765 lw $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1766 beqz $v0, .Lslow_path_\c_name
1767 nop
1768
1769 # Load the next pointer of the head and update the list head with the next pointer.
1770 lw $t5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1771 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1772
1773 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1774 # asserted to match.
1775
1776#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1777#error "Class pointer needs to overwrite next pointer."
1778#endif
1779
1780 POISON_HEAP_REF $a0
1781 sw $a0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1782
1783 # Push the new object onto the thread local allocation stack and increment the thread local
1784 # allocation stack top.
1785 sw $v0, 0($t3)
1786 addiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1787 sw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1788
1789 # Decrement the size of the free list.
1790 lw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1791 addiu $t5, $t5, -1
1792 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1793
Goran Jakovljevic854df412017-06-27 14:41:39 +02001794.if \isInitialized == 0
1795 # This barrier is only necessary when the allocation also requires a class initialization check.
1796 #
1797 # If the class is already observably initialized, then new-instance allocations are protected
1798 # from publishing by the compiler which inserts its own StoreStore barrier.
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001799 sync # Fence.
Goran Jakovljevic854df412017-06-27 14:41:39 +02001800.endif
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001801 jalr $zero, $ra
1802 nop
1803
1804 .Lslow_path_\c_name:
Goran Jakovljevic854df412017-06-27 14:41:39 +02001805 addiu $t9, $t9, (.Lslow_path_\c_name - \c_name) + 4
1806 .cpload $t9
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001807 SETUP_SAVE_REFS_ONLY_FRAME
1808 la $t9, \cxx_name
1809 jalr $t9
1810 move $a1, $s1 # Pass self as argument.
1811 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1812END \c_name
1813.endm
1814
Goran Jakovljevic854df412017-06-27 14:41:39 +02001815ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_resolved_rosalloc, artAllocObjectFromCodeResolvedRosAlloc, /* isInitialized */ 0
1816ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_initialized_rosalloc, artAllocObjectFromCodeInitializedRosAlloc, /* isInitialized */ 1
Goran Jakovljevic2449e5c2017-01-19 11:39:18 +01001817
Goran Jakovljevic854df412017-06-27 14:41:39 +02001818// The common fast path code for art_quick_alloc_object_resolved/initialized_tlab
1819// and art_quick_alloc_object_resolved/initialized_region_tlab.
1820//
1821// a0: type, s1(rSELF): Thread::Current.
1822// Need to preserve a0 to the slow path.
1823//
1824// If isInitialized=1 then the compiler assumes the object's class has already been initialized.
1825// If isInitialized=0 the compiler can only assume it's been at least resolved.
1826.macro ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH slowPathLabel isInitialized
1827 lw $v0, THREAD_LOCAL_POS_OFFSET(rSELF) # Load thread_local_pos.
1828 lw $a2, THREAD_LOCAL_END_OFFSET(rSELF) # Load thread_local_end.
1829 subu $a3, $a2, $v0 # Compute the remaining buffer size.
1830 lw $t0, MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET($a0) # Load the object size.
1831
1832 # When isInitialized == 0, then the class is potentially not yet initialized.
1833 # If the class is not yet initialized, the object size will be very large to force the branch
1834 # below to be taken.
1835 #
1836 # See InitializeClassVisitors in class-inl.h for more details.
1837 bgtu $t0, $a3, \slowPathLabel # Check if it fits.
1838 addu $t1, $v0, $t0 # Add object size to tlab pos (in branch
1839 # delay slot).
1840 # "Point of no slow path". Won't go to the slow path from here on.
1841 sw $t1, THREAD_LOCAL_POS_OFFSET(rSELF) # Store new thread_local_pos.
1842 lw $a2, THREAD_LOCAL_OBJECTS_OFFSET(rSELF) # Increment thread_local_objects.
1843 addiu $a2, $a2, 1
1844 sw $a2, THREAD_LOCAL_OBJECTS_OFFSET(rSELF)
1845 POISON_HEAP_REF $a0
1846 sw $a0, MIRROR_OBJECT_CLASS_OFFSET($v0) # Store the class pointer.
1847
1848.if \isInitialized == 0
1849 # This barrier is only necessary when the allocation also requires a class initialization check.
1850 #
1851 # If the class is already observably initialized, then new-instance allocations are protected
1852 # from publishing by the compiler which inserts its own StoreStore barrier.
1853 sync # Fence.
1854.endif
1855 jalr $zero, $ra
1856 nop
1857.endm
1858
1859// The common code for art_quick_alloc_object_resolved/initialized_tlab
1860// and art_quick_alloc_object_resolved/initialized_region_tlab.
1861.macro GENERATE_ALLOC_OBJECT_TLAB name, entrypoint, isInitialized
1862ENTRY_NO_GP \name
1863 # Fast path tlab allocation.
1864 # a0: type, s1(rSELF): Thread::Current.
1865 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lslow_path_\name, \isInitialized
1866.Lslow_path_\name:
1867 addiu $t9, $t9, (.Lslow_path_\name - \name) + 4
1868 .cpload $t9
1869 SETUP_SAVE_REFS_ONLY_FRAME # Save callee saves in case of GC.
1870 la $t9, \entrypoint
1871 jalr $t9 # (mirror::Class*, Thread*)
1872 move $a1, rSELF # Pass Thread::Current.
1873 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1874END \name
1875.endm
1876
1877GENERATE_ALLOC_OBJECT_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, /* isInitialized */ 0
1878GENERATE_ALLOC_OBJECT_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, /* isInitialized */ 1
1879GENERATE_ALLOC_OBJECT_TLAB art_quick_alloc_object_resolved_tlab, artAllocObjectFromCodeResolvedTLAB, /* isInitialized */ 0
1880GENERATE_ALLOC_OBJECT_TLAB art_quick_alloc_object_initialized_tlab, artAllocObjectFromCodeInitializedTLAB, /* isInitialized */ 1
1881
1882// The common fast path code for art_quick_alloc_array_resolved/initialized_tlab
1883// and art_quick_alloc_array_resolved/initialized_region_tlab.
1884//
1885// a0: type, a1: component_count, a2: total_size, s1(rSELF): Thread::Current.
1886// Need to preserve a0 and a1 to the slow path.
1887.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE slowPathLabel
1888 li $a3, OBJECT_ALIGNMENT_MASK_TOGGLED # Apply alignemnt mask
1889 and $a2, $a2, $a3 # (addr + 7) & ~7.
1890
1891 lw $v0, THREAD_LOCAL_POS_OFFSET(rSELF) # Load thread_local_pos.
1892 lw $t1, THREAD_LOCAL_END_OFFSET(rSELF) # Load thread_local_end.
1893 subu $t2, $t1, $v0 # Compute the remaining buffer size.
1894 bgtu $a2, $t2, \slowPathLabel # Check if it fits.
1895 addu $a2, $v0, $a2 # Add object size to tlab pos (in branch
1896 # delay slot).
1897
1898 # "Point of no slow path". Won't go to the slow path from here on.
1899 sw $a2, THREAD_LOCAL_POS_OFFSET(rSELF) # Store new thread_local_pos.
1900 lw $a2, THREAD_LOCAL_OBJECTS_OFFSET(rSELF) # Increment thread_local_objects.
1901 addiu $a2, $a2, 1
1902 sw $a2, THREAD_LOCAL_OBJECTS_OFFSET(rSELF)
1903 POISON_HEAP_REF $a0
1904 sw $a0, MIRROR_OBJECT_CLASS_OFFSET($v0) # Store the class pointer.
1905 jalr $zero, $ra
1906 sw $a1, MIRROR_ARRAY_LENGTH_OFFSET($v0) # Store the array length.
1907.endm
1908
1909.macro GENERATE_ALLOC_ARRAY_TLAB name, entrypoint, size_setup
1910ENTRY_NO_GP \name
1911 # Fast path array allocation for region tlab allocation.
1912 # a0: mirror::Class* type
1913 # a1: int32_t component_count
1914 # s1(rSELF): Thread::Current
1915 \size_setup .Lslow_path_\name
1916 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE .Lslow_path_\name
1917.Lslow_path_\name:
1918 # a0: mirror::Class* type
1919 # a1: int32_t component_count
1920 # a2: Thread* self
1921 addiu $t9, $t9, (.Lslow_path_\name - \name) + 4
1922 .cpload $t9
1923 SETUP_SAVE_REFS_ONLY_FRAME # Save callee saves in case of GC.
1924 la $t9, \entrypoint
1925 jalr $t9
1926 move $a2, rSELF # Pass Thread::Current.
1927 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1928END \name
1929.endm
1930
1931.macro COMPUTE_ARRAY_SIZE_UNKNOWN slow_path
1932 break # We should never enter here.
1933 # Code below is for reference.
1934 # Possibly a large object, go slow.
1935 # Also does negative array size check.
1936 li $a2, ((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_WIDE_ARRAY_DATA_OFFSET) / 8)
1937 bgtu $a1, $a2, \slow_path
1938 # Array classes are never finalizable
1939 # or uninitialized, no need to check.
1940 lw $a3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET($a0) # Load component type.
1941 UNPOISON_HEAP_REF $a3
1942 lw $a3, MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET($a3)
1943 srl $a3, $a3, PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT # Component size shift is in high 16 bits.
1944 sllv $a2, $a1, $a3 # Calculate data size.
1945 # Add array data offset and alignment.
1946 addiu $a2, $a2, (MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1947#if MIRROR_WIDE_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1948#error Long array data offset must be 4 greater than int array data offset.
1949#endif
1950
1951 addiu $a3, $a3, 1 # Add 4 to the length only if the component
1952 andi $a3, $a3, 4 # size shift is 3 (for 64 bit alignment).
1953 addu $a2, $a2, $a3
1954.endm
1955
1956.macro COMPUTE_ARRAY_SIZE_8 slow_path
1957 # Possibly a large object, go slow.
1958 # Also does negative array size check.
1959 li $a2, (MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET)
1960 bgtu $a1, $a2, \slow_path
1961 # Add array data offset and alignment (in branch delay slot).
1962 addiu $a2, $a1, (MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1963.endm
1964
1965.macro COMPUTE_ARRAY_SIZE_16 slow_path
1966 # Possibly a large object, go slow.
1967 # Also does negative array size check.
1968 li $a2, ((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 2)
1969 bgtu $a1, $a2, \slow_path
1970 sll $a2, $a1, 1
1971 # Add array data offset and alignment.
1972 addiu $a2, $a2, (MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1973.endm
1974
1975.macro COMPUTE_ARRAY_SIZE_32 slow_path
1976 # Possibly a large object, go slow.
1977 # Also does negative array size check.
1978 li $a2, ((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 4)
1979 bgtu $a1, $a2, \slow_path
1980 sll $a2, $a1, 2
1981 # Add array data offset and alignment.
1982 addiu $a2, $a2, (MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1983.endm
1984
1985.macro COMPUTE_ARRAY_SIZE_64 slow_path
1986 # Possibly a large object, go slow.
1987 # Also does negative array size check.
1988 li $a2, ((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_LONG_ARRAY_DATA_OFFSET) / 8)
1989 bgtu $a1, $a2, \slow_path
1990 sll $a2, $a1, 3
1991 # Add array data offset and alignment.
1992 addiu $a2, $a2, (MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1993.endm
1994
1995GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1996GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_8
1997GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_16
1998GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_32
1999GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_64
2000
2001GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
2002GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_8
2003GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_16
2004GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_32
2005GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_64
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08002006
Alexey Frunzec61c0762017-04-10 13:54:23 -07002007// Macro for string and type resolution and initialization.
2008// $a0 is both input and output.
Alexey Frunze19428ad2017-08-03 10:36:46 -07002009.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL name, entrypoint, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET
Alexey Frunzec61c0762017-04-10 13:54:23 -07002010 .extern \entrypoint
2011ENTRY_NO_GP \name
Alexey Frunze19428ad2017-08-03 10:36:46 -07002012 SETUP_SAVE_EVERYTHING_FRAME \runtime_method_offset # Save everything in case of GC.
Alexey Frunzec61c0762017-04-10 13:54:23 -07002013 move $s2, $gp # Preserve $gp across the call for exception delivery.
2014 la $t9, \entrypoint
2015 jalr $t9 # (uint32_t index, Thread*)
2016 move $a1, rSELF # Pass Thread::Current (in delay slot).
2017 beqz $v0, 1f # Success?
2018 move $a0, $v0 # Move result to $a0 (in delay slot).
2019 RESTORE_SAVE_EVERYTHING_FRAME 0 # Restore everything except $a0.
2020 jalr $zero, $ra # Return on success.
2021 nop
20221:
2023 move $gp, $s2
2024 DELIVER_PENDING_EXCEPTION_FRAME_READY
2025END \name
2026.endm
2027
Alexey Frunze19428ad2017-08-03 10:36:46 -07002028.macro ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT name, entrypoint
2029 ONE_ARG_SAVE_EVERYTHING_DOWNCALL \name, \entrypoint, RUNTIME_SAVE_EVERYTHING_FOR_CLINIT_METHOD_OFFSET
2030.endm
2031
buzbee5bc5a7b2012-03-07 15:52:59 -08002032 /*
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002033 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01002034 * exception on error. On success the String is returned. A0 holds the string index. The fast
2035 * path check for hit in strings cache has already been performed.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002036 */
Alexey Frunzec61c0762017-04-10 13:54:23 -07002037ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_string, artResolveStringFromCode
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002038
2039 /*
2040 * Entry from managed code when uninitialized static storage, this stub will run the class
2041 * initializer and deliver the exception on error. On success the static storage base is
2042 * returned.
2043 */
Alexey Frunze19428ad2017-08-03 10:36:46 -07002044ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_static_storage, artInitializeStaticStorageFromCode
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002045
2046 /*
2047 * Entry from managed code when dex cache misses for a type_idx.
2048 */
Alexey Frunze19428ad2017-08-03 10:36:46 -07002049ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_type, artInitializeTypeFromCode
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002050
2051 /*
2052 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
2053 * miss.
2054 */
Alexey Frunzec61c0762017-04-10 13:54:23 -07002055ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002056
2057 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07002058 * Called by managed code when the value in rSUSPEND has been decremented to 0.
buzbee5bc5a7b2012-03-07 15:52:59 -08002059 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002060 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01002061ENTRY_NO_GP art_quick_test_suspend
Alexey Frunze19428ad2017-08-03 10:36:46 -07002062 SETUP_SAVE_EVERYTHING_FRAME RUNTIME_SAVE_EVERYTHING_FOR_SUSPEND_CHECK_METHOD_OFFSET
2063 # save everything for stack crawl
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002064 la $t9, artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01002065 jalr $t9 # (Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07002066 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002067 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01002068 jalr $zero, $ra
2069 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002070END art_quick_test_suspend
buzbee5bc5a7b2012-03-07 15:52:59 -08002071
buzbee5bc5a7b2012-03-07 15:52:59 -08002072 /*
2073 * Called by managed code that is attempting to call a method on a proxy class. On entry
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002074 * a0 holds the proxy method; a1, a2 and a3 may contain arguments.
buzbee5bc5a7b2012-03-07 15:52:59 -08002075 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07002076 .extern artQuickProxyInvokeHandler
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002077ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002078 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07002079 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002080 la $t9, artQuickProxyInvokeHandler
2081 jalr $t9 # (Method* proxy method, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002082 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002083 lw $t7, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002084 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002085 bnez $t7, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002086 # don't care if $v0 and/or $v1 are modified, when exception branch taken
2087 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002088 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002089 nop
buzbee5bc5a7b2012-03-07 15:52:59 -080020901:
2091 DELIVER_PENDING_EXCEPTION
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002092END art_quick_proxy_invoke_handler
buzbee5bc5a7b2012-03-07 15:52:59 -08002093
Jeff Hao88474b42013-10-23 16:24:40 -07002094 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002095 * Called to resolve an imt conflict.
2096 * a0 is the conflict ArtMethod.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002097 * t7 is a hidden argument that holds the target interface method's dex method index.
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002098 *
Alexey Frunze279cfba2017-07-22 00:24:43 -07002099 * Note that this stub writes to v0-v1, a0, t2-t9, f0-f7.
Jeff Hao88474b42013-10-23 16:24:40 -07002100 */
Alexey Frunze279cfba2017-07-22 00:24:43 -07002101 .extern artLookupResolvedMethod
2102 .extern __atomic_load_8 # For int64_t std::atomic::load(std::memory_order).
Douglas Leung13738bf2014-10-27 14:44:47 -07002103ENTRY art_quick_imt_conflict_trampoline
Alexey Frunze279cfba2017-07-22 00:24:43 -07002104 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY /* save_s4_thru_s8 */ 0
2105
2106 lw $t8, FRAME_SIZE_SAVE_REFS_AND_ARGS($sp) # $t8 = referrer.
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002107 // If the method is obsolete, just go through the dex cache miss slow path.
2108 // The obsolete flag is set with suspended threads, so we do not need an acquire operation here.
2109 lw $t9, ART_METHOD_ACCESS_FLAGS_OFFSET($t8) # $t9 = access flags.
2110 sll $t9, $t9, 31 - ACC_OBSOLETE_METHOD_SHIFT # Move obsolete method bit to sign bit.
2111 bltz $t9, .Limt_conflict_trampoline_dex_cache_miss
2112 lw $t8, ART_METHOD_DECLARING_CLASS_OFFSET($t8) # $t8 = declaring class (no read barrier).
2113 lw $t8, MIRROR_CLASS_DEX_CACHE_OFFSET($t8) # $t8 = dex cache (without read barrier).
2114 UNPOISON_HEAP_REF $t8
Alexey Frunze279cfba2017-07-22 00:24:43 -07002115 la $t9, __atomic_load_8
2116 addiu $sp, $sp, -ARG_SLOT_SIZE # Reserve argument slots on the stack.
2117 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
Vladimir Marko5122e6b2017-08-17 16:10:09 +01002118 lw $t8, MIRROR_DEX_CACHE_RESOLVED_METHODS_OFFSET($t8) # $t8 = dex cache methods array.
Alexey Frunze279cfba2017-07-22 00:24:43 -07002119
2120 move $s2, $t7 # $s2 = method index (callee-saved).
2121 lw $s3, ART_METHOD_JNI_OFFSET_32($a0) # $s3 = ImtConflictTable (callee-saved).
2122
2123 sll $t7, $t7, 32 - METHOD_DEX_CACHE_HASH_BITS # $t7 = slot index in top bits, zeroes below.
2124 srl $t7, $t7, 32 - METHOD_DEX_CACHE_HASH_BITS - (POINTER_SIZE_SHIFT + 1)
2125 # $t7 = slot offset.
2126
2127 li $a1, STD_MEMORY_ORDER_RELAXED # $a1 = std::memory_order_relaxed.
2128 jalr $t9 # [$v0, $v1] = __atomic_load_8($a0, $a1).
2129 addu $a0, $t8, $t7 # $a0 = DexCache method slot address.
2130
2131 bne $v1, $s2, .Limt_conflict_trampoline_dex_cache_miss # Branch if method index miss.
2132 addiu $sp, $sp, ARG_SLOT_SIZE # Remove argument slots from the stack.
2133 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002134
2135.Limt_table_iterate:
Alexey Frunze279cfba2017-07-22 00:24:43 -07002136 lw $t8, 0($s3) # Load next entry in ImtConflictTable.
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002137 # Branch if found.
Alexey Frunze279cfba2017-07-22 00:24:43 -07002138 beq $t8, $v0, .Limt_table_found
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002139 nop
2140 # If the entry is null, the interface method is not in the ImtConflictTable.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002141 beqz $t8, .Lconflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002142 nop
2143 # Iterate over the entries of the ImtConflictTable.
2144 b .Limt_table_iterate
Alexey Frunze279cfba2017-07-22 00:24:43 -07002145 addiu $s3, $s3, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002146
2147.Limt_table_found:
2148 # We successfully hit an entry in the table. Load the target method and jump to it.
Alexey Frunze279cfba2017-07-22 00:24:43 -07002149 .cfi_remember_state
2150 lw $a0, __SIZEOF_POINTER__($s3)
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002151 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)
Alexey Frunze279cfba2017-07-22 00:24:43 -07002152 RESTORE_SAVE_REFS_AND_ARGS_FRAME /* restore_s4_thru_s8 */ 0, /* remove_arg_slots */ 0
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002153 jalr $zero, $t9
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002154 nop
Alexey Frunze279cfba2017-07-22 00:24:43 -07002155 .cfi_restore_state
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002156
2157.Lconflict_trampoline:
2158 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Alexey Frunze279cfba2017-07-22 00:24:43 -07002159 .cfi_remember_state
2160 RESTORE_SAVE_REFS_AND_ARGS_FRAME_GP # Restore clobbered $gp.
2161 RESTORE_SAVE_REFS_AND_ARGS_FRAME_A1 # Restore this.
2162 move $a0, $v0 # Load interface method.
2163 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline, /* save_s4_thru_s8_only */ 1
2164 .cfi_restore_state
2165
2166.Limt_conflict_trampoline_dex_cache_miss:
2167 # We're not creating a proper runtime method frame here,
2168 # artLookupResolvedMethod() is not allowed to walk the stack.
2169 RESTORE_SAVE_REFS_AND_ARGS_FRAME_GP # Restore clobbered $gp.
2170 lw $a1, FRAME_SIZE_SAVE_REFS_AND_ARGS($sp) # $a1 = referrer.
2171 la $t9, artLookupResolvedMethod
2172 addiu $sp, $sp, -ARG_SLOT_SIZE # Reserve argument slots on the stack.
2173 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
2174 jalr $t9 # (uint32_t method_index, ArtMethod* referrer).
2175 move $a0, $s2 # $a0 = method index.
2176
2177 # If the method wasn't resolved, skip the lookup and go to artInvokeInterfaceTrampoline().
2178 beqz $v0, .Lconflict_trampoline
2179 addiu $sp, $sp, ARG_SLOT_SIZE # Remove argument slots from the stack.
2180 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
2181
2182 b .Limt_table_iterate
2183 nop
Jeff Hao88474b42013-10-23 16:24:40 -07002184END art_quick_imt_conflict_trampoline
2185
Ian Rogers468532e2013-08-05 10:56:33 -07002186 .extern artQuickResolutionTrampoline
2187ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002188 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002189 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002190 la $t9, artQuickResolutionTrampoline
2191 jalr $t9 # (Method* called, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002192 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers468532e2013-08-05 10:56:33 -07002193 beqz $v0, 1f
Douglas Leung735b8552014-10-31 12:21:40 -07002194 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002195 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers65d1b222013-09-27 10:59:41 -07002196 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002197 jalr $zero, $t9 # tail call to method
Mathieu Chartier19841522013-10-22 11:29:00 -07002198 nop
Ian Rogers468532e2013-08-05 10:56:33 -070021991:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002200 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07002201 DELIVER_PENDING_EXCEPTION
2202END art_quick_resolution_trampoline
2203
Douglas Leung735b8552014-10-31 12:21:40 -07002204 .extern artQuickGenericJniTrampoline
2205 .extern artQuickGenericJniEndTrampoline
2206ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002207 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07002208 move $s8, $sp # save $sp to $s8
2209 move $s3, $gp # save $gp to $s3
2210
2211 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
2212 move $a0, rSELF # pass Thread::Current
2213 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002214 la $t9, artQuickGenericJniTrampoline
2215 jalr $t9 # (Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002216 addiu $sp, $sp, -5120 # reserve space on the stack
2217
2218 # The C call will have registered the complete save-frame on success.
2219 # The result of the call is:
2220 # v0: ptr to native code, 0 on error.
2221 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002222 beq $v0, $zero, 2f # check entry error
Douglas Leung735b8552014-10-31 12:21:40 -07002223 move $t9, $v0 # save the code ptr
2224 move $sp, $v1 # release part of the alloca
2225
2226 # Load parameters from stack into registers
2227 lw $a0, 0($sp)
2228 lw $a1, 4($sp)
2229 lw $a2, 8($sp)
Douglas Leung735b8552014-10-31 12:21:40 -07002230 lw $a3, 12($sp)
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002231
2232 # artQuickGenericJniTrampoline sets bit 0 of the native code address to 1
2233 # when the first two arguments are both single precision floats. This lets
2234 # us extract them properly from the stack and load into floating point
2235 # registers.
2236 MTD $a0, $a1, $f12, $f13
2237 andi $t0, $t9, 1
2238 xor $t9, $t9, $t0
2239 bnez $t0, 1f
2240 mtc1 $a1, $f14
2241 MTD $a2, $a3, $f14, $f15
2242
22431:
2244 jalr $t9 # native call
2245 nop
Douglas Leung735b8552014-10-31 12:21:40 -07002246 addiu $sp, $sp, 16 # remove arg slots
2247
2248 move $gp, $s3 # restore $gp from $s3
2249
2250 # result sign extension is handled in C code
2251 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
2252 move $a0, rSELF # pass Thread::Current
2253 move $a2, $v0 # pass result
2254 move $a3, $v1
2255 addiu $sp, $sp, -24 # reserve arg slots
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002256 la $t9, artQuickGenericJniEndTrampoline
2257 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07002258 s.d $f0, 16($sp) # pass result_f
Douglas Leung735b8552014-10-31 12:21:40 -07002259
2260 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002261 bne $t0, $zero, 2f # check for pending exceptions
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002262
Douglas Leung735b8552014-10-31 12:21:40 -07002263 move $sp, $s8 # tear down the alloca
2264
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002265 # tear down the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002266 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002267
Duane Sande34652f2014-11-04 11:09:36 -08002268 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002269 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002270 nop
Douglas Leung735b8552014-10-31 12:21:40 -07002271
Alexey Frunze1b8464d2016-11-12 17:22:05 -080022722:
Alexey Frunzec61c0762017-04-10 13:54:23 -07002273 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2274 move $gp, $s3 # restore $gp from $s3
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002275 # This will create a new save-all frame, required by the runtime.
Douglas Leung735b8552014-10-31 12:21:40 -07002276 DELIVER_PENDING_EXCEPTION
2277END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08002278
Ian Rogers468532e2013-08-05 10:56:33 -07002279 .extern artQuickToInterpreterBridge
2280ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002281 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002282 move $a1, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002283 la $t9, artQuickToInterpreterBridge
2284 jalr $t9 # (Method* method, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002285 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002286 lw $t7, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002287 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Alexey Frunze1b8464d2016-11-12 17:22:05 -08002288 bnez $t7, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002289 # don't care if $v0 and/or $v1 are modified, when exception branch taken
2290 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002291 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002292 nop
Ian Rogers7db619b2013-01-16 18:35:48 -080022931:
2294 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07002295END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08002296
Alex Lightdb01a092017-04-03 15:39:55 -07002297 .extern artInvokeObsoleteMethod
2298ENTRY art_invoke_obsolete_method_stub
2299 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
2300 la $t9, artInvokeObsoleteMethod
2301 jalr $t9 # (Method* method, Thread* self)
2302 move $a1, rSELF # pass Thread::Current
2303END art_invoke_obsolete_method_stub
2304
buzbee5bc5a7b2012-03-07 15:52:59 -08002305 /*
jeffhao725a9572012-11-13 18:20:12 -08002306 * Routine that intercepts method calls and returns.
buzbee5bc5a7b2012-03-07 15:52:59 -08002307 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002308 .extern artInstrumentationMethodEntryFromCode
2309 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07002310ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002311 SETUP_SAVE_REFS_AND_ARGS_FRAME
Alexey Frunze60454cb2017-08-09 21:28:30 -07002312 sw $a0, 28($sp) # save arg0 in free arg slot
2313 addiu $a3, $sp, ARG_SLOT_SIZE # Pass $sp.
2314 la $t9, artInstrumentationMethodEntryFromCode
2315 jalr $t9 # (Method*, Object*, Thread*, SP)
2316 move $a2, rSELF # pass Thread::Current
2317 beqz $v0, .Ldeliver_instrumentation_entry_exception
2318 move $t9, $v0 # $t9 holds reference to code
2319 lw $a0, 28($sp) # restore arg0 from free arg slot
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002320 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Alexey Frunze60454cb2017-08-09 21:28:30 -07002321 la $ra, art_quick_instrumentation_exit
2322 jalr $zero, $t9 # call method, returning to art_quick_instrumentation_exit
Goran Jakovljevic25e4d1e2017-06-14 13:47:44 +02002323 nop
2324.Ldeliver_instrumentation_entry_exception:
Goran Jakovljevic25e4d1e2017-06-14 13:47:44 +02002325 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Goran Jakovljevic25e4d1e2017-06-14 13:47:44 +02002326 DELIVER_PENDING_EXCEPTION
Alexey Frunze60454cb2017-08-09 21:28:30 -07002327END art_quick_instrumentation_entry
2328
2329ENTRY_NO_GP art_quick_instrumentation_exit
2330 move $ra, $zero # RA points here, so clobber with 0 for later checks.
2331 SETUP_SAVE_EVERYTHING_FRAME # Allocates ARG_SLOT_SIZE bytes at the bottom of the stack.
2332 move $s2, $gp # Preserve $gp across the call for exception delivery.
2333
2334 addiu $a3, $sp, ARG_SLOT_SIZE+16 # Pass fpr_res pointer ($f0 in SAVE_EVERYTHING_FRAME).
2335 addiu $a2, $sp, ARG_SLOT_SIZE+148 # Pass gpr_res pointer ($v0 in SAVE_EVERYTHING_FRAME).
2336 addiu $a1, $sp, ARG_SLOT_SIZE # Pass $sp.
2337 la $t9, artInstrumentationMethodExitFromCode
2338 jalr $t9 # (Thread*, SP, gpr_res*, fpr_res*)
2339 move $a0, rSELF # Pass Thread::Current.
2340
2341 beqz $v0, .Ldo_deliver_instrumentation_exception
2342 move $gp, $s2 # Deliver exception if we got nullptr as function.
2343 bnez $v1, .Ldeoptimize
2344
2345 # Normal return.
2346 sw $v0, (ARG_SLOT_SIZE+FRAME_SIZE_SAVE_EVERYTHING-4)($sp) # Set return pc.
2347 RESTORE_SAVE_EVERYTHING_FRAME
2348 jalr $zero, $ra
2349 nop
2350.Ldo_deliver_instrumentation_exception:
2351 DELIVER_PENDING_EXCEPTION_FRAME_READY
2352.Ldeoptimize:
2353 b art_quick_deoptimize
2354 sw $v1, (ARG_SLOT_SIZE+FRAME_SIZE_SAVE_EVERYTHING-4)($sp)
2355 # Fake a call from instrumentation return pc.
Ian Rogers468532e2013-08-05 10:56:33 -07002356END art_quick_instrumentation_exit
buzbee5bc5a7b2012-03-07 15:52:59 -08002357
jeffhao12051ea2013-01-10 11:24:31 -08002358 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08002359 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2360 * will long jump to the upcall with a special exception of -1.
jeffhao12051ea2013-01-10 11:24:31 -08002361 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002362 .extern artDeoptimize
Alexey Frunze60454cb2017-08-09 21:28:30 -07002363ENTRY_NO_GP_CUSTOM_CFA art_quick_deoptimize, ARG_SLOT_SIZE+FRAME_SIZE_SAVE_EVERYTHING
2364 # SETUP_SAVE_EVERYTHING_FRAME has been done by art_quick_instrumentation_exit.
2365 .cfi_rel_offset 31, ARG_SLOT_SIZE+252
2366 .cfi_rel_offset 30, ARG_SLOT_SIZE+248
2367 .cfi_rel_offset 28, ARG_SLOT_SIZE+244
2368 .cfi_rel_offset 25, ARG_SLOT_SIZE+240
2369 .cfi_rel_offset 24, ARG_SLOT_SIZE+236
2370 .cfi_rel_offset 23, ARG_SLOT_SIZE+232
2371 .cfi_rel_offset 22, ARG_SLOT_SIZE+228
2372 .cfi_rel_offset 21, ARG_SLOT_SIZE+224
2373 .cfi_rel_offset 20, ARG_SLOT_SIZE+220
2374 .cfi_rel_offset 19, ARG_SLOT_SIZE+216
2375 .cfi_rel_offset 18, ARG_SLOT_SIZE+212
2376 .cfi_rel_offset 17, ARG_SLOT_SIZE+208
2377 .cfi_rel_offset 16, ARG_SLOT_SIZE+204
2378 .cfi_rel_offset 15, ARG_SLOT_SIZE+200
2379 .cfi_rel_offset 14, ARG_SLOT_SIZE+196
2380 .cfi_rel_offset 13, ARG_SLOT_SIZE+192
2381 .cfi_rel_offset 12, ARG_SLOT_SIZE+188
2382 .cfi_rel_offset 11, ARG_SLOT_SIZE+184
2383 .cfi_rel_offset 10, ARG_SLOT_SIZE+180
2384 .cfi_rel_offset 9, ARG_SLOT_SIZE+176
2385 .cfi_rel_offset 8, ARG_SLOT_SIZE+172
2386 .cfi_rel_offset 7, ARG_SLOT_SIZE+168
2387 .cfi_rel_offset 6, ARG_SLOT_SIZE+164
2388 .cfi_rel_offset 5, ARG_SLOT_SIZE+160
2389 .cfi_rel_offset 4, ARG_SLOT_SIZE+156
2390 .cfi_rel_offset 3, ARG_SLOT_SIZE+152
2391 .cfi_rel_offset 2, ARG_SLOT_SIZE+148
2392 .cfi_rel_offset 1, ARG_SLOT_SIZE+144
2393
2394 la $t9, artDeoptimize
2395 jalr $t9 # (Thread*)
2396 move $a0, rSELF # pass Thread::current
2397 break
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002398END art_quick_deoptimize
jeffhao12051ea2013-01-10 11:24:31 -08002399
buzbee5bc5a7b2012-03-07 15:52:59 -08002400 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00002401 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2402 * will long jump to the upcall with a special exception of -1.
2403 */
2404 .extern artDeoptimizeFromCompiledCode
Alexey Frunze60454cb2017-08-09 21:28:30 -07002405ENTRY_NO_GP art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002406 SETUP_SAVE_EVERYTHING_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002407 la $t9, artDeoptimizeFromCompiledCode
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002408 jalr $t9 # (DeoptimizationKind, Thread*)
2409 move $a1, rSELF # pass Thread::current
Sebastien Hertz07474662015-08-25 15:12:33 +00002410END art_quick_deoptimize_from_compiled_code
2411
2412 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08002413 * Long integer shift. This is different from the generic 32/64-bit
2414 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2415 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2416 * 6 bits.
2417 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002418 * $a0: low word
2419 * $a1: high word
2420 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002421 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002422ENTRY_NO_GP art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002423 /* shl-long vAA, vBB, vCC */
jeffhao7fbee072012-08-24 17:56:54 -07002424 sll $v0, $a0, $a2 # rlo<- alo << (shift&31)
2425 not $v1, $a2 # rhi<- 31-shift (shift is 5b)
2426 srl $a0, 1
2427 srl $a0, $v1 # alo<- alo >> (32-(shift&31))
2428 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002429 andi $a2, 0x20 # shift< shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002430 beqz $a2, 1f
2431 or $v1, $a0 # rhi<- rhi | alo
2432
2433 move $v1, $v0 # rhi<- rlo (if shift&0x20)
2434 move $v0, $zero # rlo<- 0 (if shift&0x20)
2435
Andreas Gampe8d365912015-01-13 11:32:32 -080024361: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002437 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002438END art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002439
buzbee5bc5a7b2012-03-07 15:52:59 -08002440 /*
2441 * Long integer shift. This is different from the generic 32/64-bit
2442 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2443 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2444 * 6 bits.
2445 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002446 * $a0: low word
2447 * $a1: high word
2448 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002449 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002450ENTRY_NO_GP art_quick_shr_long
jeffhao7fbee072012-08-24 17:56:54 -07002451 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
2452 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
2453 sra $a3, $a1, 31 # $a3<- sign(ah)
2454 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2455 sll $a1, 1
2456 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002457 andi $a2, 0x20 # shift & 0x20
Douglas Leung475cfd82014-12-16 20:15:41 -08002458 beqz $a2, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002459 or $v0, $a1 # rlo<- rlo | ahi
2460
2461 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2462 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20)
2463
Andreas Gampe8d365912015-01-13 11:32:32 -080024641: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002465 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002466END art_quick_shr_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002467
buzbee5bc5a7b2012-03-07 15:52:59 -08002468 /*
2469 * Long integer shift. This is different from the generic 32/64-bit
2470 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2471 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2472 * 6 bits.
2473 * On entry:
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002474 * $a0: low word
2475 * $a1: high word
2476 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002477 */
2478 /* ushr-long vAA, vBB, vCC */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002479ENTRY_NO_GP art_quick_ushr_long
jeffhaofc6a30e2012-10-18 18:24:15 -07002480 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002481 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002482 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2483 sll $a1, 1
2484 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002485 andi $a2, 0x20 # shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002486 beqz $a2, 1f
2487 or $v0, $a1 # rlo<- rlo | ahi
2488
2489 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2490 move $v1, $zero # rhi<- 0 (if shift&0x20)
2491
Andreas Gampe8d365912015-01-13 11:32:32 -080024921: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002493 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002494END art_quick_ushr_long
jeffhao7fbee072012-08-24 17:56:54 -07002495
Chris Larsencf283da2016-01-19 16:45:35 -08002496/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2497ENTRY_NO_GP art_quick_indexof
2498/* $a0 holds address of "this" */
2499/* $a1 holds "ch" */
2500/* $a2 holds "fromIndex" */
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002501#if (STRING_COMPRESSION_FEATURE)
2502 lw $a3, MIRROR_STRING_COUNT_OFFSET($a0) # 'count' field of this
Chris Larsencf283da2016-01-19 16:45:35 -08002503#else
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002504 lw $t0, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002505#endif
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002506 slt $t1, $a2, $zero # if fromIndex < 0
Goran Jakovljeviccdb23d62017-02-28 14:58:01 +01002507#if defined(_MIPS_ARCH_MIPS32R6)
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002508 seleqz $a2, $a2, $t1 # fromIndex = 0;
2509#else
2510 movn $a2, $zero, $t1 # fromIndex = 0;
2511#endif
Goran Jakovljeviccdb23d62017-02-28 14:58:01 +01002512
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002513#if (STRING_COMPRESSION_FEATURE)
2514 srl $t0, $a3, 1 # $a3 holds count (with flag) and $t0 holds actual length
2515#endif
2516 subu $t0, $t0, $a2 # this.length() - fromIndex
2517 blez $t0, 6f # if this.length()-fromIndex <= 0
2518 li $v0, -1 # return -1;
Chris Larsencf283da2016-01-19 16:45:35 -08002519
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002520#if (STRING_COMPRESSION_FEATURE)
2521 sll $a3, $a3, 31 # Extract compression flag.
2522 beqz $a3, .Lstring_indexof_compressed
2523 move $t2, $a0 # Save a copy in $t2 to later compute result (in branch delay slot).
2524#endif
2525 sll $v0, $a2, 1 # $a0 += $a2 * 2
2526 addu $a0, $a0, $v0 # " ditto "
2527 move $v0, $a2 # Set i to fromIndex.
Chris Larsencf283da2016-01-19 16:45:35 -08002528
25291:
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002530 lhu $t3, MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2531 beq $t3, $a1, 6f # return i;
2532 addu $a0, $a0, 2 # i++
2533 subu $t0, $t0, 1 # this.length() - i
2534 bnez $t0, 1b # while this.length() - i > 0
2535 addu $v0, $v0, 1 # i++
Chris Larsencf283da2016-01-19 16:45:35 -08002536
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002537 li $v0, -1 # if this.length() - i <= 0
2538 # return -1;
Chris Larsencf283da2016-01-19 16:45:35 -08002539
25406:
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002541 j $ra
2542 nop
2543
2544#if (STRING_COMPRESSION_FEATURE)
2545.Lstring_indexof_compressed:
2546 addu $a0, $a0, $a2 # $a0 += $a2
2547
2548.Lstring_indexof_compressed_loop:
2549 lbu $t3, MIRROR_STRING_VALUE_OFFSET($a0)
2550 beq $t3, $a1, .Lstring_indexof_compressed_matched
2551 subu $t0, $t0, 1
2552 bgtz $t0, .Lstring_indexof_compressed_loop
2553 addu $a0, $a0, 1
2554
2555.Lstring_indexof_nomatch:
2556 jalr $zero, $ra
2557 li $v0, -1 # return -1;
2558
2559.Lstring_indexof_compressed_matched:
2560 jalr $zero, $ra
2561 subu $v0, $a0, $t2 # return (current - start);
2562#endif
Chris Larsencf283da2016-01-19 16:45:35 -08002563END art_quick_indexof
2564
Chris Larsencf283da2016-01-19 16:45:35 -08002565/* java.lang.String.compareTo(String anotherString) */
2566ENTRY_NO_GP art_quick_string_compareto
2567/* $a0 holds address of "this" */
2568/* $a1 holds address of "anotherString" */
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002569 beq $a0, $a1, .Lstring_compareto_length_diff # this and anotherString are the same object
2570 move $a3, $a2 # trick to return 0 (it returns a2 - a3)
Chris Larsencf283da2016-01-19 16:45:35 -08002571
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002572#if (STRING_COMPRESSION_FEATURE)
2573 lw $t0, MIRROR_STRING_COUNT_OFFSET($a0) # 'count' field of this
2574 lw $t1, MIRROR_STRING_COUNT_OFFSET($a1) # 'count' field of anotherString
2575 sra $a2, $t0, 1 # this.length()
2576 sra $a3, $t1, 1 # anotherString.length()
2577#else
2578 lw $a2, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2579 lw $a3, MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
2580#endif
Chris Larsencf283da2016-01-19 16:45:35 -08002581
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002582 MINu $t2, $a2, $a3
2583 # $t2 now holds min(this.length(),anotherString.length())
Chris Larsencf283da2016-01-19 16:45:35 -08002584
Goran Jakovljevicf94fa812017-02-10 17:48:52 +01002585 # while min(this.length(),anotherString.length())-i != 0
2586 beqz $t2, .Lstring_compareto_length_diff # if $t2==0
2587 nop # return (this.length() - anotherString.length())
2588
2589#if (STRING_COMPRESSION_FEATURE)
2590 # Differ cases:
2591 sll $t3, $t0, 31
2592 beqz $t3, .Lstring_compareto_this_is_compressed
2593 sll $t3, $t1, 31 # In branch delay slot.
2594 beqz $t3, .Lstring_compareto_that_is_compressed
2595 nop
2596 b .Lstring_compareto_both_not_compressed
2597 nop
2598
2599.Lstring_compareto_this_is_compressed:
2600 beqz $t3, .Lstring_compareto_both_compressed
2601 nop
2602 /* If (this->IsCompressed() && that->IsCompressed() == false) */
2603.Lstring_compareto_loop_comparison_this_compressed:
2604 lbu $t0, MIRROR_STRING_VALUE_OFFSET($a0)
2605 lhu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2606 bne $t0, $t1, .Lstring_compareto_char_diff
2607 addiu $a0, $a0, 1 # point at this.charAt(i++) - compressed
2608 subu $t2, $t2, 1 # new value of min(this.length(),anotherString.length())-i
2609 bnez $t2, .Lstring_compareto_loop_comparison_this_compressed
2610 addiu $a1, $a1, 2 # point at anotherString.charAt(i++) - uncompressed
2611 jalr $zero, $ra
2612 subu $v0, $a2, $a3 # return (this.length() - anotherString.length())
2613
2614.Lstring_compareto_that_is_compressed:
2615 lhu $t0, MIRROR_STRING_VALUE_OFFSET($a0)
2616 lbu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2617 bne $t0, $t1, .Lstring_compareto_char_diff
2618 addiu $a0, $a0, 2 # point at this.charAt(i++) - uncompressed
2619 subu $t2, $t2, 1 # new value of min(this.length(),anotherString.length())-i
2620 bnez $t2, .Lstring_compareto_that_is_compressed
2621 addiu $a1, $a1, 1 # point at anotherString.charAt(i++) - compressed
2622 jalr $zero, $ra
2623 subu $v0, $a2, $a3 # return (this.length() - anotherString.length())
2624
2625.Lstring_compareto_both_compressed:
2626 lbu $t0, MIRROR_STRING_VALUE_OFFSET($a0)
2627 lbu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2628 bne $t0, $t1, .Lstring_compareto_char_diff
2629 addiu $a0, $a0, 1 # point at this.charAt(i++) - compressed
2630 subu $t2, $t2, 1 # new value of min(this.length(),anotherString.length())-i
2631 bnez $t2, .Lstring_compareto_both_compressed
2632 addiu $a1, $a1, 1 # point at anotherString.charAt(i++) - compressed
2633 jalr $zero, $ra
2634 subu $v0, $a2, $a3 # return (this.length() - anotherString.length())
2635#endif
2636
2637.Lstring_compareto_both_not_compressed:
2638 lhu $t0, MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2639 lhu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2640 bne $t0, $t1, .Lstring_compareto_char_diff # if this.charAt(i) != anotherString.charAt(i)
2641 # return (this.charAt(i) - anotherString.charAt(i))
2642 addiu $a0, $a0, 2 # point at this.charAt(i++)
2643 subu $t2, $t2, 1 # new value of min(this.length(),anotherString.length())-i
2644 bnez $t2, .Lstring_compareto_both_not_compressed
2645 addiu $a1, $a1, 2 # point at anotherString.charAt(i++)
2646
2647.Lstring_compareto_length_diff:
2648 jalr $zero, $ra
2649 subu $v0, $a2, $a3 # return (this.length() - anotherString.length())
2650
2651.Lstring_compareto_char_diff:
2652 jalr $zero, $ra
2653 subu $v0, $t0, $t1 # return (this.charAt(i) - anotherString.charAt(i))
Chris Larsencf283da2016-01-19 16:45:35 -08002654END art_quick_string_compareto
Orion Hodsonac141392017-01-13 11:53:47 +00002655
Alexey Frunze15958152017-02-09 19:08:30 -08002656 /*
2657 * Create a function `name` calling the ReadBarrier::Mark routine,
2658 * getting its argument and returning its result through register
2659 * `reg`, saving and restoring all caller-save registers.
2660 */
2661.macro READ_BARRIER_MARK_REG name, reg
2662ENTRY \name
Alexey Frunzea3cb1322017-05-01 18:49:46 -07002663 // Null check so that we can load the lock word.
2664 bnez \reg, .Lnot_null_\name
2665 nop
2666.Lret_rb_\name:
2667 jalr $zero, $ra
2668 nop
2669.Lnot_null_\name:
2670 // Check lock word for mark bit, if marked return.
2671 lw $t9, MIRROR_OBJECT_LOCK_WORD_OFFSET(\reg)
2672 .set push
2673 .set noat
2674 sll $at, $t9, 31 - LOCK_WORD_MARK_BIT_SHIFT # Move mark bit to sign bit.
2675 bltz $at, .Lret_rb_\name
2676#if (LOCK_WORD_STATE_SHIFT != 30) || (LOCK_WORD_STATE_FORWARDING_ADDRESS != 3)
2677 // The below code depends on the lock word state being in the highest bits
2678 // and the "forwarding address" state having all bits set.
2679#error "Unexpected lock word state shift or forwarding address state value."
2680#endif
2681 // Test that both the forwarding state bits are 1.
2682 sll $at, $t9, 1
2683 and $at, $at, $t9 # Sign bit = 1 IFF both bits are 1.
2684 bltz $at, .Lret_forwarding_address\name
2685 nop
2686 .set pop
2687
2688 addiu $sp, $sp, -160 # Includes 16 bytes of space for argument registers a0-a3.
Alexey Frunze15958152017-02-09 19:08:30 -08002689 .cfi_adjust_cfa_offset 160
2690
2691 sw $ra, 156($sp)
2692 .cfi_rel_offset 31, 156
2693 sw $t8, 152($sp)
2694 .cfi_rel_offset 24, 152
2695 sw $t7, 148($sp)
2696 .cfi_rel_offset 15, 148
2697 sw $t6, 144($sp)
2698 .cfi_rel_offset 14, 144
2699 sw $t5, 140($sp)
2700 .cfi_rel_offset 13, 140
2701 sw $t4, 136($sp)
2702 .cfi_rel_offset 12, 136
2703 sw $t3, 132($sp)
2704 .cfi_rel_offset 11, 132
2705 sw $t2, 128($sp)
2706 .cfi_rel_offset 10, 128
2707 sw $t1, 124($sp)
2708 .cfi_rel_offset 9, 124
2709 sw $t0, 120($sp)
2710 .cfi_rel_offset 8, 120
2711 sw $a3, 116($sp)
2712 .cfi_rel_offset 7, 116
2713 sw $a2, 112($sp)
2714 .cfi_rel_offset 6, 112
2715 sw $a1, 108($sp)
2716 .cfi_rel_offset 5, 108
2717 sw $a0, 104($sp)
2718 .cfi_rel_offset 4, 104
2719 sw $v1, 100($sp)
2720 .cfi_rel_offset 3, 100
2721 sw $v0, 96($sp)
2722 .cfi_rel_offset 2, 96
2723
2724 la $t9, artReadBarrierMark
2725
2726 sdc1 $f18, 88($sp)
2727 sdc1 $f16, 80($sp)
2728 sdc1 $f14, 72($sp)
2729 sdc1 $f12, 64($sp)
2730 sdc1 $f10, 56($sp)
2731 sdc1 $f8, 48($sp)
2732 sdc1 $f6, 40($sp)
2733 sdc1 $f4, 32($sp)
2734 sdc1 $f2, 24($sp)
2735
2736 .ifnc \reg, $a0
2737 move $a0, \reg # pass obj from `reg` in a0
2738 .endif
2739 jalr $t9 # v0 <- artReadBarrierMark(obj)
2740 sdc1 $f0, 16($sp) # in delay slot
2741
2742 lw $ra, 156($sp)
2743 .cfi_restore 31
2744 lw $t8, 152($sp)
2745 .cfi_restore 24
2746 lw $t7, 148($sp)
2747 .cfi_restore 15
2748 lw $t6, 144($sp)
2749 .cfi_restore 14
2750 lw $t5, 140($sp)
2751 .cfi_restore 13
2752 lw $t4, 136($sp)
2753 .cfi_restore 12
2754 lw $t3, 132($sp)
2755 .cfi_restore 11
2756 lw $t2, 128($sp)
2757 .cfi_restore 10
2758 lw $t1, 124($sp)
2759 .cfi_restore 9
2760 lw $t0, 120($sp)
2761 .cfi_restore 8
2762 lw $a3, 116($sp)
2763 .cfi_restore 7
2764 lw $a2, 112($sp)
2765 .cfi_restore 6
2766 lw $a1, 108($sp)
2767 .cfi_restore 5
2768 lw $a0, 104($sp)
2769 .cfi_restore 4
2770 lw $v1, 100($sp)
2771 .cfi_restore 3
2772
2773 .ifnc \reg, $v0
2774 move \reg, $v0 # `reg` <- v0
2775 lw $v0, 96($sp)
2776 .cfi_restore 2
2777 .endif
2778
2779 ldc1 $f18, 88($sp)
2780 ldc1 $f16, 80($sp)
2781 ldc1 $f14, 72($sp)
2782 ldc1 $f12, 64($sp)
2783 ldc1 $f10, 56($sp)
2784 ldc1 $f8, 48($sp)
2785 ldc1 $f6, 40($sp)
2786 ldc1 $f4, 32($sp)
2787 ldc1 $f2, 24($sp)
2788 ldc1 $f0, 16($sp)
2789
2790 jalr $zero, $ra
2791 addiu $sp, $sp, 160
2792 .cfi_adjust_cfa_offset -160
Alexey Frunzea3cb1322017-05-01 18:49:46 -07002793
2794.Lret_forwarding_address\name:
2795 jalr $zero, $ra
2796 // Shift left by the forwarding address shift. This clears out the state bits since they are
2797 // in the top 2 bits of the lock word.
2798 sll \reg, $t9, LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
Alexey Frunze15958152017-02-09 19:08:30 -08002799END \name
2800.endm
2801
2802// Note that art_quick_read_barrier_mark_regXX corresponds to register XX+1.
2803// ZERO (register 0) is reserved.
2804// AT (register 1) is reserved as a temporary/scratch register.
2805READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, $v0
2806READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, $v1
2807READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, $a0
2808READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, $a1
2809READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, $a2
2810READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, $a3
2811READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, $t0
2812READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, $t1
2813READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, $t2
2814READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, $t3
2815READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, $t4
2816READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, $t5
2817READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, $t6
2818READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, $t7
2819// S0 and S1 (registers 16 and 17) are reserved as suspended and thread registers.
2820READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, $s2
2821READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, $s3
2822READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, $s4
2823READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, $s5
2824READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, $s6
2825READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, $s7
2826// T8 and T9 (registers 24 and 25) are reserved as temporary/scratch registers.
2827// K0, K1, GP, SP (registers 26 - 29) are reserved.
2828READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, $s8
2829// RA (register 31) is reserved.
2830
Alexey Frunze4147fcc2017-06-17 19:57:27 -07002831// Caller code:
2832// Short constant offset/index:
2833// R2: | R6:
2834// lw $t9, pReadBarrierMarkReg00
2835// beqz $t9, skip_call | beqzc $t9, skip_call
2836// addiu $t9, $t9, thunk_disp | nop
2837// jalr $t9 | jialc $t9, thunk_disp
2838// nop |
2839// skip_call: | skip_call:
2840// lw `out`, ofs(`obj`) | lw `out`, ofs(`obj`)
2841// [subu `out`, $zero, `out`] | [subu `out`, $zero, `out`] # Unpoison reference.
2842.macro BRB_FIELD_SHORT_OFFSET_ENTRY obj
28431:
2844 # Explicit null check. May be redundant (for array elements or when the field
2845 # offset is larger than the page size, 4KB).
2846 # $ra will be adjusted to point to lw's stack map when throwing NPE.
2847 beqz \obj, .Lintrospection_throw_npe
2848#if defined(_MIPS_ARCH_MIPS32R6)
2849 lapc $gp, .Lintrospection_exits # $gp = address of .Lintrospection_exits.
2850#else
2851 addiu $gp, $t9, (.Lintrospection_exits - 1b) # $gp = address of .Lintrospection_exits.
2852#endif
2853 .set push
2854 .set noat
2855 lw $at, MIRROR_OBJECT_LOCK_WORD_OFFSET(\obj)
2856 sll $at, $at, 31 - LOCK_WORD_READ_BARRIER_STATE_SHIFT # Move barrier state bit
2857 # to sign bit.
2858 bltz $at, .Lintrospection_field_array # If gray, load reference, mark.
2859 move $t8, \obj # Move `obj` to $t8 for common code.
2860 .set pop
2861 jalr $zero, $ra # Otherwise, load-load barrier and return.
2862 sync
2863.endm
2864
2865// Caller code (R2):
2866// Long constant offset/index: | Variable index:
2867// lw $t9, pReadBarrierMarkReg00
2868// lui $t8, ofs_hi | sll $t8, `index`, 2
2869// beqz $t9, skip_call | beqz $t9, skip_call
2870// addiu $t9, $t9, thunk_disp | addiu $t9, $t9, thunk_disp
2871// jalr $t9 | jalr $t9
2872// skip_call: | skip_call:
2873// addu $t8, $t8, `obj` | addu $t8, $t8, `obj`
2874// lw `out`, ofs_lo($t8) | lw `out`, ofs($t8)
2875// [subu `out`, $zero, `out`] | [subu `out`, $zero, `out`] # Unpoison reference.
2876//
2877// Caller code (R6):
2878// Long constant offset/index: | Variable index:
2879// lw $t9, pReadBarrierMarkReg00
2880// beqz $t9, skip_call | beqz $t9, skip_call
2881// aui $t8, `obj`, ofs_hi | lsa $t8, `index`, `obj`, 2
2882// jialc $t9, thunk_disp | jialc $t9, thunk_disp
2883// skip_call: | skip_call:
2884// lw `out`, ofs_lo($t8) | lw `out`, ofs($t8)
2885// [subu `out`, $zero, `out`] | [subu `out`, $zero, `out`] # Unpoison reference.
2886.macro BRB_FIELD_LONG_OFFSET_ENTRY obj
28871:
2888 # No explicit null check for variable indices or large constant indices/offsets
2889 # as it must have been done earlier.
2890#if defined(_MIPS_ARCH_MIPS32R6)
2891 lapc $gp, .Lintrospection_exits # $gp = address of .Lintrospection_exits.
2892#else
2893 addiu $gp, $t9, (.Lintrospection_exits - 1b) # $gp = address of .Lintrospection_exits.
2894#endif
2895 .set push
2896 .set noat
2897 lw $at, MIRROR_OBJECT_LOCK_WORD_OFFSET(\obj)
2898 sll $at, $at, 31 - LOCK_WORD_READ_BARRIER_STATE_SHIFT # Move barrier state bit
2899 # to sign bit.
2900 bltz $at, .Lintrospection_field_array # If gray, load reference, mark.
2901 nop
2902 .set pop
2903 jalr $zero, $ra # Otherwise, load-load barrier and return.
2904 sync
2905 break # Padding to 8 instructions.
2906.endm
2907
2908.macro BRB_GC_ROOT_ENTRY root
29091:
2910#if defined(_MIPS_ARCH_MIPS32R6)
2911 lapc $gp, .Lintrospection_exit_\root # $gp = exit point address.
2912#else
2913 addiu $gp, $t9, (.Lintrospection_exit_\root - 1b) # $gp = exit point address.
2914#endif
2915 bnez \root, .Lintrospection_common
2916 move $t8, \root # Move reference to $t8 for common code.
2917 jalr $zero, $ra # Return if null.
2918 # The next instruction (from the following BRB_GC_ROOT_ENTRY) fills the delay slot.
2919 # This instruction has no effect (actual NOP for the last entry; otherwise changes $gp,
2920 # which is unused after that anyway).
2921.endm
2922
2923.macro BRB_FIELD_EXIT out
2924.Lintrospection_exit_\out:
2925 jalr $zero, $ra
2926 move \out, $t8 # Return reference in expected register.
2927.endm
2928
2929.macro BRB_FIELD_EXIT_BREAK
2930 break
2931 break
2932.endm
2933
2934ENTRY_NO_GP art_quick_read_barrier_mark_introspection
2935 # Entry points for offsets/indices not fitting into int16_t and for variable indices.
2936 BRB_FIELD_LONG_OFFSET_ENTRY $v0
2937 BRB_FIELD_LONG_OFFSET_ENTRY $v1
2938 BRB_FIELD_LONG_OFFSET_ENTRY $a0
2939 BRB_FIELD_LONG_OFFSET_ENTRY $a1
2940 BRB_FIELD_LONG_OFFSET_ENTRY $a2
2941 BRB_FIELD_LONG_OFFSET_ENTRY $a3
2942 BRB_FIELD_LONG_OFFSET_ENTRY $t0
2943 BRB_FIELD_LONG_OFFSET_ENTRY $t1
2944 BRB_FIELD_LONG_OFFSET_ENTRY $t2
2945 BRB_FIELD_LONG_OFFSET_ENTRY $t3
2946 BRB_FIELD_LONG_OFFSET_ENTRY $t4
2947 BRB_FIELD_LONG_OFFSET_ENTRY $t5
2948 BRB_FIELD_LONG_OFFSET_ENTRY $t6
2949 BRB_FIELD_LONG_OFFSET_ENTRY $t7
2950 BRB_FIELD_LONG_OFFSET_ENTRY $s2
2951 BRB_FIELD_LONG_OFFSET_ENTRY $s3
2952 BRB_FIELD_LONG_OFFSET_ENTRY $s4
2953 BRB_FIELD_LONG_OFFSET_ENTRY $s5
2954 BRB_FIELD_LONG_OFFSET_ENTRY $s6
2955 BRB_FIELD_LONG_OFFSET_ENTRY $s7
2956 BRB_FIELD_LONG_OFFSET_ENTRY $s8
2957
2958 # Entry points for offsets/indices fitting into int16_t.
2959 BRB_FIELD_SHORT_OFFSET_ENTRY $v0
2960 BRB_FIELD_SHORT_OFFSET_ENTRY $v1
2961 BRB_FIELD_SHORT_OFFSET_ENTRY $a0
2962 BRB_FIELD_SHORT_OFFSET_ENTRY $a1
2963 BRB_FIELD_SHORT_OFFSET_ENTRY $a2
2964 BRB_FIELD_SHORT_OFFSET_ENTRY $a3
2965 BRB_FIELD_SHORT_OFFSET_ENTRY $t0
2966 BRB_FIELD_SHORT_OFFSET_ENTRY $t1
2967 BRB_FIELD_SHORT_OFFSET_ENTRY $t2
2968 BRB_FIELD_SHORT_OFFSET_ENTRY $t3
2969 BRB_FIELD_SHORT_OFFSET_ENTRY $t4
2970 BRB_FIELD_SHORT_OFFSET_ENTRY $t5
2971 BRB_FIELD_SHORT_OFFSET_ENTRY $t6
2972 BRB_FIELD_SHORT_OFFSET_ENTRY $t7
2973 BRB_FIELD_SHORT_OFFSET_ENTRY $s2
2974 BRB_FIELD_SHORT_OFFSET_ENTRY $s3
2975 BRB_FIELD_SHORT_OFFSET_ENTRY $s4
2976 BRB_FIELD_SHORT_OFFSET_ENTRY $s5
2977 BRB_FIELD_SHORT_OFFSET_ENTRY $s6
2978 BRB_FIELD_SHORT_OFFSET_ENTRY $s7
2979 BRB_FIELD_SHORT_OFFSET_ENTRY $s8
2980
2981 .global art_quick_read_barrier_mark_introspection_gc_roots
2982art_quick_read_barrier_mark_introspection_gc_roots:
2983 # Entry points for GC roots.
2984 BRB_GC_ROOT_ENTRY $v0
2985 BRB_GC_ROOT_ENTRY $v1
2986 BRB_GC_ROOT_ENTRY $a0
2987 BRB_GC_ROOT_ENTRY $a1
2988 BRB_GC_ROOT_ENTRY $a2
2989 BRB_GC_ROOT_ENTRY $a3
2990 BRB_GC_ROOT_ENTRY $t0
2991 BRB_GC_ROOT_ENTRY $t1
2992 BRB_GC_ROOT_ENTRY $t2
2993 BRB_GC_ROOT_ENTRY $t3
2994 BRB_GC_ROOT_ENTRY $t4
2995 BRB_GC_ROOT_ENTRY $t5
2996 BRB_GC_ROOT_ENTRY $t6
2997 BRB_GC_ROOT_ENTRY $t7
2998 BRB_GC_ROOT_ENTRY $s2
2999 BRB_GC_ROOT_ENTRY $s3
3000 BRB_GC_ROOT_ENTRY $s4
3001 BRB_GC_ROOT_ENTRY $s5
3002 BRB_GC_ROOT_ENTRY $s6
3003 BRB_GC_ROOT_ENTRY $s7
3004 BRB_GC_ROOT_ENTRY $s8
3005 .global art_quick_read_barrier_mark_introspection_end_of_entries
3006art_quick_read_barrier_mark_introspection_end_of_entries:
3007 nop # Fill the delay slot of the last BRB_GC_ROOT_ENTRY.
3008
3009.Lintrospection_throw_npe:
3010 b art_quick_throw_null_pointer_exception
3011 addiu $ra, $ra, 4 # Skip lw, make $ra point to lw's stack map.
3012
3013 .set push
3014 .set noat
3015
3016 // Fields and array elements.
3017
3018.Lintrospection_field_array:
3019 // Get the field/element address using $t8 and the offset from the lw instruction.
3020 lh $at, 0($ra) # $ra points to lw: $at = field/element offset.
3021 addiu $ra, $ra, 4 + HEAP_POISON_INSTR_SIZE # Skip lw(+subu).
3022 addu $t8, $t8, $at # $t8 = field/element address.
3023
3024 // Calculate the address of the exit point, store it in $gp and load the reference into $t8.
3025 lb $at, (-HEAP_POISON_INSTR_SIZE - 2)($ra) # $ra-HEAP_POISON_INSTR_SIZE-4 points to
3026 # "lw `out`, ...".
3027 andi $at, $at, 31 # Extract `out` from lw.
3028 sll $at, $at, 3 # Multiply `out` by the exit point size (BRB_FIELD_EXIT* macros).
3029
3030 lw $t8, 0($t8) # $t8 = reference.
3031 UNPOISON_HEAP_REF $t8
3032
3033 // Return if null reference.
3034 bnez $t8, .Lintrospection_common
3035 addu $gp, $gp, $at # $gp = address of the exit point.
3036
3037 // Early return through the exit point.
3038.Lintrospection_return_early:
3039 jalr $zero, $gp # Move $t8 to `out` and return.
3040 nop
3041
3042 // Code common for GC roots, fields and array elements.
3043
3044.Lintrospection_common:
3045 // Check lock word for mark bit, if marked return.
3046 lw $t9, MIRROR_OBJECT_LOCK_WORD_OFFSET($t8)
3047 sll $at, $t9, 31 - LOCK_WORD_MARK_BIT_SHIFT # Move mark bit to sign bit.
3048 bltz $at, .Lintrospection_return_early
3049#if (LOCK_WORD_STATE_SHIFT != 30) || (LOCK_WORD_STATE_FORWARDING_ADDRESS != 3)
3050 // The below code depends on the lock word state being in the highest bits
3051 // and the "forwarding address" state having all bits set.
3052#error "Unexpected lock word state shift or forwarding address state value."
3053#endif
3054 // Test that both the forwarding state bits are 1.
3055 sll $at, $t9, 1
3056 and $at, $at, $t9 # Sign bit = 1 IFF both bits are 1.
3057 bgez $at, .Lintrospection_mark
3058 nop
3059
3060 .set pop
3061
3062 // Shift left by the forwarding address shift. This clears out the state bits since they are
3063 // in the top 2 bits of the lock word.
3064 jalr $zero, $gp # Move $t8 to `out` and return.
3065 sll $t8, $t9, LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT
3066
3067.Lintrospection_mark:
3068 // Partially set up the stack frame preserving only $ra.
3069 addiu $sp, $sp, -160 # Includes 16 bytes of space for argument registers $a0-$a3.
3070 .cfi_adjust_cfa_offset 160
3071 sw $ra, 156($sp)
3072 .cfi_rel_offset 31, 156
3073
3074 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
3075 bal 1f
3076 sw $gp, 152($sp) # Preserve the exit point address.
30771:
3078 .cpload $ra
3079
3080 // Finalize the stack frame and call.
3081 sw $t7, 148($sp)
3082 .cfi_rel_offset 15, 148
3083 sw $t6, 144($sp)
3084 .cfi_rel_offset 14, 144
3085 sw $t5, 140($sp)
3086 .cfi_rel_offset 13, 140
3087 sw $t4, 136($sp)
3088 .cfi_rel_offset 12, 136
3089 sw $t3, 132($sp)
3090 .cfi_rel_offset 11, 132
3091 sw $t2, 128($sp)
3092 .cfi_rel_offset 10, 128
3093 sw $t1, 124($sp)
3094 .cfi_rel_offset 9, 124
3095 sw $t0, 120($sp)
3096 .cfi_rel_offset 8, 120
3097 sw $a3, 116($sp)
3098 .cfi_rel_offset 7, 116
3099 sw $a2, 112($sp)
3100 .cfi_rel_offset 6, 112
3101 sw $a1, 108($sp)
3102 .cfi_rel_offset 5, 108
3103 sw $a0, 104($sp)
3104 .cfi_rel_offset 4, 104
3105 sw $v1, 100($sp)
3106 .cfi_rel_offset 3, 100
3107 sw $v0, 96($sp)
3108 .cfi_rel_offset 2, 96
3109
3110 la $t9, artReadBarrierMark
3111
3112 sdc1 $f18, 88($sp)
3113 sdc1 $f16, 80($sp)
3114 sdc1 $f14, 72($sp)
3115 sdc1 $f12, 64($sp)
3116 sdc1 $f10, 56($sp)
3117 sdc1 $f8, 48($sp)
3118 sdc1 $f6, 40($sp)
3119 sdc1 $f4, 32($sp)
3120 sdc1 $f2, 24($sp)
3121 sdc1 $f0, 16($sp)
3122
3123 jalr $t9 # $v0 <- artReadBarrierMark(reference)
3124 move $a0, $t8 # Pass reference in $a0.
3125 move $t8, $v0
3126
3127 lw $ra, 156($sp)
3128 .cfi_restore 31
3129 lw $gp, 152($sp) # $gp = address of the exit point.
3130 lw $t7, 148($sp)
3131 .cfi_restore 15
3132 lw $t6, 144($sp)
3133 .cfi_restore 14
3134 lw $t5, 140($sp)
3135 .cfi_restore 13
3136 lw $t4, 136($sp)
3137 .cfi_restore 12
3138 lw $t3, 132($sp)
3139 .cfi_restore 11
3140 lw $t2, 128($sp)
3141 .cfi_restore 10
3142 lw $t1, 124($sp)
3143 .cfi_restore 9
3144 lw $t0, 120($sp)
3145 .cfi_restore 8
3146 lw $a3, 116($sp)
3147 .cfi_restore 7
3148 lw $a2, 112($sp)
3149 .cfi_restore 6
3150 lw $a1, 108($sp)
3151 .cfi_restore 5
3152 lw $a0, 104($sp)
3153 .cfi_restore 4
3154 lw $v1, 100($sp)
3155 .cfi_restore 3
3156 lw $v0, 96($sp)
3157 .cfi_restore 2
3158
3159 ldc1 $f18, 88($sp)
3160 ldc1 $f16, 80($sp)
3161 ldc1 $f14, 72($sp)
3162 ldc1 $f12, 64($sp)
3163 ldc1 $f10, 56($sp)
3164 ldc1 $f8, 48($sp)
3165 ldc1 $f6, 40($sp)
3166 ldc1 $f4, 32($sp)
3167 ldc1 $f2, 24($sp)
3168 ldc1 $f0, 16($sp)
3169
3170 // Return through the exit point.
3171 jalr $zero, $gp # Move $t8 to `out` and return.
3172 addiu $sp, $sp, 160
3173 .cfi_adjust_cfa_offset -160
3174
3175.Lintrospection_exits:
3176 BRB_FIELD_EXIT_BREAK
3177 BRB_FIELD_EXIT_BREAK
3178 BRB_FIELD_EXIT $v0
3179 BRB_FIELD_EXIT $v1
3180 BRB_FIELD_EXIT $a0
3181 BRB_FIELD_EXIT $a1
3182 BRB_FIELD_EXIT $a2
3183 BRB_FIELD_EXIT $a3
3184 BRB_FIELD_EXIT $t0
3185 BRB_FIELD_EXIT $t1
3186 BRB_FIELD_EXIT $t2
3187 BRB_FIELD_EXIT $t3
3188 BRB_FIELD_EXIT $t4
3189 BRB_FIELD_EXIT $t5
3190 BRB_FIELD_EXIT $t6
3191 BRB_FIELD_EXIT $t7
3192 BRB_FIELD_EXIT_BREAK
3193 BRB_FIELD_EXIT_BREAK
3194 BRB_FIELD_EXIT $s2
3195 BRB_FIELD_EXIT $s3
3196 BRB_FIELD_EXIT $s4
3197 BRB_FIELD_EXIT $s5
3198 BRB_FIELD_EXIT $s6
3199 BRB_FIELD_EXIT $s7
3200 BRB_FIELD_EXIT_BREAK
3201 BRB_FIELD_EXIT_BREAK
3202 BRB_FIELD_EXIT_BREAK
3203 BRB_FIELD_EXIT_BREAK
3204 BRB_FIELD_EXIT_BREAK
3205 BRB_FIELD_EXIT_BREAK
3206 BRB_FIELD_EXIT $s8
3207 BRB_FIELD_EXIT_BREAK
3208END art_quick_read_barrier_mark_introspection
3209
Orion Hodsonac141392017-01-13 11:53:47 +00003210.extern artInvokePolymorphic
3211ENTRY art_quick_invoke_polymorphic
3212 SETUP_SAVE_REFS_AND_ARGS_FRAME
3213 move $a2, rSELF # Make $a2 an alias for the current Thread.
Alexey Frunzec480b982017-01-16 19:03:21 -08003214 addiu $a3, $sp, ARG_SLOT_SIZE # Make $a3 a pointer to the saved frame context.
Orion Hodsonac141392017-01-13 11:53:47 +00003215 sw $zero, 20($sp) # Initialize JValue result.
3216 sw $zero, 16($sp)
Orion Hodsonac141392017-01-13 11:53:47 +00003217 la $t9, artInvokePolymorphic
3218 jalr $t9 # (result, receiver, Thread*, context)
Alexey Frunzec480b982017-01-16 19:03:21 -08003219 addiu $a0, $sp, 16 # Make $a0 a pointer to the JValue result
Orion Hodsonac141392017-01-13 11:53:47 +00003220.macro MATCH_RETURN_TYPE c, handler
3221 li $t0, \c
3222 beq $v0, $t0, \handler
3223.endm
3224 MATCH_RETURN_TYPE 'V', .Lcleanup_and_return
3225 MATCH_RETURN_TYPE 'L', .Lstore_int_result
3226 MATCH_RETURN_TYPE 'I', .Lstore_int_result
3227 MATCH_RETURN_TYPE 'J', .Lstore_long_result
3228 MATCH_RETURN_TYPE 'B', .Lstore_int_result
3229 MATCH_RETURN_TYPE 'C', .Lstore_char_result
3230 MATCH_RETURN_TYPE 'D', .Lstore_double_result
3231 MATCH_RETURN_TYPE 'F', .Lstore_float_result
3232 MATCH_RETURN_TYPE 'S', .Lstore_int_result
Alexey Frunzec480b982017-01-16 19:03:21 -08003233 MATCH_RETURN_TYPE 'Z', .Lstore_boolean_result
Orion Hodsonac141392017-01-13 11:53:47 +00003234.purgem MATCH_RETURN_TYPE
3235 nop
3236 b .Lcleanup_and_return
3237 nop
3238.Lstore_boolean_result:
Alexey Frunzec480b982017-01-16 19:03:21 -08003239 b .Lcleanup_and_return
Orion Hodsonac141392017-01-13 11:53:47 +00003240 lbu $v0, 16($sp) # Move byte from JValue result to return value register.
Orion Hodsonac141392017-01-13 11:53:47 +00003241.Lstore_char_result:
Orion Hodsonac141392017-01-13 11:53:47 +00003242 b .Lcleanup_and_return
Alexey Frunzec480b982017-01-16 19:03:21 -08003243 lhu $v0, 16($sp) # Move char from JValue result to return value register.
Orion Hodsonac141392017-01-13 11:53:47 +00003244.Lstore_double_result:
3245.Lstore_float_result:
3246 LDu $f0, $f1, 16, $sp, $t0 # Move double/float from JValue result to return value register.
3247 b .Lcleanup_and_return
3248 nop
3249.Lstore_long_result:
3250 lw $v1, 20($sp) # Move upper bits from JValue result to return value register.
3251 // Fall-through for lower bits.
3252.Lstore_int_result:
3253 lw $v0, 16($sp) # Move lower bits from JValue result to return value register.
3254 // Fall-through to clean up and return.
3255.Lcleanup_and_return:
Orion Hodsonac141392017-01-13 11:53:47 +00003256 lw $t7, THREAD_EXCEPTION_OFFSET(rSELF) # Load Thread::Current()->exception_
3257 RESTORE_SAVE_REFS_AND_ARGS_FRAME
3258 bnez $t7, 1f # Success if no exception is pending.
3259 nop
3260 jalr $zero, $ra
3261 nop
32621:
3263 DELIVER_PENDING_EXCEPTION
3264END art_quick_invoke_polymorphic