blob: b3dd4545f47c3aa7b6f5dbb2f7084e734bfd033f [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_x86.S"
Elliott Hughes5e284222012-04-04 13:38:03 -070018
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -070019#include "arch/quick_alloc_entrypoints.S"
20
Dave Allisonbbb32c22013-11-05 18:25:18 -080021// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
22
Ian Rogers57b86d42012-03-27 16:05:41 -070023 /*
24 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070025 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070026 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070027MACRO2(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080028 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
29 PUSH esi
30 PUSH ebp
Andreas Gampe4360be22015-07-14 23:34:44 -070031 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070032 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -070033 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070034 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -070035 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
36 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070037 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -070038 pushl RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070039 CFI_ADJUST_CFA_OFFSET(4)
40 // Store esp as the top quick frame.
41 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -070042 // Ugly compile-time check, but we only have the preprocessor.
43 // Last +4: implicit return address pushed on stack when caller made call.
44#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 3*4 + 16 + 4)
45#error "SAVE_ALL_CALLEE_SAVE_FRAME(X86) size not as expected."
46#endif
Elliott Hughes787ec202012-03-29 17:14:15 -070047END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070048
Ian Rogers7caad772012-03-30 01:07:54 -070049 /*
50 * Macro that sets up the callee save frame to conform with
51 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
52 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070053MACRO2(SETUP_REFS_ONLY_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080054 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
55 PUSH esi
56 PUSH ebp
Andreas Gampe4360be22015-07-14 23:34:44 -070057 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070058 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -070059 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070060 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -070061 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
62 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -070064 pushl RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070065 CFI_ADJUST_CFA_OFFSET(4)
66 // Store esp as the top quick frame.
67 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -070068
69 // Ugly compile-time check, but we only have the preprocessor.
70 // Last +4: implicit return address pushed on stack when caller made call.
71#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
72#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
73#endif
Ian Rogers7caad772012-03-30 01:07:54 -070074END_MACRO
75
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010076 /*
77 * Macro that sets up the callee save frame to conform with
78 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
79 * and preserves the value of got_reg at entry.
80 */
81MACRO2(SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG, got_reg, temp_reg)
82 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
83 PUSH esi
84 PUSH ebp
Vladimir Marko2ebef632016-06-21 11:24:47 +010085 PUSH RAW_VAR(got_reg) // Save got_reg
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010086 subl MACRO_LITERAL(8), %esp // Grow stack by 2 words.
87 CFI_ADJUST_CFA_OFFSET(8)
88
89 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
90 // Load Runtime::instance_ from GOT.
91 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
92 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
93 // Push save all callee-save method.
94 pushl RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
95 CFI_ADJUST_CFA_OFFSET(4)
96 // Store esp as the top quick frame.
97 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
98 // Restore got_reg.
99 movl 12(%esp), REG_VAR(got_reg)
Vladimir Marko2ebef632016-06-21 11:24:47 +0100100 CFI_RESTORE(RAW_VAR(got_reg))
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100101
102 // Ugly compile-time check, but we only have the preprocessor.
103 // Last +4: implicit return address pushed on stack when caller made call.
104#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
105#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
106#endif
107END_MACRO
108
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700109MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -0700110 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800111 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700112 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
113 POP esi
114 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
117 /*
118 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -0700119 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700120 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700121MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -0800122 PUSH edi // Save callee saves
123 PUSH esi
124 PUSH ebp
125 PUSH ebx // Save args
126 PUSH edx
127 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000128 // Create space for FPR args.
129 subl MACRO_LITERAL(4 * 8), %esp
130 CFI_ADJUST_CFA_OFFSET(4 * 8)
131 // Save FPRs.
132 movsd %xmm0, 0(%esp)
133 movsd %xmm1, 8(%esp)
134 movsd %xmm2, 16(%esp)
135 movsd %xmm3, 24(%esp)
136
Andreas Gampe4360be22015-07-14 23:34:44 -0700137 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700138 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700139 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
140 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700141 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -0700142 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143 CFI_ADJUST_CFA_OFFSET(4)
144 // Store esp as the stop quick frame.
145 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700146
147 // Ugly compile-time check, but we only have the preprocessor.
148 // Last +4: implicit return address pushed on stack when caller made call.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000149#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4*8 + 4)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700150#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
151#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700152END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700153
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 /*
155 * Macro that sets up the callee save frame to conform with
156 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX.
157 */
158MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000159 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700160 PUSH edi // Save callee saves
161 PUSH esi
162 PUSH ebp
163 PUSH ebx // Save args
164 PUSH edx
165 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000166
167 // Create space for FPR args.
168 subl MACRO_LITERAL(32), %esp
169 CFI_ADJUST_CFA_OFFSET(32)
170
171 // Save FPRs.
172 movsd %xmm0, 0(%esp)
173 movsd %xmm1, 8(%esp)
174 movsd %xmm2, 16(%esp)
175 movsd %xmm3, 24(%esp)
176
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700177 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
178 // Store esp as the stop quick frame.
179 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
180END_MACRO
181
182MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000183 // Restore FPRs. EAX is still on the stack.
184 movsd 4(%esp), %xmm0
185 movsd 12(%esp), %xmm1
186 movsd 20(%esp), %xmm2
187 movsd 28(%esp), %xmm3
188
189 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
190 CFI_ADJUST_CFA_OFFSET(-36)
191
Andreas Gampe4360be22015-07-14 23:34:44 -0700192 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800193 POP edx
194 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700195 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800196 POP esi
197 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700198END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700199
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000200// Restore register and jump to routine
201// Inputs: EDI contains pointer to code.
202// Notes: Need to pop EAX too (restores Method*)
203MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP)
204 POP eax // Restore Method*
205
206 // Restore FPRs.
207 movsd 0(%esp), %xmm0
208 movsd 8(%esp), %xmm1
209 movsd 16(%esp), %xmm2
210 movsd 24(%esp), %xmm3
211
212 addl MACRO_LITERAL(32), %esp // Remove FPRs.
213 CFI_ADJUST_CFA_OFFSET(-32)
214
215 POP ecx // Restore args except eax
216 POP edx
217 POP ebx
218 POP ebp // Restore callee saves
219 POP esi
220 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
221 ret
222END_MACRO
223
Ian Rogers57b86d42012-03-27 16:05:41 -0700224 /*
225 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
226 * exception is Thread::Current()->exception_.
227 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700228MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700229 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700230 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700231 subl MACRO_LITERAL(12), %esp // Alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700232 CFI_ADJUST_CFA_OFFSET(12)
233 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800234 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700235 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700236 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700237END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700238
Elliott Hughes787ec202012-03-29 17:14:15 -0700239MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700240 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700241 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700242 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700243 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700244 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700245 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800246 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700247 call CALLVAR(cxx_name) // cxx_name(Thread*)
248 UNREACHABLE
249 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700250END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700251
Elliott Hughes787ec202012-03-29 17:14:15 -0700252MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700253 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700254 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700255 mov %esp, %ecx
256 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700257 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700258 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700259 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800260 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700261 PUSH eax // pass arg1
262 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
263 UNREACHABLE
264 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700265END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700266
Elliott Hughes787ec202012-03-29 17:14:15 -0700267MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700268 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700269 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700270 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700271 PUSH eax // alignment padding
272 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800273 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700274 PUSH ecx // pass arg2
275 PUSH eax // pass arg1
276 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
277 UNREACHABLE
278 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700279END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700280
281 /*
282 * Called by managed code to create and deliver a NullPointerException.
283 */
Ian Rogers468532e2013-08-05 10:56:33 -0700284NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700285
286 /*
287 * Called by managed code to create and deliver an ArithmeticException.
288 */
Ian Rogers468532e2013-08-05 10:56:33 -0700289NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700290
291 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700292 * Called by managed code to create and deliver a StackOverflowError.
293 */
Ian Rogers468532e2013-08-05 10:56:33 -0700294NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700295
296 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700297 * Called by managed code, saves callee saves and then calls artThrowException
298 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
299 */
Ian Rogers468532e2013-08-05 10:56:33 -0700300ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700301
302 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700303 * Called by managed code to create and deliver a NoSuchMethodError.
304 */
Ian Rogers468532e2013-08-05 10:56:33 -0700305ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700306
307 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700308 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
309 * index, arg2 holds limit.
310 */
Ian Rogers468532e2013-08-05 10:56:33 -0700311TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700312
313 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100314 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
315 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
316 */
317TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
318
319 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700320 * All generated callsites for interface invokes and invocation slow paths will load arguments
321 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100322 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700323 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
324 *
325 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
326 * of the target Method* in r0 and method->code_ in r1.
327 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700328 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700329 * thread and we branch to another stub to deliver it.
330 *
331 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
332 * pointing back to the original caller.
333 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700334MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700335 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700336 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000337
Ian Rogers7caad772012-03-30 01:07:54 -0700338 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800339 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700340 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800341 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800342 PUSH ecx // pass arg2
343 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700344 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700345 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100346 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
347 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000348
349 // Restore FPRs.
350 movsd 0(%esp), %xmm0
351 movsd 8(%esp), %xmm1
352 movsd 16(%esp), %xmm2
353 movsd 24(%esp), %xmm3
354
355 // Remove space for FPR args.
356 addl MACRO_LITERAL(4 * 8), %esp
357 CFI_ADJUST_CFA_OFFSET(-4 * 8)
358
Dave Allisonbbb32c22013-11-05 18:25:18 -0800359 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800360 POP edx
361 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800362 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800363 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700364 // Swap EDI callee save with code pointer.
365 xchgl %edi, (%esp)
366 testl %eax, %eax // Branch forward if exception pending.
367 jz 1f
368 // Tail call to intended method.
369 ret
3701:
jeffhao20b5c6c2012-05-21 14:15:18 -0700371 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800372 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700373 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700374END_MACRO
375MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700376 DEFINE_FUNCTION VAR(c_name)
377 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
378 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700379END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700380
Logan Chien8dbb7082013-01-25 20:31:17 +0800381INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700382
Logan Chien8dbb7082013-01-25 20:31:17 +0800383INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
384INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
385INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
386INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700387
Jeff Hao5d917302013-02-27 17:57:33 -0800388 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000389 * Helper for quick invocation stub to set up XMM registers.
390 * Increments shorty and arg_array and clobbers temp_char.
391 * Branches to finished if it encounters the end of the shorty.
392 */
393MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3941: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700395 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
396 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
397 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
398 je VAR(finished) // goto finished
399 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
400 je 2f // goto FOUND_DOUBLE
401 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
402 je 3f // goto FOUND_FLOAT
403 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000404 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700405 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
406 jne 1b // goto LOOP
407 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
408 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004092: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700410 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
411 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000412 jmp 4f
4133: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700414 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
415 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004164:
417END_MACRO
418
419 /*
420 * Helper for quick invocation stub to set up GPR registers.
421 * Increments shorty and arg_array, and returns the current short character in
422 * temp_char. Branches to finished if it encounters the end of the shorty.
423 */
424MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
4251: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700426 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
427 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
428 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
429 je VAR(finished) // goto finished
430 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
431 je 3f // goto SKIP_FLOAT
432 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
433 je 4f // goto SKIP_DOUBLE
434 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004353: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700436 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
437 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004384: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700439 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
440 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004415:
442END_MACRO
443
444 /*
445 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700446 * On entry:
447 * [sp] = return address
448 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700449 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700450 * [sp + 12] = size of argument array in bytes
451 * [sp + 16] = (managed) thread pointer
452 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800453 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800454 */
455DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000456 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800457 PUSH ebp // save ebp
458 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000459 PUSH esi // save esi
460 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000461 // Set up argument XMM registers.
462 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
463 addl LITERAL(1), %esi
464 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
465 addl LITERAL(4), %edi
466 // Clobbers ESI, EDI, EAX.
467 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
468 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
469 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
470 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
471 .balign 16
472.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800473 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800474 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000475 mov 28(%ebp), %ebx // get arg array size
476 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
477 addl LITERAL(36), %ebx
478 // align frame size to 16 bytes
479 andl LITERAL(0xFFFFFFF0), %ebx
480 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800481 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000482
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700483 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000484
485 // Copy arg array into stack.
486 movl 28(%ebp), %ecx // ECX = size of args
487 movl 24(%ebp), %esi // ESI = argument array
488 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
489 rep movsb // while (ecx--) { *edi++ = *esi++ }
490
491 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
492 addl LITERAL(1), %esi
493 mov 24(%ebp), %edi // EDI := arg_array
494 mov 0(%edi), %ecx // ECX := this pointer
495 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
496
497 // Enumerate the possible cases for loading GPRS.
498 // edx (and maybe ebx):
499 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
500 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
501 je .LfirstLong
502 // Must be an integer value.
503 movl (%edi), %edx
504 addl LITERAL(4), %edi // arg_array++
505
506 // Now check ebx
507 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500508 // Must be first word of a long, or an integer. First word of long doesn't
509 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000510 movl (%edi), %ebx
511 jmp .Lgpr_setup_finished
512.LfirstLong:
513 movl (%edi), %edx
514 movl 4(%edi), %ebx
515 // Nothing left to load.
516.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000517 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700518 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800519 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800520 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000521 POP edi // pop edi
522 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800523 POP ebx // pop ebx
524 POP ebp // pop ebp
525 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800526 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800527 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800528 mov 24(%esp), %edx // get the shorty
529 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800530 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800531 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800532 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700533 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800534.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800535 movsd %xmm0, (%ecx) // store the floating point result
536 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800537.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800538 movss %xmm0, (%ecx) // store the floating point result
539 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800540END_FUNCTION art_quick_invoke_stub
541
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000542 /*
543 * Quick invocation stub (static).
544 * On entry:
545 * [sp] = return address
546 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700547 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000548 * [sp + 12] = size of argument array in bytes
549 * [sp + 16] = (managed) thread pointer
550 * [sp + 20] = JValue* result
551 * [sp + 24] = shorty
552 */
553DEFINE_FUNCTION art_quick_invoke_static_stub
554 // Save the non-volatiles.
555 PUSH ebp // save ebp
556 PUSH ebx // save ebx
557 PUSH esi // save esi
558 PUSH edi // save edi
559 // Set up argument XMM registers.
560 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
561 addl LITERAL(1), %esi
562 mov 8+16(%esp), %edi // EDI := arg_array
563 // Clobbers ESI, EDI, EAX.
564 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
565 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
566 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
567 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
568 .balign 16
569.Lxmm_setup_finished2:
570 mov %esp, %ebp // copy value of stack pointer into base pointer
571 CFI_DEF_CFA_REGISTER(ebp)
572 mov 28(%ebp), %ebx // get arg array size
573 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
574 addl LITERAL(36), %ebx
575 // align frame size to 16 bytes
576 andl LITERAL(0xFFFFFFF0), %ebx
577 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
578 subl %ebx, %esp // reserve stack space for argument array
579
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700580 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000581
582 // Copy arg array into stack.
583 movl 28(%ebp), %ecx // ECX = size of args
584 movl 24(%ebp), %esi // ESI = argument array
585 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
586 rep movsb // while (ecx--) { *edi++ = *esi++ }
587
588 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
589 addl LITERAL(1), %esi
590 mov 24(%ebp), %edi // EDI := arg_array
591
592 // Enumerate the possible cases for loading GPRS.
593 // ecx (and maybe edx)
594 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
595 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
596 je .LfirstLong2
597 // Must be an integer value. Load into ECX.
598 movl (%edi), %ecx
599 addl LITERAL(4), %edi // arg_array++
600
601 // Now check edx (and maybe ebx).
602 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
603 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
604 je .LSecondLong2
605 // Must be an integer. Load into EDX.
606 movl (%edi), %edx
607 addl LITERAL(4), %edi // arg_array++
608
609 // Is there anything for ebx?
610 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500611 // Must be first word of a long, or an integer. First word of long doesn't
612 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000613 movl (%edi), %ebx
614 jmp .Lgpr_setup_finished2
615.LSecondLong2:
616 // EDX:EBX is long. That is all.
617 movl (%edi), %edx
618 movl 4(%edi), %ebx
619 jmp .Lgpr_setup_finished2
620.LfirstLong2:
621 // ECX:EDX is a long
622 movl (%edi), %ecx
623 movl 4(%edi), %edx
624 addl LITERAL(8), %edi // arg_array += 2
625
626 // Anything for EBX?
627 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500628 // Must be first word of a long, or an integer. First word of long doesn't
629 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000630 movl (%edi), %ebx
631 jmp .Lgpr_setup_finished2
632 // Nothing left to load.
633.Lgpr_setup_finished2:
634 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700635 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000636 mov %ebp, %esp // restore stack pointer
637 CFI_DEF_CFA_REGISTER(esp)
638 POP edi // pop edi
639 POP esi // pop esi
640 POP ebx // pop ebx
641 POP ebp // pop ebp
642 mov 20(%esp), %ecx // get result pointer
643 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
644 mov %edx, 4(%ecx) // store the other half of the result
645 mov 24(%esp), %edx // get the shorty
646 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
647 je .Lreturn_double_quick2
648 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
649 je .Lreturn_float_quick2
650 ret
651.Lreturn_double_quick2:
652 movsd %xmm0, (%ecx) // store the floating point result
653 ret
654.Lreturn_float_quick2:
655 movss %xmm0, (%ecx) // store the floating point result
656 ret
657END_FUNCTION art_quick_invoke_static_stub
658
Ian Rogersd36c52e2012-04-09 16:29:25 -0700659MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700660 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700661 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700662 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700663 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700664 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700665 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800666 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700667 call CALLVAR(cxx_name) // cxx_name(Thread*)
668 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800669 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700670 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
671 CALL_MACRO(return_macro) // return or deliver exception
672 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700673END_MACRO
674
675MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700676 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700677 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700678 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700679 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700680 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700681 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800682 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700683 PUSH eax // pass arg1
684 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
685 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800686 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700687 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
688 CALL_MACRO(return_macro) // return or deliver exception
689 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700690END_MACRO
691
692MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700693 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700694 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700695 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700696 PUSH eax // push padding
697 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800698 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700699 PUSH ecx // pass arg2
700 PUSH eax // pass arg1
701 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
702 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800703 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700704 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
705 CALL_MACRO(return_macro) // return or deliver exception
706 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700707END_MACRO
708
Ian Rogersd36c52e2012-04-09 16:29:25 -0700709MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700710 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700711 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700712 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700713 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800714 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700715 PUSH edx // pass arg3
716 PUSH ecx // pass arg2
717 PUSH eax // pass arg1
718 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
719 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700720 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700721 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
722 CALL_MACRO(return_macro) // return or deliver exception
723 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700724END_MACRO
725
Jeff Hao848f70a2014-01-15 13:49:50 -0800726MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700727 DEFINE_FUNCTION VAR(c_name)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100728 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000729
Jeff Hao848f70a2014-01-15 13:49:50 -0800730 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700731 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800732 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700733 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800734 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700735 PUSH ebx // pass arg4
736 PUSH edx // pass arg3
737 PUSH ecx // pass arg2
738 PUSH eax // pass arg1
739 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
740 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800741 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700742 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
743 CALL_MACRO(return_macro) // return or deliver exception
744 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800745END_MACRO
746
Fred Shih37f05ef2014-07-16 18:38:08 -0700747MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700748 DEFINE_FUNCTION VAR(c_name)
749 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700750 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700751 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700752 PUSH eax // push padding
753 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700754 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700755 PUSH ecx // pass referrer
756 PUSH eax // pass arg1
757 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
758 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700759 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700760 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
761 CALL_MACRO(return_macro) // return or deliver exception
762 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700763END_MACRO
764
765MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700766 DEFINE_FUNCTION VAR(c_name)
767 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700768 // Outgoing argument set up
769 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700770 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700771 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700772 PUSH edx // pass referrer
773 PUSH ecx // pass arg2
774 PUSH eax // pass arg1
775 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
776 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700777 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700778 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
779 CALL_MACRO(return_macro) // return or deliver exception
780 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700781END_MACRO
782
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700783MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700784 DEFINE_FUNCTION VAR(c_name)
785 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700786 // Outgoing argument set up
787 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700788 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700789 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700790 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700791 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700792 PUSH ebx // pass referrer
793 PUSH edx // pass arg3
794 PUSH ecx // pass arg2
795 PUSH eax // pass arg1
796 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
797 // Thread*)
798 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700799 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700800 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
801 CALL_MACRO(return_macro) // return or deliver exception
802 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700803END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700804
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700805MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700806 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700807 jz 1f // if eax == 0 goto 1
808 ret // return
8091: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700810 DELIVER_PENDING_EXCEPTION
811END_MACRO
812
Ian Rogersd36c52e2012-04-09 16:29:25 -0700813MACRO0(RETURN_IF_EAX_ZERO)
814 testl %eax, %eax // eax == 0 ?
815 jnz 1f // if eax != 0 goto 1
816 ret // return
8171: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700818 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700819END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700820
jeffhaod66a8752012-05-22 15:30:16 -0700821MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700822 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700823 jne 1f // if exception field != 0 goto 1
824 ret // return
8251: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700826 DELIVER_PENDING_EXCEPTION
827END_MACRO
828
Mathieu Chartier7410f292013-11-24 13:17:35 -0800829// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700830GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800831
832// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
833DEFINE_FUNCTION art_quick_alloc_object_rosalloc
834 // Fast path rosalloc allocation.
835 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
836 // ebx, edx: free
837 PUSH edi
838 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
839 // Load the class (edx)
840 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
841 testl %edx, %edx // Check null class
842 jz .Lart_quick_alloc_object_rosalloc_slow_path
843 // Check class status
844 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
845 jne .Lart_quick_alloc_object_rosalloc_slow_path
846 // No fake dependence needed on x86
847 // between status and flags load,
848 // since each load is a load-acquire,
849 // no loads reordering.
850 // Check access flags has
851 // kAccClassIsFinalizable
852 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
853 jnz .Lart_quick_alloc_object_rosalloc_slow_path
854
855 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
856 // Check if the thread local allocation
857 // stack has room
858 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
859 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
860 jae .Lart_quick_alloc_object_rosalloc_slow_path
861
862 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
863 // Check if the size is for a thread
864 // local allocation
865 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
866 ja .Lart_quick_alloc_object_rosalloc_slow_path
867 decl %edi
868 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
869 // from object size.
870 // Align up the size by the rosalloc
871 // bracket quantum size and divide
872 // by the quantum size and subtract
873 // by 1. This code is a shorter but
874 // equivalent version.
875 // Load thread local rosalloc run (ebx)
876 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
877 // Load free_list head (edi),
878 // this will be the return value.
879 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
880 test %edi, %edi
881 jz .Lart_quick_alloc_object_rosalloc_slow_path
882 // Point of no slow path. Won't go to
883 // the slow path from here on. Ok to
884 // clobber eax and ecx.
885 movl %edi, %eax
886 // Load the next pointer of the head
887 // and update head of free list with
888 // next pointer
889 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
890 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
891 // Decrement size of free list by 1
892 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
893 // Store the class pointer in the
894 // header. This also overwrites the
895 // next pointer. The offsets are
896 // asserted to match.
897#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
898#error "Class pointer needs to overwrite next pointer."
899#endif
900 POISON_HEAP_REF edx
901 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
902 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
903 // Push the new object onto the thread
904 // local allocation stack and
905 // increment the thread local
906 // allocation stack top.
907 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
908 movl %eax, (%edi)
909 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
910 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
911 // No fence needed for x86.
912 POP edi
913 ret
914.Lart_quick_alloc_object_rosalloc_slow_path:
915 POP edi
916 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
917 // Outgoing argument set up
918 PUSH eax // alignment padding
919 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
920 CFI_ADJUST_CFA_OFFSET(4)
921 PUSH ecx
922 PUSH eax
923 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
924 addl LITERAL(16), %esp // pop arguments
925 CFI_ADJUST_CFA_OFFSET(-16)
926 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
927 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
928END_FUNCTION art_quick_alloc_object_rosalloc
929
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800930// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
931//
932// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
933MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
934 testl %edx, %edx // Check null class
935 jz VAR(slowPathLabel)
936 // Check class status.
937 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
938 jne VAR(slowPathLabel)
939 // No fake dependence needed on x86
940 // between status and flags load,
941 // since each load is a load-acquire,
942 // no loads reordering.
943 // Check access flags has
944 // kAccClassIsFinalizable
945 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
946 jnz VAR(slowPathLabel)
947 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
948 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
949 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
950 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
951 cmpl %edi, %esi // Check if it fits. OK to do this
952 // before rounding up the object size
953 // assuming the buf size alignment.
954 ja VAR(slowPathLabel)
955 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
956 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
957 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
958 // as allocated object.
959 addl %eax, %esi // Add the object size.
960 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
961 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
962 // Store the class pointer in the header.
963 // No fence needed for x86.
964 POISON_HEAP_REF edx
965 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
966 POP edi
967 POP esi
968 ret // Fast path succeeded.
969END_MACRO
970
971// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
972MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
973 POP edi
974 POP esi
975 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
976 // Outgoing argument set up
977 PUSH eax // alignment padding
978 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
979 CFI_ADJUST_CFA_OFFSET(4)
980 PUSH ecx
981 PUSH eax
982 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
983 addl LITERAL(16), %esp
984 CFI_ADJUST_CFA_OFFSET(-16)
985 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
986 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
987END_MACRO
988
989// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
990DEFINE_FUNCTION art_quick_alloc_object_tlab
991 // Fast path tlab allocation.
992 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
993 // EBX, EDX: free.
994#if defined(USE_READ_BARRIER)
995 int3
996 int3
997#endif
998 PUSH esi
999 PUSH edi
1000 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1001 // Might need to break down into multiple instructions to get the base address in a register.
1002 // Load the class
1003 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1004 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1005.Lart_quick_alloc_object_tlab_slow_path:
1006 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1007END_FUNCTION art_quick_alloc_object_tlab
1008
1009// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1010DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1011 // Fast path region tlab allocation.
1012 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1013 // EBX, EDX: free.
1014#if !defined(USE_READ_BARRIER)
1015 int3
1016 int3
1017#endif
1018 PUSH esi
1019 PUSH edi
1020 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1021 // Might need to break down into multiple instructions to get the base address in a register.
1022 // Load the class
1023 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1024 // Read barrier for class load.
1025 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1026 jne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1027.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1028 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1029.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1030 // The read barrier slow path. Mark the class.
1031 PUSH eax
1032 PUSH ecx
1033 // Outgoing argument set up
1034 subl MACRO_LITERAL(8), %esp // Alignment padding
1035 CFI_ADJUST_CFA_OFFSET(8)
1036 PUSH edx // Pass the class as the first param.
1037 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1038 movl %eax, %edx
1039 addl MACRO_LITERAL(12), %esp
1040 CFI_ADJUST_CFA_OFFSET(-12)
1041 POP ecx
1042 POP eax
1043 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1044.Lart_quick_alloc_object_region_tlab_slow_path:
1045 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1046END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001047
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001048ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1049ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1050ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1051ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersd36c52e2012-04-09 16:29:25 -07001052
Ian Rogers832336b2014-10-08 15:35:22 -07001053TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001054
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001055DEFINE_FUNCTION art_quick_lock_object
1056 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001057 jz .Lslow_lock
1058.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001059 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001060 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001061 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001062 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
1063 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001064 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001065 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001066 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001067 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001068 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1069 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1070 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1071 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1072 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001073 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001074.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1075 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001076 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001077 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001078 movl %edx, %ecx // copy the lock word to check count overflow.
1079 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
1080 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
1081 test LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // overflowed if either of the upper two bits (28-29) are set.
Ian Rogers8016a122014-02-21 20:37:21 -08001082 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001083 movl %eax, %ecx // save obj to use eax for cmpxchg.
1084 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1085 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1086 // update lockword, cmpxchg necessary for read barrier bits.
1087 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1088 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001089 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001090.Llock_cmpxchg_fail:
1091 movl %ecx, %eax // restore eax
1092 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001093.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001094 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001095 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001096 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001097 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001098 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001099 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001100 PUSH eax // pass object
1101 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1102 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001103 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001104 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001105 RETURN_IF_EAX_ZERO
1106END_FUNCTION art_quick_lock_object
1107
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001108DEFINE_FUNCTION art_quick_lock_object_no_inline
1109 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1110 // Outgoing argument set up
1111 subl LITERAL(8), %esp // alignment padding
1112 CFI_ADJUST_CFA_OFFSET(8)
1113 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1114 CFI_ADJUST_CFA_OFFSET(4)
1115 PUSH eax // pass object
1116 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1117 addl LITERAL(16), %esp // pop arguments
1118 CFI_ADJUST_CFA_OFFSET(-16)
1119 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1120 RETURN_IF_EAX_ZERO
1121END_FUNCTION art_quick_lock_object_no_inline
1122
1123
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001124DEFINE_FUNCTION art_quick_unlock_object
1125 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001126 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001127.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001128 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001129 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001130 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001131 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001132 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001133 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001134 movl %ecx, %edx // copy the lock word to detect new count of 0.
1135 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
1136 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001137 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001138 // update lockword, cmpxchg necessary for read barrier bits.
1139 movl %eax, %edx // edx: obj
1140 movl %ecx, %eax // eax: old lock word.
1141 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
1142#ifndef USE_READ_BARRIER
1143 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1144#else
1145 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1146 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1147#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001148 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001149.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1150 // update lockword, cmpxchg necessary for read barrier bits.
1151 movl %eax, %edx // edx: obj
1152 movl %ecx, %eax // eax: old lock word.
1153 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1154#ifndef USE_READ_BARRIER
1155 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1156#else
1157 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1158 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1159#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001160 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001161.Lunlock_cmpxchg_fail: // edx: obj
1162 movl %edx, %eax // restore eax
1163 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001164.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001165 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001166 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001167 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001168 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001169 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001170 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001171 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001172 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001173 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001174 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001175 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001176 RETURN_IF_EAX_ZERO
1177END_FUNCTION art_quick_unlock_object
1178
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001179DEFINE_FUNCTION art_quick_unlock_object_no_inline
1180 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1181 // Outgoing argument set up
1182 subl LITERAL(8), %esp // alignment padding
1183 CFI_ADJUST_CFA_OFFSET(8)
1184 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1185 CFI_ADJUST_CFA_OFFSET(4)
1186 PUSH eax // pass object
1187 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1188 addl LITERAL(16), %esp // pop arguments
1189 CFI_ADJUST_CFA_OFFSET(-16)
1190 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1191 RETURN_IF_EAX_ZERO
1192END_FUNCTION art_quick_unlock_object_no_inline
1193
Ian Rogers468532e2013-08-05 10:56:33 -07001194DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001195 PUSH eax // alignment padding
1196 PUSH ecx // pass arg2 - obj->klass
1197 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001198 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001199 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001200 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001201 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001202END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001203
Ian Rogersa9a82542013-10-04 11:17:26 -07001204DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001205 PUSH eax // alignment padding
1206 PUSH ecx // pass arg2 - obj->klass
1207 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001208 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001209 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001210 jz 1f // jump forward if not assignable
1211 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001212 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001213 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001214
Andreas Gampe4360be22015-07-14 23:34:44 -07001215 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070012161:
Andreas Gampe4360be22015-07-14 23:34:44 -07001217 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001218 POP ecx
1219 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001220 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001221 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001222 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001223 PUSH eax // alignment padding
1224 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001225 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001226 PUSH ecx // pass arg2
1227 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001228 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001229 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001230END_FUNCTION art_quick_check_cast
1231
Man Cao1aee9002015-07-14 22:31:42 -07001232// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1233MACRO2(POP_REG_NE, reg, exclude_reg)
1234 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1235 addl MACRO_LITERAL(4), %esp
1236 CFI_ADJUST_CFA_OFFSET(-4)
1237 .else
1238 POP RAW_VAR(reg)
1239 .endif
1240END_MACRO
1241
1242 /*
1243 * Macro to insert read barrier, only used in art_quick_aput_obj.
1244 * obj_reg and dest_reg are registers, offset is a defined literal such as
1245 * MIRROR_OBJECT_CLASS_OFFSET.
1246 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1247 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1248 */
1249MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1250#ifdef USE_READ_BARRIER
1251 PUSH eax // save registers used in art_quick_aput_obj
1252 PUSH ebx
1253 PUSH edx
1254 PUSH ecx
1255 // Outgoing argument set up
1256 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1257 CFI_ADJUST_CFA_OFFSET(4)
1258 PUSH RAW_VAR(obj_reg) // pass obj_reg
1259 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1260 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1261 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1262 .ifnc RAW_VAR(dest_reg), eax
1263 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1264 .endif
1265 addl MACRO_LITERAL(12), %esp // pop arguments
1266 CFI_ADJUST_CFA_OFFSET(-12)
1267 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1268 POP_REG_NE edx, RAW_VAR(dest_reg)
1269 POP_REG_NE ebx, RAW_VAR(dest_reg)
1270 .ifc RAW_VAR(pop_eax), true
1271 POP_REG_NE eax, RAW_VAR(dest_reg)
1272 .endif
1273#else
1274 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1275 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1276#endif // USE_READ_BARRIER
1277END_MACRO
1278
Ian Rogersa9a82542013-10-04 11:17:26 -07001279 /*
1280 * Entry from managed code for array put operations of objects where the value being stored
1281 * needs to be checked for compatibility.
1282 * eax = array, ecx = index, edx = value
1283 */
1284DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1285 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001286 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1287 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001288END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1289
1290DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001291 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001292 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001293 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001294 mov %ecx, %eax
1295 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001296 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001297END_FUNCTION art_quick_aput_obj_with_bound_check
1298
1299DEFINE_FUNCTION art_quick_aput_obj
1300 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001301 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001302 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1303 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001304 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001305#if defined(USE_READ_BARRIER)
1306 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1307 cmpl %eax, %ebx
1308 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001309 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001310#elif defined(USE_HEAP_POISONING)
1311 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001312 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1313 UNPOISON_HEAP_REF eax
1314 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001315 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001316#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001317 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001318#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001319 jne .Lcheck_assignability
1320.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001321 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001322 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001323 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1324 shrl LITERAL(7), %eax
1325 movb %dl, (%edx, %eax)
1326 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001327.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001328 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001329 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001330.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001331 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001332 PUSH ecx
1333 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001334#if defined(USE_READ_BARRIER)
1335 subl LITERAL(4), %esp // alignment padding
1336 CFI_ADJUST_CFA_OFFSET(4)
1337 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1338 subl LITERAL(4), %esp // alignment padding
1339 CFI_ADJUST_CFA_OFFSET(4)
1340 PUSH eax // pass arg2 - type of the value to be stored
1341#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001342 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001343 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001344 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001345 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001346 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001347#else
Man Cao63069212015-08-21 15:51:39 -07001348 subl LITERAL(8), %esp // alignment padding
1349 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001350 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001351 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001352#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001353 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001354 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001355 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001356 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001357 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001358 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001359 POP edx
1360 POP ecx
1361 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001362 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001363 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001364 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1365 shrl LITERAL(7), %eax
1366 movb %dl, (%edx, %eax)
1367 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001368 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001369.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001370 POP edx
1371 POP ecx
1372 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001373 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001374 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001375 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001376 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001377 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001378 PUSH edx // pass arg2 - value
1379 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001380 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001381 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001382END_FUNCTION art_quick_aput_obj
1383
Logan Chien8dbb7082013-01-25 20:31:17 +08001384DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001385 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001386 PUSH edx // pass arg3
1387 PUSH ecx // pass arg2
1388 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001389 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001390 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001391 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001392 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001393END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001394
Logan Chien8dbb7082013-01-25 20:31:17 +08001395NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001396
Ian Rogers468532e2013-08-05 10:56:33 -07001397DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001398 subl LITERAL(12), %esp // alignment padding, room for argument
1399 CFI_ADJUST_CFA_OFFSET(12)
1400 movsd %xmm0, 0(%esp) // arg a
1401 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001402 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001403 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001404 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001405END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001406
Ian Rogers468532e2013-08-05 10:56:33 -07001407DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001408 subl LITERAL(12), %esp // alignment padding
1409 CFI_ADJUST_CFA_OFFSET(12)
1410 movss %xmm0, 0(%esp) // arg a
1411 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001412 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001413 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001414 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001415END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001416
Ian Rogers468532e2013-08-05 10:56:33 -07001417DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001418 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001419 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001420 PUSH ebx // pass arg4 b.hi
1421 PUSH edx // pass arg3 b.lo
1422 PUSH ecx // pass arg2 a.hi
1423 PUSH eax // pass arg1 a.lo
1424 call SYMBOL(artLdiv) // (jlong a, jlong b)
1425 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001426 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001427 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001428END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001429
Ian Rogersa9a82542013-10-04 11:17:26 -07001430DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001431 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001432 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001433 PUSH ebx // pass arg4 b.hi
1434 PUSH edx // pass arg3 b.lo
1435 PUSH ecx // pass arg2 a.hi
1436 PUSH eax // pass arg1 a.lo
1437 call SYMBOL(artLmod) // (jlong a, jlong b)
1438 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001439 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001440 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001441END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001442
Ian Rogers468532e2013-08-05 10:56:33 -07001443DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001444 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1445 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1446 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001447 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001448 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001449 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001450END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001451
Ian Rogers468532e2013-08-05 10:56:33 -07001452DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001453 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001454 xchg %edx, %ecx
1455 shld %cl,%eax,%edx
1456 shl %cl,%eax
1457 test LITERAL(32), %cl
1458 jz 1f
1459 mov %eax, %edx
1460 xor %eax, %eax
14611:
1462 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001463END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001464
Ian Rogers468532e2013-08-05 10:56:33 -07001465DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001466 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001467 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001468 shrd %cl,%edx,%eax
1469 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001470 test LITERAL(32),%cl
1471 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001472 mov %edx, %eax
1473 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014741:
1475 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001476END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001477
Ian Rogers468532e2013-08-05 10:56:33 -07001478DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001479 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001480 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001481 shrd %cl,%edx,%eax
1482 shr %cl,%edx
1483 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001484 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001485 mov %edx, %eax
1486 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014871:
1488 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001489END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001490
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001491ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1492ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1493ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1494ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1495ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1496ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1497ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001498
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001499TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1500TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1501TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1502TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1503TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1504TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1505TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001506
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001507TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1508TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1509TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1510TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001511
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001512THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1513THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1514THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1515THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1516
1517// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001518DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001519 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001520 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001521 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001522 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001523 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001524 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001525 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001526 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001527 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1528 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001529 PUSH ebx // pass high half of new_val
1530 PUSH edx // pass low half of new_val
1531 PUSH ecx // pass object
1532 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001533 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001534 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001535 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001536 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001537 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001538END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001539
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001540// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1541// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001542DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001543 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1544 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001545 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001546 movd %xmm0, %ebx
1547 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001548 subl LITERAL(12), %esp // alignment padding
1549 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001550 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001551 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001552 PUSH ebx // pass high half of new_val
1553 PUSH edx // pass low half of new_val
1554 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001555 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001556 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001557 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001558 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001559 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001560 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001561END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001562
Logan Chien8dbb7082013-01-25 20:31:17 +08001563DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001564 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001565 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001566 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001567 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001568 PUSH ecx // pass receiver
1569 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001570 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001571 movd %eax, %xmm0 // place return value also into floating point return value
1572 movd %edx, %xmm1
1573 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001574 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1575 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1576 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001577 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001578END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001579
Jeff Hao88474b42013-10-23 16:24:40 -07001580 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001581 * Called to resolve an imt conflict.
1582 * eax is the conflict ArtMethod.
1583 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1584 *
1585 * Note that this stub writes to eax.
1586 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001587 */
1588DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001589 PUSH EDI
1590 movl 8(%esp), %edi // Load referrer
1591 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1592 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1593 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001594 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001595 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1596 popl %eax // Pop ImtConflictTable.
1597 CFI_ADJUST_CFA_OFFSET(-4)
1598.Limt_table_iterate:
1599 cmpl %edi, 0(%eax)
1600 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001601 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001602 // and jump to it.
1603 POP EDI
1604 movl __SIZEOF_POINTER__(%eax), %eax
1605 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1606.Limt_table_next_entry:
1607 // If the entry is null, the interface method is not in the ImtConflictTable.
1608 cmpl LITERAL(0), 0(%eax)
1609 jz .Lconflict_trampoline
1610 // Iterate over the entries of the ImtConflictTable.
1611 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1612 jmp .Limt_table_iterate
1613.Lconflict_trampoline:
1614 // Call the runtime stub to populate the ImtConflictTable and jump to the
1615 // resolved method.
1616 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001617 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001618END_FUNCTION art_quick_imt_conflict_trampoline
1619
Ian Rogers468532e2013-08-05 10:56:33 -07001620DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001621 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001622 movl %esp, %edi
1623 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001624 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001625 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001626 PUSH ecx // pass receiver
1627 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001628 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001629 movl %eax, %edi // remember code pointer in EDI
1630 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001631 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001632 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001633 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001634 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070016351:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001636 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001637 DELIVER_PENDING_EXCEPTION
1638END_FUNCTION art_quick_resolution_trampoline
1639
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001640DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001641 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001642 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001643 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001644 subl LITERAL(5120), %esp
1645 // prepare for artQuickGenericJniTrampoline call
1646 // (Thread*, SP)
1647 // (esp) 4(esp) <= C calling convention
1648 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001649
1650 subl LITERAL(8), %esp // Padding for 16B alignment.
1651 pushl %ebp // Pass SP (to ArtMethod).
1652 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001653 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001654
Andreas Gampec200a4a2014-06-16 18:39:09 -07001655 // The C call will have registered the complete save-frame on success.
1656 // The result of the call is:
1657 // eax: pointer to native code, 0 on error.
1658 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001659
Andreas Gampec200a4a2014-06-16 18:39:09 -07001660 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001661 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001662 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001663
Andreas Gampec200a4a2014-06-16 18:39:09 -07001664 // Release part of the alloca.
1665 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001666
1667 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001668 // Native call.
1669 call *%eax
1670
Andreas Gampe779f8c92014-06-09 18:29:38 -07001671 // result sign extension is handled in C code
1672 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001673 // (Thread*, result, result_f)
1674 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001675 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001676
Andreas Gampe4360be22015-07-14 23:34:44 -07001677 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001678 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001679 pushl %edx // Pass int result.
1680 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001681 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001682 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001683
Andreas Gampe779f8c92014-06-09 18:29:38 -07001684 // Pending exceptions possible.
1685 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1686 testl %ebx, %ebx
1687 jnz .Lexception_in_native
1688
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001689 // Tear down the alloca.
1690 movl %ebp, %esp
1691 CFI_DEF_CFA_REGISTER(esp)
1692
1693
Andreas Gampe779f8c92014-06-09 18:29:38 -07001694 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001695 // Remove space for FPR args and EAX
1696 addl LITERAL(4 + 4 * 8), %esp
1697 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1698
Andreas Gampe779f8c92014-06-09 18:29:38 -07001699 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001700 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001701 CFI_ADJUST_CFA_OFFSET(-4)
1702 POP ebx
1703 POP ebp // Restore callee saves
1704 POP esi
1705 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001706 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001707 movd %eax, %xmm0
1708 movd %edx, %xmm1
1709 punpckldq %xmm1, %xmm0
1710 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001711.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001712 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1713 // Do a call to push a new save-all frame required by the runtime.
1714 call .Lexception_call
1715.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001716 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001717END_FUNCTION art_quick_generic_jni_trampoline
1718
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001719DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001720 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001721 mov %esp, %edx // remember SP
1722 PUSH eax // alignment padding
1723 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001724 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001725 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001726 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001727 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001728 addl LITERAL(16), %esp // pop arguments
1729 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001730
1731 // Return eax:edx in xmm0 also.
1732 movd %eax, %xmm0
1733 movd %edx, %xmm1
1734 punpckldq %xmm1, %xmm0
1735
1736 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1737 CFI_ADJUST_CFA_OFFSET(-48)
1738
Andreas Gampe4360be22015-07-14 23:34:44 -07001739 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001740 POP esi
1741 POP edi
1742
Ian Rogers7db619b2013-01-16 18:35:48 -08001743 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001744END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001745
jeffhao7e4fcb82013-01-10 18:11:08 -08001746 /*
1747 * Routine that intercepts method calls and returns.
1748 */
Ian Rogers468532e2013-08-05 10:56:33 -07001749DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001750 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001751 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001752 subl LITERAL(12), %esp // Align stack.
1753 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001754 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001755 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001756 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001757 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001758 PUSH ecx // Pass receiver.
1759 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001760 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001761 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001762 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001763 movl 60(%esp), %edi // Restore edi.
1764 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001765 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001766 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001767 movl %ebx, 64(%esp)
1768 movl 0(%esp), %eax // Restore eax.
1769 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1770 movsd 8(%esp), %xmm0
1771 movsd 16(%esp), %xmm1
1772 movsd 24(%esp), %xmm2
1773 movsd 32(%esp), %xmm3
1774
1775 // Restore GPRs.
1776 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001777 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001778 movl 48(%esp), %ebx // Restore ebx.
1779 movl 52(%esp), %ebp // Restore ebp.
1780 movl 56(%esp), %esi // Restore esi.
1781 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001782 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001783 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001784END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001785
Ian Rogers468532e2013-08-05 10:56:33 -07001786DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001787 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001788 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001789 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001790 mov %esp, %ecx // Remember SP
1791 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001792 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001793 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001794 PUSH edx // Save gpr return value.
1795 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001796 subl LITERAL(16), %esp // Align stack
1797 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001798 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001799 PUSH edx // Pass gpr return value.
1800 PUSH eax
1801 PUSH ecx // Pass SP.
1802 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001803 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001804 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001805 mov %eax, %ecx // Move returned link register.
1806 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001807 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001808 movl %edx, %ebx // Move returned link register for deopt
1809 // (ebx is pretending to be our LR).
1810 POP eax // Restore gpr return value.
1811 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001812 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001813 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001814 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001815 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001816 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001817 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001818 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001819END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001820
jeffhao7e4fcb82013-01-10 18:11:08 -08001821 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001822 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1823 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001824 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001825DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001826 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001827 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1828 subl LITERAL(12), %esp // Align stack.
1829 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001830 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001831 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001832 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001833 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001834END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001835
jeffhao86e46712012-08-08 17:30:59 -07001836 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001837 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001838 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001839 */
1840DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1841 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1842 subl LITERAL(12), %esp // Align stack.
1843 CFI_ADJUST_CFA_OFFSET(12)
1844 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1845 CFI_ADJUST_CFA_OFFSET(4)
1846 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1847 UNREACHABLE
1848END_FUNCTION art_quick_deoptimize_from_compiled_code
1849
1850 /*
jeffhao86e46712012-08-08 17:30:59 -07001851 * String's compareTo.
1852 *
1853 * On entry:
1854 * eax: this string object (known non-null)
1855 * ecx: comp string object (known non-null)
1856 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001857DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001858 PUSH esi // push callee save reg
1859 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001860 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1861 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001862 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1863 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001864 /* Calculate min length and count diff */
1865 mov %edx, %ecx
1866 mov %edx, %eax
1867 subl %ebx, %eax
1868 cmovg %ebx, %ecx
1869 /*
1870 * At this point we have:
1871 * eax: value to return if first part of strings are equal
1872 * ecx: minimum among the lengths of the two strings
1873 * esi: pointer to this string data
1874 * edi: pointer to comp string data
1875 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001876 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001877 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001878 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001879.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001880 POP edi // pop callee save reg
1881 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001882 ret
1883 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001884.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001885 movzwl -2(%esi), %eax // get last compared char from this string
1886 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001887 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001888 POP edi // pop callee save reg
1889 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001890 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001891END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001892
Dave Allison8ce6b902014-08-26 11:07:58 -07001893// Return from a nested signal:
1894// Entry:
1895// eax: address of jmp_buf in TLS
1896
1897DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001898 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001899 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001900 PUSH ecx // second arg to longjmp (1)
1901 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001902 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001903 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001904END_FUNCTION art_nested_signal_return
1905
Roland Levillain7c1559a2015-12-15 10:55:36 +00001906DEFINE_FUNCTION art_quick_read_barrier_mark
1907 PUSH eax // pass arg1 - obj
1908 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
1909 addl LITERAL(4), %esp // pop argument
1910 CFI_ADJUST_CFA_OFFSET(-4)
1911 ret
1912END_FUNCTION art_quick_read_barrier_mark
1913
Man Cao1aee9002015-07-14 22:31:42 -07001914DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001915 PUSH edx // pass arg3 - offset
1916 PUSH ecx // pass arg2 - obj
1917 PUSH eax // pass arg1 - ref
1918 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1919 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001920 CFI_ADJUST_CFA_OFFSET(-12)
1921 ret
1922END_FUNCTION art_quick_read_barrier_slow
1923
Roland Levillain0d5a2812015-11-13 10:07:31 +00001924DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
1925 PUSH eax // pass arg1 - root
1926 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
1927 addl LITERAL(4), %esp // pop argument
1928 CFI_ADJUST_CFA_OFFSET(-4)
1929 ret
1930END_FUNCTION art_quick_read_barrier_for_root_slow
1931
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001932 /*
1933 * On stack replacement stub.
1934 * On entry:
1935 * [sp] = return address
1936 * [sp + 4] = stack to copy
1937 * [sp + 8] = size of stack
1938 * [sp + 12] = pc to call
1939 * [sp + 16] = JValue* result
1940 * [sp + 20] = shorty
1941 * [sp + 24] = thread
1942 */
1943DEFINE_FUNCTION art_quick_osr_stub
1944 // Save native callee saves.
1945 PUSH ebp
1946 PUSH ebx
1947 PUSH esi
1948 PUSH edi
1949 mov 4+16(%esp), %esi // ESI = argument array
1950 mov 8+16(%esp), %ecx // ECX = size of args
1951 mov 12+16(%esp), %ebx // EBX = pc to call
1952 mov %esp, %ebp // Save stack pointer
1953 andl LITERAL(0xFFFFFFF0), %esp // Align stack
1954 PUSH ebp // Save old stack pointer
1955 subl LITERAL(12), %esp // Align stack
1956 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
1957 call .Losr_entry
1958
1959 // Restore stack pointer.
1960 addl LITERAL(12), %esp
1961 POP ebp
1962 mov %ebp, %esp
1963
1964 // Restore callee saves.
1965 POP edi
1966 POP esi
1967 POP ebx
1968 POP ebp
1969 mov 16(%esp), %ecx // Get JValue result
1970 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
1971 mov %edx, 4(%ecx) // Store the other half of the result
1972 mov 20(%esp), %edx // Get the shorty
1973 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
1974 je .Losr_return_double_quick
1975 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
1976 je .Losr_return_float_quick
1977 ret
1978.Losr_return_double_quick:
1979 movsd %xmm0, (%ecx) // Store the floating point result
1980 ret
1981.Losr_return_float_quick:
1982 movss %xmm0, (%ecx) // Store the floating point result
1983 ret
1984.Losr_entry:
1985 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
1986 subl %ecx, %esp
1987 mov %esp, %edi // EDI = beginning of stack
1988 rep movsb // while (ecx--) { *edi++ = *esi++ }
1989 jmp *%ebx
1990END_FUNCTION art_quick_osr_stub
1991
Elliott Hughes787ec202012-03-29 17:14:15 -07001992 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001993UNIMPLEMENTED art_quick_memcmp16