blob: 4f9b3f787847f192b68f0c4a48113373fc91e490 [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
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070076MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -070077 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -080078 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070079 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
80 POP esi
81 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -070082END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070083
84 /*
85 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070086 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070087 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070088MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080089 PUSH edi // Save callee saves
90 PUSH esi
91 PUSH ebp
92 PUSH ebx // Save args
93 PUSH edx
94 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +000095 // Create space for FPR args.
96 subl MACRO_LITERAL(4 * 8), %esp
97 CFI_ADJUST_CFA_OFFSET(4 * 8)
98 // Save FPRs.
99 movsd %xmm0, 0(%esp)
100 movsd %xmm1, 8(%esp)
101 movsd %xmm2, 16(%esp)
102 movsd %xmm3, 24(%esp)
103
Andreas Gampe4360be22015-07-14 23:34:44 -0700104 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700106 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
107 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700108 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -0700109 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700110 CFI_ADJUST_CFA_OFFSET(4)
111 // Store esp as the stop quick frame.
112 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700113
114 // Ugly compile-time check, but we only have the preprocessor.
115 // Last +4: implicit return address pushed on stack when caller made call.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000116#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4*8 + 4)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700117#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
118#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700119END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700120
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700121 /*
122 * Macro that sets up the callee save frame to conform with
123 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX.
124 */
125MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000126 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700127 PUSH edi // Save callee saves
128 PUSH esi
129 PUSH ebp
130 PUSH ebx // Save args
131 PUSH edx
132 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000133
134 // Create space for FPR args.
135 subl MACRO_LITERAL(32), %esp
136 CFI_ADJUST_CFA_OFFSET(32)
137
138 // Save FPRs.
139 movsd %xmm0, 0(%esp)
140 movsd %xmm1, 8(%esp)
141 movsd %xmm2, 16(%esp)
142 movsd %xmm3, 24(%esp)
143
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700144 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
145 // Store esp as the stop quick frame.
146 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
147END_MACRO
148
149MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000150 // Restore FPRs. EAX is still on the stack.
151 movsd 4(%esp), %xmm0
152 movsd 12(%esp), %xmm1
153 movsd 20(%esp), %xmm2
154 movsd 28(%esp), %xmm3
155
156 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
157 CFI_ADJUST_CFA_OFFSET(-36)
158
Andreas Gampe4360be22015-07-14 23:34:44 -0700159 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800160 POP edx
161 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700162 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800163 POP esi
164 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700165END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000167// Restore register and jump to routine
168// Inputs: EDI contains pointer to code.
169// Notes: Need to pop EAX too (restores Method*)
170MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP)
171 POP eax // Restore Method*
172
173 // Restore FPRs.
174 movsd 0(%esp), %xmm0
175 movsd 8(%esp), %xmm1
176 movsd 16(%esp), %xmm2
177 movsd 24(%esp), %xmm3
178
179 addl MACRO_LITERAL(32), %esp // Remove FPRs.
180 CFI_ADJUST_CFA_OFFSET(-32)
181
182 POP ecx // Restore args except eax
183 POP edx
184 POP ebx
185 POP ebp // Restore callee saves
186 POP esi
187 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
188 ret
189END_MACRO
190
Ian Rogers57b86d42012-03-27 16:05:41 -0700191 /*
192 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
193 * exception is Thread::Current()->exception_.
194 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700195MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700196 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700197 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700198 subl MACRO_LITERAL(12), %esp // Alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700199 CFI_ADJUST_CFA_OFFSET(12)
200 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800201 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700202 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700203 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700204END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700205
Elliott Hughes787ec202012-03-29 17:14:15 -0700206MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700207 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700208 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700209 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700210 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700211 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700212 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800213 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700214 call CALLVAR(cxx_name) // cxx_name(Thread*)
215 UNREACHABLE
216 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700217END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700218
Elliott Hughes787ec202012-03-29 17:14:15 -0700219MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700220 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700221 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700222 mov %esp, %ecx
223 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700224 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700225 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700226 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800227 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700228 PUSH eax // pass arg1
229 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
230 UNREACHABLE
231 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700232END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700233
Elliott Hughes787ec202012-03-29 17:14:15 -0700234MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700235 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700236 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700237 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700238 PUSH eax // alignment padding
239 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800240 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700241 PUSH ecx // pass arg2
242 PUSH eax // pass arg1
243 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
244 UNREACHABLE
245 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700246END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700247
248 /*
249 * Called by managed code to create and deliver a NullPointerException.
250 */
Ian Rogers468532e2013-08-05 10:56:33 -0700251NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700252
253 /*
254 * Called by managed code to create and deliver an ArithmeticException.
255 */
Ian Rogers468532e2013-08-05 10:56:33 -0700256NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700257
258 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700259 * Called by managed code to create and deliver a StackOverflowError.
260 */
Ian Rogers468532e2013-08-05 10:56:33 -0700261NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700262
263 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700264 * Called by managed code, saves callee saves and then calls artThrowException
265 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
266 */
Ian Rogers468532e2013-08-05 10:56:33 -0700267ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700268
269 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700270 * Called by managed code to create and deliver a NoSuchMethodError.
271 */
Ian Rogers468532e2013-08-05 10:56:33 -0700272ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700273
274 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700275 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
276 * index, arg2 holds limit.
277 */
Ian Rogers468532e2013-08-05 10:56:33 -0700278TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700279
280 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700281 * All generated callsites for interface invokes and invocation slow paths will load arguments
282 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100283 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700284 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
285 *
286 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
287 * of the target Method* in r0 and method->code_ in r1.
288 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700289 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700290 * thread and we branch to another stub to deliver it.
291 *
292 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
293 * pointing back to the original caller.
294 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700295MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700296 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700297 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000298
Ian Rogers7caad772012-03-30 01:07:54 -0700299 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800300 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700301 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800302 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800303 PUSH ecx // pass arg2
304 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700305 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700306 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100307 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
308 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000309
310 // Restore FPRs.
311 movsd 0(%esp), %xmm0
312 movsd 8(%esp), %xmm1
313 movsd 16(%esp), %xmm2
314 movsd 24(%esp), %xmm3
315
316 // Remove space for FPR args.
317 addl MACRO_LITERAL(4 * 8), %esp
318 CFI_ADJUST_CFA_OFFSET(-4 * 8)
319
Dave Allisonbbb32c22013-11-05 18:25:18 -0800320 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800321 POP edx
322 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800323 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800324 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700325 // Swap EDI callee save with code pointer.
326 xchgl %edi, (%esp)
327 testl %eax, %eax // Branch forward if exception pending.
328 jz 1f
329 // Tail call to intended method.
330 ret
3311:
jeffhao20b5c6c2012-05-21 14:15:18 -0700332 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800333 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700334 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700335END_MACRO
336MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700337 DEFINE_FUNCTION VAR(c_name)
338 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
339 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700340END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700341
Logan Chien8dbb7082013-01-25 20:31:17 +0800342INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700343
Logan Chien8dbb7082013-01-25 20:31:17 +0800344INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
345INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
346INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
347INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700348
Jeff Hao5d917302013-02-27 17:57:33 -0800349 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000350 * Helper for quick invocation stub to set up XMM registers.
351 * Increments shorty and arg_array and clobbers temp_char.
352 * Branches to finished if it encounters the end of the shorty.
353 */
354MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3551: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700356 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
357 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
358 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
359 je VAR(finished) // goto finished
360 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
361 je 2f // goto FOUND_DOUBLE
362 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
363 je 3f // goto FOUND_FLOAT
364 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000365 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700366 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
367 jne 1b // goto LOOP
368 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
369 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003702: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700371 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
372 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000373 jmp 4f
3743: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700375 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
376 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003774:
378END_MACRO
379
380 /*
381 * Helper for quick invocation stub to set up GPR registers.
382 * Increments shorty and arg_array, and returns the current short character in
383 * temp_char. Branches to finished if it encounters the end of the shorty.
384 */
385MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
3861: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700387 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
388 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
389 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
390 je VAR(finished) // goto finished
391 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
392 je 3f // goto SKIP_FLOAT
393 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
394 je 4f // goto SKIP_DOUBLE
395 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003963: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700397 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
398 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003994: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700400 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
401 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004025:
403END_MACRO
404
405 /*
406 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700407 * On entry:
408 * [sp] = return address
409 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700410 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700411 * [sp + 12] = size of argument array in bytes
412 * [sp + 16] = (managed) thread pointer
413 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800414 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800415 */
416DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000417 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800418 PUSH ebp // save ebp
419 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000420 PUSH esi // save esi
421 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000422 // Set up argument XMM registers.
423 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
424 addl LITERAL(1), %esi
425 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
426 addl LITERAL(4), %edi
427 // Clobbers ESI, EDI, EAX.
428 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
429 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
430 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
431 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
432 .balign 16
433.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800434 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800435 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000436 mov 28(%ebp), %ebx // get arg array size
437 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
438 addl LITERAL(36), %ebx
439 // align frame size to 16 bytes
440 andl LITERAL(0xFFFFFFF0), %ebx
441 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800442 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000443
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700444 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000445
446 // Copy arg array into stack.
447 movl 28(%ebp), %ecx // ECX = size of args
448 movl 24(%ebp), %esi // ESI = argument array
449 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
450 rep movsb // while (ecx--) { *edi++ = *esi++ }
451
452 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
453 addl LITERAL(1), %esi
454 mov 24(%ebp), %edi // EDI := arg_array
455 mov 0(%edi), %ecx // ECX := this pointer
456 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
457
458 // Enumerate the possible cases for loading GPRS.
459 // edx (and maybe ebx):
460 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
461 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
462 je .LfirstLong
463 // Must be an integer value.
464 movl (%edi), %edx
465 addl LITERAL(4), %edi // arg_array++
466
467 // Now check ebx
468 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500469 // Must be first word of a long, or an integer. First word of long doesn't
470 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000471 movl (%edi), %ebx
472 jmp .Lgpr_setup_finished
473.LfirstLong:
474 movl (%edi), %edx
475 movl 4(%edi), %ebx
476 // Nothing left to load.
477.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000478 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700479 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800480 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800481 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000482 POP edi // pop edi
483 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800484 POP ebx // pop ebx
485 POP ebp // pop ebp
486 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800487 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800488 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800489 mov 24(%esp), %edx // get the shorty
490 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800491 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800492 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800493 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700494 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800495.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800496 movsd %xmm0, (%ecx) // store the floating point result
497 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800498.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800499 movss %xmm0, (%ecx) // store the floating point result
500 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800501END_FUNCTION art_quick_invoke_stub
502
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000503 /*
504 * Quick invocation stub (static).
505 * On entry:
506 * [sp] = return address
507 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700508 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000509 * [sp + 12] = size of argument array in bytes
510 * [sp + 16] = (managed) thread pointer
511 * [sp + 20] = JValue* result
512 * [sp + 24] = shorty
513 */
514DEFINE_FUNCTION art_quick_invoke_static_stub
515 // Save the non-volatiles.
516 PUSH ebp // save ebp
517 PUSH ebx // save ebx
518 PUSH esi // save esi
519 PUSH edi // save edi
520 // Set up argument XMM registers.
521 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
522 addl LITERAL(1), %esi
523 mov 8+16(%esp), %edi // EDI := arg_array
524 // Clobbers ESI, EDI, EAX.
525 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
526 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
527 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
528 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
529 .balign 16
530.Lxmm_setup_finished2:
531 mov %esp, %ebp // copy value of stack pointer into base pointer
532 CFI_DEF_CFA_REGISTER(ebp)
533 mov 28(%ebp), %ebx // get arg array size
534 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
535 addl LITERAL(36), %ebx
536 // align frame size to 16 bytes
537 andl LITERAL(0xFFFFFFF0), %ebx
538 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
539 subl %ebx, %esp // reserve stack space for argument array
540
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700541 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000542
543 // Copy arg array into stack.
544 movl 28(%ebp), %ecx // ECX = size of args
545 movl 24(%ebp), %esi // ESI = argument array
546 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
547 rep movsb // while (ecx--) { *edi++ = *esi++ }
548
549 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
550 addl LITERAL(1), %esi
551 mov 24(%ebp), %edi // EDI := arg_array
552
553 // Enumerate the possible cases for loading GPRS.
554 // ecx (and maybe edx)
555 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
556 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
557 je .LfirstLong2
558 // Must be an integer value. Load into ECX.
559 movl (%edi), %ecx
560 addl LITERAL(4), %edi // arg_array++
561
562 // Now check edx (and maybe ebx).
563 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
564 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
565 je .LSecondLong2
566 // Must be an integer. Load into EDX.
567 movl (%edi), %edx
568 addl LITERAL(4), %edi // arg_array++
569
570 // Is there anything for ebx?
571 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500572 // Must be first word of a long, or an integer. First word of long doesn't
573 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000574 movl (%edi), %ebx
575 jmp .Lgpr_setup_finished2
576.LSecondLong2:
577 // EDX:EBX is long. That is all.
578 movl (%edi), %edx
579 movl 4(%edi), %ebx
580 jmp .Lgpr_setup_finished2
581.LfirstLong2:
582 // ECX:EDX is a long
583 movl (%edi), %ecx
584 movl 4(%edi), %edx
585 addl LITERAL(8), %edi // arg_array += 2
586
587 // Anything for EBX?
588 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500589 // Must be first word of a long, or an integer. First word of long doesn't
590 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000591 movl (%edi), %ebx
592 jmp .Lgpr_setup_finished2
593 // Nothing left to load.
594.Lgpr_setup_finished2:
595 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700596 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000597 mov %ebp, %esp // restore stack pointer
598 CFI_DEF_CFA_REGISTER(esp)
599 POP edi // pop edi
600 POP esi // pop esi
601 POP ebx // pop ebx
602 POP ebp // pop ebp
603 mov 20(%esp), %ecx // get result pointer
604 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
605 mov %edx, 4(%ecx) // store the other half of the result
606 mov 24(%esp), %edx // get the shorty
607 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
608 je .Lreturn_double_quick2
609 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
610 je .Lreturn_float_quick2
611 ret
612.Lreturn_double_quick2:
613 movsd %xmm0, (%ecx) // store the floating point result
614 ret
615.Lreturn_float_quick2:
616 movss %xmm0, (%ecx) // store the floating point result
617 ret
618END_FUNCTION art_quick_invoke_static_stub
619
Ian Rogersd36c52e2012-04-09 16:29:25 -0700620MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700621 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700622 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700623 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700624 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700625 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700626 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800627 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700628 call CALLVAR(cxx_name) // cxx_name(Thread*)
629 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800630 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700631 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
632 CALL_MACRO(return_macro) // return or deliver exception
633 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700634END_MACRO
635
636MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700637 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700638 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700639 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700640 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700641 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700642 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800643 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700644 PUSH eax // pass arg1
645 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
646 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800647 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700648 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
649 CALL_MACRO(return_macro) // return or deliver exception
650 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700651END_MACRO
652
653MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700654 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700655 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700656 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700657 PUSH eax // push padding
658 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 PUSH ecx // pass arg2
661 PUSH eax // pass arg1
662 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
663 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800664 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700665 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
666 CALL_MACRO(return_macro) // return or deliver exception
667 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700668END_MACRO
669
Ian Rogersd36c52e2012-04-09 16:29:25 -0700670MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700671 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700672 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700673 // Outgoing argument set up
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 edx // pass arg3
677 PUSH ecx // pass arg2
678 PUSH eax // pass arg1
679 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
680 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700681 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700682 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
683 CALL_MACRO(return_macro) // return or deliver exception
684 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700685END_MACRO
686
Jeff Hao848f70a2014-01-15 13:49:50 -0800687MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700688 DEFINE_FUNCTION VAR(c_name)
Roland Levillainf969a202016-03-09 16:14:00 +0000689 subl MACRO_LITERAL(12), %esp // alignment padding
690 CFI_ADJUST_CFA_OFFSET(12)
691 PUSH ebx // Save ebx as the expansion of the
692 // SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
693 // macro below clobbers it.
Jeff Hao848f70a2014-01-15 13:49:50 -0800694 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000695 movl 28(%esp), %ebx // restore ebx
696 CFI_RESTORE_REG ebx
697
Jeff Hao848f70a2014-01-15 13:49:50 -0800698 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700699 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800700 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700701 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800702 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700703 PUSH ebx // pass arg4
704 PUSH edx // pass arg3
705 PUSH ecx // pass arg2
706 PUSH eax // pass arg1
707 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
708 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800709 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700710 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Roland Levillainf969a202016-03-09 16:14:00 +0000711 addl MACRO_LITERAL(16), %esp // pop ebx + padding
712 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700713 CALL_MACRO(return_macro) // return or deliver exception
714 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800715END_MACRO
716
Fred Shih37f05ef2014-07-16 18:38:08 -0700717MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700718 DEFINE_FUNCTION VAR(c_name)
719 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700720 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700721 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700722 PUSH eax // push padding
723 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700724 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700725 PUSH ecx // pass referrer
726 PUSH eax // pass arg1
727 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
728 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700729 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700730 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
731 CALL_MACRO(return_macro) // return or deliver exception
732 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700733END_MACRO
734
735MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700736 DEFINE_FUNCTION VAR(c_name)
737 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700738 // Outgoing argument set up
739 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700740 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700741 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700742 PUSH edx // pass referrer
743 PUSH ecx // pass arg2
744 PUSH eax // pass arg1
745 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
746 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700747 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700748 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
749 CALL_MACRO(return_macro) // return or deliver exception
750 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700751END_MACRO
752
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700753MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700754 DEFINE_FUNCTION VAR(c_name)
755 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700756 // Outgoing argument set up
757 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700758 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700759 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700760 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700761 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700762 PUSH ebx // pass referrer
763 PUSH edx // pass arg3
764 PUSH ecx // pass arg2
765 PUSH eax // pass arg1
766 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
767 // Thread*)
768 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700769 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700770 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
771 CALL_MACRO(return_macro) // return or deliver exception
772 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700773END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700774
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700775MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700776 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700777 jz 1f // if eax == 0 goto 1
778 ret // return
7791: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700780 DELIVER_PENDING_EXCEPTION
781END_MACRO
782
Ian Rogersd36c52e2012-04-09 16:29:25 -0700783MACRO0(RETURN_IF_EAX_ZERO)
784 testl %eax, %eax // eax == 0 ?
785 jnz 1f // if eax != 0 goto 1
786 ret // return
7871: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700788 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700789END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700790
jeffhaod66a8752012-05-22 15:30:16 -0700791MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700792 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700793 jne 1f // if exception field != 0 goto 1
794 ret // return
7951: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700796 DELIVER_PENDING_EXCEPTION
797END_MACRO
798
Mathieu Chartier7410f292013-11-24 13:17:35 -0800799// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700800GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800801
802// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
803DEFINE_FUNCTION art_quick_alloc_object_rosalloc
804 // Fast path rosalloc allocation.
805 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
806 // ebx, edx: free
807 PUSH edi
808 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
809 // Load the class (edx)
810 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
811 testl %edx, %edx // Check null class
812 jz .Lart_quick_alloc_object_rosalloc_slow_path
813 // Check class status
814 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
815 jne .Lart_quick_alloc_object_rosalloc_slow_path
816 // No fake dependence needed on x86
817 // between status and flags load,
818 // since each load is a load-acquire,
819 // no loads reordering.
820 // Check access flags has
821 // kAccClassIsFinalizable
822 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
823 jnz .Lart_quick_alloc_object_rosalloc_slow_path
824
825 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
826 // Check if the thread local allocation
827 // stack has room
828 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
829 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
830 jae .Lart_quick_alloc_object_rosalloc_slow_path
831
832 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
833 // Check if the size is for a thread
834 // local allocation
835 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
836 ja .Lart_quick_alloc_object_rosalloc_slow_path
837 decl %edi
838 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
839 // from object size.
840 // Align up the size by the rosalloc
841 // bracket quantum size and divide
842 // by the quantum size and subtract
843 // by 1. This code is a shorter but
844 // equivalent version.
845 // Load thread local rosalloc run (ebx)
846 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
847 // Load free_list head (edi),
848 // this will be the return value.
849 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
850 test %edi, %edi
851 jz .Lart_quick_alloc_object_rosalloc_slow_path
852 // Point of no slow path. Won't go to
853 // the slow path from here on. Ok to
854 // clobber eax and ecx.
855 movl %edi, %eax
856 // Load the next pointer of the head
857 // and update head of free list with
858 // next pointer
859 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
860 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
861 // Decrement size of free list by 1
862 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
863 // Store the class pointer in the
864 // header. This also overwrites the
865 // next pointer. The offsets are
866 // asserted to match.
867#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
868#error "Class pointer needs to overwrite next pointer."
869#endif
870 POISON_HEAP_REF edx
871 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
872 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
873 // Push the new object onto the thread
874 // local allocation stack and
875 // increment the thread local
876 // allocation stack top.
877 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
878 movl %eax, (%edi)
879 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
880 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
881 // No fence needed for x86.
882 POP edi
883 ret
884.Lart_quick_alloc_object_rosalloc_slow_path:
885 POP edi
886 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
887 // Outgoing argument set up
888 PUSH eax // alignment padding
889 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
890 CFI_ADJUST_CFA_OFFSET(4)
891 PUSH ecx
892 PUSH eax
893 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
894 addl LITERAL(16), %esp // pop arguments
895 CFI_ADJUST_CFA_OFFSET(-16)
896 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
897 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
898END_FUNCTION art_quick_alloc_object_rosalloc
899
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800900// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
901//
902// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
903MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
904 testl %edx, %edx // Check null class
905 jz VAR(slowPathLabel)
906 // Check class status.
907 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
908 jne VAR(slowPathLabel)
909 // No fake dependence needed on x86
910 // between status and flags load,
911 // since each load is a load-acquire,
912 // no loads reordering.
913 // Check access flags has
914 // kAccClassIsFinalizable
915 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
916 jnz VAR(slowPathLabel)
917 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
918 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
919 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
920 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
921 cmpl %edi, %esi // Check if it fits. OK to do this
922 // before rounding up the object size
923 // assuming the buf size alignment.
924 ja VAR(slowPathLabel)
925 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
926 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
927 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
928 // as allocated object.
929 addl %eax, %esi // Add the object size.
930 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
931 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
932 // Store the class pointer in the header.
933 // No fence needed for x86.
934 POISON_HEAP_REF edx
935 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
936 POP edi
937 POP esi
938 ret // Fast path succeeded.
939END_MACRO
940
941// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
942MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
943 POP edi
944 POP esi
945 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
946 // Outgoing argument set up
947 PUSH eax // alignment padding
948 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
949 CFI_ADJUST_CFA_OFFSET(4)
950 PUSH ecx
951 PUSH eax
952 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
953 addl LITERAL(16), %esp
954 CFI_ADJUST_CFA_OFFSET(-16)
955 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
956 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
957END_MACRO
958
959// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
960DEFINE_FUNCTION art_quick_alloc_object_tlab
961 // Fast path tlab allocation.
962 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
963 // EBX, EDX: free.
964#if defined(USE_READ_BARRIER)
965 int3
966 int3
967#endif
968 PUSH esi
969 PUSH edi
970 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
971 // Might need to break down into multiple instructions to get the base address in a register.
972 // Load the class
973 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
974 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
975.Lart_quick_alloc_object_tlab_slow_path:
976 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
977END_FUNCTION art_quick_alloc_object_tlab
978
979// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
980DEFINE_FUNCTION art_quick_alloc_object_region_tlab
981 // Fast path region tlab allocation.
982 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
983 // EBX, EDX: free.
984#if !defined(USE_READ_BARRIER)
985 int3
986 int3
987#endif
988 PUSH esi
989 PUSH edi
990 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
991 // Might need to break down into multiple instructions to get the base address in a register.
992 // Load the class
993 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
994 // Read barrier for class load.
995 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
996 jne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
997.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
998 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
999.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1000 // The read barrier slow path. Mark the class.
1001 PUSH eax
1002 PUSH ecx
1003 // Outgoing argument set up
1004 subl MACRO_LITERAL(8), %esp // Alignment padding
1005 CFI_ADJUST_CFA_OFFSET(8)
1006 PUSH edx // Pass the class as the first param.
1007 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1008 movl %eax, %edx
1009 addl MACRO_LITERAL(12), %esp
1010 CFI_ADJUST_CFA_OFFSET(-12)
1011 POP ecx
1012 POP eax
1013 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1014.Lart_quick_alloc_object_region_tlab_slow_path:
1015 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1016END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001017
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001018ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1019ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1020ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1021ONE_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 -07001022
Ian Rogers832336b2014-10-08 15:35:22 -07001023TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001024
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001025DEFINE_FUNCTION art_quick_lock_object
1026 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001027 jz .Lslow_lock
1028.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001029 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001030 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001031 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001032 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
1033 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001034 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001035 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001036 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001037 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001038 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1039 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1040 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1041 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1042 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001043 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001044.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1045 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001046 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001047 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001048 movl %edx, %ecx // copy the lock word to check count overflow.
1049 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
1050 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
1051 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 -08001052 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001053 movl %eax, %ecx // save obj to use eax for cmpxchg.
1054 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1055 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1056 // update lockword, cmpxchg necessary for read barrier bits.
1057 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1058 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001059 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001060.Llock_cmpxchg_fail:
1061 movl %ecx, %eax // restore eax
1062 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001063.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001064 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001065 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001066 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001067 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001068 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001069 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001070 PUSH eax // pass object
1071 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1072 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001073 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001074 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001075 RETURN_IF_EAX_ZERO
1076END_FUNCTION art_quick_lock_object
1077
1078DEFINE_FUNCTION art_quick_unlock_object
1079 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001080 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001081.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001082 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001083 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001084 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001085 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001086 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001087 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001088 movl %ecx, %edx // copy the lock word to detect new count of 0.
1089 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
1090 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001091 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001092 // update lockword, cmpxchg necessary for read barrier bits.
1093 movl %eax, %edx // edx: obj
1094 movl %ecx, %eax // eax: old lock word.
1095 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
1096#ifndef USE_READ_BARRIER
1097 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1098#else
1099 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1100 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1101#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001102 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001103.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1104 // update lockword, cmpxchg necessary for read barrier bits.
1105 movl %eax, %edx // edx: obj
1106 movl %ecx, %eax // eax: old lock word.
1107 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1108#ifndef USE_READ_BARRIER
1109 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1110#else
1111 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1112 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1113#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001114 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001115.Lunlock_cmpxchg_fail: // edx: obj
1116 movl %edx, %eax // restore eax
1117 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001118.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001119 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001120 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001121 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001122 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001123 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001124 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001125 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001126 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001127 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001128 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001129 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001130 RETURN_IF_EAX_ZERO
1131END_FUNCTION art_quick_unlock_object
1132
Ian Rogers468532e2013-08-05 10:56:33 -07001133DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001134 PUSH eax // alignment padding
1135 PUSH ecx // pass arg2 - obj->klass
1136 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001137 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001138 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001139 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001140 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001141END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001142
Ian Rogersa9a82542013-10-04 11:17:26 -07001143DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001144 PUSH eax // alignment padding
1145 PUSH ecx // pass arg2 - obj->klass
1146 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001147 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001148 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001149 jz 1f // jump forward if not assignable
1150 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001151 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001152 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001153
Andreas Gampe4360be22015-07-14 23:34:44 -07001154 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070011551:
Andreas Gampe4360be22015-07-14 23:34:44 -07001156 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001157 POP ecx
1158 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001159 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001160 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001161 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001162 PUSH eax // alignment padding
1163 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001164 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001165 PUSH ecx // pass arg2
1166 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001167 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001168 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001169END_FUNCTION art_quick_check_cast
1170
Man Cao1aee9002015-07-14 22:31:42 -07001171// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1172MACRO2(POP_REG_NE, reg, exclude_reg)
1173 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1174 addl MACRO_LITERAL(4), %esp
1175 CFI_ADJUST_CFA_OFFSET(-4)
1176 .else
1177 POP RAW_VAR(reg)
1178 .endif
1179END_MACRO
1180
1181 /*
1182 * Macro to insert read barrier, only used in art_quick_aput_obj.
1183 * obj_reg and dest_reg are registers, offset is a defined literal such as
1184 * MIRROR_OBJECT_CLASS_OFFSET.
1185 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1186 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1187 */
1188MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1189#ifdef USE_READ_BARRIER
1190 PUSH eax // save registers used in art_quick_aput_obj
1191 PUSH ebx
1192 PUSH edx
1193 PUSH ecx
1194 // Outgoing argument set up
1195 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1196 CFI_ADJUST_CFA_OFFSET(4)
1197 PUSH RAW_VAR(obj_reg) // pass obj_reg
1198 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1199 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1200 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1201 .ifnc RAW_VAR(dest_reg), eax
1202 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1203 .endif
1204 addl MACRO_LITERAL(12), %esp // pop arguments
1205 CFI_ADJUST_CFA_OFFSET(-12)
1206 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1207 POP_REG_NE edx, RAW_VAR(dest_reg)
1208 POP_REG_NE ebx, RAW_VAR(dest_reg)
1209 .ifc RAW_VAR(pop_eax), true
1210 POP_REG_NE eax, RAW_VAR(dest_reg)
1211 .endif
1212#else
1213 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1214 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1215#endif // USE_READ_BARRIER
1216END_MACRO
1217
Ian Rogersa9a82542013-10-04 11:17:26 -07001218 /*
1219 * Entry from managed code for array put operations of objects where the value being stored
1220 * needs to be checked for compatibility.
1221 * eax = array, ecx = index, edx = value
1222 */
1223DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1224 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001225 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1226 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001227END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1228
1229DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001230 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001231 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001232 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001233 mov %ecx, %eax
1234 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001235 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001236END_FUNCTION art_quick_aput_obj_with_bound_check
1237
1238DEFINE_FUNCTION art_quick_aput_obj
1239 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001240 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001241 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1242 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001243 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001244#if defined(USE_READ_BARRIER)
1245 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1246 cmpl %eax, %ebx
1247 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001248 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001249#elif defined(USE_HEAP_POISONING)
1250 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001251 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1252 UNPOISON_HEAP_REF eax
1253 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001254 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001255#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001256 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001257#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001258 jne .Lcheck_assignability
1259.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001260 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001261 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001262 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1263 shrl LITERAL(7), %eax
1264 movb %dl, (%edx, %eax)
1265 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001266.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001267 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001268 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001269.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001270 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001271 PUSH ecx
1272 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001273#if defined(USE_READ_BARRIER)
1274 subl LITERAL(4), %esp // alignment padding
1275 CFI_ADJUST_CFA_OFFSET(4)
1276 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1277 subl LITERAL(4), %esp // alignment padding
1278 CFI_ADJUST_CFA_OFFSET(4)
1279 PUSH eax // pass arg2 - type of the value to be stored
1280#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001281 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001282 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001283 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001284 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001285 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001286#else
Man Cao63069212015-08-21 15:51:39 -07001287 subl LITERAL(8), %esp // alignment padding
1288 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001289 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001290 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001291#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001292 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001293 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001294 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001295 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001296 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001297 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001298 POP edx
1299 POP ecx
1300 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001301 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001302 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001303 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1304 shrl LITERAL(7), %eax
1305 movb %dl, (%edx, %eax)
1306 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001307 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001308.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001309 POP edx
1310 POP ecx
1311 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001312 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001313 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001314 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001315 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001316 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001317 PUSH edx // pass arg2 - value
1318 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001319 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001320 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001321END_FUNCTION art_quick_aput_obj
1322
Logan Chien8dbb7082013-01-25 20:31:17 +08001323DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001324 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001325 PUSH edx // pass arg3
1326 PUSH ecx // pass arg2
1327 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001328 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001329 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001330 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001331 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001332END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001333
Logan Chien8dbb7082013-01-25 20:31:17 +08001334NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001335
Ian Rogers468532e2013-08-05 10:56:33 -07001336DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001337 subl LITERAL(12), %esp // alignment padding, room for argument
1338 CFI_ADJUST_CFA_OFFSET(12)
1339 movsd %xmm0, 0(%esp) // arg a
1340 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001341 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001342 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001343 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001344END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001345
Ian Rogers468532e2013-08-05 10:56:33 -07001346DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001347 subl LITERAL(12), %esp // alignment padding
1348 CFI_ADJUST_CFA_OFFSET(12)
1349 movss %xmm0, 0(%esp) // arg a
1350 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001351 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001352 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001353 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001354END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001355
Ian Rogers468532e2013-08-05 10:56:33 -07001356DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001357 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001358 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001359 PUSH ebx // pass arg4 b.hi
1360 PUSH edx // pass arg3 b.lo
1361 PUSH ecx // pass arg2 a.hi
1362 PUSH eax // pass arg1 a.lo
1363 call SYMBOL(artLdiv) // (jlong a, jlong b)
1364 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001365 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001366 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001367END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001368
Ian Rogersa9a82542013-10-04 11:17:26 -07001369DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001370 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001371 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001372 PUSH ebx // pass arg4 b.hi
1373 PUSH edx // pass arg3 b.lo
1374 PUSH ecx // pass arg2 a.hi
1375 PUSH eax // pass arg1 a.lo
1376 call SYMBOL(artLmod) // (jlong a, jlong b)
1377 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001378 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001379 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001380END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001381
Ian Rogers468532e2013-08-05 10:56:33 -07001382DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001383 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1384 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1385 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001386 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001387 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001388 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001389END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001390
Ian Rogers468532e2013-08-05 10:56:33 -07001391DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001392 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001393 xchg %edx, %ecx
1394 shld %cl,%eax,%edx
1395 shl %cl,%eax
1396 test LITERAL(32), %cl
1397 jz 1f
1398 mov %eax, %edx
1399 xor %eax, %eax
14001:
1401 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001402END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001403
Ian Rogers468532e2013-08-05 10:56:33 -07001404DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001405 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001406 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001407 shrd %cl,%edx,%eax
1408 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001409 test LITERAL(32),%cl
1410 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001411 mov %edx, %eax
1412 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014131:
1414 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001415END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001416
Ian Rogers468532e2013-08-05 10:56:33 -07001417DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001418 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001419 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001420 shrd %cl,%edx,%eax
1421 shr %cl,%edx
1422 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001423 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001424 mov %edx, %eax
1425 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014261:
1427 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001428END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001429
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001430ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1431ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1432ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1433ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1434ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1435ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1436ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001437
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001438TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1439TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1440TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1441TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1442TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1443TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1444TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001445
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001446TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1447TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1448TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1449TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001450
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001451THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1452THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1453THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1454THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1455
1456// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001457DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001458 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001459 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001460 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001461 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001462 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001463 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001464 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001465 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001466 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1467 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001468 PUSH ebx // pass high half of new_val
1469 PUSH edx // pass low half of new_val
1470 PUSH ecx // pass object
1471 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001472 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001473 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001474 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001475 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001476 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001477END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001478
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001479// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1480// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001481DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001482 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1483 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001484 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001485 movd %xmm0, %ebx
1486 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001487 subl LITERAL(12), %esp // alignment padding
1488 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001489 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001490 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001491 PUSH ebx // pass high half of new_val
1492 PUSH edx // pass low half of new_val
1493 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001494 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001495 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001496 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001497 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001498 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001499 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001500END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001501
Logan Chien8dbb7082013-01-25 20:31:17 +08001502DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001503 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001504 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001505 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001506 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001507 PUSH ecx // pass receiver
1508 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001509 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001510 movd %eax, %xmm0 // place return value also into floating point return value
1511 movd %edx, %xmm1
1512 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001513 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1514 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1515 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001516 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001517END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001518
Jeff Hao88474b42013-10-23 16:24:40 -07001519 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001520 * Called to resolve an imt conflict.
1521 * eax is the conflict ArtMethod.
1522 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1523 *
1524 * Note that this stub writes to eax.
1525 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001526 */
1527DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001528 PUSH EDI
1529 movl 8(%esp), %edi // Load referrer
1530 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1531 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1532 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001533 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001534 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1535 popl %eax // Pop ImtConflictTable.
1536 CFI_ADJUST_CFA_OFFSET(-4)
1537.Limt_table_iterate:
1538 cmpl %edi, 0(%eax)
1539 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001540 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001541 // and jump to it.
1542 POP EDI
1543 movl __SIZEOF_POINTER__(%eax), %eax
1544 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1545.Limt_table_next_entry:
1546 // If the entry is null, the interface method is not in the ImtConflictTable.
1547 cmpl LITERAL(0), 0(%eax)
1548 jz .Lconflict_trampoline
1549 // Iterate over the entries of the ImtConflictTable.
1550 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1551 jmp .Limt_table_iterate
1552.Lconflict_trampoline:
1553 // Call the runtime stub to populate the ImtConflictTable and jump to the
1554 // resolved method.
1555 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001556 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001557END_FUNCTION art_quick_imt_conflict_trampoline
1558
Ian Rogers468532e2013-08-05 10:56:33 -07001559DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001560 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001561 movl %esp, %edi
1562 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001563 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001564 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001565 PUSH ecx // pass receiver
1566 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001567 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001568 movl %eax, %edi // remember code pointer in EDI
1569 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001570 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001571 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001572 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001573 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070015741:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001575 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001576 DELIVER_PENDING_EXCEPTION
1577END_FUNCTION art_quick_resolution_trampoline
1578
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001579DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001580 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001581 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001582 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001583 subl LITERAL(5120), %esp
1584 // prepare for artQuickGenericJniTrampoline call
1585 // (Thread*, SP)
1586 // (esp) 4(esp) <= C calling convention
1587 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001588
1589 subl LITERAL(8), %esp // Padding for 16B alignment.
1590 pushl %ebp // Pass SP (to ArtMethod).
1591 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001592 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001593
Andreas Gampec200a4a2014-06-16 18:39:09 -07001594 // The C call will have registered the complete save-frame on success.
1595 // The result of the call is:
1596 // eax: pointer to native code, 0 on error.
1597 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001598
Andreas Gampec200a4a2014-06-16 18:39:09 -07001599 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001600 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001601 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001602
Andreas Gampec200a4a2014-06-16 18:39:09 -07001603 // Release part of the alloca.
1604 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001605
1606 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001607 // Native call.
1608 call *%eax
1609
Andreas Gampe779f8c92014-06-09 18:29:38 -07001610 // result sign extension is handled in C code
1611 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001612 // (Thread*, result, result_f)
1613 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001614 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001615
Andreas Gampe4360be22015-07-14 23:34:44 -07001616 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001617 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001618 pushl %edx // Pass int result.
1619 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001620 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001621 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001622
Andreas Gampe779f8c92014-06-09 18:29:38 -07001623 // Pending exceptions possible.
1624 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1625 testl %ebx, %ebx
1626 jnz .Lexception_in_native
1627
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001628 // Tear down the alloca.
1629 movl %ebp, %esp
1630 CFI_DEF_CFA_REGISTER(esp)
1631
1632
Andreas Gampe779f8c92014-06-09 18:29:38 -07001633 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001634 // Remove space for FPR args and EAX
1635 addl LITERAL(4 + 4 * 8), %esp
1636 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1637
Andreas Gampe779f8c92014-06-09 18:29:38 -07001638 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001639 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001640 CFI_ADJUST_CFA_OFFSET(-4)
1641 POP ebx
1642 POP ebp // Restore callee saves
1643 POP esi
1644 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001645 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001646 movd %eax, %xmm0
1647 movd %edx, %xmm1
1648 punpckldq %xmm1, %xmm0
1649 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001650.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001651 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1652 // Do a call to push a new save-all frame required by the runtime.
1653 call .Lexception_call
1654.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001655 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001656END_FUNCTION art_quick_generic_jni_trampoline
1657
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001658DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001659 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001660 mov %esp, %edx // remember SP
1661 PUSH eax // alignment padding
1662 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001663 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001664 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001665 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001666 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001667 addl LITERAL(16), %esp // pop arguments
1668 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001669
1670 // Return eax:edx in xmm0 also.
1671 movd %eax, %xmm0
1672 movd %edx, %xmm1
1673 punpckldq %xmm1, %xmm0
1674
1675 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1676 CFI_ADJUST_CFA_OFFSET(-48)
1677
Andreas Gampe4360be22015-07-14 23:34:44 -07001678 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001679 POP esi
1680 POP edi
1681
Ian Rogers7db619b2013-01-16 18:35:48 -08001682 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001683END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001684
jeffhao7e4fcb82013-01-10 18:11:08 -08001685 /*
1686 * Routine that intercepts method calls and returns.
1687 */
Ian Rogers468532e2013-08-05 10:56:33 -07001688DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001689 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001690 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001691 subl LITERAL(12), %esp // Align stack.
1692 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001693 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001694 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001695 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001696 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001697 PUSH ecx // Pass receiver.
1698 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001699 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001700 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001701 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001702 movl 60(%esp), %edi // Restore edi.
1703 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001704 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001705 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001706 movl %ebx, 64(%esp)
1707 movl 0(%esp), %eax // Restore eax.
1708 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1709 movsd 8(%esp), %xmm0
1710 movsd 16(%esp), %xmm1
1711 movsd 24(%esp), %xmm2
1712 movsd 32(%esp), %xmm3
1713
1714 // Restore GPRs.
1715 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001716 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001717 movl 48(%esp), %ebx // Restore ebx.
1718 movl 52(%esp), %ebp // Restore ebp.
1719 movl 56(%esp), %esi // Restore esi.
1720 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001721 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001722 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001723END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001724
Ian Rogers468532e2013-08-05 10:56:33 -07001725DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001726 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001727 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001728 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001729 mov %esp, %ecx // Remember SP
1730 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001731 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001732 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001733 PUSH edx // Save gpr return value.
1734 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001735 subl LITERAL(16), %esp // Align stack
1736 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001737 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001738 PUSH edx // Pass gpr return value.
1739 PUSH eax
1740 PUSH ecx // Pass SP.
1741 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001742 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001743 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001744 mov %eax, %ecx // Move returned link register.
1745 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001746 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001747 movl %edx, %ebx // Move returned link register for deopt
1748 // (ebx is pretending to be our LR).
1749 POP eax // Restore gpr return value.
1750 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001751 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001752 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001753 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001754 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001755 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001756 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001757 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001758END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001759
jeffhao7e4fcb82013-01-10 18:11:08 -08001760 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001761 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1762 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001763 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001764DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001765 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001766 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1767 subl LITERAL(12), %esp // Align stack.
1768 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001769 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001770 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001771 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001772 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001773END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001774
jeffhao86e46712012-08-08 17:30:59 -07001775 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001776 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001777 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001778 */
1779DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1780 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1781 subl LITERAL(12), %esp // Align stack.
1782 CFI_ADJUST_CFA_OFFSET(12)
1783 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1784 CFI_ADJUST_CFA_OFFSET(4)
1785 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1786 UNREACHABLE
1787END_FUNCTION art_quick_deoptimize_from_compiled_code
1788
1789 /*
jeffhao86e46712012-08-08 17:30:59 -07001790 * String's compareTo.
1791 *
1792 * On entry:
1793 * eax: this string object (known non-null)
1794 * ecx: comp string object (known non-null)
1795 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001796DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001797 PUSH esi // push callee save reg
1798 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001799 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1800 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001801 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1802 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001803 /* Calculate min length and count diff */
1804 mov %edx, %ecx
1805 mov %edx, %eax
1806 subl %ebx, %eax
1807 cmovg %ebx, %ecx
1808 /*
1809 * At this point we have:
1810 * eax: value to return if first part of strings are equal
1811 * ecx: minimum among the lengths of the two strings
1812 * esi: pointer to this string data
1813 * edi: pointer to comp string data
1814 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001815 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001816 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001817 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001818.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001819 POP edi // pop callee save reg
1820 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001821 ret
1822 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001823.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001824 movzwl -2(%esi), %eax // get last compared char from this string
1825 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001826 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001827 POP edi // pop callee save reg
1828 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001829 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001830END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001831
Dave Allison8ce6b902014-08-26 11:07:58 -07001832// Return from a nested signal:
1833// Entry:
1834// eax: address of jmp_buf in TLS
1835
1836DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001837 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001838 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001839 PUSH ecx // second arg to longjmp (1)
1840 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001841 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001842 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001843END_FUNCTION art_nested_signal_return
1844
Roland Levillain7c1559a2015-12-15 10:55:36 +00001845DEFINE_FUNCTION art_quick_read_barrier_mark
1846 PUSH eax // pass arg1 - obj
1847 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
1848 addl LITERAL(4), %esp // pop argument
1849 CFI_ADJUST_CFA_OFFSET(-4)
1850 ret
1851END_FUNCTION art_quick_read_barrier_mark
1852
Man Cao1aee9002015-07-14 22:31:42 -07001853DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001854 PUSH edx // pass arg3 - offset
1855 PUSH ecx // pass arg2 - obj
1856 PUSH eax // pass arg1 - ref
1857 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1858 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001859 CFI_ADJUST_CFA_OFFSET(-12)
1860 ret
1861END_FUNCTION art_quick_read_barrier_slow
1862
Roland Levillain0d5a2812015-11-13 10:07:31 +00001863DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
1864 PUSH eax // pass arg1 - root
1865 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
1866 addl LITERAL(4), %esp // pop argument
1867 CFI_ADJUST_CFA_OFFSET(-4)
1868 ret
1869END_FUNCTION art_quick_read_barrier_for_root_slow
1870
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001871 /*
1872 * On stack replacement stub.
1873 * On entry:
1874 * [sp] = return address
1875 * [sp + 4] = stack to copy
1876 * [sp + 8] = size of stack
1877 * [sp + 12] = pc to call
1878 * [sp + 16] = JValue* result
1879 * [sp + 20] = shorty
1880 * [sp + 24] = thread
1881 */
1882DEFINE_FUNCTION art_quick_osr_stub
1883 // Save native callee saves.
1884 PUSH ebp
1885 PUSH ebx
1886 PUSH esi
1887 PUSH edi
1888 mov 4+16(%esp), %esi // ESI = argument array
1889 mov 8+16(%esp), %ecx // ECX = size of args
1890 mov 12+16(%esp), %ebx // EBX = pc to call
1891 mov %esp, %ebp // Save stack pointer
1892 andl LITERAL(0xFFFFFFF0), %esp // Align stack
1893 PUSH ebp // Save old stack pointer
1894 subl LITERAL(12), %esp // Align stack
1895 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
1896 call .Losr_entry
1897
1898 // Restore stack pointer.
1899 addl LITERAL(12), %esp
1900 POP ebp
1901 mov %ebp, %esp
1902
1903 // Restore callee saves.
1904 POP edi
1905 POP esi
1906 POP ebx
1907 POP ebp
1908 mov 16(%esp), %ecx // Get JValue result
1909 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
1910 mov %edx, 4(%ecx) // Store the other half of the result
1911 mov 20(%esp), %edx // Get the shorty
1912 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
1913 je .Losr_return_double_quick
1914 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
1915 je .Losr_return_float_quick
1916 ret
1917.Losr_return_double_quick:
1918 movsd %xmm0, (%ecx) // Store the floating point result
1919 ret
1920.Losr_return_float_quick:
1921 movss %xmm0, (%ecx) // Store the floating point result
1922 ret
1923.Losr_entry:
1924 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
1925 subl %ecx, %esp
1926 mov %esp, %edi // EDI = beginning of stack
1927 rep movsb // while (ecx--) { *edi++ = *esi++ }
1928 jmp *%ebx
1929END_FUNCTION art_quick_osr_stub
1930
Elliott Hughes787ec202012-03-29 17:14:15 -07001931 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001932UNIMPLEMENTED art_quick_memcmp16