blob: bb89674caf1f97ab951b26054b1aa929b9657f50 [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
33 * Runtime::CreateCalleeSaveMethod(kSaveAll)
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.
37 * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080038 */
Ian Rogers57b86d42012-03-27 16:05:41 -070039.macro SETUP_SAVE_ALL_CALLEE_SAVE_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.
Andreas Gampea4e0e672015-05-27 18:31:42 -070044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 96)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070045#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS) size not as expected."
46#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)
Douglas Leung4af77b72014-10-22 16:32:28 -070082 lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_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
91 * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC.
92 * 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.
96 * Reserves FRAME_SIZE_REFS_ONLY_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080097 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070098.macro SETUP_REFS_ONLY_CALLEE_SAVE_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.
Douglas Leung735b8552014-10-31 12:21:40 -0700103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 48)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700104#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS) size not as expected."
105#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)
Douglas Leung4af77b72014-10-22 16:32:28 -0700129 lw $t0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_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
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700136.macro RESTORE_REFS_ONLY_CALLEE_SAVE_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
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700161.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Douglas Leung735b8552014-10-31 12:21:40 -0700162 RESTORE_REFS_ONLY_CALLEE_SAVE_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 /*
168 * Macro that sets up the callee save frame to conform with
Douglas Leung735b8552014-10-31 12:21:40 -0700169 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
Jeff Hao1f3bc2f2013-04-30 15:17:19 -0700170 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
buzbee5bc5a7b2012-03-07 15:52:59 -0800171 */
Douglas Leung735b8552014-10-31 12:21:40 -0700172.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Goran Jakovljevicff734982015-08-24 12:58:55 +0000173 addiu $sp, $sp, -80
174 .cfi_adjust_cfa_offset 80
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700175
176 // Ugly compile-time check, but we only have the preprocessor.
Goran Jakovljevicff734982015-08-24 12:58:55 +0000177#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 80)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700178#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS) size not as expected."
179#endif
180
Goran Jakovljevicff734982015-08-24 12:58:55 +0000181 sw $ra, 76($sp)
182 .cfi_rel_offset 31, 76
183 sw $s8, 72($sp)
184 .cfi_rel_offset 30, 72
185 sw $gp, 68($sp)
186 .cfi_rel_offset 28, 68
187 sw $s7, 64($sp)
188 .cfi_rel_offset 23, 64
189 sw $s6, 60($sp)
190 .cfi_rel_offset 22, 60
191 sw $s5, 56($sp)
192 .cfi_rel_offset 21, 56
193 sw $s4, 52($sp)
194 .cfi_rel_offset 20, 52
195 sw $s3, 48($sp)
196 .cfi_rel_offset 19, 48
197 sw $s2, 44($sp)
198 .cfi_rel_offset 18, 44
199 sw $a3, 40($sp)
200 .cfi_rel_offset 7, 40
201 sw $a2, 36($sp)
202 .cfi_rel_offset 6, 36
203 sw $a1, 32($sp)
204 .cfi_rel_offset 5, 32
205 SDu $f14, $f15, 24, $sp, $t0
206 SDu $f12, $f13, 16, $sp, $t0
jeffhaofa147e22012-10-12 17:03:32 -0700207 # bottom will hold Method*
Douglas Leung735b8552014-10-31 12:21:40 -0700208.endm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700209
Douglas Leung735b8552014-10-31 12:21:40 -0700210 /*
211 * Macro that sets up the callee save frame to conform with
212 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
Goran Jakovljevicff734982015-08-24 12:58:55 +0000213 * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700214 * Clobbers $t0 and $sp
215 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
216 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
217 */
218.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
219 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Douglas Leung4af77b72014-10-22 16:32:28 -0700220 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
221 lw $t0, 0($t0)
Douglas Leung4af77b72014-10-22 16:32:28 -0700222 lw $t0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700223 sw $t0, 0($sp) # Place Method* at bottom of stack.
224 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700225 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
226 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
227.endm
228
229 /*
230 * Macro that sets up the callee save frame to conform with
231 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
Goran Jakovljevicff734982015-08-24 12:58:55 +0000232 * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700233 * Clobbers $sp
234 * Use $a0 as the Method* and loads it into bottom of stack.
235 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
236 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
237 */
238.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
239 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
240 sw $a0, 0($sp) # Place Method* at bottom of stack.
241 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
242 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
243 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800244.endm
245
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700246.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -0700247 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
248 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +0000249 lw $ra, 76($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800250 .cfi_restore 31
Goran Jakovljevicff734982015-08-24 12:58:55 +0000251 lw $s8, 72($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800252 .cfi_restore 30
Goran Jakovljevicff734982015-08-24 12:58:55 +0000253 lw $gp, 68($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800254 .cfi_restore 28
Goran Jakovljevicff734982015-08-24 12:58:55 +0000255 lw $s7, 64($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800256 .cfi_restore 23
Goran Jakovljevicff734982015-08-24 12:58:55 +0000257 lw $s6, 60($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800258 .cfi_restore 22
Goran Jakovljevicff734982015-08-24 12:58:55 +0000259 lw $s5, 56($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800260 .cfi_restore 21
Goran Jakovljevicff734982015-08-24 12:58:55 +0000261 lw $s4, 52($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800262 .cfi_restore 20
Goran Jakovljevicff734982015-08-24 12:58:55 +0000263 lw $s3, 48($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800264 .cfi_restore 19
Goran Jakovljevicff734982015-08-24 12:58:55 +0000265 lw $s2, 44($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800266 .cfi_restore 18
Goran Jakovljevicff734982015-08-24 12:58:55 +0000267 lw $a3, 40($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800268 .cfi_restore 7
Goran Jakovljevicff734982015-08-24 12:58:55 +0000269 lw $a2, 36($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800270 .cfi_restore 6
Goran Jakovljevicff734982015-08-24 12:58:55 +0000271 lw $a1, 32($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800272 .cfi_restore 5
Goran Jakovljevicff734982015-08-24 12:58:55 +0000273 LDu $f14, $f15, 24, $sp, $t1
274 LDu $f12, $f13, 16, $sp, $t1
275 addiu $sp, $sp, 80 # pop frame
276 .cfi_adjust_cfa_offset -80
buzbee5bc5a7b2012-03-07 15:52:59 -0800277.endm
278
279 /*
280 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
281 * exception is Thread::Current()->exception_
282 */
283.macro DELIVER_PENDING_EXCEPTION
jeffhao8161c032012-10-31 15:50:00 -0700284 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME # save callee saves for throw
jeffhao8161c032012-10-31 15:50:00 -0700285 la $t9, artDeliverPendingExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800286 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700287 move $a0, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800288.endm
289
290.macro RETURN_IF_NO_EXCEPTION
jeffhao7fbee072012-08-24 17:56:54 -0700291 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700292 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700293 bnez $t0, 1f # success if no exception is pending
buzbee5bc5a7b2012-03-07 15:52:59 -0800294 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800295 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -0800296 nop
2971:
298 DELIVER_PENDING_EXCEPTION
299.endm
300
301.macro RETURN_IF_ZERO
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700302 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700303 bnez $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800304 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800305 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800306 nop
3071:
308 DELIVER_PENDING_EXCEPTION
309.endm
310
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800311.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700312 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700313 beqz $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800314 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800315 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800316 nop
3171:
318 DELIVER_PENDING_EXCEPTION
319.endm
320
buzbee5bc5a7b2012-03-07 15:52:59 -0800321 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100322 * On stack replacement stub.
323 * On entry:
324 * a0 = stack to copy
325 * a1 = size of stack
326 * a2 = pc to call
327 * a3 = JValue* result
328 * [sp + 16] = shorty
329 * [sp + 20] = thread
330 */
331ENTRY art_quick_osr_stub
332 // Save callee general purpose registers, RA and GP.
333 addiu $sp, $sp, -48
334 .cfi_adjust_cfa_offset 48
335 sw $ra, 44($sp)
336 .cfi_rel_offset 31, 44
337 sw $s8, 40($sp)
338 .cfi_rel_offset 30, 40
339 sw $gp, 36($sp)
340 .cfi_rel_offset 28, 36
341 sw $s7, 32($sp)
342 .cfi_rel_offset 23, 32
343 sw $s6, 28($sp)
344 .cfi_rel_offset 22, 28
345 sw $s5, 24($sp)
346 .cfi_rel_offset 21, 24
347 sw $s4, 20($sp)
348 .cfi_rel_offset 20, 20
349 sw $s3, 16($sp)
350 .cfi_rel_offset 19, 16
351 sw $s2, 12($sp)
352 .cfi_rel_offset 18, 12
353 sw $s1, 8($sp)
354 .cfi_rel_offset 17, 8
355 sw $s0, 4($sp)
356 .cfi_rel_offset 16, 4
357
358 move $s8, $sp # Save the stack pointer
359 move $s7, $a1 # Save size of stack
360 move $s6, $a2 # Save the pc to call
361 lw rSELF, 48+20($sp) # Save managed thread pointer into rSELF
362 addiu $t0, $sp, -12 # Reserve space for stack pointer,
363 # JValue* result, and ArtMethod* slot.
364 srl $t0, $t0, 4 # Align stack pointer to 16 bytes
365 sll $sp, $t0, 4 # Update stack pointer
366 sw $s8, 4($sp) # Save old stack pointer
367 sw $a3, 8($sp) # Save JValue* result
368 sw $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
369 subu $sp, $a1 # Reserve space for callee stack
370 move $a2, $a1
371 move $a1, $a0
372 move $a0, $sp
373 la $t9, memcpy
374 jalr $t9 # memcpy (dest a0, src a1, bytes a2)
375 addiu $sp, $sp, -16 # make space for argument slots for memcpy
376 bal .Losr_entry # Call the method
377 addiu $sp, $sp, 16 # restore stack after memcpy
378 lw $a2, 8($sp) # Restore JValue* result
379 lw $sp, 4($sp) # Restore saved stack pointer
380 lw $a0, 48+16($sp) # load shorty
381 lbu $a0, 0($a0) # load return type
382 li $a1, 'D' # put char 'D' into a1
383 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'D'
384 li $a1, 'F' # put char 'F' into a1
385 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'F'
386 nop
387 sw $v0, 0($a2)
388 b .Losr_exit
389 sw $v1, 4($a2) # store v0/v1 into result
390.Losr_fp_result:
391 SDu $f0, $f1, 0, $a2, $t0 # store f0/f1 into result
392.Losr_exit:
393 lw $ra, 44($sp)
394 .cfi_restore 31
395 lw $s8, 40($sp)
396 .cfi_restore 30
397 lw $gp, 36($sp)
398 .cfi_restore 28
399 lw $s7, 32($sp)
400 .cfi_restore 23
401 lw $s6, 28($sp)
402 .cfi_restore 22
403 lw $s5, 24($sp)
404 .cfi_restore 21
405 lw $s4, 20($sp)
406 .cfi_restore 20
407 lw $s3, 16($sp)
408 .cfi_restore 19
409 lw $s2, 12($sp)
410 .cfi_restore 18
411 lw $s1, 8($sp)
412 .cfi_restore 17
413 lw $s0, 4($sp)
414 .cfi_restore 16
415 jalr $zero, $ra
416 addiu $sp, $sp, 48
417 .cfi_adjust_cfa_offset -48
418.Losr_entry:
419 addiu $s7, $s7, -4
420 addu $t0, $s7, $sp
421 move $t9, $s6
422 jalr $zero, $t9
423 sw $ra, 0($t0) # Store RA per the compiler ABI
424END art_quick_osr_stub
425
426 /*
jeffhao7fbee072012-08-24 17:56:54 -0700427 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
buzbee5bc5a7b2012-03-07 15:52:59 -0800428 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
429 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800430ENTRY art_quick_do_long_jump
Duane Sande34652f2014-11-04 11:09:36 -0800431 LDu $f0, $f1, 0*8, $a1, $t1
432 LDu $f2, $f3, 1*8, $a1, $t1
433 LDu $f4, $f5, 2*8, $a1, $t1
434 LDu $f6, $f7, 3*8, $a1, $t1
435 LDu $f8, $f9, 4*8, $a1, $t1
436 LDu $f10, $f11, 5*8, $a1, $t1
437 LDu $f12, $f13, 6*8, $a1, $t1
438 LDu $f14, $f15, 7*8, $a1, $t1
439 LDu $f16, $f17, 8*8, $a1, $t1
440 LDu $f18, $f19, 9*8, $a1, $t1
441 LDu $f20, $f21, 10*8, $a1, $t1
442 LDu $f22, $f23, 11*8, $a1, $t1
443 LDu $f24, $f25, 12*8, $a1, $t1
444 LDu $f26, $f27, 13*8, $a1, $t1
445 LDu $f28, $f29, 14*8, $a1, $t1
446 LDu $f30, $f31, 15*8, $a1, $t1
447
Chris Dearman748dd952014-05-23 10:47:01 -0700448 .set push
449 .set nomacro
450 .set noat
jeffhao7fbee072012-08-24 17:56:54 -0700451 lw $at, 4($a0)
Chris Dearman748dd952014-05-23 10:47:01 -0700452 .set pop
jeffhao7fbee072012-08-24 17:56:54 -0700453 lw $v0, 8($a0)
454 lw $v1, 12($a0)
455 lw $a1, 20($a0)
456 lw $a2, 24($a0)
457 lw $a3, 28($a0)
458 lw $t0, 32($a0)
459 lw $t1, 36($a0)
460 lw $t2, 40($a0)
461 lw $t3, 44($a0)
462 lw $t4, 48($a0)
463 lw $t5, 52($a0)
464 lw $t6, 56($a0)
465 lw $t7, 60($a0)
466 lw $s0, 64($a0)
467 lw $s1, 68($a0)
468 lw $s2, 72($a0)
469 lw $s3, 76($a0)
470 lw $s4, 80($a0)
471 lw $s5, 84($a0)
472 lw $s6, 88($a0)
473 lw $s7, 92($a0)
474 lw $t8, 96($a0)
475 lw $t9, 100($a0)
jeffhao7fbee072012-08-24 17:56:54 -0700476 lw $gp, 112($a0)
477 lw $sp, 116($a0)
478 lw $fp, 120($a0)
479 lw $ra, 124($a0)
480 lw $a0, 16($a0)
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100481 move $v0, $zero # clear result registers v0 and v1 (in branch delay slot)
Goran Jakovljevic75969962015-10-27 12:29:07 +0100482 jalr $zero, $t9 # do long jump
jeffhao7fbee072012-08-24 17:56:54 -0700483 move $v1, $zero
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800484END art_quick_do_long_jump
buzbee5bc5a7b2012-03-07 15:52:59 -0800485
buzbee5bc5a7b2012-03-07 15:52:59 -0800486 /*
487 * Called by managed code, saves most registers (forms basis of long jump context) and passes
488 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200489 * the bottom of the thread. On entry a0 holds Throwable*
buzbee5bc5a7b2012-03-07 15:52:59 -0800490 */
Ian Rogers468532e2013-08-05 10:56:33 -0700491ENTRY art_quick_deliver_exception
Ian Rogers57b86d42012-03-27 16:05:41 -0700492 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700493 la $t9, artDeliverExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800494 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700495 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700496END art_quick_deliver_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800497
buzbee5bc5a7b2012-03-07 15:52:59 -0800498 /*
499 * Called by managed code to create and deliver a NullPointerException
500 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800501 .extern artThrowNullPointerExceptionFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700502ENTRY art_quick_throw_null_pointer_exception
Ian Rogers57b86d42012-03-27 16:05:41 -0700503 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700504 la $t9, artThrowNullPointerExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800505 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700506 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700507END art_quick_throw_null_pointer_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800508
buzbee5bc5a7b2012-03-07 15:52:59 -0800509 /*
510 * Called by managed code to create and deliver an ArithmeticException
511 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800512 .extern artThrowDivZeroFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700513ENTRY art_quick_throw_div_zero
Ian Rogers57b86d42012-03-27 16:05:41 -0700514 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700515 la $t9, artThrowDivZeroFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800516 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700517 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700518END art_quick_throw_div_zero
buzbee5bc5a7b2012-03-07 15:52:59 -0800519
buzbee5bc5a7b2012-03-07 15:52:59 -0800520 /*
521 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
522 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800523 .extern artThrowArrayBoundsFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700524ENTRY art_quick_throw_array_bounds
Ian Rogers57b86d42012-03-27 16:05:41 -0700525 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700526 la $t9, artThrowArrayBoundsFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800527 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700528 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700529END art_quick_throw_array_bounds
buzbee5bc5a7b2012-03-07 15:52:59 -0800530
Ian Rogers57b86d42012-03-27 16:05:41 -0700531 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100532 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
533 * as if thrown from a call to String.charAt().
534 */
535 .extern artThrowStringBoundsFromCode
536ENTRY art_quick_throw_string_bounds
537 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
538 la $t9, artThrowStringBoundsFromCode
539 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
540 move $a2, rSELF # pass Thread::Current
541END art_quick_throw_string_bounds
542
543 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700544 * Called by managed code to create and deliver a StackOverflowError.
545 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800546 .extern artThrowStackOverflowFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700547ENTRY art_quick_throw_stack_overflow
Ian Rogers57b86d42012-03-27 16:05:41 -0700548 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700549 la $t9, artThrowStackOverflowFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800550 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700551 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700552END art_quick_throw_stack_overflow
buzbee5bc5a7b2012-03-07 15:52:59 -0800553
Ian Rogers57b86d42012-03-27 16:05:41 -0700554 /*
555 * Called by managed code to create and deliver a NoSuchMethodError.
556 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800557 .extern artThrowNoSuchMethodFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700558ENTRY art_quick_throw_no_such_method
Ian Rogers57b86d42012-03-27 16:05:41 -0700559 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700560 la $t9, artThrowNoSuchMethodFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800561 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700562 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700563END art_quick_throw_no_such_method
buzbee5bc5a7b2012-03-07 15:52:59 -0800564
buzbee5bc5a7b2012-03-07 15:52:59 -0800565 /*
566 * All generated callsites for interface invokes and invocation slow paths will load arguments
jeffhao7fbee072012-08-24 17:56:54 -0700567 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100568 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
jeffhao7fbee072012-08-24 17:56:54 -0700569 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800570 *
jeffhao7fbee072012-08-24 17:56:54 -0700571 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
572 * of the target Method* in $v0 and method->code_ in $v1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800573 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700574 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
buzbee5bc5a7b2012-03-07 15:52:59 -0800575 * thread and we branch to another stub to deliver it.
576 *
577 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
578 * pointing back to the original caller.
579 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700580.macro INVOKE_TRAMPOLINE_BODY cxx_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800581 .extern \cxx_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700582 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100583 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100584 la $t9, \cxx_name
585 jalr $t9 # (method_idx, this, Thread*, $sp)
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100586 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
587 move $a0, $v0 # save target Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700588 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhaofa147e22012-10-12 17:03:32 -0700589 beqz $v0, 1f
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100590 move $t9, $v1 # save $v0->code_
Andreas Gampe8d365912015-01-13 11:32:32 -0800591 jalr $zero, $t9
buzbee5bc5a7b2012-03-07 15:52:59 -0800592 nop
5931:
594 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700595.endm
596.macro INVOKE_TRAMPOLINE c_name, cxx_name
597ENTRY \c_name
598 INVOKE_TRAMPOLINE_BODY \cxx_name
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800599END \c_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800600.endm
601
Logan Chien8dbb7082013-01-25 20:31:17 +0800602INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800603
Logan Chien8dbb7082013-01-25 20:31:17 +0800604INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
605INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
606INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
607INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800608
Goran Jakovljevicff734982015-08-24 12:58:55 +0000609.macro LOAD_WORD_TO_REG reg, next_arg, index, label
610 lw $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
611 b \label
612 addiu $\index, 1
613.endm
614
615.macro LOAD_LONG_TO_REG reg1, reg2, next_arg, index, label
616 lw $\reg1, -8($\next_arg) # next_arg points to argument after the current one (offset is 8)
617 lw $\reg2, -4($\next_arg)
618 b \label
619 li $\index, 4 # long can be loaded only to a2_a3 pair so index will be always 4
620.endm
621
622.macro LOAD_FLOAT_TO_REG reg, next_arg, index, label
623 lwc1 $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
624 b \label
625 addiu $\index, 1
626.endm
627
628.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index, tmp, label
629 LDu $\reg1, $\reg2, -8, $\next_arg, $\tmp # next_arg points to argument after the current one
630 # (offset is 8)
631 b \label
632 addiu $\index, 1
633.endm
634
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100635#define SPILL_SIZE 32
636
Jeff Hao79fe5392013-04-24 18:41:58 -0700637 /*
Ian Rogersef7d42f2014-01-06 12:55:46 -0800638 * Invocation stub for quick code.
Jeff Hao5d917302013-02-27 17:57:33 -0800639 * On entry:
640 * a0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700641 * a1 = argument array or null for no argument methods
Jeff Hao5d917302013-02-27 17:57:33 -0800642 * a2 = size of argument array in bytes
643 * a3 = (managed) thread pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700644 * [sp + 16] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800645 * [sp + 20] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800646 */
647ENTRY art_quick_invoke_stub
Jeff Hao5d917302013-02-27 17:57:33 -0800648 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100649 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
650 .cfi_adjust_cfa_offset SPILL_SIZE
651 sw $gp, 16($sp)
Jeff Hao5d917302013-02-27 17:57:33 -0800652 sw $ra, 12($sp)
653 .cfi_rel_offset 31, 12
654 sw $fp, 8($sp)
655 .cfi_rel_offset 30, 8
656 sw $s1, 4($sp)
657 .cfi_rel_offset 17, 4
658 sw $s0, 0($sp)
659 .cfi_rel_offset 16, 0
660 move $fp, $sp # save sp in fp
661 .cfi_def_cfa_register 30
662 move $s1, $a3 # move managed thread pointer into s1
663 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
Goran Jakovljevicff734982015-08-24 12:58:55 +0000664 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700665 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
Goran Jakovljevicff734982015-08-24 12:58:55 +0000666 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
667 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
668 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100669 la $t9, memcpy
670 jalr $t9 # (dest, src, bytes)
Jeff Hao5d917302013-02-27 17:57:33 -0800671 addiu $sp, $sp, -16 # make space for argument slots for memcpy
672 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100673 lw $gp, 16($fp) # restore $gp
674 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000675 lw $a1, 4($sp) # a1 = this*
676 addiu $t0, $sp, 8 # t0 = pointer to the current argument (skip ArtMethod* and this*)
677 li $t3, 2 # t3 = gpr_index = 2 (skip A0 and A1)
678 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100679 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
680 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000681 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
682loop:
683 lbu $t2, 0($t1) # t2 = shorty[i]
684 beqz $t2, loopEnd # finish getting args when shorty[i] == '\0'
685 addiu $t1, 1
686
687 li $t9, 'J' # put char 'J' into t9
688 beq $t9, $t2, isLong # branch if result type char == 'J'
689 li $t9, 'D' # put char 'D' into t9
690 beq $t9, $t2, isDouble # branch if result type char == 'D'
691 li $t9, 'F' # put char 'F' into t9
692 beq $t9, $t2, isSingle # branch if result type char == 'F'
693 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
694 # for both, int and single)
695
696 li $t5, 2 # skip a0 and a1 (ArtMethod* and this*)
697 bne $t5, $t3, 1f # if (gpr_index == 2)
698 addiu $t5, 1
699 LOAD_WORD_TO_REG a2, t0, t3, loop # a2 = current argument, gpr_index++
7001: bne $t5, $t3, loop # else if (gpr_index == 3)
701 nop
702 LOAD_WORD_TO_REG a3, t0, t3, loop # a3 = current argument, gpr_index++
703
704isLong:
705 addiu $t0, 8 # next_arg = curr_arg + 8
706 slti $t5, $t3, 3
707 beqz $t5, 2f # if (gpr_index < 3)
708 nop
709 LOAD_LONG_TO_REG a2, a3, t0, t3, loop # a2_a3 = curr_arg, gpr_index = 4
7102: b loop # else
711 li $t3, 4 # gpr_index = 4
712
713isDouble:
714 addiu $t0, 8 # next_arg = curr_arg + 8
715 li $t5, 0
716 bne $t5, $t4, 3f # if (fp_index == 0)
717 addiu $t5, 1
718 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loop # f12_f13 = curr_arg, fp_index++
7193: bne $t5, $t4, loop # else if (fp_index == 1)
720 nop
721 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loop # f14_f15 = curr_arg, fp_index++
722
723isSingle:
724 li $t5, 0
725 bne $t5, $t4, 4f # if (fp_index == 0)
726 addiu $t5, 1
727 LOAD_FLOAT_TO_REG f12, t0, t4, loop # f12 = curr_arg, fp_index++
7284: bne $t5, $t4, loop # else if (fp_index == 1)
729 nop
730 LOAD_FLOAT_TO_REG f14, t0, t4, loop # f14 = curr_arg, fp_index++
731
732loopEnd:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700733 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800734 jalr $t9 # call the method
Goran Jakovljevicff734982015-08-24 12:58:55 +0000735 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
Jeff Hao5d917302013-02-27 17:57:33 -0800736 move $sp, $fp # restore the stack
737 lw $s0, 0($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800738 .cfi_restore 16
Jeff Hao5d917302013-02-27 17:57:33 -0800739 lw $s1, 4($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800740 .cfi_restore 17
Jeff Hao5d917302013-02-27 17:57:33 -0800741 lw $fp, 8($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800742 .cfi_restore 30
Jeff Hao5d917302013-02-27 17:57:33 -0800743 lw $ra, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800744 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100745 addiu $sp, $sp, SPILL_SIZE
746 .cfi_adjust_cfa_offset -SPILL_SIZE
Jeff Hao5d917302013-02-27 17:57:33 -0800747 lw $t0, 16($sp) # get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800748 lw $t1, 20($sp) # get shorty
749 lb $t1, 0($t1) # get result type char
Goran Jakovljevicff734982015-08-24 12:58:55 +0000750 li $t2, 'D' # put char 'D' into t2
751 beq $t1, $t2, 5f # branch if result type char == 'D'
752 li $t3, 'F' # put char 'F' into t3
753 beq $t1, $t3, 5f # branch if result type char == 'F'
Jeff Hao5d917302013-02-27 17:57:33 -0800754 sw $v0, 0($t0) # store the result
Andreas Gampe8d365912015-01-13 11:32:32 -0800755 jalr $zero, $ra
Jeff Hao5d917302013-02-27 17:57:33 -0800756 sw $v1, 4($t0) # store the other half of the result
Goran Jakovljevicff734982015-08-24 12:58:55 +00007575:
Duane Sande34652f2014-11-04 11:09:36 -0800758 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
Andreas Gampe8d365912015-01-13 11:32:32 -0800759 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -0800760 nop
Jeff Hao5d917302013-02-27 17:57:33 -0800761END art_quick_invoke_stub
762
763 /*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000764 * Invocation static stub for quick code.
765 * On entry:
766 * a0 = method pointer
767 * a1 = argument array or null for no argument methods
768 * a2 = size of argument array in bytes
769 * a3 = (managed) thread pointer
770 * [sp + 16] = JValue* result
771 * [sp + 20] = shorty
772 */
773ENTRY art_quick_invoke_static_stub
774 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100775 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
776 .cfi_adjust_cfa_offset SPILL_SIZE
777 sw $gp, 16($sp)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000778 sw $ra, 12($sp)
779 .cfi_rel_offset 31, 12
780 sw $fp, 8($sp)
781 .cfi_rel_offset 30, 8
782 sw $s1, 4($sp)
783 .cfi_rel_offset 17, 4
784 sw $s0, 0($sp)
785 .cfi_rel_offset 16, 0
786 move $fp, $sp # save sp in fp
787 .cfi_def_cfa_register 30
788 move $s1, $a3 # move managed thread pointer into s1
789 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
790 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
791 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
792 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
793 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
794 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100795 la $t9, memcpy
796 jalr $t9 # (dest, src, bytes)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000797 addiu $sp, $sp, -16 # make space for argument slots for memcpy
798 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100799 lw $gp, 16($fp) # restore $gp
800 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000801 addiu $t0, $sp, 4 # t0 = pointer to the current argument (skip ArtMethod*)
802 li $t3, 1 # t3 = gpr_index = 1 (skip A0)
803 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100804 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
805 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000806 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
807loopS:
808 lbu $t2, 0($t1) # t2 = shorty[i]
809 beqz $t2, loopEndS # finish getting args when shorty[i] == '\0'
810 addiu $t1, 1
811
812 li $t9, 'J' # put char 'J' into t9
813 beq $t9, $t2, isLongS # branch if result type char == 'J'
814 li $t9, 'D' # put char 'D' into t9
815 beq $t9, $t2, isDoubleS # branch if result type char == 'D'
816 li $t9, 'F' # put char 'F' into t9
817 beq $t9, $t2, isSingleS # branch if result type char == 'F'
818 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
819 # for both, int and single)
820
821 li $t5, 1 # skip a0 (ArtMethod*)
822 bne $t5, $t3, 1f # if (gpr_index == 1)
823 addiu $t5, 1
824 LOAD_WORD_TO_REG a1, t0, t3, loopS # a1 = current argument, gpr_index++
8251: bne $t5, $t3, 2f # else if (gpr_index == 2)
826 addiu $t5, 1
827 LOAD_WORD_TO_REG a2, t0, t3, loopS # a2 = current argument, gpr_index++
8282: bne $t5, $t3, loopS # else if (gpr_index == 3)
829 nop
830 LOAD_WORD_TO_REG a3, t0, t3, loopS # a3 = current argument, gpr_index++
831
832isLongS:
833 addiu $t0, 8 # next_arg = curr_arg + 8
834 slti $t5, $t3, 3
835 beqz $t5, 3f # if (gpr_index < 3)
836 nop
837 LOAD_LONG_TO_REG a2, a3, t0, t3, loopS # a2_a3 = curr_arg, gpr_index = 4
8383: b loopS # else
839 li $t3, 4 # gpr_index = 4
840
841isDoubleS:
842 addiu $t0, 8 # next_arg = curr_arg + 8
843 li $t5, 0
844 bne $t5, $t4, 4f # if (fp_index == 0)
845 addiu $t5, 1
846 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loopS # f12_f13 = curr_arg, fp_index++
8474: bne $t5, $t4, loopS # else if (fp_index == 1)
848 nop
849 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loopS # f14_f15 = curr_arg, fp_index++
850
851isSingleS:
852 li $t5, 0
853 bne $t5, $t4, 5f # if (fp_index == 0)
854 addiu $t5, 1
855 LOAD_FLOAT_TO_REG f12, t0, t4, loopS # f12 = curr_arg, fp_index++
8565: bne $t5, $t4, loopS # else if (fp_index == 1)
857 nop
858 LOAD_FLOAT_TO_REG f14, t0, t4, loopS # f14 = curr_arg, fp_index++
859
860loopEndS:
861 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
862 jalr $t9 # call the method
863 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
864 move $sp, $fp # restore the stack
865 lw $s0, 0($sp)
866 .cfi_restore 16
867 lw $s1, 4($sp)
868 .cfi_restore 17
869 lw $fp, 8($sp)
870 .cfi_restore 30
871 lw $ra, 12($sp)
872 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100873 addiu $sp, $sp, SPILL_SIZE
874 .cfi_adjust_cfa_offset -SPILL_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +0000875 lw $t0, 16($sp) # get result pointer
876 lw $t1, 20($sp) # get shorty
877 lb $t1, 0($t1) # get result type char
878 li $t2, 'D' # put char 'D' into t2
879 beq $t1, $t2, 6f # branch if result type char == 'D'
880 li $t3, 'F' # put char 'F' into t3
881 beq $t1, $t3, 6f # branch if result type char == 'F'
882 sw $v0, 0($t0) # store the result
883 jalr $zero, $ra
884 sw $v1, 4($t0) # store the other half of the result
8856:
886 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
887 jalr $zero, $ra
888 nop
889END art_quick_invoke_static_stub
890
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100891#undef SPILL_SIZE
892
Goran Jakovljevicff734982015-08-24 12:58:55 +0000893 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800894 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
895 * failure.
896 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800897 .extern artHandleFillArrayDataFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700898ENTRY art_quick_handle_fill_data
Douglas Leung735b8552014-10-31 12:21:40 -0700899 lw $a2, 0($sp) # pass referrer's Method*
900 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100901 la $t9, artHandleFillArrayDataFromCode
902 jalr $t9 # (payload offset, Array*, method, Thread*)
Ian Rogers832336b2014-10-08 15:35:22 -0700903 move $a3, rSELF # pass Thread::Current
jeffhaofc6a30e2012-10-18 18:24:15 -0700904 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700905END art_quick_handle_fill_data
buzbee5bc5a7b2012-03-07 15:52:59 -0800906
buzbee5bc5a7b2012-03-07 15:52:59 -0800907 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700908 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
buzbee5bc5a7b2012-03-07 15:52:59 -0800909 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800910 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700911ENTRY art_quick_lock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -0800912 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700913 nop
Douglas Leung735b8552014-10-31 12:21:40 -0700914 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100915 la $t9, artLockObjectFromCode
916 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700917 move $a1, rSELF # pass Thread::Current
Ian Rogers6bcd1632013-10-08 18:50:47 -0700918 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700919END art_quick_lock_object
buzbee5bc5a7b2012-03-07 15:52:59 -0800920
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700921ENTRY art_quick_lock_object_no_inline
922 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
923 nop
924 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
925 la $t9, artLockObjectFromCode
926 jalr $t9 # (Object* obj, Thread*)
927 move $a1, rSELF # pass Thread::Current
928 RETURN_IF_ZERO
929END art_quick_lock_object_no_inline
930
buzbee5bc5a7b2012-03-07 15:52:59 -0800931 /*
932 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
933 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800934 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700935ENTRY art_quick_unlock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -0800936 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700937 nop
Douglas Leung735b8552014-10-31 12:21:40 -0700938 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100939 la $t9, artUnlockObjectFromCode
940 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700941 move $a1, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800942 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700943END art_quick_unlock_object
buzbee5bc5a7b2012-03-07 15:52:59 -0800944
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700945ENTRY art_quick_unlock_object_no_inline
946 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
947 nop
948 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
949 la $t9, artUnlockObjectFromCode
950 jalr $t9 # (Object* obj, Thread*)
951 move $a1, rSELF # pass Thread::Current
952 RETURN_IF_ZERO
953END art_quick_unlock_object_no_inline
954
buzbee5bc5a7b2012-03-07 15:52:59 -0800955 /*
956 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
957 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700958 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700959ENTRY art_quick_check_cast
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100960 addiu $sp, $sp, -32
961 .cfi_adjust_cfa_offset 32
962 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -0700963 sw $ra, 12($sp)
964 .cfi_rel_offset 31, 12
965 sw $t9, 8($sp)
966 sw $a1, 4($sp)
967 sw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100968 la $t9, artIsAssignableFromCode
969 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -0700970 addiu $sp, $sp, -16 # reserve argument slots on the stack
971 addiu $sp, $sp, 16
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100972 lw $gp, 16($sp)
Ian Rogers86bcdc22014-02-21 22:06:38 -0800973 beqz $v0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700974 lw $ra, 12($sp)
Andreas Gampe8d365912015-01-13 11:32:32 -0800975 jalr $zero, $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100976 addiu $sp, $sp, 32
977 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -0800978.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700979 lw $t9, 8($sp)
980 lw $a1, 4($sp)
981 lw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100982 addiu $sp, $sp, 32
983 .cfi_adjust_cfa_offset -32
Ian Rogersa9a82542013-10-04 11:17:26 -0700984 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -0700985 la $t9, artThrowClassCastException
Andreas Gampe8d365912015-01-13 11:32:32 -0800986 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700987 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700988END art_quick_check_cast
buzbee5bc5a7b2012-03-07 15:52:59 -0800989
buzbee5bc5a7b2012-03-07 15:52:59 -0800990 /*
Man Cao1aee9002015-07-14 22:31:42 -0700991 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
992 * nReg is the register number for rReg.
993 */
994.macro POP_REG_NE rReg, nReg, offset, rExclude
995 .ifnc \rReg, \rExclude
996 lw \rReg, \offset($sp) # restore rReg
997 .cfi_restore \nReg
998 .endif
999.endm
1000
1001 /*
1002 * Macro to insert read barrier, only used in art_quick_aput_obj.
1003 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1004 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1005 */
1006.macro READ_BARRIER rDest, rObj, offset
1007#ifdef USE_READ_BARRIER
1008 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
1009 addiu $sp, $sp, -32
1010 .cfi_adjust_cfa_offset 32
1011 sw $ra, 28($sp)
1012 .cfi_rel_offset 31, 28
1013 sw $t9, 24($sp)
1014 .cfi_rel_offset 25, 24
1015 sw $t1, 20($sp)
1016 .cfi_rel_offset 9, 20
1017 sw $t0, 16($sp)
1018 .cfi_rel_offset 8, 16
1019 sw $a2, 8($sp) # padding slot at offset 12 (padding can be any slot in the 32B)
1020 .cfi_rel_offset 6, 8
1021 sw $a1, 4($sp)
1022 .cfi_rel_offset 5, 4
1023 sw $a0, 0($sp)
1024 .cfi_rel_offset 4, 0
1025
Man Cao63069212015-08-21 15:51:39 -07001026 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001027 .ifnc \rObj, $a1
1028 move $a1, \rObj # pass rObj
1029 .endif
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001030 addiu $a2, $zero, \offset # pass offset
1031 la $t9, artReadBarrierSlow
1032 jalr $t9 # artReadBarrierSlow(ref, rObj, offset)
Man Cao1aee9002015-07-14 22:31:42 -07001033 addiu $sp, $sp, -16 # Use branch delay slot to reserve argument slots on the stack
1034 # before the call to artReadBarrierSlow.
1035 addiu $sp, $sp, 16 # restore stack after call to artReadBarrierSlow
1036 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1037 move \rDest, $v0 # save return value in rDest
1038 # (rDest cannot be v0 in art_quick_aput_obj)
1039
1040 lw $a0, 0($sp) # restore registers except rDest
1041 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1042 .cfi_restore 4
1043 lw $a1, 4($sp)
1044 .cfi_restore 5
1045 lw $a2, 8($sp)
1046 .cfi_restore 6
1047 POP_REG_NE $t0, 8, 16, \rDest
1048 POP_REG_NE $t1, 9, 20, \rDest
1049 lw $t9, 24($sp)
1050 .cfi_restore 25
1051 lw $ra, 28($sp) # restore $ra
1052 .cfi_restore 31
1053 addiu $sp, $sp, 32
1054 .cfi_adjust_cfa_offset -32
1055#else
1056 lw \rDest, \offset(\rObj)
1057 UNPOISON_HEAP_REF \rDest
1058#endif // USE_READ_BARRIER
1059.endm
1060
1061 /*
Ian Rogersa9a82542013-10-04 11:17:26 -07001062 * Entry from managed code for array put operations of objects where the value being stored
1063 * needs to be checked for compatibility.
1064 * a0 = array, a1 = index, a2 = value
buzbee5bc5a7b2012-03-07 15:52:59 -08001065 */
Ian Rogersa9a82542013-10-04 11:17:26 -07001066ENTRY art_quick_aput_obj_with_null_and_bound_check
Ian Rogers86bcdc22014-02-21 22:06:38 -08001067 bnez $a0, .Lart_quick_aput_obj_with_bound_check_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001068 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001069 b .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001070 nop
1071END art_quick_aput_obj_with_null_and_bound_check
1072
1073ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001074 lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001075 sltu $t1, $a1, $t0
Ian Rogers86bcdc22014-02-21 22:06:38 -08001076 bnez $t1, .Lart_quick_aput_obj_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001077 nop
1078 move $a0, $a1
Ian Rogers86bcdc22014-02-21 22:06:38 -08001079 b .Lart_quick_throw_array_bounds_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001080 move $a1, $t0
1081END art_quick_aput_obj_with_bound_check
1082
Man Cao1aee9002015-07-14 22:31:42 -07001083#ifdef USE_READ_BARRIER
1084 .extern artReadBarrierSlow
1085#endif
Ian Rogersa9a82542013-10-04 11:17:26 -07001086ENTRY art_quick_aput_obj
Ian Rogers86bcdc22014-02-21 22:06:38 -08001087 beqz $a2, .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -07001088 nop
Man Cao1aee9002015-07-14 22:31:42 -07001089 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1090 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1091 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogers86bcdc22014-02-21 22:06:38 -08001092 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
Ian Rogersa9a82542013-10-04 11:17:26 -07001093 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001094.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -07001095 sll $a1, $a1, 2
1096 add $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001097 POISON_HEAP_REF $a2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001098 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001099 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1100 srl $t1, $a0, 7
1101 add $t1, $t1, $t0
1102 sb $t0, ($t1)
Andreas Gampe8d365912015-01-13 11:32:32 -08001103 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001104 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001105.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -07001106 sll $a1, $a1, 2
1107 add $t0, $a0, $a1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001108 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Andreas Gampe8d365912015-01-13 11:32:32 -08001109 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001110 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001111.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -07001112 addiu $sp, $sp, -32
1113 .cfi_adjust_cfa_offset 32
1114 sw $ra, 28($sp)
1115 .cfi_rel_offset 31, 28
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001116 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001117 sw $t9, 12($sp)
1118 sw $a2, 8($sp)
1119 sw $a1, 4($sp)
1120 sw $a0, 0($sp)
1121 move $a1, $t1
1122 move $a0, $t0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001123 la $t9, artIsAssignableFromCode
1124 jalr $t9 # (Class*, Class*)
1125 addiu $sp, $sp, -16 # reserve argument slots on the stack
1126 addiu $sp, $sp, 16
Ian Rogersa9a82542013-10-04 11:17:26 -07001127 lw $ra, 28($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001128 lw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001129 lw $t9, 12($sp)
1130 lw $a2, 8($sp)
1131 lw $a1, 4($sp)
1132 lw $a0, 0($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001133 addiu $sp, 32
Ian Rogersa9a82542013-10-04 11:17:26 -07001134 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001135 bnez $v0, .Ldo_aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001136 nop
1137 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1138 move $a1, $a2
Ian Rogersa9a82542013-10-04 11:17:26 -07001139 la $t9, artThrowArrayStoreException
Andreas Gampe8d365912015-01-13 11:32:32 -08001140 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001141 move $a2, rSELF # pass Thread::Current
Ian Rogersa9a82542013-10-04 11:17:26 -07001142END art_quick_aput_obj
buzbee5bc5a7b2012-03-07 15:52:59 -08001143
buzbee5bc5a7b2012-03-07 15:52:59 -08001144 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001145 * Called by managed code to resolve a static field and load a boolean primitive value.
1146 */
1147 .extern artGetBooleanStaticFromCode
1148ENTRY art_quick_get_boolean_static
Douglas Leung735b8552014-10-31 12:21:40 -07001149 lw $a1, 0($sp) # pass referrer's Method*
1150 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001151 la $t9, artGetBooleanStaticFromCode
1152 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001153 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001154 RETURN_IF_NO_EXCEPTION
1155END art_quick_get_boolean_static
1156 /*
1157 * Called by managed code to resolve a static field and load a byte primitive value.
1158 */
1159 .extern artGetByteStaticFromCode
1160ENTRY art_quick_get_byte_static
Douglas Leung735b8552014-10-31 12:21:40 -07001161 lw $a1, 0($sp) # pass referrer's Method*
1162 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001163 la $t9, artGetByteStaticFromCode
1164 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001165 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001166 RETURN_IF_NO_EXCEPTION
1167END art_quick_get_byte_static
1168
1169 /*
1170 * Called by managed code to resolve a static field and load a char primitive value.
1171 */
1172 .extern artGetCharStaticFromCode
1173ENTRY art_quick_get_char_static
Douglas Leung735b8552014-10-31 12:21:40 -07001174 lw $a1, 0($sp) # pass referrer's Method*
1175 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001176 la $t9, artGetCharStaticFromCode
1177 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001178 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001179 RETURN_IF_NO_EXCEPTION
1180END art_quick_get_char_static
1181 /*
1182 * Called by managed code to resolve a static field and load a short primitive value.
1183 */
1184 .extern artGetShortStaticFromCode
1185ENTRY art_quick_get_short_static
Douglas Leung735b8552014-10-31 12:21:40 -07001186 lw $a1, 0($sp) # pass referrer's Method*
1187 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001188 la $t9, artGetShortStaticFromCode
1189 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001190 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001191 RETURN_IF_NO_EXCEPTION
1192END art_quick_get_short_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001193
buzbee5bc5a7b2012-03-07 15:52:59 -08001194 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001195 * Called by managed code to resolve a static field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001196 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001197 .extern artGet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001198ENTRY art_quick_get32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001199 lw $a1, 0($sp) # pass referrer's Method*
1200 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001201 la $t9, artGet32StaticFromCode
1202 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001203 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001204 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001205END art_quick_get32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001206
buzbee5bc5a7b2012-03-07 15:52:59 -08001207 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001208 * Called by managed code to resolve a static field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001209 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001210 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001211ENTRY art_quick_get64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001212 lw $a1, 0($sp) # pass referrer's Method*
1213 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001214 la $t9, artGet64StaticFromCode
1215 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001216 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001217 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001218END art_quick_get64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001219
buzbee5bc5a7b2012-03-07 15:52:59 -08001220 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001221 * Called by managed code to resolve a static field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001222 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001223 .extern artGetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001224ENTRY art_quick_get_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001225 lw $a1, 0($sp) # pass referrer's Method*
1226 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001227 la $t9, artGetObjStaticFromCode
1228 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001229 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001230 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001231END art_quick_get_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001232
buzbee5bc5a7b2012-03-07 15:52:59 -08001233 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001234 * Called by managed code to resolve an instance field and load a boolean primitive value.
1235 */
1236 .extern artGetBooleanInstanceFromCode
1237ENTRY art_quick_get_boolean_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001238 lw $a2, 0($sp) # pass referrer's Method*
1239 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001240 la $t9, artGetBooleanInstanceFromCode
1241 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001242 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001243 RETURN_IF_NO_EXCEPTION
1244END art_quick_get_boolean_instance
1245 /*
1246 * Called by managed code to resolve an instance field and load a byte primitive value.
1247 */
1248 .extern artGetByteInstanceFromCode
1249ENTRY art_quick_get_byte_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001250 lw $a2, 0($sp) # pass referrer's Method*
1251 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001252 la $t9, artGetByteInstanceFromCode
1253 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001254 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001255 RETURN_IF_NO_EXCEPTION
1256END art_quick_get_byte_instance
1257
1258 /*
1259 * Called by managed code to resolve an instance field and load a char primitive value.
1260 */
1261 .extern artGetCharInstanceFromCode
1262ENTRY art_quick_get_char_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001263 lw $a2, 0($sp) # pass referrer's Method*
1264 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001265 la $t9, artGetCharInstanceFromCode
1266 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001267 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001268 RETURN_IF_NO_EXCEPTION
1269END art_quick_get_char_instance
1270 /*
1271 * Called by managed code to resolve an instance field and load a short primitive value.
1272 */
1273 .extern artGetShortInstanceFromCode
1274ENTRY art_quick_get_short_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001275 lw $a2, 0($sp) # pass referrer's Method*
1276 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001277 la $t9, artGetShortInstanceFromCode
1278 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001279 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001280 RETURN_IF_NO_EXCEPTION
1281END art_quick_get_short_instance
1282
1283 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001284 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001285 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001286 .extern artGet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001287ENTRY art_quick_get32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001288 lw $a2, 0($sp) # pass referrer's Method*
1289 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001290 la $t9, artGet32InstanceFromCode
1291 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001292 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001293 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001294END art_quick_get32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001295
buzbee5bc5a7b2012-03-07 15:52:59 -08001296 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001297 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001298 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001299 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001300ENTRY art_quick_get64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001301 lw $a2, 0($sp) # pass referrer's Method*
1302 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001303 la $t9, artGet64InstanceFromCode
1304 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001305 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001306 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001307END art_quick_get64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001308
buzbee5bc5a7b2012-03-07 15:52:59 -08001309 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001310 * Called by managed code to resolve an instance field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001311 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001312 .extern artGetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001313ENTRY art_quick_get_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001314 lw $a2, 0($sp) # pass referrer's Method*
1315 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001316 la $t9, artGetObjInstanceFromCode
1317 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001318 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001319 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001320END art_quick_get_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001321
buzbee5bc5a7b2012-03-07 15:52:59 -08001322 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001323 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1324 */
1325 .extern artSet8StaticFromCode
1326ENTRY art_quick_set8_static
Douglas Leung735b8552014-10-31 12:21:40 -07001327 lw $a2, 0($sp) # pass referrer's Method*
1328 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001329 la $t9, artSet8StaticFromCode
1330 jalr $t9 # (field_idx, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001331 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001332 RETURN_IF_ZERO
1333END art_quick_set8_static
1334
1335 /*
1336 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1337 */
1338 .extern artSet16StaticFromCode
1339ENTRY art_quick_set16_static
Douglas Leung735b8552014-10-31 12:21:40 -07001340 lw $a2, 0($sp) # pass referrer's Method*
1341 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001342 la $t9, artSet16StaticFromCode
1343 jalr $t9 # (field_idx, new_val, referrer, Thread*, $sp)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001344 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001345 RETURN_IF_ZERO
1346END art_quick_set16_static
1347
1348 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001349 * Called by managed code to resolve a static field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001350 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001351 .extern artSet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001352ENTRY art_quick_set32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001353 lw $a2, 0($sp) # pass referrer's Method*
1354 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001355 la $t9, artSet32StaticFromCode
1356 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001357 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001358 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001359END art_quick_set32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001360
buzbee5bc5a7b2012-03-07 15:52:59 -08001361 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001362 * Called by managed code to resolve a static field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001363 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001364 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001365ENTRY art_quick_set64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001366 lw $a1, 0($sp) # pass referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001367 # 64 bit new_val is in a2:a3 pair
Douglas Leung735b8552014-10-31 12:21:40 -07001368 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001369 la $t9, artSet64StaticFromCode
1370 jalr $t9 # (field_idx, referrer, new_val, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001371 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001372 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001373END art_quick_set64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001374
buzbee5bc5a7b2012-03-07 15:52:59 -08001375 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001376 * Called by managed code to resolve a static field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001377 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001378 .extern artSetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001379ENTRY art_quick_set_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001380 lw $a2, 0($sp) # pass referrer's Method*
1381 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001382 la $t9, artSetObjStaticFromCode
1383 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001384 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001385 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001386END art_quick_set_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001387
buzbee5bc5a7b2012-03-07 15:52:59 -08001388 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001389 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1390 */
1391 .extern artSet8InstanceFromCode
1392ENTRY art_quick_set8_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001393 lw $a3, 0($sp) # pass referrer's Method*
1394 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001395 la $t9, artSet8InstanceFromCode
1396 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001397 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001398 RETURN_IF_ZERO
1399END art_quick_set8_instance
1400
1401 /*
1402 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1403 */
1404 .extern artSet16InstanceFromCode
1405ENTRY art_quick_set16_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001406 lw $a3, 0($sp) # pass referrer's Method*
1407 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001408 la $t9, artSet16InstanceFromCode
1409 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001410 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001411 RETURN_IF_ZERO
1412END art_quick_set16_instance
1413
1414 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001415 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001416 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001417 .extern artSet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001418ENTRY art_quick_set32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001419 lw $a3, 0($sp) # pass referrer's Method*
1420 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001421 la $t9, artSet32InstanceFromCode
1422 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001423 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001424 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001425END art_quick_set32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001426
buzbee5bc5a7b2012-03-07 15:52:59 -08001427 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001428 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001429 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001430 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001431ENTRY art_quick_set64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001432 lw $t1, 0($sp) # load referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001433 # 64 bit new_val is in a2:a3 pair
Douglas Leung735b8552014-10-31 12:21:40 -07001434 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001435 sw rSELF, 20($sp) # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001436 la $t9, artSet64InstanceFromCode
1437 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Douglas Leung735b8552014-10-31 12:21:40 -07001438 sw $t1, 16($sp) # pass referrer's Method*
buzbee5bc5a7b2012-03-07 15:52:59 -08001439 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001440END art_quick_set64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001441
buzbee5bc5a7b2012-03-07 15:52:59 -08001442 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001443 * Called by managed code to resolve an instance field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001444 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001445 .extern artSetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001446ENTRY art_quick_set_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001447 lw $a3, 0($sp) # pass referrer's Method*
1448 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001449 la $t9, artSetObjInstanceFromCode
1450 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001451 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001452 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001453END art_quick_set_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001454
Vladimir Markoa3c38272015-04-28 12:37:09 +01001455// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001456.macro ONE_ARG_DOWNCALL name, entrypoint, return
1457 .extern \entrypoint
1458ENTRY \name
1459 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001460 la $t9, \entrypoint
1461 jalr $t9
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001462 move $a1, rSELF # pass Thread::Current
1463 \return
1464END \name
1465.endm
1466
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001467.macro TWO_ARG_DOWNCALL name, entrypoint, return
1468 .extern \entrypoint
1469ENTRY \name
Douglas Leung735b8552014-10-31 12:21:40 -07001470 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001471 la $t9, \entrypoint
1472 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001473 move $a2, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001474 \return
1475END \name
1476.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001477
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001478.macro THREE_ARG_DOWNCALL name, entrypoint, return
1479 .extern \entrypoint
1480ENTRY \name
Douglas Leung735b8552014-10-31 12:21:40 -07001481 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001482 la $t9, \entrypoint
1483 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001484 move $a3, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001485 \return
1486END \name
1487.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001488
Jeff Hao848f70a2014-01-15 13:49:50 -08001489.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1490 .extern \entrypoint
1491ENTRY \name
Vladimir Markoa3c38272015-04-28 12:37:09 +01001492 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001493 la $t9, \entrypoint
1494 jalr $t9
Vladimir Markoa3c38272015-04-28 12:37:09 +01001495 sw rSELF, 16($sp) # pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -08001496 \return
1497END \name
1498.endm
1499
Mathieu Chartier7410f292013-11-24 13:17:35 -08001500// Generate the allocation entrypoints for each allocator.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001501GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001502
Pavle Batuta712c59d2015-12-02 18:39:01 +01001503// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1504ENTRY art_quick_alloc_object_rosalloc
1505
1506 # Fast path rosalloc allocation
1507 # a0: type_idx
1508 # a1: ArtMethod*
1509 # s1: Thread::Current
1510 # -----------------------------
1511 # t0: class
1512 # t1: object size
1513 # t2: rosalloc run
1514 # t3: thread stack top offset
1515 # t4: thread stack bottom offset
1516 # v0: free list head
1517 #
1518 # t5, t6 : temps
1519
1520 lw $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_32($a1) # Load dex cache resolved types
1521 # array.
1522
1523 sll $t5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1524 addu $t5, $t0, $t5 # Compute the index.
1525 lw $t0, 0($t5) # Load class (t0).
1526 beqz $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1527
1528 li $t6, MIRROR_CLASS_STATUS_INITIALIZED
1529 lw $t5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1530 bne $t5, $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1531
1532 # Add a fake dependence from the following access flag and size loads to the status load. This
1533 # is to prevent those loads from being reordered above the status load and reading wrong values.
1534 xor $t5, $t5, $t5
1535 addu $t0, $t0, $t5
1536
1537 lw $t5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1538 li $t6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1539 and $t6, $t5, $t6
1540 bnez $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1541
1542 lw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation
1543 lw $t4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # stack has any room left.
1544 bgeu $t3, $t4, .Lart_quick_alloc_object_rosalloc_slow_path
1545
1546 lw $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1547 li $t5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1548 # allocation.
1549 bgtu $t1, $t5, .Lart_quick_alloc_object_rosalloc_slow_path
1550
1551 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1552 # quantum size and divide by the quantum size and subtract by 1.
1553
1554 addiu $t1, $t1, -1 # Decrease obj size and shift right
1555 srl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # by quantum.
1556
1557 sll $t2, $t1, POINTER_SIZE_SHIFT
1558 addu $t2, $t2, $s1
1559 lw $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1560
1561 # Load the free list head (v0).
1562 # NOTE: this will be the return val.
1563
1564 lw $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1565 beqz $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1566 nop
1567
1568 # Load the next pointer of the head and update the list head with the next pointer.
1569
1570 lw $t5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1571 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1572
1573 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1574 # asserted to match.
1575
1576#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1577#error "Class pointer needs to overwrite next pointer."
1578#endif
1579
1580 POISON_HEAP_REF $t0
1581 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1582
1583 # Push the new object onto the thread local allocation stack and increment the thread local
1584 # allocation stack top.
1585
1586 sw $v0, 0($t3)
1587 addiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1588 sw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1589
1590 # Decrement the size of the free list.
1591
1592 lw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1593 addiu $t5, $t5, -1
1594 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1595
1596 sync # Fence.
1597
1598 jalr $zero, $ra
1599 nop
1600
1601 .Lart_quick_alloc_object_rosalloc_slow_path:
1602
1603 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001604 la $t9, artAllocObjectFromCodeRosAlloc
1605 jalr $t9
Chris Larsencf283da2016-01-19 16:45:35 -08001606 move $a2, $s1 # Pass self as argument.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001607 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1608
1609END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001610
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001611GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1612GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1613
buzbee5bc5a7b2012-03-07 15:52:59 -08001614 /*
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001615 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001616 * exception on error. On success the String is returned. A0 holds the string index. The fast
1617 * path check for hit in strings cache has already been performed.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001618 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001619ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001620
1621 /*
1622 * Entry from managed code when uninitialized static storage, this stub will run the class
1623 * initializer and deliver the exception on error. On success the static storage base is
1624 * returned.
1625 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001626ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001627
1628 /*
1629 * Entry from managed code when dex cache misses for a type_idx.
1630 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001631ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001632
1633 /*
1634 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1635 * miss.
1636 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001637ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001638
1639 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001640 * Called by managed code when the value in rSUSPEND has been decremented to 0.
buzbee5bc5a7b2012-03-07 15:52:59 -08001641 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001642 .extern artTestSuspendFromCode
1643ENTRY art_quick_test_suspend
Ian Rogers474b6da2012-09-25 00:20:38 -07001644 lh $a0, THREAD_FLAGS_OFFSET(rSELF)
jeffhao7fbee072012-08-24 17:56:54 -07001645 bnez $a0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001646 addiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Andreas Gampe8d365912015-01-13 11:32:32 -08001647 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -08001648 nop
16491:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001650 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves for stack crawl
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001651 la $t9, artTestSuspendFromCode
1652 jalr $t9 # (Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001653 move $a0, rSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001654 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001655END art_quick_test_suspend
buzbee5bc5a7b2012-03-07 15:52:59 -08001656
buzbee5bc5a7b2012-03-07 15:52:59 -08001657 /*
1658 * Called by managed code that is attempting to call a method on a proxy class. On entry
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001659 * a0 holds the proxy method; a1, a2 and a3 may contain arguments.
buzbee5bc5a7b2012-03-07 15:52:59 -08001660 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001661 .extern artQuickProxyInvokeHandler
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001662ENTRY art_quick_proxy_invoke_handler
Douglas Leung735b8552014-10-31 12:21:40 -07001663 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1664 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001665 la $t9, artQuickProxyInvokeHandler
1666 jalr $t9 # (Method* proxy method, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001667 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
jeffhao7fbee072012-08-24 17:56:54 -07001668 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Douglas Leung735b8552014-10-31 12:21:40 -07001669 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -07001670 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001671 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1672 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001673 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001674 nop
buzbee5bc5a7b2012-03-07 15:52:59 -080016751:
1676 DELIVER_PENDING_EXCEPTION
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001677END art_quick_proxy_invoke_handler
buzbee5bc5a7b2012-03-07 15:52:59 -08001678
Jeff Hao88474b42013-10-23 16:24:40 -07001679 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001680 * Called to resolve an imt conflict.
1681 * a0 is the conflict ArtMethod.
1682 * t0 is a hidden argument that holds the target interface method's dex method index.
1683 *
1684 * Note that this stub writes to a0, t0 and t1.
Jeff Hao88474b42013-10-23 16:24:40 -07001685 */
Douglas Leung13738bf2014-10-27 14:44:47 -07001686ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001687 lw $t1, 0($sp) # Load referrer.
1688 lw $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_32($t1) # Load dex cache methods array.
1689 sll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1690 addu $t0, $t1, $t0 # Add offset to base.
1691 lw $t0, 0($t0) # Load interface method.
1692 lw $a0, ART_METHOD_JNI_OFFSET_32($a0) # Load ImtConflictTable.
1693
1694.Limt_table_iterate:
1695 lw $t1, 0($a0) # Load next entry in ImtConflictTable.
1696 # Branch if found.
1697 beq $t1, $t0, .Limt_table_found
1698 nop
1699 # If the entry is null, the interface method is not in the ImtConflictTable.
1700 beqz $t1, .Lconflict_trampoline
1701 nop
1702 # Iterate over the entries of the ImtConflictTable.
1703 b .Limt_table_iterate
1704 addiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1705
1706.Limt_table_found:
1707 # We successfully hit an entry in the table. Load the target method and jump to it.
1708 lw $a0, __SIZEOF_POINTER__($a0)
1709 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)
1710 jr $t9
1711 nop
1712
1713.Lconflict_trampoline:
1714 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001715 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001716END art_quick_imt_conflict_trampoline
1717
Ian Rogers468532e2013-08-05 10:56:33 -07001718 .extern artQuickResolutionTrampoline
1719ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001720 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001721 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001722 la $t9, artQuickResolutionTrampoline
1723 jalr $t9 # (Method* called, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001724 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers468532e2013-08-05 10:56:33 -07001725 beqz $v0, 1f
Douglas Leung735b8552014-10-31 12:21:40 -07001726 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001727 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers65d1b222013-09-27 10:59:41 -07001728 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001729 jalr $zero, $t9 # tail call to method
Mathieu Chartier19841522013-10-22 11:29:00 -07001730 nop
Ian Rogers468532e2013-08-05 10:56:33 -070017311:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001732 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001733 DELIVER_PENDING_EXCEPTION
1734END art_quick_resolution_trampoline
1735
Douglas Leung735b8552014-10-31 12:21:40 -07001736 .extern artQuickGenericJniTrampoline
1737 .extern artQuickGenericJniEndTrampoline
1738ENTRY art_quick_generic_jni_trampoline
1739 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1740 move $s8, $sp # save $sp to $s8
1741 move $s3, $gp # save $gp to $s3
1742
1743 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1744 move $a0, rSELF # pass Thread::Current
1745 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001746 la $t9, artQuickGenericJniTrampoline
1747 jalr $t9 # (Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001748 addiu $sp, $sp, -5120 # reserve space on the stack
1749
1750 # The C call will have registered the complete save-frame on success.
1751 # The result of the call is:
1752 # v0: ptr to native code, 0 on error.
1753 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1754 beq $v0, $zero, 1f # check entry error
1755 move $t9, $v0 # save the code ptr
1756 move $sp, $v1 # release part of the alloca
1757
1758 # Load parameters from stack into registers
1759 lw $a0, 0($sp)
1760 lw $a1, 4($sp)
1761 lw $a2, 8($sp)
1762
1763 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1764 jalr $t9 # native call
1765 lw $a3, 12($sp)
1766 addiu $sp, $sp, 16 # remove arg slots
1767
1768 move $gp, $s3 # restore $gp from $s3
1769
1770 # result sign extension is handled in C code
1771 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1772 move $a0, rSELF # pass Thread::Current
1773 move $a2, $v0 # pass result
1774 move $a3, $v1
1775 addiu $sp, $sp, -24 # reserve arg slots
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001776 la $t9, artQuickGenericJniEndTrampoline
1777 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07001778 s.d $f0, 16($sp) # pass result_f
Douglas Leung735b8552014-10-31 12:21:40 -07001779
1780 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001781 bne $t0, $zero, 1f # check for pending exceptions
1782
Douglas Leung735b8552014-10-31 12:21:40 -07001783 move $sp, $s8 # tear down the alloca
1784
1785 # tear dpown the callee-save frame
1786 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1787
Duane Sande34652f2014-11-04 11:09:36 -08001788 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001789 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001790 nop
Douglas Leung735b8552014-10-31 12:21:40 -07001791
17921:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001793 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
1794 # This will create a new save-all frame, required by the runtime.
Douglas Leung735b8552014-10-31 12:21:40 -07001795 DELIVER_PENDING_EXCEPTION
1796END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001797
Ian Rogers468532e2013-08-05 10:56:33 -07001798 .extern artQuickToInterpreterBridge
1799ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001800 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001801 move $a1, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001802 la $t9, artQuickToInterpreterBridge
1803 jalr $t9 # (Method* method, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001804 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers7db619b2013-01-16 18:35:48 -08001805 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Douglas Leung735b8552014-10-31 12:21:40 -07001806 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08001807 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001808 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1809 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001810 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001811 nop
Ian Rogers7db619b2013-01-16 18:35:48 -080018121:
1813 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001814END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001815
buzbee5bc5a7b2012-03-07 15:52:59 -08001816 /*
jeffhao725a9572012-11-13 18:20:12 -08001817 * Routine that intercepts method calls and returns.
buzbee5bc5a7b2012-03-07 15:52:59 -08001818 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001819 .extern artInstrumentationMethodEntryFromCode
1820 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001821ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001822 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001823 sw $a0, 28($sp) # save arg0 in free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001824 move $a3, $ra # pass $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001825 la $t9, artInstrumentationMethodEntryFromCode
1826 jalr $t9 # (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001827 move $a2, rSELF # pass Thread::Current
jeffhao8161c032012-10-31 15:50:00 -07001828 move $t9, $v0 # $t9 holds reference to code
Douglas Leung735b8552014-10-31 12:21:40 -07001829 lw $a0, 28($sp) # restore arg0 from free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001830 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -07001831 jalr $t9 # call method
Ian Rogers62d6c772013-02-27 08:32:07 -08001832 nop
Ian Rogers468532e2013-08-05 10:56:33 -07001833END art_quick_instrumentation_entry
buzbee5bc5a7b2012-03-07 15:52:59 -08001834 /* intentional fallthrough */
Ian Rogers468532e2013-08-05 10:56:33 -07001835 .global art_quick_instrumentation_exit
1836art_quick_instrumentation_exit:
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001837 .cfi_startproc
jeffhao12051ea2013-01-10 11:24:31 -08001838 addiu $t9, $ra, 4 # put current address into $t9 to rebuild $gp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001839 .cpload $t9
Douglas Leungc3d131e2014-07-16 17:32:41 -07001840 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Douglas Leung735b8552014-10-31 12:21:40 -07001841
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001842 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001843 addiu $sp, $sp, -16 # allocate temp storage on the stack
1844 .cfi_adjust_cfa_offset 16
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001845 sw $v0, ARG_SLOT_SIZE+12($sp)
1846 .cfi_rel_offset 2, ARG_SLOT_SIZE+12
1847 sw $v1, ARG_SLOT_SIZE+8($sp)
1848 .cfi_rel_offset 3, ARG_SLOT_SIZE+8
1849 s.d $f0, ARG_SLOT_SIZE($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001850 s.d $f0, 16($sp) # pass fpr result
Ian Rogers62d6c772013-02-27 08:32:07 -08001851 move $a2, $v0 # pass gpr result
1852 move $a3, $v1
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001853 addiu $a1, $sp, ARG_SLOT_SIZE+16 # pass $sp (remove arg slots and temp storage)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001854 la $t9, artInstrumentationMethodExitFromCode
1855 jalr $t9 # (Thread*, SP, gpr_res, fpr_res)
jeffhao12051ea2013-01-10 11:24:31 -08001856 move $a0, rSELF # pass Thread::Current
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001857 move $t9, $v0 # set aside returned link register
jeffhao12051ea2013-01-10 11:24:31 -08001858 move $ra, $v1 # set link register for deoptimization
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001859 lw $v0, ARG_SLOT_SIZE+12($sp) # restore return values
1860 lw $v1, ARG_SLOT_SIZE+8($sp)
1861 l.d $f0, ARG_SLOT_SIZE($sp)
1862 jalr $zero, $t9 # return
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001863 addiu $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16 # restore stack
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001864 .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16)
Ian Rogers468532e2013-08-05 10:56:33 -07001865END art_quick_instrumentation_exit
buzbee5bc5a7b2012-03-07 15:52:59 -08001866
jeffhao12051ea2013-01-10 11:24:31 -08001867 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001868 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1869 * will long jump to the upcall with a special exception of -1.
jeffhao12051ea2013-01-10 11:24:31 -08001870 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001871 .extern artDeoptimize
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001872ENTRY art_quick_deoptimize
Jeff Hao14dd5a82013-04-11 10:23:36 -07001873 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001874 la $t9, artDeoptimize
1875 jalr $t9 # artDeoptimize(Thread*)
jeffhao12051ea2013-01-10 11:24:31 -08001876 # Returns caller method's frame size.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001877 move $a0, rSELF # pass Thread::current
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001878END art_quick_deoptimize
jeffhao12051ea2013-01-10 11:24:31 -08001879
buzbee5bc5a7b2012-03-07 15:52:59 -08001880 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001881 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
1882 * will long jump to the upcall with a special exception of -1.
1883 */
1884 .extern artDeoptimizeFromCompiledCode
1885ENTRY art_quick_deoptimize_from_compiled_code
1886 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001887 la $t9, artDeoptimizeFromCompiledCode
1888 jalr $t9 # artDeoptimizeFromCompiledCode(Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00001889 # Returns caller method's frame size.
1890 move $a0, rSELF # pass Thread::current
1891END art_quick_deoptimize_from_compiled_code
1892
1893 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08001894 * Long integer shift. This is different from the generic 32/64-bit
1895 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1896 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1897 * 6 bits.
1898 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07001899 * $a0: low word
1900 * $a1: high word
1901 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08001902 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001903ENTRY_NO_GP art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001904 /* shl-long vAA, vBB, vCC */
jeffhao7fbee072012-08-24 17:56:54 -07001905 sll $v0, $a0, $a2 # rlo<- alo << (shift&31)
1906 not $v1, $a2 # rhi<- 31-shift (shift is 5b)
1907 srl $a0, 1
1908 srl $a0, $v1 # alo<- alo >> (32-(shift&31))
1909 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001910 andi $a2, 0x20 # shift< shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08001911 beqz $a2, 1f
1912 or $v1, $a0 # rhi<- rhi | alo
1913
1914 move $v1, $v0 # rhi<- rlo (if shift&0x20)
1915 move $v0, $zero # rlo<- 0 (if shift&0x20)
1916
Andreas Gampe8d365912015-01-13 11:32:32 -080019171: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001918 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001919END art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001920
buzbee5bc5a7b2012-03-07 15:52:59 -08001921 /*
1922 * Long integer shift. This is different from the generic 32/64-bit
1923 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1924 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1925 * 6 bits.
1926 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07001927 * $a0: low word
1928 * $a1: high word
1929 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08001930 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001931ENTRY_NO_GP art_quick_shr_long
jeffhao7fbee072012-08-24 17:56:54 -07001932 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
1933 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
1934 sra $a3, $a1, 31 # $a3<- sign(ah)
1935 not $a0, $a2 # alo<- 31-shift (shift is 5b)
1936 sll $a1, 1
1937 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07001938 andi $a2, 0x20 # shift & 0x20
Douglas Leung475cfd82014-12-16 20:15:41 -08001939 beqz $a2, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001940 or $v0, $a1 # rlo<- rlo | ahi
1941
1942 move $v0, $v1 # rlo<- rhi (if shift&0x20)
1943 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20)
1944
Andreas Gampe8d365912015-01-13 11:32:32 -080019451: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001946 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001947END art_quick_shr_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001948
buzbee5bc5a7b2012-03-07 15:52:59 -08001949 /*
1950 * Long integer shift. This is different from the generic 32/64-bit
1951 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1952 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1953 * 6 bits.
1954 * On entry:
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001955 * $a0: low word
1956 * $a1: high word
1957 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08001958 */
1959 /* ushr-long vAA, vBB, vCC */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001960ENTRY_NO_GP art_quick_ushr_long
jeffhaofc6a30e2012-10-18 18:24:15 -07001961 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001962 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001963 not $a0, $a2 # alo<- 31-shift (shift is 5b)
1964 sll $a1, 1
1965 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07001966 andi $a2, 0x20 # shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08001967 beqz $a2, 1f
1968 or $v0, $a1 # rlo<- rlo | ahi
1969
1970 move $v0, $v1 # rlo<- rhi (if shift&0x20)
1971 move $v1, $zero # rhi<- 0 (if shift&0x20)
1972
Andreas Gampe8d365912015-01-13 11:32:32 -080019731: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001974 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001975END art_quick_ushr_long
jeffhao7fbee072012-08-24 17:56:54 -07001976
Chris Larsencf283da2016-01-19 16:45:35 -08001977/* java.lang.String.indexOf(int ch, int fromIndex=0) */
1978ENTRY_NO_GP art_quick_indexof
1979/* $a0 holds address of "this" */
1980/* $a1 holds "ch" */
1981/* $a2 holds "fromIndex" */
1982 lw $t0, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001983 slt $t1, $a2, $zero # if fromIndex < 0
Chris Larsencf283da2016-01-19 16:45:35 -08001984#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001985 seleqz $a2, $a2, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08001986#else
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001987 movn $a2, $zero, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08001988#endif
1989 subu $t0, $t0, $a2 # this.length() - fromIndex
1990 blez $t0, 6f # if this.length()-fromIndex <= 0
1991 li $v0, -1 # return -1;
1992
1993 sll $v0, $a2, 1 # $a0 += $a2 * 2
1994 addu $a0, $a0, $v0 # " " " " "
1995 move $v0, $a2 # Set i to fromIndex.
1996
19971:
1998 lhu $t3, MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
1999 beq $t3, $a1, 6f # return i;
2000 addu $a0, $a0, 2 # i++
2001 subu $t0, $t0, 1 # this.length() - i
2002 bnez $t0, 1b # while this.length() - i > 0
2003 addu $v0, $v0, 1 # i++
2004
2005 li $v0, -1 # if this.length() - i <= 0
2006 # return -1;
2007
20086:
2009 j $ra
2010 nop
2011END art_quick_indexof
2012
Chris Larsencf283da2016-01-19 16:45:35 -08002013/* java.lang.String.compareTo(String anotherString) */
2014ENTRY_NO_GP art_quick_string_compareto
2015/* $a0 holds address of "this" */
2016/* $a1 holds address of "anotherString" */
2017 beq $a0, $a1, 9f # this and anotherString are the same object
2018 move $v0, $zero
2019
2020 lw $a2, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2021 lw $a3, MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
2022 MINu $t2, $a2, $a3
2023# $t2 now holds min(this.length(),anotherString.length())
2024
2025 beqz $t2, 9f # while min(this.length(),anotherString.length())-i != 0
2026 subu $v0, $a2, $a3 # if $t2==0 return
2027 # (this.length() - anotherString.length())
20281:
2029 lhu $t0, MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2030 lhu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2031 bne $t0, $t1, 9f # if this.charAt(i) != anotherString.charAt(i)
2032 subu $v0, $t0, $t1 # return (this.charAt(i) - anotherString.charAt(i))
2033 addiu $a0, $a0, 2 # point at this.charAt(i++)
2034 subu $t2, $t2, 1 # new value of
2035 # min(this.length(),anotherString.length())-i
2036 bnez $t2, 1b
2037 addiu $a1, $a1, 2 # point at anotherString.charAt(i++)
2038 subu $v0, $a2, $a3
2039
20409:
2041 j $ra
2042 nop
2043END art_quick_string_compareto