blob: 46a6cdb0a4a586fc9b86351170939b1cdca35af7 [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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010025 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Ian Rogers57b86d42012-03-27 16:05:41 -070026 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010027MACRO2(SETUP_SAVE_ALL_CALLEE_SAVES_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010038 pushl RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 3*4 + 16 + 4)
45#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070046#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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010051 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly)
Ian Rogers7caad772012-03-30 01:07:54 -070052 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010053MACRO2(SETUP_SAVE_REFS_ONLY_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010064 pushl RUNTIME_SAVE_REFS_ONLY_METHOD_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010071#if (FRAME_SIZE_SAVE_REFS_ONLY != 3*4 + 16 + 4)
72#error "FRAME_SIZE_SAVE_REFS_ONLY(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070073#endif
Ian Rogers7caad772012-03-30 01:07:54 -070074END_MACRO
75
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010076 /*
77 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010078 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010079 * and preserves the value of got_reg at entry.
80 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010081MACRO2(SETUP_SAVE_REFS_ONLY_FRAME_PRESERVE_GOT_REG, got_reg, temp_reg)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010082 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
83 PUSH esi
84 PUSH ebp
Vladimir Marko2ebef632016-06-21 11:24:47 +010085 PUSH RAW_VAR(got_reg) // Save got_reg
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010086 subl MACRO_LITERAL(8), %esp // Grow stack by 2 words.
87 CFI_ADJUST_CFA_OFFSET(8)
88
89 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
90 // Load Runtime::instance_ from GOT.
91 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
92 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
93 // Push save all callee-save method.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010094 pushl RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET(REG_VAR(temp_reg))
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010095 CFI_ADJUST_CFA_OFFSET(4)
96 // Store esp as the top quick frame.
97 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
98 // Restore got_reg.
99 movl 12(%esp), REG_VAR(got_reg)
Vladimir Marko2ebef632016-06-21 11:24:47 +0100100 CFI_RESTORE(RAW_VAR(got_reg))
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100101
102 // Ugly compile-time check, but we only have the preprocessor.
103 // Last +4: implicit return address pushed on stack when caller made call.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100104#if (FRAME_SIZE_SAVE_REFS_ONLY != 3*4 + 16 + 4)
105#error "FRAME_SIZE_SAVE_REFS_ONLY(X86) size not as expected."
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100106#endif
107END_MACRO
108
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100109MACRO0(RESTORE_SAVE_REFS_ONLY_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -0700110 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800111 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700112 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
113 POP esi
114 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
117 /*
118 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100119 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700120 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100121MACRO2(SETUP_SAVE_REFS_AND_ARGS_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -0800122 PUSH edi // Save callee saves
123 PUSH esi
124 PUSH ebp
125 PUSH ebx // Save args
126 PUSH edx
127 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000128 // Create space for FPR args.
129 subl MACRO_LITERAL(4 * 8), %esp
130 CFI_ADJUST_CFA_OFFSET(4 * 8)
131 // Save FPRs.
132 movsd %xmm0, 0(%esp)
133 movsd %xmm1, 8(%esp)
134 movsd %xmm2, 16(%esp)
135 movsd %xmm3, 24(%esp)
136
Andreas Gampe4360be22015-07-14 23:34:44 -0700137 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700138 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700139 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
140 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700141 // Push save all callee-save method.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100142 pushl RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143 CFI_ADJUST_CFA_OFFSET(4)
144 // Store esp as the stop quick frame.
145 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700146
147 // Ugly compile-time check, but we only have the preprocessor.
148 // Last +4: implicit return address pushed on stack when caller made call.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100149#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 7*4 + 4*8 + 4)
150#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700151#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700152END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700153
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 /*
155 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100156 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs) where the method is passed in EAX.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700157 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100158MACRO0(SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000159 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700160 PUSH edi // Save callee saves
161 PUSH esi
162 PUSH ebp
163 PUSH ebx // Save args
164 PUSH edx
165 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000166
167 // Create space for FPR args.
168 subl MACRO_LITERAL(32), %esp
169 CFI_ADJUST_CFA_OFFSET(32)
170
171 // Save FPRs.
172 movsd %xmm0, 0(%esp)
173 movsd %xmm1, 8(%esp)
174 movsd %xmm2, 16(%esp)
175 movsd %xmm3, 24(%esp)
176
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700177 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
178 // Store esp as the stop quick frame.
179 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
180END_MACRO
181
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100182MACRO0(RESTORE_SAVE_REFS_AND_ARGS_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000183 // Restore FPRs. EAX is still on the stack.
184 movsd 4(%esp), %xmm0
185 movsd 12(%esp), %xmm1
186 movsd 20(%esp), %xmm2
187 movsd 28(%esp), %xmm3
188
189 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
190 CFI_ADJUST_CFA_OFFSET(-36)
191
Andreas Gampe4360be22015-07-14 23:34:44 -0700192 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800193 POP edx
194 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700195 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800196 POP esi
197 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700198END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700199
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000200// Restore register and jump to routine
201// Inputs: EDI contains pointer to code.
202// Notes: Need to pop EAX too (restores Method*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100203MACRO0(RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000204 POP eax // Restore Method*
205
206 // Restore FPRs.
207 movsd 0(%esp), %xmm0
208 movsd 8(%esp), %xmm1
209 movsd 16(%esp), %xmm2
210 movsd 24(%esp), %xmm3
211
212 addl MACRO_LITERAL(32), %esp // Remove FPRs.
213 CFI_ADJUST_CFA_OFFSET(-32)
214
215 POP ecx // Restore args except eax
216 POP edx
217 POP ebx
218 POP ebp // Restore callee saves
219 POP esi
220 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
221 ret
222END_MACRO
223
Ian Rogers57b86d42012-03-27 16:05:41 -0700224 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100225 * Macro that sets up the callee save frame to conform with
226 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100227 * when EDI and ESI are already saved.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100228 */
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100229MACRO2(SETUP_SAVE_EVERYTHING_FRAME_EDI_ESI_SAVED, got_reg, temp_reg)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000230 // Save core registers from highest to lowest to agree with core spills bitmap.
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100231 // EDI and ESI, or at least placeholders for them, are already on the stack.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100232 PUSH ebp
233 PUSH ebx
234 PUSH edx
235 PUSH ecx
236 PUSH eax
237 // Create space for FPR registers and stack alignment padding.
238 subl MACRO_LITERAL(12 + 8 * 8), %esp
239 CFI_ADJUST_CFA_OFFSET(12 + 8 * 8)
240 // Save FPRs.
241 movsd %xmm0, 12(%esp)
242 movsd %xmm1, 20(%esp)
243 movsd %xmm2, 28(%esp)
244 movsd %xmm3, 36(%esp)
245 movsd %xmm4, 44(%esp)
246 movsd %xmm5, 52(%esp)
247 movsd %xmm6, 60(%esp)
248 movsd %xmm7, 68(%esp)
249
250 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
251 // Load Runtime::instance_ from GOT.
252 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
253 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
254 // Push save everything callee-save method.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100255 pushl RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET(REG_VAR(temp_reg))
Vladimir Marko952dbb12016-07-28 12:01:51 +0100256 CFI_ADJUST_CFA_OFFSET(4)
257 // Store esp as the stop quick frame.
258 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
259
260 // Ugly compile-time check, but we only have the preprocessor.
261 // Last +4: implicit return address pushed on stack when caller made call.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100262#if (FRAME_SIZE_SAVE_EVERYTHING != 7*4 + 8*8 + 12 + 4 + 4)
263#error "FRAME_SIZE_SAVE_EVERYTHING(X86) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100264#endif
265END_MACRO
266
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000267 /*
268 * Macro that sets up the callee save frame to conform with
269 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100270 * when EDI is already saved.
271 */
272MACRO2(SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED, got_reg, temp_reg)
273 // Save core registers from highest to lowest to agree with core spills bitmap.
274 // EDI, or at least a placeholder for it, is already on the stack.
275 PUSH esi
276 SETUP_SAVE_EVERYTHING_FRAME_EDI_ESI_SAVED RAW_VAR(got_reg), RAW_VAR(temp_reg)
277END_MACRO
278
279 /*
280 * Macro that sets up the callee save frame to conform with
281 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000282 */
283MACRO2(SETUP_SAVE_EVERYTHING_FRAME, got_reg, temp_reg)
284 PUSH edi
285 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED RAW_VAR(got_reg), RAW_VAR(temp_reg)
286END_MACRO
287
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100288MACRO0(RESTORE_SAVE_EVERYTHING_FRAME_FRPS)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100289 // Restore FPRs. Method and padding is still on the stack.
290 movsd 16(%esp), %xmm0
291 movsd 24(%esp), %xmm1
292 movsd 32(%esp), %xmm2
293 movsd 40(%esp), %xmm3
294 movsd 48(%esp), %xmm4
295 movsd 56(%esp), %xmm5
296 movsd 64(%esp), %xmm6
297 movsd 72(%esp), %xmm7
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100298END_MACRO
Vladimir Marko952dbb12016-07-28 12:01:51 +0100299
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100300MACRO0(RESTORE_SAVE_EVERYTHING_FRAME_GPRS_EXCEPT_EAX)
301 // Restore core registers (except eax).
Vladimir Marko952dbb12016-07-28 12:01:51 +0100302 POP ecx
303 POP edx
304 POP ebx
305 POP ebp
306 POP esi
307 POP edi
308END_MACRO
309
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100310MACRO0(RESTORE_SAVE_EVERYTHING_FRAME)
311 RESTORE_SAVE_EVERYTHING_FRAME_FRPS
312
313 // Remove save everything callee save method, stack alignment padding and FPRs.
314 addl MACRO_LITERAL(16 + 8 * 8), %esp
315 CFI_ADJUST_CFA_OFFSET(-(16 + 8 * 8))
316
317 POP eax
318 RESTORE_SAVE_EVERYTHING_FRAME_GPRS_EXCEPT_EAX
319END_MACRO
320
321MACRO0(RESTORE_SAVE_EVERYTHING_FRAME_KEEP_EAX)
322 RESTORE_SAVE_EVERYTHING_FRAME_FRPS
323
324 // Remove save everything callee save method, stack alignment padding and FPRs, skip EAX.
325 addl MACRO_LITERAL(16 + 8 * 8 + 4), %esp
326 CFI_ADJUST_CFA_OFFSET(-(16 + 8 * 8 + 4))
327
328 RESTORE_SAVE_EVERYTHING_FRAME_GPRS_EXCEPT_EAX
329END_MACRO
330
Vladimir Marko952dbb12016-07-28 12:01:51 +0100331 /*
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100332 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
333 * exception is Thread::Current()->exception_ when the runtime method frame is ready.
Ian Rogers57b86d42012-03-27 16:05:41 -0700334 */
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100335MACRO0(DELIVER_PENDING_EXCEPTION_FRAME_READY)
Ian Rogers57b86d42012-03-27 16:05:41 -0700336 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100337 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700338 CFI_ADJUST_CFA_OFFSET(12)
339 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800340 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700341 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700342 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700343END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700344
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100345 /*
346 * Macro that calls through to artDeliverPendingExceptionFromCode, where the pending
347 * exception is Thread::Current()->exception_.
348 */
349MACRO0(DELIVER_PENDING_EXCEPTION)
350 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save callee saves for throw
351 DELIVER_PENDING_EXCEPTION_FRAME_READY
352END_MACRO
353
Elliott Hughes787ec202012-03-29 17:14:15 -0700354MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700355 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100356 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700357 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100358 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700359 CFI_ADJUST_CFA_OFFSET(12)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100360 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800361 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100362 call CALLVAR(cxx_name) // cxx_name(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700363 UNREACHABLE
364 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700365END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700366
Vladimir Marko804b03f2016-09-14 16:26:36 +0100367MACRO2(NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING, c_name, cxx_name)
368 DEFINE_FUNCTION VAR(c_name)
369 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save all registers as basis for long jump context
370 // Outgoing argument set up
371 subl MACRO_LITERAL(12), %esp // alignment padding
372 CFI_ADJUST_CFA_OFFSET(12)
373 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
374 CFI_ADJUST_CFA_OFFSET(4)
375 call CALLVAR(cxx_name) // cxx_name(Thread*)
376 UNREACHABLE
377 END_FUNCTION VAR(c_name)
378END_MACRO
379
Elliott Hughes787ec202012-03-29 17:14:15 -0700380MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700381 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100382 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700383 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100384 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700385 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700386 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800387 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700388 PUSH eax // pass arg1
389 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
390 UNREACHABLE
391 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700392END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700393
Vladimir Marko804b03f2016-09-14 16:26:36 +0100394MACRO2(TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700395 DEFINE_FUNCTION VAR(c_name)
Vladimir Marko804b03f2016-09-14 16:26:36 +0100396 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700397 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700398 PUSH eax // alignment padding
399 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800400 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700401 PUSH ecx // pass arg2
402 PUSH eax // pass arg1
403 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
404 UNREACHABLE
405 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700406END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700407
408 /*
409 * Called by managed code to create and deliver a NullPointerException.
410 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100411NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700412
413 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100414 * Call installed by a signal handler to create and deliver a NullPointerException.
415 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000416DEFINE_FUNCTION_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, 2 * __SIZEOF_POINTER__
417 // Fault address and return address were saved by the fault handler.
418 // Save all registers as basis for long jump context; EDI will replace fault address later.
419 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED ebx, ebx
420 // Retrieve fault address and save EDI.
421 movl (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp), %eax
422 movl %edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp)
423 CFI_REL_OFFSET(%edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__))
424 // Outgoing argument set up
425 subl MACRO_LITERAL(8), %esp // alignment padding
426 CFI_ADJUST_CFA_OFFSET(8)
427 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
428 CFI_ADJUST_CFA_OFFSET(4)
429 PUSH eax // pass arg1
430 call SYMBOL(artThrowNullPointerExceptionFromSignal) // (addr, self)
431 UNREACHABLE
432END_FUNCTION art_quick_throw_null_pointer_exception
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100433
434 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700435 * Called by managed code to create and deliver an ArithmeticException.
436 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100437NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700438
439 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700440 * Called by managed code to create and deliver a StackOverflowError.
441 */
Ian Rogers468532e2013-08-05 10:56:33 -0700442NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700443
444 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700445 * Called by managed code, saves callee saves and then calls artThrowException
446 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
447 */
Ian Rogers468532e2013-08-05 10:56:33 -0700448ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700449
450 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700451 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
452 * index, arg2 holds limit.
453 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100454TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700455
456 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100457 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
458 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
459 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100460TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_string_bounds, artThrowStringBoundsFromCode
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100461
462 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700463 * All generated callsites for interface invokes and invocation slow paths will load arguments
464 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100465 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700466 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
467 *
468 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
469 * of the target Method* in r0 and method->code_ in r1.
470 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700471 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700472 * thread and we branch to another stub to deliver it.
473 *
474 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
475 * pointing back to the original caller.
476 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700477MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100478 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700479 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000480
Ian Rogers7caad772012-03-30 01:07:54 -0700481 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800482 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700483 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800484 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800485 PUSH ecx // pass arg2
486 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700487 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700488 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100489 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
490 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000491
492 // Restore FPRs.
493 movsd 0(%esp), %xmm0
494 movsd 8(%esp), %xmm1
495 movsd 16(%esp), %xmm2
496 movsd 24(%esp), %xmm3
497
498 // Remove space for FPR args.
499 addl MACRO_LITERAL(4 * 8), %esp
500 CFI_ADJUST_CFA_OFFSET(-4 * 8)
501
Dave Allisonbbb32c22013-11-05 18:25:18 -0800502 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800503 POP edx
504 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800505 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800506 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700507 // Swap EDI callee save with code pointer.
508 xchgl %edi, (%esp)
509 testl %eax, %eax // Branch forward if exception pending.
510 jz 1f
511 // Tail call to intended method.
512 ret
5131:
jeffhao20b5c6c2012-05-21 14:15:18 -0700514 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800515 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700516 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700517END_MACRO
518MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700519 DEFINE_FUNCTION VAR(c_name)
520 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
521 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700522END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700523
Logan Chien8dbb7082013-01-25 20:31:17 +0800524INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700525
Logan Chien8dbb7082013-01-25 20:31:17 +0800526INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
527INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
528INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
529INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700530
Jeff Hao5d917302013-02-27 17:57:33 -0800531 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000532 * Helper for quick invocation stub to set up XMM registers.
533 * Increments shorty and arg_array and clobbers temp_char.
534 * Branches to finished if it encounters the end of the shorty.
535 */
536MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
5371: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700538 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
539 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
540 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
541 je VAR(finished) // goto finished
542 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
543 je 2f // goto FOUND_DOUBLE
544 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
545 je 3f // goto FOUND_FLOAT
546 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000547 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700548 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
549 jne 1b // goto LOOP
550 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
551 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005522: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700553 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
554 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000555 jmp 4f
5563: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700557 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
558 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005594:
560END_MACRO
561
562 /*
563 * Helper for quick invocation stub to set up GPR registers.
564 * Increments shorty and arg_array, and returns the current short character in
565 * temp_char. Branches to finished if it encounters the end of the shorty.
566 */
567MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
5681: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700569 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
570 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
571 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
572 je VAR(finished) // goto finished
573 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
574 je 3f // goto SKIP_FLOAT
575 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
576 je 4f // goto SKIP_DOUBLE
577 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005783: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700579 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
580 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005814: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700582 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
583 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005845:
585END_MACRO
586
587 /*
588 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700589 * On entry:
590 * [sp] = return address
591 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700592 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700593 * [sp + 12] = size of argument array in bytes
594 * [sp + 16] = (managed) thread pointer
595 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800596 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800597 */
598DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000599 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800600 PUSH ebp // save ebp
601 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000602 PUSH esi // save esi
603 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000604 // Set up argument XMM registers.
605 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
606 addl LITERAL(1), %esi
607 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
608 addl LITERAL(4), %edi
609 // Clobbers ESI, EDI, EAX.
610 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
611 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
612 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
613 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
614 .balign 16
615.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800616 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800617 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000618 mov 28(%ebp), %ebx // get arg array size
619 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
620 addl LITERAL(36), %ebx
621 // align frame size to 16 bytes
622 andl LITERAL(0xFFFFFFF0), %ebx
623 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800624 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000625
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700626 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000627
628 // Copy arg array into stack.
629 movl 28(%ebp), %ecx // ECX = size of args
630 movl 24(%ebp), %esi // ESI = argument array
631 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
632 rep movsb // while (ecx--) { *edi++ = *esi++ }
633
634 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
635 addl LITERAL(1), %esi
636 mov 24(%ebp), %edi // EDI := arg_array
637 mov 0(%edi), %ecx // ECX := this pointer
638 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
639
640 // Enumerate the possible cases for loading GPRS.
641 // edx (and maybe ebx):
642 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
643 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
644 je .LfirstLong
645 // Must be an integer value.
646 movl (%edi), %edx
647 addl LITERAL(4), %edi // arg_array++
648
649 // Now check ebx
650 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500651 // Must be first word of a long, or an integer. First word of long doesn't
652 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000653 movl (%edi), %ebx
654 jmp .Lgpr_setup_finished
655.LfirstLong:
656 movl (%edi), %edx
657 movl 4(%edi), %ebx
658 // Nothing left to load.
659.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000660 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700661 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800662 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800663 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000664 POP edi // pop edi
665 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800666 POP ebx // pop ebx
667 POP ebp // pop ebp
668 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800669 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800670 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800671 mov 24(%esp), %edx // get the shorty
672 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800673 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800674 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800675 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700676 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800677.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800678 movsd %xmm0, (%ecx) // store the floating point result
679 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800680.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800681 movss %xmm0, (%ecx) // store the floating point result
682 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800683END_FUNCTION art_quick_invoke_stub
684
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000685 /*
686 * Quick invocation stub (static).
687 * On entry:
688 * [sp] = return address
689 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700690 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000691 * [sp + 12] = size of argument array in bytes
692 * [sp + 16] = (managed) thread pointer
693 * [sp + 20] = JValue* result
694 * [sp + 24] = shorty
695 */
696DEFINE_FUNCTION art_quick_invoke_static_stub
697 // Save the non-volatiles.
698 PUSH ebp // save ebp
699 PUSH ebx // save ebx
700 PUSH esi // save esi
701 PUSH edi // save edi
702 // Set up argument XMM registers.
703 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
704 addl LITERAL(1), %esi
705 mov 8+16(%esp), %edi // EDI := arg_array
706 // Clobbers ESI, EDI, EAX.
707 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
708 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
709 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
710 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
711 .balign 16
712.Lxmm_setup_finished2:
713 mov %esp, %ebp // copy value of stack pointer into base pointer
714 CFI_DEF_CFA_REGISTER(ebp)
715 mov 28(%ebp), %ebx // get arg array size
716 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
717 addl LITERAL(36), %ebx
718 // align frame size to 16 bytes
719 andl LITERAL(0xFFFFFFF0), %ebx
720 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
721 subl %ebx, %esp // reserve stack space for argument array
722
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700723 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000724
725 // Copy arg array into stack.
726 movl 28(%ebp), %ecx // ECX = size of args
727 movl 24(%ebp), %esi // ESI = argument array
728 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
729 rep movsb // while (ecx--) { *edi++ = *esi++ }
730
731 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
732 addl LITERAL(1), %esi
733 mov 24(%ebp), %edi // EDI := arg_array
734
735 // Enumerate the possible cases for loading GPRS.
736 // ecx (and maybe edx)
737 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
738 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
739 je .LfirstLong2
740 // Must be an integer value. Load into ECX.
741 movl (%edi), %ecx
742 addl LITERAL(4), %edi // arg_array++
743
744 // Now check edx (and maybe ebx).
745 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
746 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
747 je .LSecondLong2
748 // Must be an integer. Load into EDX.
749 movl (%edi), %edx
750 addl LITERAL(4), %edi // arg_array++
751
752 // Is there anything for ebx?
753 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500754 // Must be first word of a long, or an integer. First word of long doesn't
755 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000756 movl (%edi), %ebx
757 jmp .Lgpr_setup_finished2
758.LSecondLong2:
759 // EDX:EBX is long. That is all.
760 movl (%edi), %edx
761 movl 4(%edi), %ebx
762 jmp .Lgpr_setup_finished2
763.LfirstLong2:
764 // ECX:EDX is a long
765 movl (%edi), %ecx
766 movl 4(%edi), %edx
767 addl LITERAL(8), %edi // arg_array += 2
768
769 // Anything for EBX?
770 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500771 // Must be first word of a long, or an integer. First word of long doesn't
772 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000773 movl (%edi), %ebx
774 jmp .Lgpr_setup_finished2
775 // Nothing left to load.
776.Lgpr_setup_finished2:
777 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700778 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000779 mov %ebp, %esp // restore stack pointer
780 CFI_DEF_CFA_REGISTER(esp)
781 POP edi // pop edi
782 POP esi // pop esi
783 POP ebx // pop ebx
784 POP ebp // pop ebp
785 mov 20(%esp), %ecx // get result pointer
786 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
787 mov %edx, 4(%ecx) // store the other half of the result
788 mov 24(%esp), %edx // get the shorty
789 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
790 je .Lreturn_double_quick2
791 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
792 je .Lreturn_float_quick2
793 ret
794.Lreturn_double_quick2:
795 movsd %xmm0, (%ecx) // store the floating point result
796 ret
797.Lreturn_float_quick2:
798 movss %xmm0, (%ecx) // store the floating point result
799 ret
800END_FUNCTION art_quick_invoke_static_stub
801
Ian Rogersd36c52e2012-04-09 16:29:25 -0700802MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700803 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100804 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700805 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700806 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700807 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700808 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800809 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700810 PUSH eax // pass arg1
811 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
812 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800813 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100814 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700815 CALL_MACRO(return_macro) // return or deliver exception
816 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700817END_MACRO
818
819MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700820 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100821 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700822 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700823 PUSH eax // push padding
824 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800825 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700826 PUSH ecx // pass arg2
827 PUSH eax // pass arg1
828 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
829 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800830 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100831 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700832 CALL_MACRO(return_macro) // return or deliver exception
833 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700834END_MACRO
835
Ian Rogersd36c52e2012-04-09 16:29:25 -0700836MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700837 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100838 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700839 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700840 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800841 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700842 PUSH edx // pass arg3
843 PUSH ecx // pass arg2
844 PUSH eax // pass arg1
845 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
846 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700847 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100848 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700849 CALL_MACRO(return_macro) // return or deliver exception
850 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700851END_MACRO
852
Jeff Hao848f70a2014-01-15 13:49:50 -0800853MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700854 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100855 SETUP_SAVE_REFS_ONLY_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000856
Jeff Hao848f70a2014-01-15 13:49:50 -0800857 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700858 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800859 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700860 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800861 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700862 PUSH ebx // pass arg4
863 PUSH edx // pass arg3
864 PUSH ecx // pass arg2
865 PUSH eax // pass arg1
866 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
867 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800868 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100869 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700870 CALL_MACRO(return_macro) // return or deliver exception
871 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800872END_MACRO
873
Fred Shih37f05ef2014-07-16 18:38:08 -0700874MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700875 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100876 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700877 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100878 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700879 PUSH eax // push padding
880 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700881 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700882 PUSH ecx // pass referrer
883 PUSH eax // pass arg1
884 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
885 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700886 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100887 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700888 CALL_MACRO(return_macro) // return or deliver exception
889 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700890END_MACRO
891
892MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700893 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100894 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700895 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100896 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700897 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700898 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700899 PUSH edx // pass referrer
900 PUSH ecx // pass arg2
901 PUSH eax // pass arg1
902 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
903 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700904 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100905 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700906 CALL_MACRO(return_macro) // return or deliver exception
907 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700908END_MACRO
909
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700910MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700911 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100912 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700913 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100914 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700915 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700916 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700917 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700918 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700919 PUSH ebx // pass referrer
920 PUSH edx // pass arg3
921 PUSH ecx // pass arg2
922 PUSH eax // pass arg1
923 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
924 // Thread*)
925 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700926 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100927 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700928 CALL_MACRO(return_macro) // return or deliver exception
929 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700930END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700931
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700932MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700933 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700934 jz 1f // if eax == 0 goto 1
935 ret // return
9361: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700937 DELIVER_PENDING_EXCEPTION
938END_MACRO
939
Ian Rogersd36c52e2012-04-09 16:29:25 -0700940MACRO0(RETURN_IF_EAX_ZERO)
941 testl %eax, %eax // eax == 0 ?
942 jnz 1f // if eax != 0 goto 1
943 ret // return
9441: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700945 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700946END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700947
jeffhaod66a8752012-05-22 15:30:16 -0700948MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700949 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700950 jne 1f // if exception field != 0 goto 1
951 ret // return
9521: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700953 DELIVER_PENDING_EXCEPTION
954END_MACRO
955
Mathieu Chartier7410f292013-11-24 13:17:35 -0800956// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700957GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800958
959// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
960DEFINE_FUNCTION art_quick_alloc_object_rosalloc
961 // Fast path rosalloc allocation.
962 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
963 // ebx, edx: free
964 PUSH edi
965 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
966 // Load the class (edx)
967 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
968 testl %edx, %edx // Check null class
969 jz .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800970
971 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
972 // Check if the thread local allocation
973 // stack has room
974 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
975 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
976 jae .Lart_quick_alloc_object_rosalloc_slow_path
977
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700978 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %edi // Load the object size (edi)
lwang85de95c872015-11-10 17:26:31 +0800979 // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700980 // local allocation. Also does the
981 // finalizable and initialization check.
lwang85de95c872015-11-10 17:26:31 +0800982 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
983 ja .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800984 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
985 // from object size.
lwang85de95c872015-11-10 17:26:31 +0800986 // Load thread local rosalloc run (ebx)
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700987 // Subtract __SIZEOF_POINTER__ to subtract
988 // one from edi as there is no 0 byte run
989 // and the size is already aligned.
990 movl (THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)(%ebx, %edi, __SIZEOF_POINTER__), %ebx
lwang85de95c872015-11-10 17:26:31 +0800991 // Load free_list head (edi),
992 // this will be the return value.
993 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
994 test %edi, %edi
995 jz .Lart_quick_alloc_object_rosalloc_slow_path
996 // Point of no slow path. Won't go to
997 // the slow path from here on. Ok to
998 // clobber eax and ecx.
999 movl %edi, %eax
1000 // Load the next pointer of the head
1001 // and update head of free list with
1002 // next pointer
1003 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
1004 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
1005 // Decrement size of free list by 1
1006 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
1007 // Store the class pointer in the
1008 // header. This also overwrites the
1009 // next pointer. The offsets are
1010 // asserted to match.
1011#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1012#error "Class pointer needs to overwrite next pointer."
1013#endif
1014 POISON_HEAP_REF edx
1015 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
1016 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1017 // Push the new object onto the thread
1018 // local allocation stack and
1019 // increment the thread local
1020 // allocation stack top.
1021 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
1022 movl %eax, (%edi)
1023 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
1024 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
1025 // No fence needed for x86.
1026 POP edi
1027 ret
1028.Lart_quick_alloc_object_rosalloc_slow_path:
1029 POP edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001030 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
lwang85de95c872015-11-10 17:26:31 +08001031 // Outgoing argument set up
1032 PUSH eax // alignment padding
1033 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1034 CFI_ADJUST_CFA_OFFSET(4)
1035 PUSH ecx
1036 PUSH eax
1037 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001038 addl LITERAL(16), %esp // pop arguments
lwang85de95c872015-11-10 17:26:31 +08001039 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001040 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
lwang85de95c872015-11-10 17:26:31 +08001041 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
1042END_FUNCTION art_quick_alloc_object_rosalloc
1043
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001044// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1045//
1046// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
1047MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001048 testl %edx, %edx // Check null class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001049 jz VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001050 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1051 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
1052 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001053 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %esi // Load the object size.
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001054 cmpl %edi, %esi // Check if it fits.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001055 ja VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001056 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
1057 // as allocated object.
1058 addl %eax, %esi // Add the object size.
1059 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001060 incl THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001061 // Store the class pointer in the header.
1062 // No fence needed for x86.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001063 POISON_HEAP_REF edx
1064 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
1065 POP edi
1066 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001067 ret // Fast path succeeded.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001068END_MACRO
1069
1070// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1071MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
1072 POP edi
1073 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001074 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001075 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001076 PUSH eax // alignment padding
1077 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001078 CFI_ADJUST_CFA_OFFSET(4)
1079 PUSH ecx
1080 PUSH eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001081 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001082 addl LITERAL(16), %esp
1083 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001084 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
1085 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001086END_MACRO
1087
1088// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1089DEFINE_FUNCTION art_quick_alloc_object_tlab
1090 // Fast path tlab allocation.
1091 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1092 // EBX, EDX: free.
1093#if defined(USE_READ_BARRIER)
1094 int3
1095 int3
1096#endif
1097 PUSH esi
1098 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001099 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001100 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001101 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001102 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1103 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1104.Lart_quick_alloc_object_tlab_slow_path:
1105 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1106END_FUNCTION art_quick_alloc_object_tlab
1107
1108// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1109DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1110 // Fast path region tlab allocation.
1111 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1112 // EBX, EDX: free.
1113#if !defined(USE_READ_BARRIER)
1114 int3
1115 int3
1116#endif
1117 PUSH esi
1118 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001119 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001120 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001121 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001122 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001123 // Read barrier for class load.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001124 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001125 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1126 // Null check so that we can load the lock word.
1127 testl %edx, %edx
1128 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1129 // Check the mark bit, if it is 1 return.
1130 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1131 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001132.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1133 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1134.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1135 // The read barrier slow path. Mark the class.
1136 PUSH eax
1137 PUSH ecx
1138 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001139 subl MACRO_LITERAL(8), %esp // Alignment padding
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001140 CFI_ADJUST_CFA_OFFSET(8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001141 PUSH edx // Pass the class as the first param.
1142 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001143 movl %eax, %edx
1144 addl MACRO_LITERAL(12), %esp
1145 CFI_ADJUST_CFA_OFFSET(-12)
1146 POP ecx
1147 POP eax
1148 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1149.Lart_quick_alloc_object_region_tlab_slow_path:
1150 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1151END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001152
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001153DEFINE_FUNCTION art_quick_resolve_string
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001154 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001155 // Outgoing argument set up
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001156 subl LITERAL(8), %esp // push padding
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001157 CFI_ADJUST_CFA_OFFSET(8)
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001158 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001159 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001160 PUSH eax // pass arg1
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001161 call SYMBOL(artResolveStringFromCode)
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001162 addl LITERAL(16), %esp // pop arguments
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001163 CFI_ADJUST_CFA_OFFSET(-16)
Nicolas Geoffrayfbc75db2016-11-10 15:30:47 +00001164 testl %eax, %eax // If result is null, deliver the OOME.
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001165 jz 1f
1166 CFI_REMEMBER_STATE
1167 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_EAX
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001168 ret
Vladimir Marko94ce9c22016-09-30 14:50:51 +01001169 CFI_RESTORE_STATE
1170 CFI_DEF_CFA(esp, FRAME_SIZE_SAVE_EVERYTHING) // workaround for clang bug: 31975598
11711:
1172 DELIVER_PENDING_EXCEPTION_FRAME_READY
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001173END_FUNCTION art_quick_resolve_string
1174
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001175ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1176ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1177ONE_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 -07001178
Ian Rogers832336b2014-10-08 15:35:22 -07001179TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001180
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001181DEFINE_FUNCTION art_quick_lock_object
1182 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001183 jz .Lslow_lock
1184.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001185 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001186 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001187 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001188 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001189 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the gc bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001190 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001191 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001192 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001193 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001194 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1195 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1196 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1197 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1198 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001199 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001200.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1201 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001202 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001203 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001204 movl %edx, %ecx // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001205 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the read barrier bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001206 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001207 test LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED), %ecx // overflowed if the first gc state bit is set.
Ian Rogers8016a122014-02-21 20:37:21 -08001208 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001209 movl %eax, %ecx // save obj to use eax for cmpxchg.
1210 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1211 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1212 // update lockword, cmpxchg necessary for read barrier bits.
1213 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1214 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001215 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001216.Llock_cmpxchg_fail:
1217 movl %ecx, %eax // restore eax
1218 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001219.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001220 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001221 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001222 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001223 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001224 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001225 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001226 PUSH eax // pass object
1227 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1228 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001229 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001230 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001231 RETURN_IF_EAX_ZERO
1232END_FUNCTION art_quick_lock_object
1233
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001234DEFINE_FUNCTION art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001235 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001236 // Outgoing argument set up
1237 subl LITERAL(8), %esp // alignment padding
1238 CFI_ADJUST_CFA_OFFSET(8)
1239 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1240 CFI_ADJUST_CFA_OFFSET(4)
1241 PUSH eax // pass object
1242 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1243 addl LITERAL(16), %esp // pop arguments
1244 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001245 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001246 RETURN_IF_EAX_ZERO
1247END_FUNCTION art_quick_lock_object_no_inline
1248
1249
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001250DEFINE_FUNCTION art_quick_unlock_object
1251 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001252 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001253.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001254 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001255 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001256 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001257 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001258 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001259 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001260 movl %ecx, %edx // copy the lock word to detect new count of 0.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001261 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %edx // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001262 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001263 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001264 // update lockword, cmpxchg necessary for read barrier bits.
1265 movl %eax, %edx // edx: obj
1266 movl %ecx, %eax // eax: old lock word.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001267 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED), %ecx // ecx: new lock word zero except original rb bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001268#ifndef USE_READ_BARRIER
1269 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1270#else
1271 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1272 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1273#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001274 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001275.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1276 // update lockword, cmpxchg necessary for read barrier bits.
1277 movl %eax, %edx // edx: obj
1278 movl %ecx, %eax // eax: old lock word.
1279 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1280#ifndef USE_READ_BARRIER
1281 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1282#else
1283 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1284 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1285#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001286 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001287.Lunlock_cmpxchg_fail: // edx: obj
1288 movl %edx, %eax // restore eax
1289 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001290.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001291 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001292 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001293 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001294 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001295 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001296 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001297 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001298 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001299 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001300 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001301 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001302 RETURN_IF_EAX_ZERO
1303END_FUNCTION art_quick_unlock_object
1304
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001305DEFINE_FUNCTION art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001306 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001307 // Outgoing argument set up
1308 subl LITERAL(8), %esp // alignment padding
1309 CFI_ADJUST_CFA_OFFSET(8)
1310 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1311 CFI_ADJUST_CFA_OFFSET(4)
1312 PUSH eax // pass object
1313 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1314 addl LITERAL(16), %esp // pop arguments
1315 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001316 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001317 RETURN_IF_EAX_ZERO
1318END_FUNCTION art_quick_unlock_object_no_inline
1319
Ian Rogers468532e2013-08-05 10:56:33 -07001320DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001321 PUSH eax // alignment padding
1322 PUSH ecx // pass arg2 - obj->klass
1323 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001324 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001325 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001326 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001327 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001328END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001329
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001330DEFINE_FUNCTION art_quick_check_instance_of
Andreas Gampe4360be22015-07-14 23:34:44 -07001331 PUSH eax // alignment padding
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001332 PUSH ecx // pass arg2 - checked class
1333 PUSH eax // pass arg1 - obj
1334 call SYMBOL(artInstanceOfFromCode) // (Object* obj, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001335 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001336 jz 1f // jump forward if not assignable
1337 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001338 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001339 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001340
Andreas Gampe4360be22015-07-14 23:34:44 -07001341 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070013421:
Andreas Gampe4360be22015-07-14 23:34:44 -07001343 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001344 POP ecx
1345 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001346 CFI_ADJUST_CFA_OFFSET(-4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001347 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001348 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001349 PUSH eax // alignment padding
1350 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001351 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001352 PUSH ecx // pass arg2
1353 PUSH eax // pass arg1
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001354 call SYMBOL(artThrowClassCastExceptionForObject) // (Object* src, Class* dest, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001355 UNREACHABLE
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001356END_FUNCTION art_quick_check_instance_of
Ian Rogersa9a82542013-10-04 11:17:26 -07001357
Man Cao1aee9002015-07-14 22:31:42 -07001358// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1359MACRO2(POP_REG_NE, reg, exclude_reg)
1360 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1361 addl MACRO_LITERAL(4), %esp
1362 CFI_ADJUST_CFA_OFFSET(-4)
1363 .else
1364 POP RAW_VAR(reg)
1365 .endif
1366END_MACRO
1367
1368 /*
1369 * Macro to insert read barrier, only used in art_quick_aput_obj.
1370 * obj_reg and dest_reg are registers, offset is a defined literal such as
1371 * MIRROR_OBJECT_CLASS_OFFSET.
1372 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1373 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1374 */
1375MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1376#ifdef USE_READ_BARRIER
1377 PUSH eax // save registers used in art_quick_aput_obj
1378 PUSH ebx
1379 PUSH edx
1380 PUSH ecx
1381 // Outgoing argument set up
1382 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1383 CFI_ADJUST_CFA_OFFSET(4)
1384 PUSH RAW_VAR(obj_reg) // pass obj_reg
1385 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1386 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1387 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1388 .ifnc RAW_VAR(dest_reg), eax
1389 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1390 .endif
1391 addl MACRO_LITERAL(12), %esp // pop arguments
1392 CFI_ADJUST_CFA_OFFSET(-12)
1393 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1394 POP_REG_NE edx, RAW_VAR(dest_reg)
1395 POP_REG_NE ebx, RAW_VAR(dest_reg)
1396 .ifc RAW_VAR(pop_eax), true
1397 POP_REG_NE eax, RAW_VAR(dest_reg)
1398 .endif
1399#else
1400 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1401 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1402#endif // USE_READ_BARRIER
1403END_MACRO
1404
Ian Rogersa9a82542013-10-04 11:17:26 -07001405 /*
1406 * Entry from managed code for array put operations of objects where the value being stored
1407 * needs to be checked for compatibility.
1408 * eax = array, ecx = index, edx = value
1409 */
1410DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1411 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001412 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1413 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001414END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1415
1416DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001417 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001418 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001419 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001420 mov %ecx, %eax
1421 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001422 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001423END_FUNCTION art_quick_aput_obj_with_bound_check
1424
1425DEFINE_FUNCTION art_quick_aput_obj
1426 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001427 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001428 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1429 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001430 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001431#if defined(USE_READ_BARRIER)
1432 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1433 cmpl %eax, %ebx
1434 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001435 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001436#elif defined(USE_HEAP_POISONING)
1437 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001438 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1439 UNPOISON_HEAP_REF eax
1440 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001441 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001442#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001443 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001444#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001445 jne .Lcheck_assignability
1446.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001447 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001448 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001449 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1450 shrl LITERAL(7), %eax
1451 movb %dl, (%edx, %eax)
1452 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001453.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001454 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001455 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001456.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001457 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001458 PUSH ecx
1459 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001460#if defined(USE_READ_BARRIER)
1461 subl LITERAL(4), %esp // alignment padding
1462 CFI_ADJUST_CFA_OFFSET(4)
1463 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1464 subl LITERAL(4), %esp // alignment padding
1465 CFI_ADJUST_CFA_OFFSET(4)
1466 PUSH eax // pass arg2 - type of the value to be stored
1467#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001468 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001469 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001470 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001471 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001472 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001473#else
Man Cao63069212015-08-21 15:51:39 -07001474 subl LITERAL(8), %esp // alignment padding
1475 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001476 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001477 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001478#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001479 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001480 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001481 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001482 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001483 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001484 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001485 POP edx
1486 POP ecx
1487 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001488 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001489 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001490 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1491 shrl LITERAL(7), %eax
1492 movb %dl, (%edx, %eax)
1493 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001494 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001495.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001496 POP edx
1497 POP ecx
1498 POP eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001499 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001500 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001501 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001502 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001503 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001504 PUSH edx // pass arg2 - value
1505 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001506 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001507 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001508END_FUNCTION art_quick_aput_obj
1509
Logan Chien8dbb7082013-01-25 20:31:17 +08001510DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001511 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001512 PUSH edx // pass arg3
1513 PUSH ecx // pass arg2
1514 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001515 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001516 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001517 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001518 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001519END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001520
Vladimir Marko952dbb12016-07-28 12:01:51 +01001521DEFINE_FUNCTION art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001522 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save everything for GC
Vladimir Marko952dbb12016-07-28 12:01:51 +01001523 // Outgoing argument set up
1524 subl MACRO_LITERAL(12), %esp // push padding
1525 CFI_ADJUST_CFA_OFFSET(12)
1526 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1527 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko603b7ca2016-08-04 16:46:51 +01001528 call SYMBOL(artTestSuspendFromCode) // (Thread*)
Vladimir Marko952dbb12016-07-28 12:01:51 +01001529 addl MACRO_LITERAL(16), %esp // pop arguments
1530 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001531 RESTORE_SAVE_EVERYTHING_FRAME // restore frame up to return address
Vladimir Marko952dbb12016-07-28 12:01:51 +01001532 ret // return
1533END_FUNCTION art_quick_test_suspend
Ian Rogers7caad772012-03-30 01:07:54 -07001534
Ian Rogers468532e2013-08-05 10:56:33 -07001535DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001536 subl LITERAL(12), %esp // alignment padding, room for argument
1537 CFI_ADJUST_CFA_OFFSET(12)
1538 movsd %xmm0, 0(%esp) // arg a
1539 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001540 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001541 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001542 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001543END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001544
Ian Rogers468532e2013-08-05 10:56:33 -07001545DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001546 subl LITERAL(12), %esp // alignment padding
1547 CFI_ADJUST_CFA_OFFSET(12)
1548 movss %xmm0, 0(%esp) // arg a
1549 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001550 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001551 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001552 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001553END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001554
Ian Rogers468532e2013-08-05 10:56:33 -07001555DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001556 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001557 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001558 PUSH ebx // pass arg4 b.hi
1559 PUSH edx // pass arg3 b.lo
1560 PUSH ecx // pass arg2 a.hi
1561 PUSH eax // pass arg1 a.lo
1562 call SYMBOL(artLdiv) // (jlong a, jlong b)
1563 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001564 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001565 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001566END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001567
Ian Rogersa9a82542013-10-04 11:17:26 -07001568DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001569 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001570 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001571 PUSH ebx // pass arg4 b.hi
1572 PUSH edx // pass arg3 b.lo
1573 PUSH ecx // pass arg2 a.hi
1574 PUSH eax // pass arg1 a.lo
1575 call SYMBOL(artLmod) // (jlong a, jlong b)
1576 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001577 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001578 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001579END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001580
Ian Rogers468532e2013-08-05 10:56:33 -07001581DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001582 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1583 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1584 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001585 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001586 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001587 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001588END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001589
Ian Rogers468532e2013-08-05 10:56:33 -07001590DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001591 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001592 xchg %edx, %ecx
1593 shld %cl,%eax,%edx
1594 shl %cl,%eax
1595 test LITERAL(32), %cl
1596 jz 1f
1597 mov %eax, %edx
1598 xor %eax, %eax
15991:
1600 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001601END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001602
Ian Rogers468532e2013-08-05 10:56:33 -07001603DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001604 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001605 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001606 shrd %cl,%edx,%eax
1607 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001608 test LITERAL(32),%cl
1609 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001610 mov %edx, %eax
1611 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070016121:
1613 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001614END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001615
Ian Rogers468532e2013-08-05 10:56:33 -07001616DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001617 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001618 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001619 shrd %cl,%edx,%eax
1620 shr %cl,%edx
1621 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001622 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001623 mov %edx, %eax
1624 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070016251:
1626 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001627END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001628
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001629ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1630ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1631ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1632ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1633ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1634ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1635ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001636
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001637TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1638TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1639TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1640TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1641TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1642TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1643TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001644
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001645TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1646TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1647TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1648TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001649
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001650THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1651THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1652THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1653THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1654
1655// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001656DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001657 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001658 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001659 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001660 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001661 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001662 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001663 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001664 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001665 pushl (FRAME_SIZE_SAVE_REFS_ONLY+12)(%esp) // pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001666 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001667 PUSH ebx // pass high half of new_val
1668 PUSH edx // pass low half of new_val
1669 PUSH ecx // pass object
1670 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001671 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001672 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001673 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001674 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001675 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001676END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001677
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001678// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1679// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001680DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001681 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1682 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001683 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001684 movd %xmm0, %ebx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001685 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001686 subl LITERAL(12), %esp // alignment padding
1687 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001688 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001689 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001690 PUSH ebx // pass high half of new_val
1691 PUSH edx // pass low half of new_val
1692 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001693 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001694 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001695 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001696 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001697 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001698 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001699END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001700
Logan Chien8dbb7082013-01-25 20:31:17 +08001701DEFINE_FUNCTION art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001702 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001703 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001704 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001705 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001706 PUSH ecx // pass receiver
1707 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001708 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001709 movd %eax, %xmm0 // place return value also into floating point return value
1710 movd %edx, %xmm1
1711 punpckldq %xmm1, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001712 addl LITERAL(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY), %esp
1713 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY))
1714 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001715 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001716END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001717
Jeff Hao88474b42013-10-23 16:24:40 -07001718 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001719 * Called to resolve an imt conflict.
1720 * eax is the conflict ArtMethod.
1721 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1722 *
1723 * Note that this stub writes to eax.
1724 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001725 */
1726DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001727 PUSH EDI
1728 movl 8(%esp), %edi // Load referrer
1729 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1730 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1731 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001732 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001733 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1734 popl %eax // Pop ImtConflictTable.
1735 CFI_ADJUST_CFA_OFFSET(-4)
1736.Limt_table_iterate:
1737 cmpl %edi, 0(%eax)
1738 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001739 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001740 // and jump to it.
1741 POP EDI
1742 movl __SIZEOF_POINTER__(%eax), %eax
1743 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1744.Limt_table_next_entry:
1745 // If the entry is null, the interface method is not in the ImtConflictTable.
1746 cmpl LITERAL(0), 0(%eax)
1747 jz .Lconflict_trampoline
1748 // Iterate over the entries of the ImtConflictTable.
1749 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1750 jmp .Limt_table_iterate
1751.Lconflict_trampoline:
1752 // Call the runtime stub to populate the ImtConflictTable and jump to the
1753 // resolved method.
1754 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001755 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001756END_FUNCTION art_quick_imt_conflict_trampoline
1757
Ian Rogers468532e2013-08-05 10:56:33 -07001758DEFINE_FUNCTION art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001759 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001760 movl %esp, %edi
1761 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001762 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001763 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001764 PUSH ecx // pass receiver
1765 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001766 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001767 movl %eax, %edi // remember code pointer in EDI
1768 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001769 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001770 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001771 jz 1f
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001772 RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070017731:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001774 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001775 DELIVER_PENDING_EXCEPTION
1776END_FUNCTION art_quick_resolution_trampoline
1777
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001778DEFINE_FUNCTION art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001779 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001780 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001781 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001782 subl LITERAL(5120), %esp
1783 // prepare for artQuickGenericJniTrampoline call
1784 // (Thread*, SP)
1785 // (esp) 4(esp) <= C calling convention
1786 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001787
1788 subl LITERAL(8), %esp // Padding for 16B alignment.
1789 pushl %ebp // Pass SP (to ArtMethod).
1790 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001791 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001792
Andreas Gampec200a4a2014-06-16 18:39:09 -07001793 // The C call will have registered the complete save-frame on success.
1794 // The result of the call is:
1795 // eax: pointer to native code, 0 on error.
1796 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001797
Andreas Gampec200a4a2014-06-16 18:39:09 -07001798 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001799 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001800 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001801
Andreas Gampec200a4a2014-06-16 18:39:09 -07001802 // Release part of the alloca.
1803 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001804
1805 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001806 // Native call.
1807 call *%eax
1808
Andreas Gampe779f8c92014-06-09 18:29:38 -07001809 // result sign extension is handled in C code
1810 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001811 // (Thread*, result, result_f)
1812 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001813 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001814
Andreas Gampe4360be22015-07-14 23:34:44 -07001815 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001816 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001817 pushl %edx // Pass int result.
1818 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001819 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001820 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001821
Andreas Gampe779f8c92014-06-09 18:29:38 -07001822 // Pending exceptions possible.
1823 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1824 testl %ebx, %ebx
1825 jnz .Lexception_in_native
1826
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001827 // Tear down the alloca.
1828 movl %ebp, %esp
1829 CFI_DEF_CFA_REGISTER(esp)
1830
1831
Andreas Gampe779f8c92014-06-09 18:29:38 -07001832 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001833 // Remove space for FPR args and EAX
1834 addl LITERAL(4 + 4 * 8), %esp
1835 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1836
Andreas Gampe779f8c92014-06-09 18:29:38 -07001837 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001838 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001839 CFI_ADJUST_CFA_OFFSET(-4)
1840 POP ebx
1841 POP ebp // Restore callee saves
1842 POP esi
1843 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001844 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001845 movd %eax, %xmm0
1846 movd %edx, %xmm1
1847 punpckldq %xmm1, %xmm0
1848 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001849.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001850 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1851 // Do a call to push a new save-all frame required by the runtime.
1852 call .Lexception_call
1853.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001854 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001855END_FUNCTION art_quick_generic_jni_trampoline
1856
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001857DEFINE_FUNCTION art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001858 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001859 mov %esp, %edx // remember SP
1860 PUSH eax // alignment padding
1861 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001862 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001863 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001864 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001865 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001866 addl LITERAL(16), %esp // pop arguments
1867 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001868
1869 // Return eax:edx in xmm0 also.
1870 movd %eax, %xmm0
1871 movd %edx, %xmm1
1872 punpckldq %xmm1, %xmm0
1873
1874 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1875 CFI_ADJUST_CFA_OFFSET(-48)
1876
Andreas Gampe4360be22015-07-14 23:34:44 -07001877 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001878 POP esi
1879 POP edi
1880
Ian Rogers7db619b2013-01-16 18:35:48 -08001881 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001882END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001883
jeffhao7e4fcb82013-01-10 18:11:08 -08001884 /*
1885 * Routine that intercepts method calls and returns.
1886 */
Ian Rogers468532e2013-08-05 10:56:33 -07001887DEFINE_FUNCTION art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001888 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001889 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001890 subl LITERAL(12), %esp // Align stack.
1891 CFI_ADJUST_CFA_OFFSET(12)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001892 pushl FRAME_SIZE_SAVE_REFS_AND_ARGS-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001893 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001894 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001895 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001896 PUSH ecx // Pass receiver.
1897 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001898 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001899 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001900 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001901 movl 60(%esp), %edi // Restore edi.
1902 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001903 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001904 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001905 movl %ebx, 64(%esp)
1906 movl 0(%esp), %eax // Restore eax.
1907 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1908 movsd 8(%esp), %xmm0
1909 movsd 16(%esp), %xmm1
1910 movsd 24(%esp), %xmm2
1911 movsd 32(%esp), %xmm3
1912
1913 // Restore GPRs.
1914 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001915 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001916 movl 48(%esp), %ebx // Restore ebx.
1917 movl 52(%esp), %ebp // Restore ebp.
1918 movl 56(%esp), %esi // Restore esi.
1919 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001920 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001921 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001922END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001923
Ian Rogers468532e2013-08-05 10:56:33 -07001924DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001925 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001926 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001927 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001928 mov %esp, %ecx // Remember SP
1929 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001930 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001931 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001932 PUSH edx // Save gpr return value.
1933 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001934 subl LITERAL(16), %esp // Align stack
1935 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001936 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001937 PUSH edx // Pass gpr return value.
1938 PUSH eax
1939 PUSH ecx // Pass SP.
1940 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001941 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001942 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001943 mov %eax, %ecx // Move returned link register.
1944 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001945 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001946 movl %edx, %ebx // Move returned link register for deopt
1947 // (ebx is pretending to be our LR).
1948 POP eax // Restore gpr return value.
1949 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001950 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001951 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001952 CFI_ADJUST_CFA_OFFSET(-8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001953 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001954 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001955 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001956 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001957END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001958
jeffhao7e4fcb82013-01-10 18:11:08 -08001959 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001960 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1961 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001962 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001963DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001964 PUSH ebx // Entry point for a jump. Fake that we were called.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001965 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001966 subl LITERAL(12), %esp // Align stack.
1967 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001968 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001969 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001970 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001971 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001972END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001973
jeffhao86e46712012-08-08 17:30:59 -07001974 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001975 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001976 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001977 */
1978DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001979 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Sebastien Hertz07474662015-08-25 15:12:33 +00001980 subl LITERAL(12), %esp // Align stack.
1981 CFI_ADJUST_CFA_OFFSET(12)
1982 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1983 CFI_ADJUST_CFA_OFFSET(4)
1984 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1985 UNREACHABLE
1986END_FUNCTION art_quick_deoptimize_from_compiled_code
1987
1988 /*
jeffhao86e46712012-08-08 17:30:59 -07001989 * String's compareTo.
1990 *
1991 * On entry:
1992 * eax: this string object (known non-null)
1993 * ecx: comp string object (known non-null)
1994 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001995DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001996 PUSH esi // push callee save reg
1997 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001998 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1999 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08002000 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
2001 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jessicahandojo4877b792016-09-08 19:49:13 -07002002#if (STRING_COMPRESSION_FEATURE)
2003 /* Differ cases */
2004 cmpl LITERAL(0), %edx
2005 jl .Lstring_compareto_this_is_compressed
2006 cmpl LITERAL(0), %ebx
2007 jl .Lstring_compareto_that_is_compressed
2008 jmp .Lstring_compareto_both_not_compressed
2009.Lstring_compareto_this_is_compressed:
2010 andl LITERAL(0x7FFFFFFF), %edx
2011 cmpl LITERAL(0), %ebx
2012 jl .Lstring_compareto_both_compressed
2013 /* If (this->IsCompressed() && that->IsCompressed() == false) */
2014 mov %edx, %eax
2015 subl %ebx, %eax
2016 mov %edx, %ecx
2017 cmovg %ebx, %ecx
2018 /* Going into loop to compare each character */
2019 jecxz .Lstring_compareto_keep_length // check loop counter (if 0, don't compare)
2020.Lstring_compareto_loop_comparison_this_compressed:
2021 movzbl (%esi), %edx // move *(this_cur_char) byte to long
2022 movzwl (%edi), %ebx // move *(that_cur_char) word to long
2023 addl LITERAL(1), %esi // ++this_cur_char (8-bit)
2024 addl LITERAL(2), %edi // ++that_cur_char (16-bit)
2025 subl %ebx, %edx
2026 loope .Lstring_compareto_loop_comparison_this_compressed
2027 cmovne %edx, %eax // return eax = *(this_cur_char) - *(that_cur_char)
2028 jmp .Lstring_compareto_return
2029.Lstring_compareto_that_is_compressed:
2030 andl LITERAL(0x7FFFFFFF), %ebx
2031 mov %edx, %eax
2032 subl %ebx, %eax
2033 mov %edx, %ecx
2034 cmovg %ebx, %ecx
2035 /* If (this->IsCompressed() == false && that->IsCompressed()) */
2036 jecxz .Lstring_compareto_keep_length // check loop counter, if 0, don't compare
2037.Lstring_compareto_loop_comparison_that_compressed:
2038 movzwl (%esi), %edx // move *(this_cur_char) word to long
2039 movzbl (%edi), %ebx // move *(that_cur_char) byte to long
2040 addl LITERAL(2), %esi // ++this_cur_char (16-bit)
2041 addl LITERAL(1), %edi // ++that_cur_char (8-bit)
2042 subl %ebx, %edx
2043 loope .Lstring_compareto_loop_comparison_that_compressed
2044 cmovne %edx, %eax
2045 jmp .Lstring_compareto_return // return eax = *(this_cur_char) - *(that_cur_char)
2046.Lstring_compareto_both_compressed:
2047 andl LITERAL(0x7FFFFFFF), %ebx
jeffhao86e46712012-08-08 17:30:59 -07002048 /* Calculate min length and count diff */
jessicahandojo4877b792016-09-08 19:49:13 -07002049 mov %edx, %ecx
2050 mov %edx, %eax
2051 subl %ebx, %eax
2052 cmovg %ebx, %ecx
2053 jecxz .Lstring_compareto_keep_length
2054 repe cmpsb
2055 je .Lstring_compareto_keep_length
2056 movzbl -1(%esi), %eax // get last compared char from this string (8-bit)
2057 movzbl -1(%edi), %ecx // get last compared char from comp string (8-bit)
2058 jmp .Lstring_compareto_count_difference
2059#endif // STRING_COMPRESSION_FEATURE
2060.Lstring_compareto_both_not_compressed:
2061 /* Calculate min length and count diff */
2062 mov %edx, %ecx
2063 mov %edx, %eax
2064 subl %ebx, %eax
2065 cmovg %ebx, %ecx
jeffhao86e46712012-08-08 17:30:59 -07002066 /*
2067 * At this point we have:
2068 * eax: value to return if first part of strings are equal
2069 * ecx: minimum among the lengths of the two strings
2070 * esi: pointer to this string data
2071 * edi: pointer to comp string data
2072 */
jessicahandojo4877b792016-09-08 19:49:13 -07002073 jecxz .Lstring_compareto_keep_length
2074 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
2075 je .Lstring_compareto_keep_length
2076 movzwl -2(%esi), %eax // get last compared char from this string (16-bit)
2077 movzwl -2(%edi), %ecx // get last compared char from comp string (16-bit)
2078.Lstring_compareto_count_difference:
2079 subl %ecx, %eax
2080.Lstring_compareto_keep_length:
2081.Lstring_compareto_return:
Ian Rogersaeeada42013-02-13 11:28:34 -08002082 POP edi // pop callee save reg
2083 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07002084 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08002085END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07002086
Dave Allison8ce6b902014-08-26 11:07:58 -07002087// Return from a nested signal:
2088// Entry:
2089// eax: address of jmp_buf in TLS
2090
2091DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002092 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07002093 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002094 PUSH ecx // second arg to longjmp (1)
2095 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07002096 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07002097 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07002098END_FUNCTION art_nested_signal_return
2099
Roland Levillain02b75802016-07-13 11:54:35 +01002100// Create a function `name` calling the ReadBarrier::Mark routine,
2101// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01002102// `reg`, saving and restoring all caller-save registers.
2103//
2104// If `reg` is different from `eax`, the generated function follows a
2105// non-standard runtime calling convention:
2106// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002107// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01002108// - register `reg` is used to return the result of this function
2109// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01002110// - EAX is treated like a normal (non-argument) caller-save register;
2111// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002112// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002113MACRO2(READ_BARRIER_MARK_REG, name, reg)
2114 DEFINE_FUNCTION VAR(name)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002115 // Null check so that we can load the lock word.
2116 test REG_VAR(reg), REG_VAR(reg)
2117 jz .Lret_rb_\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002118.Lnot_null_\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002119 // Check the mark bit, if it is 1 return.
2120 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg))
2121 jz .Lslow_rb_\name
2122 ret
2123.Lslow_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002124 PUSH eax
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002125 mov MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg)), %eax
2126 add LITERAL(LOCK_WORD_STATE_FORWARDING_ADDRESS_OVERFLOW), %eax
2127 // Jump if overflow, the only case where it overflows should be the forwarding address one.
2128 // Taken ~25% of the time.
2129 jnae .Lret_forwarding_address\name
2130
2131 // Save all potentially live caller-save core registers.
2132 mov 0(%esp), %eax
Roland Levillain4359e612016-07-20 11:32:19 +01002133 PUSH ecx
2134 PUSH edx
2135 PUSH ebx
2136 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
2137 // and create space for caller-save floating-point registers.
2138 subl MACRO_LITERAL(4 + 8 * 8), %esp
2139 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
2140 // Save all potentially live caller-save floating-point registers.
2141 movsd %xmm0, 0(%esp)
2142 movsd %xmm1, 8(%esp)
2143 movsd %xmm2, 16(%esp)
2144 movsd %xmm3, 24(%esp)
2145 movsd %xmm4, 32(%esp)
2146 movsd %xmm5, 40(%esp)
2147 movsd %xmm6, 48(%esp)
2148 movsd %xmm7, 56(%esp)
2149
2150 subl LITERAL(4), %esp // alignment padding
2151 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01002152 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
2153 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002154 .ifnc RAW_VAR(reg), eax
2155 movl %eax, REG_VAR(reg) // return result into `reg`
2156 .endif
2157 addl LITERAL(8), %esp // pop argument and remove padding
2158 CFI_ADJUST_CFA_OFFSET(-8)
2159
2160 // Restore floating-point registers.
2161 movsd 0(%esp), %xmm0
2162 movsd 8(%esp), %xmm1
2163 movsd 16(%esp), %xmm2
2164 movsd 24(%esp), %xmm3
2165 movsd 32(%esp), %xmm4
2166 movsd 40(%esp), %xmm5
2167 movsd 48(%esp), %xmm6
2168 movsd 56(%esp), %xmm7
2169 // Remove floating-point registers and padding.
2170 addl MACRO_LITERAL(8 * 8 + 4), %esp
2171 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
2172 // Restore core regs, except `reg`, as it is used to return the
2173 // result of this function (simply remove it from the stack instead).
2174 POP_REG_NE ebx, RAW_VAR(reg)
2175 POP_REG_NE edx, RAW_VAR(reg)
2176 POP_REG_NE ecx, RAW_VAR(reg)
2177 POP_REG_NE eax, RAW_VAR(reg)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002178.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002179 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002180.Lret_forwarding_address\name:
2181 // The overflow cleared the top bits.
2182 sall LITERAL(LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT), %eax
2183 mov %eax, REG_VAR(reg)
2184 POP_REG_NE eax, RAW_VAR(reg)
2185 ret
Roland Levillain02b75802016-07-13 11:54:35 +01002186 END_FUNCTION VAR(name)
2187END_MACRO
2188
Roland Levillain4359e612016-07-20 11:32:19 +01002189READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01002190READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
2191READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
2192READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
2193READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
2194// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
2195// cannot be used to pass arguments.
2196READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
2197READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00002198
Man Cao1aee9002015-07-14 22:31:42 -07002199DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00002200 PUSH edx // pass arg3 - offset
2201 PUSH ecx // pass arg2 - obj
2202 PUSH eax // pass arg1 - ref
2203 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
2204 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07002205 CFI_ADJUST_CFA_OFFSET(-12)
2206 ret
2207END_FUNCTION art_quick_read_barrier_slow
2208
Roland Levillain0d5a2812015-11-13 10:07:31 +00002209DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01002210 subl LITERAL(8), %esp // alignment padding
2211 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002212 PUSH eax // pass arg1 - root
2213 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002214 addl LITERAL(12), %esp // pop argument and remove padding
2215 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002216 ret
2217END_FUNCTION art_quick_read_barrier_for_root_slow
2218
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002219 /*
2220 * On stack replacement stub.
2221 * On entry:
2222 * [sp] = return address
2223 * [sp + 4] = stack to copy
2224 * [sp + 8] = size of stack
2225 * [sp + 12] = pc to call
2226 * [sp + 16] = JValue* result
2227 * [sp + 20] = shorty
2228 * [sp + 24] = thread
2229 */
2230DEFINE_FUNCTION art_quick_osr_stub
2231 // Save native callee saves.
2232 PUSH ebp
2233 PUSH ebx
2234 PUSH esi
2235 PUSH edi
2236 mov 4+16(%esp), %esi // ESI = argument array
2237 mov 8+16(%esp), %ecx // ECX = size of args
2238 mov 12+16(%esp), %ebx // EBX = pc to call
2239 mov %esp, %ebp // Save stack pointer
2240 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2241 PUSH ebp // Save old stack pointer
2242 subl LITERAL(12), %esp // Align stack
2243 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2244 call .Losr_entry
2245
2246 // Restore stack pointer.
2247 addl LITERAL(12), %esp
2248 POP ebp
2249 mov %ebp, %esp
2250
2251 // Restore callee saves.
2252 POP edi
2253 POP esi
2254 POP ebx
2255 POP ebp
2256 mov 16(%esp), %ecx // Get JValue result
2257 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2258 mov %edx, 4(%ecx) // Store the other half of the result
2259 mov 20(%esp), %edx // Get the shorty
2260 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2261 je .Losr_return_double_quick
2262 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2263 je .Losr_return_float_quick
2264 ret
2265.Losr_return_double_quick:
2266 movsd %xmm0, (%ecx) // Store the floating point result
2267 ret
2268.Losr_return_float_quick:
2269 movss %xmm0, (%ecx) // Store the floating point result
2270 ret
2271.Losr_entry:
2272 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2273 subl %ecx, %esp
2274 mov %esp, %edi // EDI = beginning of stack
2275 rep movsb // while (ecx--) { *edi++ = *esi++ }
2276 jmp *%ebx
2277END_FUNCTION art_quick_osr_stub
2278
Elliott Hughes787ec202012-03-29 17:14:15 -07002279 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002280UNIMPLEMENTED art_quick_memcmp16