blob: 2d7f664809123e553f531c67462880afbf8e6b2f [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 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700313 * All generated callsites for interface invokes and invocation slow paths will load arguments
314 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100315 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700316 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
317 *
318 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
319 * of the target Method* in r0 and method->code_ in r1.
320 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700321 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700322 * thread and we branch to another stub to deliver it.
323 *
324 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
325 * pointing back to the original caller.
326 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700327MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700328 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700329 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000330
Ian Rogers7caad772012-03-30 01:07:54 -0700331 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800332 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700333 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800334 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800335 PUSH ecx // pass arg2
336 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700337 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700338 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100339 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
340 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000341
342 // Restore FPRs.
343 movsd 0(%esp), %xmm0
344 movsd 8(%esp), %xmm1
345 movsd 16(%esp), %xmm2
346 movsd 24(%esp), %xmm3
347
348 // Remove space for FPR args.
349 addl MACRO_LITERAL(4 * 8), %esp
350 CFI_ADJUST_CFA_OFFSET(-4 * 8)
351
Dave Allisonbbb32c22013-11-05 18:25:18 -0800352 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800353 POP edx
354 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800355 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800356 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700357 // Swap EDI callee save with code pointer.
358 xchgl %edi, (%esp)
359 testl %eax, %eax // Branch forward if exception pending.
360 jz 1f
361 // Tail call to intended method.
362 ret
3631:
jeffhao20b5c6c2012-05-21 14:15:18 -0700364 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800365 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700366 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700367END_MACRO
368MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700369 DEFINE_FUNCTION VAR(c_name)
370 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
371 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700372END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700373
Logan Chien8dbb7082013-01-25 20:31:17 +0800374INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700375
Logan Chien8dbb7082013-01-25 20:31:17 +0800376INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
377INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
378INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
379INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700380
Jeff Hao5d917302013-02-27 17:57:33 -0800381 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000382 * Helper for quick invocation stub to set up XMM registers.
383 * Increments shorty and arg_array and clobbers temp_char.
384 * Branches to finished if it encounters the end of the shorty.
385 */
386MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3871: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700388 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
389 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
390 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
391 je VAR(finished) // goto finished
392 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
393 je 2f // goto FOUND_DOUBLE
394 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
395 je 3f // goto FOUND_FLOAT
396 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000397 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700398 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
399 jne 1b // goto LOOP
400 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
401 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004022: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700403 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
404 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000405 jmp 4f
4063: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700407 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
408 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004094:
410END_MACRO
411
412 /*
413 * Helper for quick invocation stub to set up GPR registers.
414 * Increments shorty and arg_array, and returns the current short character in
415 * temp_char. Branches to finished if it encounters the end of the shorty.
416 */
417MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
4181: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700419 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
420 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
421 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
422 je VAR(finished) // goto finished
423 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
424 je 3f // goto SKIP_FLOAT
425 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
426 je 4f // goto SKIP_DOUBLE
427 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004283: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700429 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
430 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004314: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700432 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
433 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004345:
435END_MACRO
436
437 /*
438 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700439 * On entry:
440 * [sp] = return address
441 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700442 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700443 * [sp + 12] = size of argument array in bytes
444 * [sp + 16] = (managed) thread pointer
445 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800446 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800447 */
448DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000449 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800450 PUSH ebp // save ebp
451 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000452 PUSH esi // save esi
453 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000454 // Set up argument XMM registers.
455 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
456 addl LITERAL(1), %esi
457 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
458 addl LITERAL(4), %edi
459 // Clobbers ESI, EDI, EAX.
460 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
461 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
462 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
463 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
464 .balign 16
465.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800466 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800467 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000468 mov 28(%ebp), %ebx // get arg array size
469 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
470 addl LITERAL(36), %ebx
471 // align frame size to 16 bytes
472 andl LITERAL(0xFFFFFFF0), %ebx
473 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800474 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000475
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700476 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000477
478 // Copy arg array into stack.
479 movl 28(%ebp), %ecx // ECX = size of args
480 movl 24(%ebp), %esi // ESI = argument array
481 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
482 rep movsb // while (ecx--) { *edi++ = *esi++ }
483
484 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
485 addl LITERAL(1), %esi
486 mov 24(%ebp), %edi // EDI := arg_array
487 mov 0(%edi), %ecx // ECX := this pointer
488 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
489
490 // Enumerate the possible cases for loading GPRS.
491 // edx (and maybe ebx):
492 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
493 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
494 je .LfirstLong
495 // Must be an integer value.
496 movl (%edi), %edx
497 addl LITERAL(4), %edi // arg_array++
498
499 // Now check ebx
500 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500501 // Must be first word of a long, or an integer. First word of long doesn't
502 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000503 movl (%edi), %ebx
504 jmp .Lgpr_setup_finished
505.LfirstLong:
506 movl (%edi), %edx
507 movl 4(%edi), %ebx
508 // Nothing left to load.
509.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000510 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800512 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800513 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000514 POP edi // pop edi
515 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800516 POP ebx // pop ebx
517 POP ebp // pop ebp
518 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800519 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800520 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800521 mov 24(%esp), %edx // get the shorty
522 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800523 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800524 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800525 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700526 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800527.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800528 movsd %xmm0, (%ecx) // store the floating point result
529 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800530.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800531 movss %xmm0, (%ecx) // store the floating point result
532 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800533END_FUNCTION art_quick_invoke_stub
534
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000535 /*
536 * Quick invocation stub (static).
537 * On entry:
538 * [sp] = return address
539 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700540 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000541 * [sp + 12] = size of argument array in bytes
542 * [sp + 16] = (managed) thread pointer
543 * [sp + 20] = JValue* result
544 * [sp + 24] = shorty
545 */
546DEFINE_FUNCTION art_quick_invoke_static_stub
547 // Save the non-volatiles.
548 PUSH ebp // save ebp
549 PUSH ebx // save ebx
550 PUSH esi // save esi
551 PUSH edi // save edi
552 // Set up argument XMM registers.
553 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
554 addl LITERAL(1), %esi
555 mov 8+16(%esp), %edi // EDI := arg_array
556 // Clobbers ESI, EDI, EAX.
557 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
558 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
559 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
560 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
561 .balign 16
562.Lxmm_setup_finished2:
563 mov %esp, %ebp // copy value of stack pointer into base pointer
564 CFI_DEF_CFA_REGISTER(ebp)
565 mov 28(%ebp), %ebx // get arg array size
566 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
567 addl LITERAL(36), %ebx
568 // align frame size to 16 bytes
569 andl LITERAL(0xFFFFFFF0), %ebx
570 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
571 subl %ebx, %esp // reserve stack space for argument array
572
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700573 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000574
575 // Copy arg array into stack.
576 movl 28(%ebp), %ecx // ECX = size of args
577 movl 24(%ebp), %esi // ESI = argument array
578 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
579 rep movsb // while (ecx--) { *edi++ = *esi++ }
580
581 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
582 addl LITERAL(1), %esi
583 mov 24(%ebp), %edi // EDI := arg_array
584
585 // Enumerate the possible cases for loading GPRS.
586 // ecx (and maybe edx)
587 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
588 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
589 je .LfirstLong2
590 // Must be an integer value. Load into ECX.
591 movl (%edi), %ecx
592 addl LITERAL(4), %edi // arg_array++
593
594 // Now check edx (and maybe ebx).
595 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
596 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
597 je .LSecondLong2
598 // Must be an integer. Load into EDX.
599 movl (%edi), %edx
600 addl LITERAL(4), %edi // arg_array++
601
602 // Is there anything for ebx?
603 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500604 // Must be first word of a long, or an integer. First word of long doesn't
605 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000606 movl (%edi), %ebx
607 jmp .Lgpr_setup_finished2
608.LSecondLong2:
609 // EDX:EBX is long. That is all.
610 movl (%edi), %edx
611 movl 4(%edi), %ebx
612 jmp .Lgpr_setup_finished2
613.LfirstLong2:
614 // ECX:EDX is a long
615 movl (%edi), %ecx
616 movl 4(%edi), %edx
617 addl LITERAL(8), %edi // arg_array += 2
618
619 // Anything for EBX?
620 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500621 // Must be first word of a long, or an integer. First word of long doesn't
622 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000623 movl (%edi), %ebx
624 jmp .Lgpr_setup_finished2
625 // Nothing left to load.
626.Lgpr_setup_finished2:
627 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700628 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000629 mov %ebp, %esp // restore stack pointer
630 CFI_DEF_CFA_REGISTER(esp)
631 POP edi // pop edi
632 POP esi // pop esi
633 POP ebx // pop ebx
634 POP ebp // pop ebp
635 mov 20(%esp), %ecx // get result pointer
636 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
637 mov %edx, 4(%ecx) // store the other half of the result
638 mov 24(%esp), %edx // get the shorty
639 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
640 je .Lreturn_double_quick2
641 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
642 je .Lreturn_float_quick2
643 ret
644.Lreturn_double_quick2:
645 movsd %xmm0, (%ecx) // store the floating point result
646 ret
647.Lreturn_float_quick2:
648 movss %xmm0, (%ecx) // store the floating point result
649 ret
650END_FUNCTION art_quick_invoke_static_stub
651
Ian Rogersd36c52e2012-04-09 16:29:25 -0700652MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700653 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700654 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700655 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700656 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700657 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700658 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800659 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700660 call CALLVAR(cxx_name) // cxx_name(Thread*)
661 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800662 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700663 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
664 CALL_MACRO(return_macro) // return or deliver exception
665 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700666END_MACRO
667
668MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700669 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700670 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700671 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700672 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700673 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700674 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800675 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700676 PUSH eax // pass arg1
677 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
678 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800679 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700680 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
681 CALL_MACRO(return_macro) // return or deliver exception
682 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700683END_MACRO
684
685MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700686 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700687 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700688 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700689 PUSH eax // push padding
690 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800691 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700692 PUSH ecx // pass arg2
693 PUSH eax // pass arg1
694 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
695 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800696 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700697 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
698 CALL_MACRO(return_macro) // return or deliver exception
699 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700700END_MACRO
701
Ian Rogersd36c52e2012-04-09 16:29:25 -0700702MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700703 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700704 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700705 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700706 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800707 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700708 PUSH edx // pass arg3
709 PUSH ecx // pass arg2
710 PUSH eax // pass arg1
711 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
712 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700713 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700714 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
715 CALL_MACRO(return_macro) // return or deliver exception
716 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700717END_MACRO
718
Jeff Hao848f70a2014-01-15 13:49:50 -0800719MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700720 DEFINE_FUNCTION VAR(c_name)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100721 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000722
Jeff Hao848f70a2014-01-15 13:49:50 -0800723 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700724 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800725 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700726 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800727 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700728 PUSH ebx // pass arg4
729 PUSH edx // pass arg3
730 PUSH ecx // pass arg2
731 PUSH eax // pass arg1
732 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
733 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800734 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700735 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
736 CALL_MACRO(return_macro) // return or deliver exception
737 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800738END_MACRO
739
Fred Shih37f05ef2014-07-16 18:38:08 -0700740MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700741 DEFINE_FUNCTION VAR(c_name)
742 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700743 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700744 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700745 PUSH eax // push padding
746 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700747 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700748 PUSH ecx // pass referrer
749 PUSH eax // pass arg1
750 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
751 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700752 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700753 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
754 CALL_MACRO(return_macro) // return or deliver exception
755 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700756END_MACRO
757
758MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700759 DEFINE_FUNCTION VAR(c_name)
760 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700761 // Outgoing argument set up
762 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700763 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700764 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700765 PUSH edx // pass referrer
766 PUSH ecx // pass arg2
767 PUSH eax // pass arg1
768 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
769 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700770 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700771 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
772 CALL_MACRO(return_macro) // return or deliver exception
773 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700774END_MACRO
775
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700776MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700777 DEFINE_FUNCTION VAR(c_name)
778 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700779 // Outgoing argument set up
780 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700781 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700782 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700783 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700784 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700785 PUSH ebx // pass referrer
786 PUSH edx // pass arg3
787 PUSH ecx // pass arg2
788 PUSH eax // pass arg1
789 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
790 // Thread*)
791 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700792 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700793 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
794 CALL_MACRO(return_macro) // return or deliver exception
795 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700796END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700797
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700798MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700799 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700800 jz 1f // if eax == 0 goto 1
801 ret // return
8021: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700803 DELIVER_PENDING_EXCEPTION
804END_MACRO
805
Ian Rogersd36c52e2012-04-09 16:29:25 -0700806MACRO0(RETURN_IF_EAX_ZERO)
807 testl %eax, %eax // eax == 0 ?
808 jnz 1f // if eax != 0 goto 1
809 ret // return
8101: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700811 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700812END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700813
jeffhaod66a8752012-05-22 15:30:16 -0700814MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700815 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700816 jne 1f // if exception field != 0 goto 1
817 ret // return
8181: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700819 DELIVER_PENDING_EXCEPTION
820END_MACRO
821
Mathieu Chartier7410f292013-11-24 13:17:35 -0800822// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700823GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800824
825// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
826DEFINE_FUNCTION art_quick_alloc_object_rosalloc
827 // Fast path rosalloc allocation.
828 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
829 // ebx, edx: free
830 PUSH edi
831 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
832 // Load the class (edx)
833 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
834 testl %edx, %edx // Check null class
835 jz .Lart_quick_alloc_object_rosalloc_slow_path
836 // Check class status
837 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
838 jne .Lart_quick_alloc_object_rosalloc_slow_path
839 // No fake dependence needed on x86
840 // between status and flags load,
841 // since each load is a load-acquire,
842 // no loads reordering.
843 // Check access flags has
844 // kAccClassIsFinalizable
845 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
846 jnz .Lart_quick_alloc_object_rosalloc_slow_path
847
848 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
849 // Check if the thread local allocation
850 // stack has room
851 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
852 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
853 jae .Lart_quick_alloc_object_rosalloc_slow_path
854
855 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
856 // Check if the size is for a thread
857 // local allocation
858 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
859 ja .Lart_quick_alloc_object_rosalloc_slow_path
860 decl %edi
861 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
862 // from object size.
863 // Align up the size by the rosalloc
864 // bracket quantum size and divide
865 // by the quantum size and subtract
866 // by 1. This code is a shorter but
867 // equivalent version.
868 // Load thread local rosalloc run (ebx)
869 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
870 // Load free_list head (edi),
871 // this will be the return value.
872 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
873 test %edi, %edi
874 jz .Lart_quick_alloc_object_rosalloc_slow_path
875 // Point of no slow path. Won't go to
876 // the slow path from here on. Ok to
877 // clobber eax and ecx.
878 movl %edi, %eax
879 // Load the next pointer of the head
880 // and update head of free list with
881 // next pointer
882 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
883 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
884 // Decrement size of free list by 1
885 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
886 // Store the class pointer in the
887 // header. This also overwrites the
888 // next pointer. The offsets are
889 // asserted to match.
890#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
891#error "Class pointer needs to overwrite next pointer."
892#endif
893 POISON_HEAP_REF edx
894 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
895 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
896 // Push the new object onto the thread
897 // local allocation stack and
898 // increment the thread local
899 // allocation stack top.
900 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
901 movl %eax, (%edi)
902 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
903 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
904 // No fence needed for x86.
905 POP edi
906 ret
907.Lart_quick_alloc_object_rosalloc_slow_path:
908 POP edi
909 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
910 // Outgoing argument set up
911 PUSH eax // alignment padding
912 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
913 CFI_ADJUST_CFA_OFFSET(4)
914 PUSH ecx
915 PUSH eax
916 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
917 addl LITERAL(16), %esp // pop arguments
918 CFI_ADJUST_CFA_OFFSET(-16)
919 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
920 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
921END_FUNCTION art_quick_alloc_object_rosalloc
922
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800923// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
924//
925// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
926MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
927 testl %edx, %edx // Check null class
928 jz VAR(slowPathLabel)
929 // Check class status.
930 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
931 jne VAR(slowPathLabel)
932 // No fake dependence needed on x86
933 // between status and flags load,
934 // since each load is a load-acquire,
935 // no loads reordering.
936 // Check access flags has
937 // kAccClassIsFinalizable
938 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
939 jnz VAR(slowPathLabel)
940 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
941 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
942 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
943 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
944 cmpl %edi, %esi // Check if it fits. OK to do this
945 // before rounding up the object size
946 // assuming the buf size alignment.
947 ja VAR(slowPathLabel)
948 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
949 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
950 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
951 // as allocated object.
952 addl %eax, %esi // Add the object size.
953 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
954 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
955 // Store the class pointer in the header.
956 // No fence needed for x86.
957 POISON_HEAP_REF edx
958 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
959 POP edi
960 POP esi
961 ret // Fast path succeeded.
962END_MACRO
963
964// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
965MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
966 POP edi
967 POP esi
968 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
969 // Outgoing argument set up
970 PUSH eax // alignment padding
971 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
972 CFI_ADJUST_CFA_OFFSET(4)
973 PUSH ecx
974 PUSH eax
975 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
976 addl LITERAL(16), %esp
977 CFI_ADJUST_CFA_OFFSET(-16)
978 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
979 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
980END_MACRO
981
982// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
983DEFINE_FUNCTION art_quick_alloc_object_tlab
984 // Fast path tlab allocation.
985 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
986 // EBX, EDX: free.
987#if defined(USE_READ_BARRIER)
988 int3
989 int3
990#endif
991 PUSH esi
992 PUSH edi
993 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
994 // Might need to break down into multiple instructions to get the base address in a register.
995 // Load the class
996 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
997 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
998.Lart_quick_alloc_object_tlab_slow_path:
999 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1000END_FUNCTION art_quick_alloc_object_tlab
1001
1002// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1003DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1004 // Fast path region tlab allocation.
1005 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1006 // EBX, EDX: free.
1007#if !defined(USE_READ_BARRIER)
1008 int3
1009 int3
1010#endif
1011 PUSH esi
1012 PUSH edi
1013 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1014 // Might need to break down into multiple instructions to get the base address in a register.
1015 // Load the class
1016 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1017 // Read barrier for class load.
1018 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1019 jne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1020.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1021 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1022.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1023 // The read barrier slow path. Mark the class.
1024 PUSH eax
1025 PUSH ecx
1026 // Outgoing argument set up
1027 subl MACRO_LITERAL(8), %esp // Alignment padding
1028 CFI_ADJUST_CFA_OFFSET(8)
1029 PUSH edx // Pass the class as the first param.
1030 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1031 movl %eax, %edx
1032 addl MACRO_LITERAL(12), %esp
1033 CFI_ADJUST_CFA_OFFSET(-12)
1034 POP ecx
1035 POP eax
1036 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1037.Lart_quick_alloc_object_region_tlab_slow_path:
1038 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1039END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001040
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001041ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1042ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1043ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1044ONE_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 -07001045
Ian Rogers832336b2014-10-08 15:35:22 -07001046TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001047
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001048DEFINE_FUNCTION art_quick_lock_object
1049 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001050 jz .Lslow_lock
1051.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001052 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001053 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001054 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001055 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
1056 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001057 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001058 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001059 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001060 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001061 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1062 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1063 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1064 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1065 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001066 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001067.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1068 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001069 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001070 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001071 movl %edx, %ecx // copy the lock word to check count overflow.
1072 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
1073 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
1074 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 -08001075 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001076 movl %eax, %ecx // save obj to use eax for cmpxchg.
1077 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1078 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1079 // update lockword, cmpxchg necessary for read barrier bits.
1080 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1081 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001082 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001083.Llock_cmpxchg_fail:
1084 movl %ecx, %eax // restore eax
1085 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001086.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001087 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001088 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001089 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001090 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001091 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001092 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001093 PUSH eax // pass object
1094 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1095 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001096 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001097 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001098 RETURN_IF_EAX_ZERO
1099END_FUNCTION art_quick_lock_object
1100
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001101DEFINE_FUNCTION art_quick_lock_object_no_inline
1102 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1103 // Outgoing argument set up
1104 subl LITERAL(8), %esp // alignment padding
1105 CFI_ADJUST_CFA_OFFSET(8)
1106 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1107 CFI_ADJUST_CFA_OFFSET(4)
1108 PUSH eax // pass object
1109 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1110 addl LITERAL(16), %esp // pop arguments
1111 CFI_ADJUST_CFA_OFFSET(-16)
1112 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1113 RETURN_IF_EAX_ZERO
1114END_FUNCTION art_quick_lock_object_no_inline
1115
1116
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001117DEFINE_FUNCTION art_quick_unlock_object
1118 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001119 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001120.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001121 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001122 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001123 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001124 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001125 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001126 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001127 movl %ecx, %edx // copy the lock word to detect new count of 0.
1128 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
1129 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001130 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001131 // update lockword, cmpxchg necessary for read barrier bits.
1132 movl %eax, %edx // edx: obj
1133 movl %ecx, %eax // eax: old lock word.
1134 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
1135#ifndef USE_READ_BARRIER
1136 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1137#else
1138 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1139 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1140#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001141 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001142.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1143 // update lockword, cmpxchg necessary for read barrier bits.
1144 movl %eax, %edx // edx: obj
1145 movl %ecx, %eax // eax: old lock word.
1146 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1147#ifndef USE_READ_BARRIER
1148 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1149#else
1150 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1151 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1152#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001153 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001154.Lunlock_cmpxchg_fail: // edx: obj
1155 movl %edx, %eax // restore eax
1156 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001157.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001158 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001159 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001160 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001161 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001162 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001163 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001164 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001165 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001166 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001167 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001168 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001169 RETURN_IF_EAX_ZERO
1170END_FUNCTION art_quick_unlock_object
1171
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001172DEFINE_FUNCTION art_quick_unlock_object_no_inline
1173 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1174 // Outgoing argument set up
1175 subl LITERAL(8), %esp // alignment padding
1176 CFI_ADJUST_CFA_OFFSET(8)
1177 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1178 CFI_ADJUST_CFA_OFFSET(4)
1179 PUSH eax // pass object
1180 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1181 addl LITERAL(16), %esp // pop arguments
1182 CFI_ADJUST_CFA_OFFSET(-16)
1183 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1184 RETURN_IF_EAX_ZERO
1185END_FUNCTION art_quick_unlock_object_no_inline
1186
Ian Rogers468532e2013-08-05 10:56:33 -07001187DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001188 PUSH eax // alignment padding
1189 PUSH ecx // pass arg2 - obj->klass
1190 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001191 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001192 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001193 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001194 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001195END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001196
Ian Rogersa9a82542013-10-04 11:17:26 -07001197DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001198 PUSH eax // alignment padding
1199 PUSH ecx // pass arg2 - obj->klass
1200 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001201 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001202 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001203 jz 1f // jump forward if not assignable
1204 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001205 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001206 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001207
Andreas Gampe4360be22015-07-14 23:34:44 -07001208 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070012091:
Andreas Gampe4360be22015-07-14 23:34:44 -07001210 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001211 POP ecx
1212 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001213 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001214 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001215 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001216 PUSH eax // alignment padding
1217 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001218 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001219 PUSH ecx // pass arg2
1220 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001221 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001222 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001223END_FUNCTION art_quick_check_cast
1224
Man Cao1aee9002015-07-14 22:31:42 -07001225// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1226MACRO2(POP_REG_NE, reg, exclude_reg)
1227 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1228 addl MACRO_LITERAL(4), %esp
1229 CFI_ADJUST_CFA_OFFSET(-4)
1230 .else
1231 POP RAW_VAR(reg)
1232 .endif
1233END_MACRO
1234
1235 /*
1236 * Macro to insert read barrier, only used in art_quick_aput_obj.
1237 * obj_reg and dest_reg are registers, offset is a defined literal such as
1238 * MIRROR_OBJECT_CLASS_OFFSET.
1239 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1240 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1241 */
1242MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1243#ifdef USE_READ_BARRIER
1244 PUSH eax // save registers used in art_quick_aput_obj
1245 PUSH ebx
1246 PUSH edx
1247 PUSH ecx
1248 // Outgoing argument set up
1249 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1250 CFI_ADJUST_CFA_OFFSET(4)
1251 PUSH RAW_VAR(obj_reg) // pass obj_reg
1252 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1253 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1254 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1255 .ifnc RAW_VAR(dest_reg), eax
1256 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1257 .endif
1258 addl MACRO_LITERAL(12), %esp // pop arguments
1259 CFI_ADJUST_CFA_OFFSET(-12)
1260 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1261 POP_REG_NE edx, RAW_VAR(dest_reg)
1262 POP_REG_NE ebx, RAW_VAR(dest_reg)
1263 .ifc RAW_VAR(pop_eax), true
1264 POP_REG_NE eax, RAW_VAR(dest_reg)
1265 .endif
1266#else
1267 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1268 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1269#endif // USE_READ_BARRIER
1270END_MACRO
1271
Ian Rogersa9a82542013-10-04 11:17:26 -07001272 /*
1273 * Entry from managed code for array put operations of objects where the value being stored
1274 * needs to be checked for compatibility.
1275 * eax = array, ecx = index, edx = value
1276 */
1277DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1278 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001279 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1280 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001281END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1282
1283DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001284 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001285 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001286 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001287 mov %ecx, %eax
1288 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001289 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001290END_FUNCTION art_quick_aput_obj_with_bound_check
1291
1292DEFINE_FUNCTION art_quick_aput_obj
1293 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001294 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001295 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1296 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001297 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001298#if defined(USE_READ_BARRIER)
1299 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1300 cmpl %eax, %ebx
1301 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001302 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001303#elif defined(USE_HEAP_POISONING)
1304 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001305 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1306 UNPOISON_HEAP_REF eax
1307 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001308 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001309#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001310 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001311#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001312 jne .Lcheck_assignability
1313.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001314 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001315 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001316 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1317 shrl LITERAL(7), %eax
1318 movb %dl, (%edx, %eax)
1319 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001320.Ldo_aput_null:
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 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001323.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001324 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001325 PUSH ecx
1326 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001327#if defined(USE_READ_BARRIER)
1328 subl LITERAL(4), %esp // alignment padding
1329 CFI_ADJUST_CFA_OFFSET(4)
1330 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1331 subl LITERAL(4), %esp // alignment padding
1332 CFI_ADJUST_CFA_OFFSET(4)
1333 PUSH eax // pass arg2 - type of the value to be stored
1334#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001335 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001336 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001337 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001338 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001339 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001340#else
Man Cao63069212015-08-21 15:51:39 -07001341 subl LITERAL(8), %esp // alignment padding
1342 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001343 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001344 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001345#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001346 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001347 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001348 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001349 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001350 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001351 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001352 POP edx
1353 POP ecx
1354 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001355 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001356 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001357 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1358 shrl LITERAL(7), %eax
1359 movb %dl, (%edx, %eax)
1360 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001361 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001362.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001363 POP edx
1364 POP ecx
1365 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001366 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001367 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001368 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001369 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001370 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001371 PUSH edx // pass arg2 - value
1372 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001373 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001374 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001375END_FUNCTION art_quick_aput_obj
1376
Logan Chien8dbb7082013-01-25 20:31:17 +08001377DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001378 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001379 PUSH edx // pass arg3
1380 PUSH ecx // pass arg2
1381 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001382 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001383 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001384 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001385 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001386END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001387
Logan Chien8dbb7082013-01-25 20:31:17 +08001388NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001389
Ian Rogers468532e2013-08-05 10:56:33 -07001390DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001391 subl LITERAL(12), %esp // alignment padding, room for argument
1392 CFI_ADJUST_CFA_OFFSET(12)
1393 movsd %xmm0, 0(%esp) // arg a
1394 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001395 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001396 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001397 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001398END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001399
Ian Rogers468532e2013-08-05 10:56:33 -07001400DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001401 subl LITERAL(12), %esp // alignment padding
1402 CFI_ADJUST_CFA_OFFSET(12)
1403 movss %xmm0, 0(%esp) // arg a
1404 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001405 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001406 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001407 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001408END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001409
Ian Rogers468532e2013-08-05 10:56:33 -07001410DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001411 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001412 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001413 PUSH ebx // pass arg4 b.hi
1414 PUSH edx // pass arg3 b.lo
1415 PUSH ecx // pass arg2 a.hi
1416 PUSH eax // pass arg1 a.lo
1417 call SYMBOL(artLdiv) // (jlong a, jlong b)
1418 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001419 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001420 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001421END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001422
Ian Rogersa9a82542013-10-04 11:17:26 -07001423DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001424 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001425 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001426 PUSH ebx // pass arg4 b.hi
1427 PUSH edx // pass arg3 b.lo
1428 PUSH ecx // pass arg2 a.hi
1429 PUSH eax // pass arg1 a.lo
1430 call SYMBOL(artLmod) // (jlong a, jlong b)
1431 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001432 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001433 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001434END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001435
Ian Rogers468532e2013-08-05 10:56:33 -07001436DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001437 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1438 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1439 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001440 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001441 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001442 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001443END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001444
Ian Rogers468532e2013-08-05 10:56:33 -07001445DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001446 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001447 xchg %edx, %ecx
1448 shld %cl,%eax,%edx
1449 shl %cl,%eax
1450 test LITERAL(32), %cl
1451 jz 1f
1452 mov %eax, %edx
1453 xor %eax, %eax
14541:
1455 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001456END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001457
Ian Rogers468532e2013-08-05 10:56:33 -07001458DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001459 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001460 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001461 shrd %cl,%edx,%eax
1462 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001463 test LITERAL(32),%cl
1464 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001465 mov %edx, %eax
1466 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014671:
1468 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001469END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001470
Ian Rogers468532e2013-08-05 10:56:33 -07001471DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001472 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001473 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001474 shrd %cl,%edx,%eax
1475 shr %cl,%edx
1476 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001477 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001478 mov %edx, %eax
1479 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014801:
1481 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001482END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001483
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001484ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1485ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1486ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1487ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1488ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1489ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1490ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001491
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001492TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1493TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1494TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1495TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1496TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1497TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1498TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001499
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001500TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1501TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1502TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1503TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001504
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001505THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1506THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1507THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1508THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1509
1510// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001511DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001512 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001513 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001514 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001515 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001516 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001517 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001518 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001519 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001520 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1521 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001522 PUSH ebx // pass high half of new_val
1523 PUSH edx // pass low half of new_val
1524 PUSH ecx // pass object
1525 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001526 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001527 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001528 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001529 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001530 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001531END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001532
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001533// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1534// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001535DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001536 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1537 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001538 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001539 movd %xmm0, %ebx
1540 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001541 subl LITERAL(12), %esp // alignment padding
1542 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001543 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001544 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001545 PUSH ebx // pass high half of new_val
1546 PUSH edx // pass low half of new_val
1547 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001548 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001549 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001550 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001551 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001552 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001553 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001554END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001555
Logan Chien8dbb7082013-01-25 20:31:17 +08001556DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001557 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001558 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001559 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001560 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001561 PUSH ecx // pass receiver
1562 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001563 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001564 movd %eax, %xmm0 // place return value also into floating point return value
1565 movd %edx, %xmm1
1566 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001567 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1568 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1569 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001570 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001571END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001572
Jeff Hao88474b42013-10-23 16:24:40 -07001573 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001574 * Called to resolve an imt conflict.
1575 * eax is the conflict ArtMethod.
1576 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1577 *
1578 * Note that this stub writes to eax.
1579 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001580 */
1581DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001582 PUSH EDI
1583 movl 8(%esp), %edi // Load referrer
1584 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1585 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1586 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001587 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001588 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1589 popl %eax // Pop ImtConflictTable.
1590 CFI_ADJUST_CFA_OFFSET(-4)
1591.Limt_table_iterate:
1592 cmpl %edi, 0(%eax)
1593 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001594 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001595 // and jump to it.
1596 POP EDI
1597 movl __SIZEOF_POINTER__(%eax), %eax
1598 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1599.Limt_table_next_entry:
1600 // If the entry is null, the interface method is not in the ImtConflictTable.
1601 cmpl LITERAL(0), 0(%eax)
1602 jz .Lconflict_trampoline
1603 // Iterate over the entries of the ImtConflictTable.
1604 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1605 jmp .Limt_table_iterate
1606.Lconflict_trampoline:
1607 // Call the runtime stub to populate the ImtConflictTable and jump to the
1608 // resolved method.
1609 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001610 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001611END_FUNCTION art_quick_imt_conflict_trampoline
1612
Ian Rogers468532e2013-08-05 10:56:33 -07001613DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001614 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001615 movl %esp, %edi
1616 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001617 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001618 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001619 PUSH ecx // pass receiver
1620 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001621 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001622 movl %eax, %edi // remember code pointer in EDI
1623 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001624 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001625 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001626 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001627 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070016281:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001629 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001630 DELIVER_PENDING_EXCEPTION
1631END_FUNCTION art_quick_resolution_trampoline
1632
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001633DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001634 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001635 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001636 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001637 subl LITERAL(5120), %esp
1638 // prepare for artQuickGenericJniTrampoline call
1639 // (Thread*, SP)
1640 // (esp) 4(esp) <= C calling convention
1641 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001642
1643 subl LITERAL(8), %esp // Padding for 16B alignment.
1644 pushl %ebp // Pass SP (to ArtMethod).
1645 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001646 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001647
Andreas Gampec200a4a2014-06-16 18:39:09 -07001648 // The C call will have registered the complete save-frame on success.
1649 // The result of the call is:
1650 // eax: pointer to native code, 0 on error.
1651 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001652
Andreas Gampec200a4a2014-06-16 18:39:09 -07001653 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001654 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001655 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001656
Andreas Gampec200a4a2014-06-16 18:39:09 -07001657 // Release part of the alloca.
1658 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001659
1660 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001661 // Native call.
1662 call *%eax
1663
Andreas Gampe779f8c92014-06-09 18:29:38 -07001664 // result sign extension is handled in C code
1665 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001666 // (Thread*, result, result_f)
1667 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001668 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001669
Andreas Gampe4360be22015-07-14 23:34:44 -07001670 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001671 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001672 pushl %edx // Pass int result.
1673 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001674 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001675 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001676
Andreas Gampe779f8c92014-06-09 18:29:38 -07001677 // Pending exceptions possible.
1678 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1679 testl %ebx, %ebx
1680 jnz .Lexception_in_native
1681
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001682 // Tear down the alloca.
1683 movl %ebp, %esp
1684 CFI_DEF_CFA_REGISTER(esp)
1685
1686
Andreas Gampe779f8c92014-06-09 18:29:38 -07001687 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001688 // Remove space for FPR args and EAX
1689 addl LITERAL(4 + 4 * 8), %esp
1690 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1691
Andreas Gampe779f8c92014-06-09 18:29:38 -07001692 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001693 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001694 CFI_ADJUST_CFA_OFFSET(-4)
1695 POP ebx
1696 POP ebp // Restore callee saves
1697 POP esi
1698 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001699 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001700 movd %eax, %xmm0
1701 movd %edx, %xmm1
1702 punpckldq %xmm1, %xmm0
1703 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001704.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001705 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1706 // Do a call to push a new save-all frame required by the runtime.
1707 call .Lexception_call
1708.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001709 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001710END_FUNCTION art_quick_generic_jni_trampoline
1711
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001712DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001713 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001714 mov %esp, %edx // remember SP
1715 PUSH eax // alignment padding
1716 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001717 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001718 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001719 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001720 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001721 addl LITERAL(16), %esp // pop arguments
1722 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001723
1724 // Return eax:edx in xmm0 also.
1725 movd %eax, %xmm0
1726 movd %edx, %xmm1
1727 punpckldq %xmm1, %xmm0
1728
1729 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1730 CFI_ADJUST_CFA_OFFSET(-48)
1731
Andreas Gampe4360be22015-07-14 23:34:44 -07001732 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001733 POP esi
1734 POP edi
1735
Ian Rogers7db619b2013-01-16 18:35:48 -08001736 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001737END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001738
jeffhao7e4fcb82013-01-10 18:11:08 -08001739 /*
1740 * Routine that intercepts method calls and returns.
1741 */
Ian Rogers468532e2013-08-05 10:56:33 -07001742DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001743 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001744 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001745 subl LITERAL(12), %esp // Align stack.
1746 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001747 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001748 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001749 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001750 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001751 PUSH ecx // Pass receiver.
1752 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001753 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001754 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001755 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001756 movl 60(%esp), %edi // Restore edi.
1757 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001758 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001759 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001760 movl %ebx, 64(%esp)
1761 movl 0(%esp), %eax // Restore eax.
1762 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1763 movsd 8(%esp), %xmm0
1764 movsd 16(%esp), %xmm1
1765 movsd 24(%esp), %xmm2
1766 movsd 32(%esp), %xmm3
1767
1768 // Restore GPRs.
1769 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001770 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001771 movl 48(%esp), %ebx // Restore ebx.
1772 movl 52(%esp), %ebp // Restore ebp.
1773 movl 56(%esp), %esi // Restore esi.
1774 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001775 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001776 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001777END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001778
Ian Rogers468532e2013-08-05 10:56:33 -07001779DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001780 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001781 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001782 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001783 mov %esp, %ecx // Remember SP
1784 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001785 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001786 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001787 PUSH edx // Save gpr return value.
1788 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001789 subl LITERAL(16), %esp // Align stack
1790 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001791 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001792 PUSH edx // Pass gpr return value.
1793 PUSH eax
1794 PUSH ecx // Pass SP.
1795 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001796 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001797 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001798 mov %eax, %ecx // Move returned link register.
1799 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001800 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001801 movl %edx, %ebx // Move returned link register for deopt
1802 // (ebx is pretending to be our LR).
1803 POP eax // Restore gpr return value.
1804 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001805 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001806 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001807 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001808 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001809 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001810 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001811 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001812END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001813
jeffhao7e4fcb82013-01-10 18:11:08 -08001814 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001815 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1816 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001817 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001818DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001819 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001820 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1821 subl LITERAL(12), %esp // Align stack.
1822 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001823 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001824 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001825 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001826 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001827END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001828
jeffhao86e46712012-08-08 17:30:59 -07001829 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001830 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001831 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001832 */
1833DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1834 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1835 subl LITERAL(12), %esp // Align stack.
1836 CFI_ADJUST_CFA_OFFSET(12)
1837 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1838 CFI_ADJUST_CFA_OFFSET(4)
1839 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1840 UNREACHABLE
1841END_FUNCTION art_quick_deoptimize_from_compiled_code
1842
1843 /*
jeffhao86e46712012-08-08 17:30:59 -07001844 * String's compareTo.
1845 *
1846 * On entry:
1847 * eax: this string object (known non-null)
1848 * ecx: comp string object (known non-null)
1849 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001850DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001851 PUSH esi // push callee save reg
1852 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001853 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1854 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001855 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1856 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001857 /* Calculate min length and count diff */
1858 mov %edx, %ecx
1859 mov %edx, %eax
1860 subl %ebx, %eax
1861 cmovg %ebx, %ecx
1862 /*
1863 * At this point we have:
1864 * eax: value to return if first part of strings are equal
1865 * ecx: minimum among the lengths of the two strings
1866 * esi: pointer to this string data
1867 * edi: pointer to comp string data
1868 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001869 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001870 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001871 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001872.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001873 POP edi // pop callee save reg
1874 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001875 ret
1876 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001877.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001878 movzwl -2(%esi), %eax // get last compared char from this string
1879 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001880 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001881 POP edi // pop callee save reg
1882 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001883 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001884END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001885
Dave Allison8ce6b902014-08-26 11:07:58 -07001886// Return from a nested signal:
1887// Entry:
1888// eax: address of jmp_buf in TLS
1889
1890DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001891 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001892 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001893 PUSH ecx // second arg to longjmp (1)
1894 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001895 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001896 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001897END_FUNCTION art_nested_signal_return
1898
Roland Levillain7c1559a2015-12-15 10:55:36 +00001899DEFINE_FUNCTION art_quick_read_barrier_mark
1900 PUSH eax // pass arg1 - obj
1901 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
1902 addl LITERAL(4), %esp // pop argument
1903 CFI_ADJUST_CFA_OFFSET(-4)
1904 ret
1905END_FUNCTION art_quick_read_barrier_mark
1906
Man Cao1aee9002015-07-14 22:31:42 -07001907DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001908 PUSH edx // pass arg3 - offset
1909 PUSH ecx // pass arg2 - obj
1910 PUSH eax // pass arg1 - ref
1911 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1912 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001913 CFI_ADJUST_CFA_OFFSET(-12)
1914 ret
1915END_FUNCTION art_quick_read_barrier_slow
1916
Roland Levillain0d5a2812015-11-13 10:07:31 +00001917DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
1918 PUSH eax // pass arg1 - root
1919 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
1920 addl LITERAL(4), %esp // pop argument
1921 CFI_ADJUST_CFA_OFFSET(-4)
1922 ret
1923END_FUNCTION art_quick_read_barrier_for_root_slow
1924
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001925 /*
1926 * On stack replacement stub.
1927 * On entry:
1928 * [sp] = return address
1929 * [sp + 4] = stack to copy
1930 * [sp + 8] = size of stack
1931 * [sp + 12] = pc to call
1932 * [sp + 16] = JValue* result
1933 * [sp + 20] = shorty
1934 * [sp + 24] = thread
1935 */
1936DEFINE_FUNCTION art_quick_osr_stub
1937 // Save native callee saves.
1938 PUSH ebp
1939 PUSH ebx
1940 PUSH esi
1941 PUSH edi
1942 mov 4+16(%esp), %esi // ESI = argument array
1943 mov 8+16(%esp), %ecx // ECX = size of args
1944 mov 12+16(%esp), %ebx // EBX = pc to call
1945 mov %esp, %ebp // Save stack pointer
1946 andl LITERAL(0xFFFFFFF0), %esp // Align stack
1947 PUSH ebp // Save old stack pointer
1948 subl LITERAL(12), %esp // Align stack
1949 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
1950 call .Losr_entry
1951
1952 // Restore stack pointer.
1953 addl LITERAL(12), %esp
1954 POP ebp
1955 mov %ebp, %esp
1956
1957 // Restore callee saves.
1958 POP edi
1959 POP esi
1960 POP ebx
1961 POP ebp
1962 mov 16(%esp), %ecx // Get JValue result
1963 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
1964 mov %edx, 4(%ecx) // Store the other half of the result
1965 mov 20(%esp), %edx // Get the shorty
1966 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
1967 je .Losr_return_double_quick
1968 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
1969 je .Losr_return_float_quick
1970 ret
1971.Losr_return_double_quick:
1972 movsd %xmm0, (%ecx) // Store the floating point result
1973 ret
1974.Losr_return_float_quick:
1975 movss %xmm0, (%ecx) // Store the floating point result
1976 ret
1977.Losr_entry:
1978 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
1979 subl %ecx, %esp
1980 mov %esp, %edi // EDI = beginning of stack
1981 rep movsb // while (ecx--) { *edi++ = *esi++ }
1982 jmp *%ebx
1983END_FUNCTION art_quick_osr_stub
1984
Elliott Hughes787ec202012-03-29 17:14:15 -07001985 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001986UNIMPLEMENTED art_quick_memcmp16