blob: 4ab47b9f07d7c297dbdd07df16b96026a0182e95 [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
85 pushl REG_VAR(got_reg) // Save got_reg
86 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)
100
101 // Ugly compile-time check, but we only have the preprocessor.
102 // Last +4: implicit return address pushed on stack when caller made call.
103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
104#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
105#endif
106END_MACRO
107
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700108MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -0700109 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800110 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700111 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
112 POP esi
113 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700114END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700115
116 /*
117 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -0700118 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700119 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700120MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -0800121 PUSH edi // Save callee saves
122 PUSH esi
123 PUSH ebp
124 PUSH ebx // Save args
125 PUSH edx
126 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000127 // Create space for FPR args.
128 subl MACRO_LITERAL(4 * 8), %esp
129 CFI_ADJUST_CFA_OFFSET(4 * 8)
130 // Save FPRs.
131 movsd %xmm0, 0(%esp)
132 movsd %xmm1, 8(%esp)
133 movsd %xmm2, 16(%esp)
134 movsd %xmm3, 24(%esp)
135
Andreas Gampe4360be22015-07-14 23:34:44 -0700136 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700137 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700138 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
139 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700140 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -0700141 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700142 CFI_ADJUST_CFA_OFFSET(4)
143 // Store esp as the stop quick frame.
144 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700145
146 // Ugly compile-time check, but we only have the preprocessor.
147 // Last +4: implicit return address pushed on stack when caller made call.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000148#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4*8 + 4)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700149#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
150#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700151END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700152
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700153 /*
154 * Macro that sets up the callee save frame to conform with
155 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX.
156 */
157MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000158 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700159 PUSH edi // Save callee saves
160 PUSH esi
161 PUSH ebp
162 PUSH ebx // Save args
163 PUSH edx
164 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000165
166 // Create space for FPR args.
167 subl MACRO_LITERAL(32), %esp
168 CFI_ADJUST_CFA_OFFSET(32)
169
170 // Save FPRs.
171 movsd %xmm0, 0(%esp)
172 movsd %xmm1, 8(%esp)
173 movsd %xmm2, 16(%esp)
174 movsd %xmm3, 24(%esp)
175
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700176 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
177 // Store esp as the stop quick frame.
178 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
179END_MACRO
180
181MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000182 // Restore FPRs. EAX is still on the stack.
183 movsd 4(%esp), %xmm0
184 movsd 12(%esp), %xmm1
185 movsd 20(%esp), %xmm2
186 movsd 28(%esp), %xmm3
187
188 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
189 CFI_ADJUST_CFA_OFFSET(-36)
190
Andreas Gampe4360be22015-07-14 23:34:44 -0700191 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800192 POP edx
193 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700194 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800195 POP esi
196 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700197END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700198
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000199// Restore register and jump to routine
200// Inputs: EDI contains pointer to code.
201// Notes: Need to pop EAX too (restores Method*)
202MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP)
203 POP eax // Restore Method*
204
205 // Restore FPRs.
206 movsd 0(%esp), %xmm0
207 movsd 8(%esp), %xmm1
208 movsd 16(%esp), %xmm2
209 movsd 24(%esp), %xmm3
210
211 addl MACRO_LITERAL(32), %esp // Remove FPRs.
212 CFI_ADJUST_CFA_OFFSET(-32)
213
214 POP ecx // Restore args except eax
215 POP edx
216 POP ebx
217 POP ebp // Restore callee saves
218 POP esi
219 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
220 ret
221END_MACRO
222
Ian Rogers57b86d42012-03-27 16:05:41 -0700223 /*
224 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
225 * exception is Thread::Current()->exception_.
226 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700227MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700228 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700229 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700230 subl MACRO_LITERAL(12), %esp // Alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700231 CFI_ADJUST_CFA_OFFSET(12)
232 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800233 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700234 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700235 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700236END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700237
Elliott Hughes787ec202012-03-29 17:14:15 -0700238MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700239 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700240 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700241 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700242 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700243 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700244 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800245 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700246 call CALLVAR(cxx_name) // cxx_name(Thread*)
247 UNREACHABLE
248 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700249END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700250
Elliott Hughes787ec202012-03-29 17:14:15 -0700251MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700252 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700253 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700254 mov %esp, %ecx
255 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700256 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700257 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700258 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800259 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700260 PUSH eax // pass arg1
261 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
262 UNREACHABLE
263 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700264END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700265
Elliott Hughes787ec202012-03-29 17:14:15 -0700266MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700267 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700268 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700269 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700270 PUSH eax // alignment padding
271 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800272 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700273 PUSH ecx // pass arg2
274 PUSH eax // pass arg1
275 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
276 UNREACHABLE
277 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700278END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700279
280 /*
281 * Called by managed code to create and deliver a NullPointerException.
282 */
Ian Rogers468532e2013-08-05 10:56:33 -0700283NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700284
285 /*
286 * Called by managed code to create and deliver an ArithmeticException.
287 */
Ian Rogers468532e2013-08-05 10:56:33 -0700288NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700289
290 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700291 * Called by managed code to create and deliver a StackOverflowError.
292 */
Ian Rogers468532e2013-08-05 10:56:33 -0700293NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700294
295 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700296 * Called by managed code, saves callee saves and then calls artThrowException
297 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
298 */
Ian Rogers468532e2013-08-05 10:56:33 -0700299ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700300
301 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700302 * Called by managed code to create and deliver a NoSuchMethodError.
303 */
Ian Rogers468532e2013-08-05 10:56:33 -0700304ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700305
306 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700307 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
308 * index, arg2 holds limit.
309 */
Ian Rogers468532e2013-08-05 10:56:33 -0700310TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700311
312 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100313 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
314 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
315 */
316TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
317
318 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700319 * All generated callsites for interface invokes and invocation slow paths will load arguments
320 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100321 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700322 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
323 *
324 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
325 * of the target Method* in r0 and method->code_ in r1.
326 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700327 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700328 * thread and we branch to another stub to deliver it.
329 *
330 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
331 * pointing back to the original caller.
332 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700333MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700334 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700335 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000336
Ian Rogers7caad772012-03-30 01:07:54 -0700337 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800338 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700339 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800340 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800341 PUSH ecx // pass arg2
342 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700343 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700344 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100345 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
346 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000347
348 // Restore FPRs.
349 movsd 0(%esp), %xmm0
350 movsd 8(%esp), %xmm1
351 movsd 16(%esp), %xmm2
352 movsd 24(%esp), %xmm3
353
354 // Remove space for FPR args.
355 addl MACRO_LITERAL(4 * 8), %esp
356 CFI_ADJUST_CFA_OFFSET(-4 * 8)
357
Dave Allisonbbb32c22013-11-05 18:25:18 -0800358 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800359 POP edx
360 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800361 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800362 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700363 // Swap EDI callee save with code pointer.
364 xchgl %edi, (%esp)
365 testl %eax, %eax // Branch forward if exception pending.
366 jz 1f
367 // Tail call to intended method.
368 ret
3691:
jeffhao20b5c6c2012-05-21 14:15:18 -0700370 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800371 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700372 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700373END_MACRO
374MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700375 DEFINE_FUNCTION VAR(c_name)
376 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
377 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700378END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700379
Logan Chien8dbb7082013-01-25 20:31:17 +0800380INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700381
Logan Chien8dbb7082013-01-25 20:31:17 +0800382INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
383INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
384INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
385INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700386
Jeff Hao5d917302013-02-27 17:57:33 -0800387 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000388 * Helper for quick invocation stub to set up XMM registers.
389 * Increments shorty and arg_array and clobbers temp_char.
390 * Branches to finished if it encounters the end of the shorty.
391 */
392MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3931: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700394 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
395 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
396 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
397 je VAR(finished) // goto finished
398 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
399 je 2f // goto FOUND_DOUBLE
400 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
401 je 3f // goto FOUND_FLOAT
402 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000403 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700404 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
405 jne 1b // goto LOOP
406 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
407 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004082: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700409 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
410 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000411 jmp 4f
4123: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700413 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
414 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004154:
416END_MACRO
417
418 /*
419 * Helper for quick invocation stub to set up GPR registers.
420 * Increments shorty and arg_array, and returns the current short character in
421 * temp_char. Branches to finished if it encounters the end of the shorty.
422 */
423MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
4241: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700425 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
426 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
427 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
428 je VAR(finished) // goto finished
429 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
430 je 3f // goto SKIP_FLOAT
431 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
432 je 4f // goto SKIP_DOUBLE
433 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004343: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700435 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
436 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004374: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700438 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
439 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004405:
441END_MACRO
442
443 /*
444 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700445 * On entry:
446 * [sp] = return address
447 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700448 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700449 * [sp + 12] = size of argument array in bytes
450 * [sp + 16] = (managed) thread pointer
451 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800452 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800453 */
454DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000455 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800456 PUSH ebp // save ebp
457 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000458 PUSH esi // save esi
459 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000460 // Set up argument XMM registers.
461 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
462 addl LITERAL(1), %esi
463 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
464 addl LITERAL(4), %edi
465 // Clobbers ESI, EDI, EAX.
466 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
467 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
468 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
469 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
470 .balign 16
471.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800472 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800473 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000474 mov 28(%ebp), %ebx // get arg array size
475 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
476 addl LITERAL(36), %ebx
477 // align frame size to 16 bytes
478 andl LITERAL(0xFFFFFFF0), %ebx
479 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800480 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000481
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700482 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000483
484 // Copy arg array into stack.
485 movl 28(%ebp), %ecx // ECX = size of args
486 movl 24(%ebp), %esi // ESI = argument array
487 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
488 rep movsb // while (ecx--) { *edi++ = *esi++ }
489
490 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
491 addl LITERAL(1), %esi
492 mov 24(%ebp), %edi // EDI := arg_array
493 mov 0(%edi), %ecx // ECX := this pointer
494 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
495
496 // Enumerate the possible cases for loading GPRS.
497 // edx (and maybe ebx):
498 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
499 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
500 je .LfirstLong
501 // Must be an integer value.
502 movl (%edi), %edx
503 addl LITERAL(4), %edi // arg_array++
504
505 // Now check ebx
506 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500507 // Must be first word of a long, or an integer. First word of long doesn't
508 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000509 movl (%edi), %ebx
510 jmp .Lgpr_setup_finished
511.LfirstLong:
512 movl (%edi), %edx
513 movl 4(%edi), %ebx
514 // Nothing left to load.
515.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000516 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700517 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800518 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800519 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000520 POP edi // pop edi
521 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800522 POP ebx // pop ebx
523 POP ebp // pop ebp
524 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800525 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800526 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800527 mov 24(%esp), %edx // get the shorty
528 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800529 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800530 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800531 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700532 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800533.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800534 movsd %xmm0, (%ecx) // store the floating point result
535 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800536.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800537 movss %xmm0, (%ecx) // store the floating point result
538 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800539END_FUNCTION art_quick_invoke_stub
540
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000541 /*
542 * Quick invocation stub (static).
543 * On entry:
544 * [sp] = return address
545 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700546 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000547 * [sp + 12] = size of argument array in bytes
548 * [sp + 16] = (managed) thread pointer
549 * [sp + 20] = JValue* result
550 * [sp + 24] = shorty
551 */
552DEFINE_FUNCTION art_quick_invoke_static_stub
553 // Save the non-volatiles.
554 PUSH ebp // save ebp
555 PUSH ebx // save ebx
556 PUSH esi // save esi
557 PUSH edi // save edi
558 // Set up argument XMM registers.
559 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
560 addl LITERAL(1), %esi
561 mov 8+16(%esp), %edi // EDI := arg_array
562 // Clobbers ESI, EDI, EAX.
563 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
564 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
565 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
566 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
567 .balign 16
568.Lxmm_setup_finished2:
569 mov %esp, %ebp // copy value of stack pointer into base pointer
570 CFI_DEF_CFA_REGISTER(ebp)
571 mov 28(%ebp), %ebx // get arg array size
572 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
573 addl LITERAL(36), %ebx
574 // align frame size to 16 bytes
575 andl LITERAL(0xFFFFFFF0), %ebx
576 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
577 subl %ebx, %esp // reserve stack space for argument array
578
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700579 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000580
581 // Copy arg array into stack.
582 movl 28(%ebp), %ecx // ECX = size of args
583 movl 24(%ebp), %esi // ESI = argument array
584 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
585 rep movsb // while (ecx--) { *edi++ = *esi++ }
586
587 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
588 addl LITERAL(1), %esi
589 mov 24(%ebp), %edi // EDI := arg_array
590
591 // Enumerate the possible cases for loading GPRS.
592 // ecx (and maybe edx)
593 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
594 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
595 je .LfirstLong2
596 // Must be an integer value. Load into ECX.
597 movl (%edi), %ecx
598 addl LITERAL(4), %edi // arg_array++
599
600 // Now check edx (and maybe ebx).
601 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
602 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
603 je .LSecondLong2
604 // Must be an integer. Load into EDX.
605 movl (%edi), %edx
606 addl LITERAL(4), %edi // arg_array++
607
608 // Is there anything for ebx?
609 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500610 // Must be first word of a long, or an integer. First word of long doesn't
611 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000612 movl (%edi), %ebx
613 jmp .Lgpr_setup_finished2
614.LSecondLong2:
615 // EDX:EBX is long. That is all.
616 movl (%edi), %edx
617 movl 4(%edi), %ebx
618 jmp .Lgpr_setup_finished2
619.LfirstLong2:
620 // ECX:EDX is a long
621 movl (%edi), %ecx
622 movl 4(%edi), %edx
623 addl LITERAL(8), %edi // arg_array += 2
624
625 // Anything for EBX?
626 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500627 // Must be first word of a long, or an integer. First word of long doesn't
628 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000629 movl (%edi), %ebx
630 jmp .Lgpr_setup_finished2
631 // Nothing left to load.
632.Lgpr_setup_finished2:
633 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700634 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000635 mov %ebp, %esp // restore stack pointer
636 CFI_DEF_CFA_REGISTER(esp)
637 POP edi // pop edi
638 POP esi // pop esi
639 POP ebx // pop ebx
640 POP ebp // pop ebp
641 mov 20(%esp), %ecx // get result pointer
642 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
643 mov %edx, 4(%ecx) // store the other half of the result
644 mov 24(%esp), %edx // get the shorty
645 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
646 je .Lreturn_double_quick2
647 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
648 je .Lreturn_float_quick2
649 ret
650.Lreturn_double_quick2:
651 movsd %xmm0, (%ecx) // store the floating point result
652 ret
653.Lreturn_float_quick2:
654 movss %xmm0, (%ecx) // store the floating point result
655 ret
656END_FUNCTION art_quick_invoke_static_stub
657
Ian Rogersd36c52e2012-04-09 16:29:25 -0700658MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700659 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700660 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700661 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700662 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700663 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700664 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800665 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700666 call CALLVAR(cxx_name) // cxx_name(Thread*)
667 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800668 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700669 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
670 CALL_MACRO(return_macro) // return or deliver exception
671 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700672END_MACRO
673
674MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700675 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700676 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700677 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700678 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700679 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700680 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800681 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700682 PUSH eax // pass arg1
683 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
684 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800685 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700686 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
687 CALL_MACRO(return_macro) // return or deliver exception
688 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700689END_MACRO
690
691MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700692 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700693 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700694 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700695 PUSH eax // push padding
696 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800697 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700698 PUSH ecx // pass arg2
699 PUSH eax // pass arg1
700 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
701 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800702 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700703 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
704 CALL_MACRO(return_macro) // return or deliver exception
705 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700706END_MACRO
707
Ian Rogersd36c52e2012-04-09 16:29:25 -0700708MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700709 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700710 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700711 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700712 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800713 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700714 PUSH edx // pass arg3
715 PUSH ecx // pass arg2
716 PUSH eax // pass arg1
717 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
718 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700719 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700720 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
721 CALL_MACRO(return_macro) // return or deliver exception
722 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700723END_MACRO
724
Jeff Hao848f70a2014-01-15 13:49:50 -0800725MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700726 DEFINE_FUNCTION VAR(c_name)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100727 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000728
Jeff Hao848f70a2014-01-15 13:49:50 -0800729 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700730 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800731 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700732 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800733 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700734 PUSH ebx // pass arg4
735 PUSH edx // pass arg3
736 PUSH ecx // pass arg2
737 PUSH eax // pass arg1
738 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
739 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800740 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700741 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
742 CALL_MACRO(return_macro) // return or deliver exception
743 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800744END_MACRO
745
Fred Shih37f05ef2014-07-16 18:38:08 -0700746MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700747 DEFINE_FUNCTION VAR(c_name)
748 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700749 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700750 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700751 PUSH eax // push padding
752 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700753 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700754 PUSH ecx // pass referrer
755 PUSH eax // pass arg1
756 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
757 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700758 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700759 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
760 CALL_MACRO(return_macro) // return or deliver exception
761 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700762END_MACRO
763
764MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700765 DEFINE_FUNCTION VAR(c_name)
766 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700767 // Outgoing argument set up
768 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700769 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700770 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700771 PUSH edx // pass referrer
772 PUSH ecx // pass arg2
773 PUSH eax // pass arg1
774 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
775 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700776 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700777 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
778 CALL_MACRO(return_macro) // return or deliver exception
779 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700780END_MACRO
781
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700782MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700783 DEFINE_FUNCTION VAR(c_name)
784 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700785 // Outgoing argument set up
786 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700787 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700788 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700789 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700790 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700791 PUSH ebx // pass referrer
792 PUSH edx // pass arg3
793 PUSH ecx // pass arg2
794 PUSH eax // pass arg1
795 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
796 // Thread*)
797 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700798 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700799 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
800 CALL_MACRO(return_macro) // return or deliver exception
801 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700802END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700803
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700804MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700805 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700806 jz 1f // if eax == 0 goto 1
807 ret // return
8081: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700809 DELIVER_PENDING_EXCEPTION
810END_MACRO
811
Ian Rogersd36c52e2012-04-09 16:29:25 -0700812MACRO0(RETURN_IF_EAX_ZERO)
813 testl %eax, %eax // eax == 0 ?
814 jnz 1f // if eax != 0 goto 1
815 ret // return
8161: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700817 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700818END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700819
jeffhaod66a8752012-05-22 15:30:16 -0700820MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700821 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700822 jne 1f // if exception field != 0 goto 1
823 ret // return
8241: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700825 DELIVER_PENDING_EXCEPTION
826END_MACRO
827
Mathieu Chartier7410f292013-11-24 13:17:35 -0800828// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700829GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800830
831// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
832DEFINE_FUNCTION art_quick_alloc_object_rosalloc
833 // Fast path rosalloc allocation.
834 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
835 // ebx, edx: free
836 PUSH edi
837 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
838 // Load the class (edx)
839 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
840 testl %edx, %edx // Check null class
841 jz .Lart_quick_alloc_object_rosalloc_slow_path
842 // Check class status
843 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
844 jne .Lart_quick_alloc_object_rosalloc_slow_path
845 // No fake dependence needed on x86
846 // between status and flags load,
847 // since each load is a load-acquire,
848 // no loads reordering.
849 // Check access flags has
850 // kAccClassIsFinalizable
851 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
852 jnz .Lart_quick_alloc_object_rosalloc_slow_path
853
854 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
855 // Check if the thread local allocation
856 // stack has room
857 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
858 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
859 jae .Lart_quick_alloc_object_rosalloc_slow_path
860
861 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
862 // Check if the size is for a thread
863 // local allocation
864 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
865 ja .Lart_quick_alloc_object_rosalloc_slow_path
866 decl %edi
867 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
868 // from object size.
869 // Align up the size by the rosalloc
870 // bracket quantum size and divide
871 // by the quantum size and subtract
872 // by 1. This code is a shorter but
873 // equivalent version.
874 // Load thread local rosalloc run (ebx)
875 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
876 // Load free_list head (edi),
877 // this will be the return value.
878 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
879 test %edi, %edi
880 jz .Lart_quick_alloc_object_rosalloc_slow_path
881 // Point of no slow path. Won't go to
882 // the slow path from here on. Ok to
883 // clobber eax and ecx.
884 movl %edi, %eax
885 // Load the next pointer of the head
886 // and update head of free list with
887 // next pointer
888 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
889 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
890 // Decrement size of free list by 1
891 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
892 // Store the class pointer in the
893 // header. This also overwrites the
894 // next pointer. The offsets are
895 // asserted to match.
896#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
897#error "Class pointer needs to overwrite next pointer."
898#endif
899 POISON_HEAP_REF edx
900 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
901 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
902 // Push the new object onto the thread
903 // local allocation stack and
904 // increment the thread local
905 // allocation stack top.
906 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
907 movl %eax, (%edi)
908 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
909 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
910 // No fence needed for x86.
911 POP edi
912 ret
913.Lart_quick_alloc_object_rosalloc_slow_path:
914 POP edi
915 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
916 // Outgoing argument set up
917 PUSH eax // alignment padding
918 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
919 CFI_ADJUST_CFA_OFFSET(4)
920 PUSH ecx
921 PUSH eax
922 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
923 addl LITERAL(16), %esp // pop arguments
924 CFI_ADJUST_CFA_OFFSET(-16)
925 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
926 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
927END_FUNCTION art_quick_alloc_object_rosalloc
928
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800929// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
930//
931// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
932MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
933 testl %edx, %edx // Check null class
934 jz VAR(slowPathLabel)
935 // Check class status.
936 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
937 jne VAR(slowPathLabel)
938 // No fake dependence needed on x86
939 // between status and flags load,
940 // since each load is a load-acquire,
941 // no loads reordering.
942 // Check access flags has
943 // kAccClassIsFinalizable
944 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
945 jnz VAR(slowPathLabel)
946 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
947 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
948 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
949 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
950 cmpl %edi, %esi // Check if it fits. OK to do this
951 // before rounding up the object size
952 // assuming the buf size alignment.
953 ja VAR(slowPathLabel)
954 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
955 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
956 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
957 // as allocated object.
958 addl %eax, %esi // Add the object size.
959 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
960 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
961 // Store the class pointer in the header.
962 // No fence needed for x86.
963 POISON_HEAP_REF edx
964 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
965 POP edi
966 POP esi
967 ret // Fast path succeeded.
968END_MACRO
969
970// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
971MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
972 POP edi
973 POP esi
974 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
975 // Outgoing argument set up
976 PUSH eax // alignment padding
977 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
978 CFI_ADJUST_CFA_OFFSET(4)
979 PUSH ecx
980 PUSH eax
981 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
982 addl LITERAL(16), %esp
983 CFI_ADJUST_CFA_OFFSET(-16)
984 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
985 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
986END_MACRO
987
988// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
989DEFINE_FUNCTION art_quick_alloc_object_tlab
990 // Fast path tlab allocation.
991 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
992 // EBX, EDX: free.
993#if defined(USE_READ_BARRIER)
994 int3
995 int3
996#endif
997 PUSH esi
998 PUSH edi
999 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1000 // Might need to break down into multiple instructions to get the base address in a register.
1001 // Load the class
1002 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1003 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1004.Lart_quick_alloc_object_tlab_slow_path:
1005 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1006END_FUNCTION art_quick_alloc_object_tlab
1007
1008// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1009DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1010 // Fast path region tlab allocation.
1011 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1012 // EBX, EDX: free.
1013#if !defined(USE_READ_BARRIER)
1014 int3
1015 int3
1016#endif
1017 PUSH esi
1018 PUSH edi
1019 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1020 // Might need to break down into multiple instructions to get the base address in a register.
1021 // Load the class
1022 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1023 // Read barrier for class load.
1024 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1025 jne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1026.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1027 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1028.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1029 // The read barrier slow path. Mark the class.
1030 PUSH eax
1031 PUSH ecx
1032 // Outgoing argument set up
1033 subl MACRO_LITERAL(8), %esp // Alignment padding
1034 CFI_ADJUST_CFA_OFFSET(8)
1035 PUSH edx // Pass the class as the first param.
1036 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1037 movl %eax, %edx
1038 addl MACRO_LITERAL(12), %esp
1039 CFI_ADJUST_CFA_OFFSET(-12)
1040 POP ecx
1041 POP eax
1042 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1043.Lart_quick_alloc_object_region_tlab_slow_path:
1044 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1045END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001046
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001047ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1048ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1049ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1050ONE_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 -07001051
Ian Rogers832336b2014-10-08 15:35:22 -07001052TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001053
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001054DEFINE_FUNCTION art_quick_lock_object
1055 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001056 jz .Lslow_lock
1057.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001058 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001059 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001060 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001061 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
1062 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001063 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001064 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001065 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001066 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001067 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1068 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1069 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1070 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1071 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001072 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001073.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1074 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001075 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001076 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001077 movl %edx, %ecx // copy the lock word to check count overflow.
1078 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
1079 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
1080 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 -08001081 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001082 movl %eax, %ecx // save obj to use eax for cmpxchg.
1083 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1084 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1085 // update lockword, cmpxchg necessary for read barrier bits.
1086 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1087 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001088 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001089.Llock_cmpxchg_fail:
1090 movl %ecx, %eax // restore eax
1091 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001092.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001093 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001094 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001095 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001096 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001097 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001098 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001099 PUSH eax // pass object
1100 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1101 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001102 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001103 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001104 RETURN_IF_EAX_ZERO
1105END_FUNCTION art_quick_lock_object
1106
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001107DEFINE_FUNCTION art_quick_lock_object_no_inline
1108 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1109 // Outgoing argument set up
1110 subl LITERAL(8), %esp // alignment padding
1111 CFI_ADJUST_CFA_OFFSET(8)
1112 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1113 CFI_ADJUST_CFA_OFFSET(4)
1114 PUSH eax // pass object
1115 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1116 addl LITERAL(16), %esp // pop arguments
1117 CFI_ADJUST_CFA_OFFSET(-16)
1118 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1119 RETURN_IF_EAX_ZERO
1120END_FUNCTION art_quick_lock_object_no_inline
1121
1122
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001123DEFINE_FUNCTION art_quick_unlock_object
1124 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001125 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001126.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001127 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001128 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001129 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001130 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001131 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001132 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001133 movl %ecx, %edx // copy the lock word to detect new count of 0.
1134 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
1135 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001136 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001137 // update lockword, cmpxchg necessary for read barrier bits.
1138 movl %eax, %edx // edx: obj
1139 movl %ecx, %eax // eax: old lock word.
1140 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
1141#ifndef USE_READ_BARRIER
1142 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1143#else
1144 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1145 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1146#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001147 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001148.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1149 // update lockword, cmpxchg necessary for read barrier bits.
1150 movl %eax, %edx // edx: obj
1151 movl %ecx, %eax // eax: old lock word.
1152 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1153#ifndef USE_READ_BARRIER
1154 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1155#else
1156 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1157 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1158#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001159 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001160.Lunlock_cmpxchg_fail: // edx: obj
1161 movl %edx, %eax // restore eax
1162 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001163.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001164 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001165 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001166 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001167 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001168 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001169 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001170 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001171 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001172 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001173 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001174 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001175 RETURN_IF_EAX_ZERO
1176END_FUNCTION art_quick_unlock_object
1177
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001178DEFINE_FUNCTION art_quick_unlock_object_no_inline
1179 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1180 // Outgoing argument set up
1181 subl LITERAL(8), %esp // alignment padding
1182 CFI_ADJUST_CFA_OFFSET(8)
1183 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1184 CFI_ADJUST_CFA_OFFSET(4)
1185 PUSH eax // pass object
1186 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1187 addl LITERAL(16), %esp // pop arguments
1188 CFI_ADJUST_CFA_OFFSET(-16)
1189 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1190 RETURN_IF_EAX_ZERO
1191END_FUNCTION art_quick_unlock_object_no_inline
1192
Ian Rogers468532e2013-08-05 10:56:33 -07001193DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001194 PUSH eax // alignment padding
1195 PUSH ecx // pass arg2 - obj->klass
1196 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001197 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001198 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001199 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001200 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001201END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001202
Ian Rogersa9a82542013-10-04 11:17:26 -07001203DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001204 PUSH eax // alignment padding
1205 PUSH ecx // pass arg2 - obj->klass
1206 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001207 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001208 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001209 jz 1f // jump forward if not assignable
1210 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001211 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001212 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001213
Andreas Gampe4360be22015-07-14 23:34:44 -07001214 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070012151:
Andreas Gampe4360be22015-07-14 23:34:44 -07001216 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001217 POP ecx
1218 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001219 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001220 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001221 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001222 PUSH eax // alignment padding
1223 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001224 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001225 PUSH ecx // pass arg2
1226 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001227 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001228 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001229END_FUNCTION art_quick_check_cast
1230
Man Cao1aee9002015-07-14 22:31:42 -07001231// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1232MACRO2(POP_REG_NE, reg, exclude_reg)
1233 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1234 addl MACRO_LITERAL(4), %esp
1235 CFI_ADJUST_CFA_OFFSET(-4)
1236 .else
1237 POP RAW_VAR(reg)
1238 .endif
1239END_MACRO
1240
1241 /*
1242 * Macro to insert read barrier, only used in art_quick_aput_obj.
1243 * obj_reg and dest_reg are registers, offset is a defined literal such as
1244 * MIRROR_OBJECT_CLASS_OFFSET.
1245 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1246 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1247 */
1248MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1249#ifdef USE_READ_BARRIER
1250 PUSH eax // save registers used in art_quick_aput_obj
1251 PUSH ebx
1252 PUSH edx
1253 PUSH ecx
1254 // Outgoing argument set up
1255 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1256 CFI_ADJUST_CFA_OFFSET(4)
1257 PUSH RAW_VAR(obj_reg) // pass obj_reg
1258 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1259 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1260 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1261 .ifnc RAW_VAR(dest_reg), eax
1262 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1263 .endif
1264 addl MACRO_LITERAL(12), %esp // pop arguments
1265 CFI_ADJUST_CFA_OFFSET(-12)
1266 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1267 POP_REG_NE edx, RAW_VAR(dest_reg)
1268 POP_REG_NE ebx, RAW_VAR(dest_reg)
1269 .ifc RAW_VAR(pop_eax), true
1270 POP_REG_NE eax, RAW_VAR(dest_reg)
1271 .endif
1272#else
1273 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1274 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1275#endif // USE_READ_BARRIER
1276END_MACRO
1277
Ian Rogersa9a82542013-10-04 11:17:26 -07001278 /*
1279 * Entry from managed code for array put operations of objects where the value being stored
1280 * needs to be checked for compatibility.
1281 * eax = array, ecx = index, edx = value
1282 */
1283DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1284 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001285 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1286 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001287END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1288
1289DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001290 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001291 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001292 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001293 mov %ecx, %eax
1294 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001295 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001296END_FUNCTION art_quick_aput_obj_with_bound_check
1297
1298DEFINE_FUNCTION art_quick_aput_obj
1299 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001300 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001301 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1302 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001303 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001304#if defined(USE_READ_BARRIER)
1305 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1306 cmpl %eax, %ebx
1307 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001308 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001309#elif defined(USE_HEAP_POISONING)
1310 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001311 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1312 UNPOISON_HEAP_REF eax
1313 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001314 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001315#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001316 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001317#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001318 jne .Lcheck_assignability
1319.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001320 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001321 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001322 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1323 shrl LITERAL(7), %eax
1324 movb %dl, (%edx, %eax)
1325 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001326.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001327 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001328 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001329.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001330 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001331 PUSH ecx
1332 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001333#if defined(USE_READ_BARRIER)
1334 subl LITERAL(4), %esp // alignment padding
1335 CFI_ADJUST_CFA_OFFSET(4)
1336 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1337 subl LITERAL(4), %esp // alignment padding
1338 CFI_ADJUST_CFA_OFFSET(4)
1339 PUSH eax // pass arg2 - type of the value to be stored
1340#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001341 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001342 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001343 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001344 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001345 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001346#else
Man Cao63069212015-08-21 15:51:39 -07001347 subl LITERAL(8), %esp // alignment padding
1348 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001349 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001350 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001351#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001352 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001353 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001354 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001355 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001356 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001357 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001358 POP edx
1359 POP ecx
1360 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001361 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001362 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001363 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1364 shrl LITERAL(7), %eax
1365 movb %dl, (%edx, %eax)
1366 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001367 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001368.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001369 POP edx
1370 POP ecx
1371 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001372 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001373 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001374 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001375 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001376 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001377 PUSH edx // pass arg2 - value
1378 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001379 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001380 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001381END_FUNCTION art_quick_aput_obj
1382
Logan Chien8dbb7082013-01-25 20:31:17 +08001383DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001384 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001385 PUSH edx // pass arg3
1386 PUSH ecx // pass arg2
1387 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001388 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001389 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001390 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001391 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001392END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001393
Logan Chien8dbb7082013-01-25 20:31:17 +08001394NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001395
Ian Rogers468532e2013-08-05 10:56:33 -07001396DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001397 subl LITERAL(12), %esp // alignment padding, room for argument
1398 CFI_ADJUST_CFA_OFFSET(12)
1399 movsd %xmm0, 0(%esp) // arg a
1400 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001401 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001402 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001403 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001404END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001405
Ian Rogers468532e2013-08-05 10:56:33 -07001406DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001407 subl LITERAL(12), %esp // alignment padding
1408 CFI_ADJUST_CFA_OFFSET(12)
1409 movss %xmm0, 0(%esp) // arg a
1410 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001411 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001412 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001413 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001414END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001415
Ian Rogers468532e2013-08-05 10:56:33 -07001416DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001417 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001418 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001419 PUSH ebx // pass arg4 b.hi
1420 PUSH edx // pass arg3 b.lo
1421 PUSH ecx // pass arg2 a.hi
1422 PUSH eax // pass arg1 a.lo
1423 call SYMBOL(artLdiv) // (jlong a, jlong b)
1424 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001425 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001426 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001427END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001428
Ian Rogersa9a82542013-10-04 11:17:26 -07001429DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001430 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001431 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001432 PUSH ebx // pass arg4 b.hi
1433 PUSH edx // pass arg3 b.lo
1434 PUSH ecx // pass arg2 a.hi
1435 PUSH eax // pass arg1 a.lo
1436 call SYMBOL(artLmod) // (jlong a, jlong b)
1437 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001438 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001439 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001440END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001441
Ian Rogers468532e2013-08-05 10:56:33 -07001442DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001443 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1444 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1445 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001446 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001447 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001448 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001449END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001450
Ian Rogers468532e2013-08-05 10:56:33 -07001451DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001452 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001453 xchg %edx, %ecx
1454 shld %cl,%eax,%edx
1455 shl %cl,%eax
1456 test LITERAL(32), %cl
1457 jz 1f
1458 mov %eax, %edx
1459 xor %eax, %eax
14601:
1461 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001462END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001463
Ian Rogers468532e2013-08-05 10:56:33 -07001464DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001465 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001466 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001467 shrd %cl,%edx,%eax
1468 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001469 test LITERAL(32),%cl
1470 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001471 mov %edx, %eax
1472 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014731:
1474 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001475END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001476
Ian Rogers468532e2013-08-05 10:56:33 -07001477DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001478 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001479 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001480 shrd %cl,%edx,%eax
1481 shr %cl,%edx
1482 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001483 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001484 mov %edx, %eax
1485 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014861:
1487 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001488END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001489
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001490ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1491ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1492ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1493ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1494ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1495ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1496ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001497
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001498TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1499TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1500TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1501TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1502TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1503TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1504TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001505
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001506TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1507TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1508TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1509TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001510
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001511THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1512THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1513THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1514THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1515
1516// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001517DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001518 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001519 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001520 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001521 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001522 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001523 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001524 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001525 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001526 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1527 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001528 PUSH ebx // pass high half of new_val
1529 PUSH edx // pass low half of new_val
1530 PUSH ecx // pass object
1531 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001532 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001533 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001534 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001535 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001536 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001537END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001538
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001539// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1540// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001541DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001542 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1543 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001544 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001545 movd %xmm0, %ebx
1546 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001547 subl LITERAL(12), %esp // alignment padding
1548 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001549 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001550 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001551 PUSH ebx // pass high half of new_val
1552 PUSH edx // pass low half of new_val
1553 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001554 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001555 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001556 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001557 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001558 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001559 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001560END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001561
Logan Chien8dbb7082013-01-25 20:31:17 +08001562DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001563 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001564 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001565 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001566 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001567 PUSH ecx // pass receiver
1568 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001569 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001570 movd %eax, %xmm0 // place return value also into floating point return value
1571 movd %edx, %xmm1
1572 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001573 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1574 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1575 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001576 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001577END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001578
Jeff Hao88474b42013-10-23 16:24:40 -07001579 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001580 * Called to resolve an imt conflict.
1581 * eax is the conflict ArtMethod.
1582 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1583 *
1584 * Note that this stub writes to eax.
1585 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001586 */
1587DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001588 PUSH EDI
1589 movl 8(%esp), %edi // Load referrer
1590 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1591 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1592 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001593 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001594 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1595 popl %eax // Pop ImtConflictTable.
1596 CFI_ADJUST_CFA_OFFSET(-4)
1597.Limt_table_iterate:
1598 cmpl %edi, 0(%eax)
1599 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001600 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001601 // and jump to it.
1602 POP EDI
1603 movl __SIZEOF_POINTER__(%eax), %eax
1604 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1605.Limt_table_next_entry:
1606 // If the entry is null, the interface method is not in the ImtConflictTable.
1607 cmpl LITERAL(0), 0(%eax)
1608 jz .Lconflict_trampoline
1609 // Iterate over the entries of the ImtConflictTable.
1610 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1611 jmp .Limt_table_iterate
1612.Lconflict_trampoline:
1613 // Call the runtime stub to populate the ImtConflictTable and jump to the
1614 // resolved method.
1615 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001616 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001617END_FUNCTION art_quick_imt_conflict_trampoline
1618
Ian Rogers468532e2013-08-05 10:56:33 -07001619DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001620 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001621 movl %esp, %edi
1622 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001623 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001624 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001625 PUSH ecx // pass receiver
1626 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001627 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001628 movl %eax, %edi // remember code pointer in EDI
1629 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001630 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001631 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001632 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001633 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070016341:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001635 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001636 DELIVER_PENDING_EXCEPTION
1637END_FUNCTION art_quick_resolution_trampoline
1638
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001639DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001640 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001641 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001642 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001643 subl LITERAL(5120), %esp
1644 // prepare for artQuickGenericJniTrampoline call
1645 // (Thread*, SP)
1646 // (esp) 4(esp) <= C calling convention
1647 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001648
1649 subl LITERAL(8), %esp // Padding for 16B alignment.
1650 pushl %ebp // Pass SP (to ArtMethod).
1651 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001652 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001653
Andreas Gampec200a4a2014-06-16 18:39:09 -07001654 // The C call will have registered the complete save-frame on success.
1655 // The result of the call is:
1656 // eax: pointer to native code, 0 on error.
1657 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001658
Andreas Gampec200a4a2014-06-16 18:39:09 -07001659 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001660 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001661 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001662
Andreas Gampec200a4a2014-06-16 18:39:09 -07001663 // Release part of the alloca.
1664 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001665
1666 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001667 // Native call.
1668 call *%eax
1669
Andreas Gampe779f8c92014-06-09 18:29:38 -07001670 // result sign extension is handled in C code
1671 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001672 // (Thread*, result, result_f)
1673 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001674 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001675
Andreas Gampe4360be22015-07-14 23:34:44 -07001676 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001677 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001678 pushl %edx // Pass int result.
1679 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001680 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001681 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001682
Andreas Gampe779f8c92014-06-09 18:29:38 -07001683 // Pending exceptions possible.
1684 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1685 testl %ebx, %ebx
1686 jnz .Lexception_in_native
1687
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001688 // Tear down the alloca.
1689 movl %ebp, %esp
1690 CFI_DEF_CFA_REGISTER(esp)
1691
1692
Andreas Gampe779f8c92014-06-09 18:29:38 -07001693 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001694 // Remove space for FPR args and EAX
1695 addl LITERAL(4 + 4 * 8), %esp
1696 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1697
Andreas Gampe779f8c92014-06-09 18:29:38 -07001698 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001699 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001700 CFI_ADJUST_CFA_OFFSET(-4)
1701 POP ebx
1702 POP ebp // Restore callee saves
1703 POP esi
1704 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001705 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001706 movd %eax, %xmm0
1707 movd %edx, %xmm1
1708 punpckldq %xmm1, %xmm0
1709 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001710.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001711 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1712 // Do a call to push a new save-all frame required by the runtime.
1713 call .Lexception_call
1714.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001715 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001716END_FUNCTION art_quick_generic_jni_trampoline
1717
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001718DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001719 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001720 mov %esp, %edx // remember SP
1721 PUSH eax // alignment padding
1722 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001723 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001724 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001725 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001726 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001727 addl LITERAL(16), %esp // pop arguments
1728 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001729
1730 // Return eax:edx in xmm0 also.
1731 movd %eax, %xmm0
1732 movd %edx, %xmm1
1733 punpckldq %xmm1, %xmm0
1734
1735 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1736 CFI_ADJUST_CFA_OFFSET(-48)
1737
Andreas Gampe4360be22015-07-14 23:34:44 -07001738 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001739 POP esi
1740 POP edi
1741
Ian Rogers7db619b2013-01-16 18:35:48 -08001742 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001743END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001744
jeffhao7e4fcb82013-01-10 18:11:08 -08001745 /*
1746 * Routine that intercepts method calls and returns.
1747 */
Ian Rogers468532e2013-08-05 10:56:33 -07001748DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001749 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001750 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001751 subl LITERAL(12), %esp // Align stack.
1752 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001753 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001754 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001755 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001756 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001757 PUSH ecx // Pass receiver.
1758 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001759 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001760 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001761 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001762 movl 60(%esp), %edi // Restore edi.
1763 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001764 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001765 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001766 movl %ebx, 64(%esp)
1767 movl 0(%esp), %eax // Restore eax.
1768 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1769 movsd 8(%esp), %xmm0
1770 movsd 16(%esp), %xmm1
1771 movsd 24(%esp), %xmm2
1772 movsd 32(%esp), %xmm3
1773
1774 // Restore GPRs.
1775 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001776 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001777 movl 48(%esp), %ebx // Restore ebx.
1778 movl 52(%esp), %ebp // Restore ebp.
1779 movl 56(%esp), %esi // Restore esi.
1780 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001781 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001782 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001783END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001784
Ian Rogers468532e2013-08-05 10:56:33 -07001785DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001786 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001787 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001788 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001789 mov %esp, %ecx // Remember SP
1790 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001791 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001792 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001793 PUSH edx // Save gpr return value.
1794 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001795 subl LITERAL(16), %esp // Align stack
1796 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001797 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001798 PUSH edx // Pass gpr return value.
1799 PUSH eax
1800 PUSH ecx // Pass SP.
1801 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001802 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001803 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001804 mov %eax, %ecx // Move returned link register.
1805 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001806 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001807 movl %edx, %ebx // Move returned link register for deopt
1808 // (ebx is pretending to be our LR).
1809 POP eax // Restore gpr return value.
1810 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001811 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001812 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001813 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001814 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001815 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001816 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001817 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001818END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001819
jeffhao7e4fcb82013-01-10 18:11:08 -08001820 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001821 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1822 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001823 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001824DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001825 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001826 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1827 subl LITERAL(12), %esp // Align stack.
1828 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001829 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001830 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001831 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001832 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001833END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001834
jeffhao86e46712012-08-08 17:30:59 -07001835 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001836 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001837 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001838 */
1839DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1840 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1841 subl LITERAL(12), %esp // Align stack.
1842 CFI_ADJUST_CFA_OFFSET(12)
1843 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1844 CFI_ADJUST_CFA_OFFSET(4)
1845 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1846 UNREACHABLE
1847END_FUNCTION art_quick_deoptimize_from_compiled_code
1848
1849 /*
jeffhao86e46712012-08-08 17:30:59 -07001850 * String's compareTo.
1851 *
1852 * On entry:
1853 * eax: this string object (known non-null)
1854 * ecx: comp string object (known non-null)
1855 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001856DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001857 PUSH esi // push callee save reg
1858 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001859 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1860 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001861 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1862 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001863 /* Calculate min length and count diff */
1864 mov %edx, %ecx
1865 mov %edx, %eax
1866 subl %ebx, %eax
1867 cmovg %ebx, %ecx
1868 /*
1869 * At this point we have:
1870 * eax: value to return if first part of strings are equal
1871 * ecx: minimum among the lengths of the two strings
1872 * esi: pointer to this string data
1873 * edi: pointer to comp string data
1874 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001875 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001876 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001877 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001878.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001879 POP edi // pop callee save reg
1880 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001881 ret
1882 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001883.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001884 movzwl -2(%esi), %eax // get last compared char from this string
1885 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001886 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001887 POP edi // pop callee save reg
1888 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001889 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001890END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001891
Dave Allison8ce6b902014-08-26 11:07:58 -07001892// Return from a nested signal:
1893// Entry:
1894// eax: address of jmp_buf in TLS
1895
1896DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001897 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001898 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001899 PUSH ecx // second arg to longjmp (1)
1900 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001901 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001902 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001903END_FUNCTION art_nested_signal_return
1904
Roland Levillain7c1559a2015-12-15 10:55:36 +00001905DEFINE_FUNCTION art_quick_read_barrier_mark
1906 PUSH eax // pass arg1 - obj
1907 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
1908 addl LITERAL(4), %esp // pop argument
1909 CFI_ADJUST_CFA_OFFSET(-4)
1910 ret
1911END_FUNCTION art_quick_read_barrier_mark
1912
Man Cao1aee9002015-07-14 22:31:42 -07001913DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001914 PUSH edx // pass arg3 - offset
1915 PUSH ecx // pass arg2 - obj
1916 PUSH eax // pass arg1 - ref
1917 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1918 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001919 CFI_ADJUST_CFA_OFFSET(-12)
1920 ret
1921END_FUNCTION art_quick_read_barrier_slow
1922
Roland Levillain0d5a2812015-11-13 10:07:31 +00001923DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
1924 PUSH eax // pass arg1 - root
1925 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
1926 addl LITERAL(4), %esp // pop argument
1927 CFI_ADJUST_CFA_OFFSET(-4)
1928 ret
1929END_FUNCTION art_quick_read_barrier_for_root_slow
1930
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001931 /*
1932 * On stack replacement stub.
1933 * On entry:
1934 * [sp] = return address
1935 * [sp + 4] = stack to copy
1936 * [sp + 8] = size of stack
1937 * [sp + 12] = pc to call
1938 * [sp + 16] = JValue* result
1939 * [sp + 20] = shorty
1940 * [sp + 24] = thread
1941 */
1942DEFINE_FUNCTION art_quick_osr_stub
1943 // Save native callee saves.
1944 PUSH ebp
1945 PUSH ebx
1946 PUSH esi
1947 PUSH edi
1948 mov 4+16(%esp), %esi // ESI = argument array
1949 mov 8+16(%esp), %ecx // ECX = size of args
1950 mov 12+16(%esp), %ebx // EBX = pc to call
1951 mov %esp, %ebp // Save stack pointer
1952 andl LITERAL(0xFFFFFFF0), %esp // Align stack
1953 PUSH ebp // Save old stack pointer
1954 subl LITERAL(12), %esp // Align stack
1955 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
1956 call .Losr_entry
1957
1958 // Restore stack pointer.
1959 addl LITERAL(12), %esp
1960 POP ebp
1961 mov %ebp, %esp
1962
1963 // Restore callee saves.
1964 POP edi
1965 POP esi
1966 POP ebx
1967 POP ebp
1968 mov 16(%esp), %ecx // Get JValue result
1969 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
1970 mov %edx, 4(%ecx) // Store the other half of the result
1971 mov 20(%esp), %edx // Get the shorty
1972 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
1973 je .Losr_return_double_quick
1974 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
1975 je .Losr_return_float_quick
1976 ret
1977.Losr_return_double_quick:
1978 movsd %xmm0, (%ecx) // Store the floating point result
1979 ret
1980.Losr_return_float_quick:
1981 movss %xmm0, (%ecx) // Store the floating point result
1982 ret
1983.Losr_entry:
1984 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
1985 subl %ecx, %esp
1986 mov %esp, %edi // EDI = beginning of stack
1987 rep movsb // while (ecx--) { *edi++ = *esi++ }
1988 jmp *%ebx
1989END_FUNCTION art_quick_osr_stub
1990
Elliott Hughes787ec202012-03-29 17:14:15 -07001991 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001992UNIMPLEMENTED art_quick_memcmp16