blob: 93cb6656dc62903912bbd6bb416d6e989f908984 [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 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700229MACRO3(SETUP_SAVE_EVERYTHING_FRAME_EDI_ESI_SAVED, got_reg, temp_reg, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET)
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.
Mingyao Yang0a87a652017-04-12 13:43:15 -0700255 pushl \runtime_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 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700272MACRO3(SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED, got_reg, temp_reg, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET)
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100273 // 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
Mingyao Yang0a87a652017-04-12 13:43:15 -0700276 SETUP_SAVE_EVERYTHING_FRAME_EDI_ESI_SAVED RAW_VAR(got_reg), RAW_VAR(temp_reg), \runtime_method_offset
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100277END_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 */
Mingyao Yang0a87a652017-04-12 13:43:15 -0700283MACRO3(SETUP_SAVE_EVERYTHING_FRAME, got_reg, temp_reg, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000284 PUSH edi
Mingyao Yang0a87a652017-04-12 13:43:15 -0700285 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED RAW_VAR(got_reg), RAW_VAR(temp_reg), \runtime_method_offset
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000286END_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 *
Orion Hodsonac141392017-01-13 11:53:47 +0000471 * If unsuccessful, the helper will return null/null and there will be a 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
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000878 subl MACRO_LITERAL(8), %esp // alignment padding
879 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700880 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 eax // pass arg1
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000883 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700884 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700885 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100886 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700887 CALL_MACRO(return_macro) // return or deliver exception
888 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700889END_MACRO
890
891MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700892 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100893 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700894 // Outgoing argument set up
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000895 PUSH eax // alignment padding
Andreas Gampe4360be22015-07-14 23:34:44 -0700896 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700897 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700898 PUSH ecx // pass arg2
899 PUSH eax // pass arg1
900 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
901 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700902 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100903 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700904 CALL_MACRO(return_macro) // return or deliver exception
905 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700906END_MACRO
907
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700908MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700909 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100910 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700911 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700912 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700913 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700914 PUSH edx // pass arg3
915 PUSH ecx // pass arg2
916 PUSH eax // pass arg1
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000917 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
918 addl LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700919 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100920 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700921 CALL_MACRO(return_macro) // return or deliver exception
922 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700923END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700924
Vladimir Markoea4c1262017-02-06 19:59:33 +0000925// Macro for string and type resolution and initialization.
Mingyao Yang0a87a652017-04-12 13:43:15 -0700926MACRO3(ONE_ARG_SAVE_EVERYTHING_DOWNCALL, c_name, cxx_name, runtime_method_offset = RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET)
Vladimir Markoea4c1262017-02-06 19:59:33 +0000927 DEFINE_FUNCTION VAR(c_name)
Mingyao Yang0a87a652017-04-12 13:43:15 -0700928 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx, \runtime_method_offset // save ref containing registers for GC
Vladimir Markoea4c1262017-02-06 19:59:33 +0000929 // Outgoing argument set up
930 subl MACRO_LITERAL(8), %esp // push padding
931 CFI_ADJUST_CFA_OFFSET(8)
932 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
933 CFI_ADJUST_CFA_OFFSET(4)
934 PUSH eax // pass arg1
935 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
936 addl MACRO_LITERAL(16), %esp // pop arguments
937 CFI_ADJUST_CFA_OFFSET(-16)
938 testl %eax, %eax // If result is null, deliver the OOME.
939 jz 1f
940 CFI_REMEMBER_STATE
941 RESTORE_SAVE_EVERYTHING_FRAME_KEEP_EAX // restore frame up to return address
942 ret // return
943 CFI_RESTORE_STATE
944 CFI_DEF_CFA(esp, FRAME_SIZE_SAVE_EVERYTHING) // workaround for clang bug: 31975598
9451:
946 DELIVER_PENDING_EXCEPTION_FRAME_READY
947 END_FUNCTION VAR(c_name)
948END_MACRO
949
Mingyao Yang0a87a652017-04-12 13:43:15 -0700950MACRO2(ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT, c_name, cxx_name)
951 ONE_ARG_SAVE_EVERYTHING_DOWNCALL \c_name, \cxx_name, RUNTIME_SAVE_EVERYTHING_FOR_CLINIT_METHOD_OFFSET
952END_MACRO
953
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700954MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700955 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700956 jz 1f // if eax == 0 goto 1
957 ret // return
9581: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700959 DELIVER_PENDING_EXCEPTION
960END_MACRO
961
Ian Rogersd36c52e2012-04-09 16:29:25 -0700962MACRO0(RETURN_IF_EAX_ZERO)
963 testl %eax, %eax // eax == 0 ?
964 jnz 1f // if eax != 0 goto 1
965 ret // return
9661: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700967 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700968END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700969
jeffhaod66a8752012-05-22 15:30:16 -0700970MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700971 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700972 jne 1f // if exception field != 0 goto 1
973 ret // return
9741: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700975 DELIVER_PENDING_EXCEPTION
976END_MACRO
977
Mathieu Chartier7410f292013-11-24 13:17:35 -0800978// Generate the allocation entrypoints for each allocator.
Nicolas Geoffrayd0958442017-01-30 14:57:16 +0000979GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_TLAB_ALLOCATORS
980
981// Comment out allocators that have x86 specific asm.
982// Region TLAB:
983// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
984// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
985GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
986// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
987// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_region_tlab, RegionTLAB)
988// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_region_tlab, RegionTLAB)
989// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_region_tlab, RegionTLAB)
990// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_region_tlab, RegionTLAB)
991GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
992GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
993GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
994// Normal TLAB:
995// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB)
996// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB)
997GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB)
998// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB)
999// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED8(_tlab, TLAB)
1000// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED16(_tlab, TLAB)
1001// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED32(_tlab, TLAB)
1002// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED64(_tlab, TLAB)
1003GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_tlab, TLAB)
1004GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_tlab, TLAB)
1005GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_tlab, TLAB)
lwang85de95c872015-11-10 17:26:31 +08001006
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001007// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc, RosAlloc).
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001008MACRO2(ART_QUICK_ALLOC_OBJECT_ROSALLOC, c_name, cxx_name)
1009 DEFINE_FUNCTION VAR(c_name)
lwang85de95c872015-11-10 17:26:31 +08001010 // Fast path rosalloc allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001011 // eax: type/return value
1012 // ecx, ebx, edx: free
lwang85de95c872015-11-10 17:26:31 +08001013 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1014 // Check if the thread local allocation
1015 // stack has room
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001016 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %ecx
1017 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %ecx
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001018 jae .Lslow_path\c_name
lwang85de95c872015-11-10 17:26:31 +08001019
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001020 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%eax), %ecx // Load the object size (ecx)
lwang85de95c872015-11-10 17:26:31 +08001021 // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001022 // local allocation. Also does the
1023 // finalizable and initialization check.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001024 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %ecx
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001025 ja .Lslow_path\c_name
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001026 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %ecx // Calculate the rosalloc bracket index
lwang85de95c872015-11-10 17:26:31 +08001027 // from object size.
lwang85de95c872015-11-10 17:26:31 +08001028 // Load thread local rosalloc run (ebx)
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001029 // Subtract __SIZEOF_POINTER__ to subtract
1030 // one from edi as there is no 0 byte run
1031 // and the size is already aligned.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001032 movl (THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)(%ebx, %ecx, __SIZEOF_POINTER__), %ebx
lwang85de95c872015-11-10 17:26:31 +08001033 // Load free_list head (edi),
1034 // this will be the return value.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001035 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %ecx
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001036 jecxz .Lslow_path\c_name
lwang85de95c872015-11-10 17:26:31 +08001037 // Point of no slow path. Won't go to
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001038 // the slow path from here on.
lwang85de95c872015-11-10 17:26:31 +08001039 // Load the next pointer of the head
1040 // and update head of free list with
1041 // next pointer
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001042 movl ROSALLOC_SLOT_NEXT_OFFSET(%ecx), %edx
1043 movl %edx, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
lwang85de95c872015-11-10 17:26:31 +08001044 // Decrement size of free list by 1
1045 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
1046 // Store the class pointer in the
1047 // header. This also overwrites the
1048 // next pointer. The offsets are
1049 // asserted to match.
1050#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1051#error "Class pointer needs to overwrite next pointer."
1052#endif
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001053 POISON_HEAP_REF eax
1054 movl %eax, MIRROR_OBJECT_CLASS_OFFSET(%ecx)
lwang85de95c872015-11-10 17:26:31 +08001055 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1056 // Push the new object onto the thread
1057 // local allocation stack and
1058 // increment the thread local
1059 // allocation stack top.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001060 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %eax
1061 movl %ecx, (%eax)
1062 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %eax
1063 movl %eax, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
lwang85de95c872015-11-10 17:26:31 +08001064 // No fence needed for x86.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001065 movl %ecx, %eax // Move object to return register
lwang85de95c872015-11-10 17:26:31 +08001066 ret
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001067.Lslow_path\c_name:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001068 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
lwang85de95c872015-11-10 17:26:31 +08001069 // Outgoing argument set up
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001070 subl LITERAL(8), %esp // alignment padding
lwang85de95c872015-11-10 17:26:31 +08001071 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1072 CFI_ADJUST_CFA_OFFSET(4)
lwang85de95c872015-11-10 17:26:31 +08001073 PUSH eax
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001074 call SYMBOL(artAllocObjectFromCodeResolvedRosAlloc) // cxx_name(arg0, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001075 addl LITERAL(16), %esp // pop arguments
lwang85de95c872015-11-10 17:26:31 +08001076 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001077 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
lwang85de95c872015-11-10 17:26:31 +08001078 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001079 END_FUNCTION VAR(c_name)
1080END_MACRO
lwang85de95c872015-11-10 17:26:31 +08001081
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001082ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_resolved_rosalloc, artAllocObjectFromCodeResolvedRosAlloc
1083ART_QUICK_ALLOC_OBJECT_ROSALLOC art_quick_alloc_object_initialized_rosalloc, artAllocObjectFromCodeInitializedRosAlloc
1084
1085// The common fast path code for art_quick_alloc_object_resolved/initialized_tlab
1086// and art_quick_alloc_object_resolved/initialized_region_tlab.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001087//
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001088// EAX: type/return_value
1089MACRO1(ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH, slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001090 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1091 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
1092 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001093 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%eax), %ecx // Load the object size.
1094 cmpl %edi, %ecx // Check if it fits.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001095 ja VAR(slowPathLabel)
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001096 movl THREAD_LOCAL_POS_OFFSET(%ebx), %edx // Load thread_local_pos
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001097 // as allocated object.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001098 addl %edx, %ecx // Add the object size.
1099 movl %ecx, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001100 incl THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001101 // Store the class pointer in the header.
1102 // No fence needed for x86.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001103 POISON_HEAP_REF eax
1104 movl %eax, MIRROR_OBJECT_CLASS_OFFSET(%edx)
1105 movl %edx, %eax
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001106 POP edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001107 ret // Fast path succeeded.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001108END_MACRO
1109
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001110// The common slow path code for art_quick_alloc_object_resolved/initialized_tlab
1111// and art_quick_alloc_object_resolved/initialized_region_tlab.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001112MACRO1(ALLOC_OBJECT_RESOLVED_TLAB_SLOW_PATH, cxx_name)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001113 POP edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001114 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001115 // Outgoing argument set up
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001116 subl LITERAL(8), %esp // alignment padding
1117 CFI_ADJUST_CFA_OFFSET(8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001118 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001119 CFI_ADJUST_CFA_OFFSET(4)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001120 PUSH eax
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001121 call CALLVAR(cxx_name) // cxx_name(arg0, Thread*)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001122 addl LITERAL(16), %esp
1123 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001124 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
1125 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001126END_MACRO
1127
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001128MACRO2(ART_QUICK_ALLOC_OBJECT_TLAB, c_name, cxx_name)
1129 DEFINE_FUNCTION VAR(c_name)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001130 // Fast path tlab allocation.
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001131 // EAX: type
1132 // EBX, ECX, EDX: free.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001133 PUSH edi
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001134 ALLOC_OBJECT_RESOLVED_TLAB_FAST_PATH .Lslow_path\c_name
1135.Lslow_path\c_name:
1136 ALLOC_OBJECT_RESOLVED_TLAB_SLOW_PATH RAW_VAR(cxx_name)
1137 END_FUNCTION VAR(c_name)
1138END_MACRO
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001139
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001140ART_QUICK_ALLOC_OBJECT_TLAB art_quick_alloc_object_resolved_tlab, artAllocObjectFromCodeResolvedTLAB
1141ART_QUICK_ALLOC_OBJECT_TLAB art_quick_alloc_object_initialized_tlab, artAllocObjectFromCodeInitializedTLAB
1142ART_QUICK_ALLOC_OBJECT_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB
1143ART_QUICK_ALLOC_OBJECT_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB
1144
1145// The fast path code for art_quick_alloc_array_region_tlab.
1146// Inputs: EAX: the class, ECX: int32_t component_count, EDX: total_size
1147// Free temp: EBX
1148// Output: EAX: return value.
1149MACRO1(ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE, slowPathLabel)
1150 mov %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1151 // Mask out the unaligned part to make sure we are 8 byte aligned.
1152 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %edx
1153 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi
1154 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi
1155 cmpl %edi, %edx // Check if it fits.
1156 ja RAW_VAR(slowPathLabel)
1157 movl THREAD_LOCAL_POS_OFFSET(%ebx), %edi
1158 addl %edi, %edx // Add the object size.
1159 movl %edx, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos_
1160 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
1161 // Store the class pointer in the
1162 // header.
1163 // No fence needed for x86.
1164 POISON_HEAP_REF eax
1165 movl %eax, MIRROR_OBJECT_CLASS_OFFSET(%edi)
1166 movl %ecx, MIRROR_ARRAY_LENGTH_OFFSET(%edi)
1167 movl %edi, %eax
1168 POP edi
1169 ret // Fast path succeeded.
1170END_MACRO
1171
1172MACRO1(COMPUTE_ARRAY_SIZE_UNKNOWN, slow_path)
1173 // We should never enter here. Code is provided for reference.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001174 int3
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001175 // Possibly a large object, go slow.
1176 // Also does negative array size check.
1177 cmpl LITERAL((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_WIDE_ARRAY_DATA_OFFSET) / 8), %ecx
1178 ja RAW_VAR(slow_path)
1179 PUSH ecx
1180 movl %ecx, %edx
1181 movl MIRROR_CLASS_COMPONENT_TYPE_OFFSET(%eax), %ecx // Load component type.
1182 UNPOISON_HEAP_REF ecx
1183 movl MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET(%ecx), %ecx // Load primitive type.
1184 shr MACRO_LITERAL(PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT), %ecx // Get component size shift.
1185 sall %cl, %edx // Calculate array count shifted.
1186 // Add array header + alignment rounding.
1187 add MACRO_LITERAL(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK), %edx
1188 // Add 4 extra bytes if we are doing a long array.
1189 add MACRO_LITERAL(1), %ecx
1190 and MACRO_LITERAL(4), %ecx
1191#if MIRROR_WIDE_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1192#error Long array data offset must be 4 greater than int array data offset.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001193#endif
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001194 addl %ecx, %edx
1195 POP ecx
1196END_MACRO
Nicolas Geoffray0d3998b2017-01-12 15:35:12 +00001197
Nicolas Geoffrayd0958442017-01-30 14:57:16 +00001198MACRO1(COMPUTE_ARRAY_SIZE_8, slow_path)
1199 // EAX: mirror::Class* klass, ECX: int32_t component_count
1200 // Possibly a large object, go slow.
1201 // Also does negative array size check.
1202 cmpl LITERAL(MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET), %ecx
1203 ja RAW_VAR(slow_path)
1204 // Add array header + alignment rounding.
1205 leal (MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)(%ecx), %edx
1206END_MACRO
1207
1208MACRO1(COMPUTE_ARRAY_SIZE_16, slow_path)
1209 // EAX: mirror::Class* klass, ECX: int32_t component_count
1210 // Possibly a large object, go slow.
1211 // Also does negative array size check.
1212 cmpl LITERAL((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 2), %ecx
1213 ja RAW_VAR(slow_path)
1214 // Add array header + alignment rounding.
1215 leal ((MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK) / 2)(%ecx), %edx
1216 sall MACRO_LITERAL(1), %edx
1217END_MACRO
1218
1219MACRO1(COMPUTE_ARRAY_SIZE_32, slow_path)
1220 // EAX: mirror::Class* klass, ECX: int32_t component_count
1221 // Possibly a large object, go slow.
1222 // Also does negative array size check.
1223 cmpl LITERAL((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_INT_ARRAY_DATA_OFFSET) / 4), %ecx
1224 ja RAW_VAR(slow_path)
1225 // Add array header + alignment rounding.
1226 leal ((MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK) / 4)(%ecx), %edx
1227 sall MACRO_LITERAL(2), %edx
1228END_MACRO
1229
1230MACRO1(COMPUTE_ARRAY_SIZE_64, slow_path)
1231 // EAX: mirror::Class* klass, ECX: int32_t component_count
1232 // Possibly a large object, go slow.
1233 // Also does negative array size check.
1234 cmpl LITERAL((MIN_LARGE_OBJECT_THRESHOLD - MIRROR_WIDE_ARRAY_DATA_OFFSET) / 8), %ecx
1235 ja RAW_VAR(slow_path)
1236 // Add array header + alignment rounding.
1237 leal ((MIRROR_WIDE_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK) / 8)(%ecx), %edx
1238 sall MACRO_LITERAL(3), %edx
1239END_MACRO
1240
1241MACRO3(GENERATE_ALLOC_ARRAY_TLAB, c_entrypoint, cxx_name, size_setup)
1242 DEFINE_FUNCTION VAR(c_entrypoint)
1243 // EAX: mirror::Class* klass, ECX: int32_t component_count
1244 PUSH edi
1245 CALL_MACRO(size_setup) .Lslow_path\c_entrypoint
1246 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED_WITH_SIZE .Lslow_path\c_entrypoint
1247.Lslow_path\c_entrypoint:
1248 POP edi
1249 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
1250 // Outgoing argument set up
1251 PUSH eax // alignment padding
1252 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1253 CFI_ADJUST_CFA_OFFSET(4)
1254 PUSH ecx
1255 PUSH eax
1256 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
1257 addl LITERAL(16), %esp // pop arguments
1258 CFI_ADJUST_CFA_OFFSET(-16)
1259 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
1260 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
1261 END_FUNCTION VAR(c_entrypoint)
1262END_MACRO
1263
1264
1265GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1266GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_8
1267GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_16
1268GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_32
1269GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, COMPUTE_ARRAY_SIZE_64
1270
1271GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_UNKNOWN
1272GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved8_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_8
1273GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved16_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_16
1274GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved32_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_32
1275GENERATE_ALLOC_ARRAY_TLAB art_quick_alloc_array_resolved64_tlab, artAllocArrayFromCodeResolvedTLAB, COMPUTE_ARRAY_SIZE_64
Mark Mendell3f2d0312014-01-20 17:20:27 -08001276
Mingyao Yang0a87a652017-04-12 13:43:15 -07001277ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_static_storage, artInitializeStaticStorageFromCode
1278ONE_ARG_SAVE_EVERYTHING_DOWNCALL_FOR_CLINIT art_quick_initialize_type, artInitializeTypeFromCode
Vladimir Markoea4c1262017-02-06 19:59:33 +00001279ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode
1280ONE_ARG_SAVE_EVERYTHING_DOWNCALL art_quick_resolve_string, artResolveStringFromCode
Ian Rogersd36c52e2012-04-09 16:29:25 -07001281
Ian Rogers832336b2014-10-08 15:35:22 -07001282TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001283
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001284DEFINE_FUNCTION art_quick_lock_object
1285 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001286 jz .Lslow_lock
1287.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001288 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001289 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001290 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001291 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001292 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the gc bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001293 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001294 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001295 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001296 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001297 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1298 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1299 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1300 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1301 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001302 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001303.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1304 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001305 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001306 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001307 movl %edx, %ecx // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001308 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the read barrier bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001309 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001310 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 -08001311 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001312 movl %eax, %ecx // save obj to use eax for cmpxchg.
1313 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1314 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1315 // update lockword, cmpxchg necessary for read barrier bits.
1316 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1317 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001318 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001319.Llock_cmpxchg_fail:
1320 movl %ecx, %eax // restore eax
1321 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001322.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001323 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001324 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001325 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001326 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001327 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001328 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001329 PUSH eax // pass object
1330 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1331 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001332 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001333 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001334 RETURN_IF_EAX_ZERO
1335END_FUNCTION art_quick_lock_object
1336
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001337DEFINE_FUNCTION art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001338 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001339 // Outgoing argument set up
1340 subl LITERAL(8), %esp // alignment padding
1341 CFI_ADJUST_CFA_OFFSET(8)
1342 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1343 CFI_ADJUST_CFA_OFFSET(4)
1344 PUSH eax // pass object
1345 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1346 addl LITERAL(16), %esp // pop arguments
1347 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001348 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001349 RETURN_IF_EAX_ZERO
1350END_FUNCTION art_quick_lock_object_no_inline
1351
1352
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001353DEFINE_FUNCTION art_quick_unlock_object
1354 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001355 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001356.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001357 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001358 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001359 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001360 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001361 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001362 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001363 movl %ecx, %edx // copy the lock word to detect new count of 0.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001364 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %edx // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001365 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001366 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001367 // update lockword, cmpxchg necessary for read barrier bits.
1368 movl %eax, %edx // edx: obj
1369 movl %ecx, %eax // eax: old lock word.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001370 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 -08001371#ifndef USE_READ_BARRIER
1372 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1373#else
1374 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1375 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1376#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001377 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001378.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1379 // update lockword, cmpxchg necessary for read barrier bits.
1380 movl %eax, %edx // edx: obj
1381 movl %ecx, %eax // eax: old lock word.
1382 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1383#ifndef USE_READ_BARRIER
1384 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1385#else
1386 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1387 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1388#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001389 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001390.Lunlock_cmpxchg_fail: // edx: obj
1391 movl %edx, %eax // restore eax
1392 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001393.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001394 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001395 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001396 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001397 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001398 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001399 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001400 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001401 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001402 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001403 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001404 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001405 RETURN_IF_EAX_ZERO
1406END_FUNCTION art_quick_unlock_object
1407
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001408DEFINE_FUNCTION art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001409 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001410 // Outgoing argument set up
1411 subl LITERAL(8), %esp // alignment padding
1412 CFI_ADJUST_CFA_OFFSET(8)
1413 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1414 CFI_ADJUST_CFA_OFFSET(4)
1415 PUSH eax // pass object
1416 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1417 addl LITERAL(16), %esp // pop arguments
1418 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001419 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001420 RETURN_IF_EAX_ZERO
1421END_FUNCTION art_quick_unlock_object_no_inline
1422
Mathieu Chartier9fd8c602016-11-14 14:38:53 -08001423DEFINE_FUNCTION art_quick_instance_of
Andreas Gampe4360be22015-07-14 23:34:44 -07001424 PUSH eax // alignment padding
1425 PUSH ecx // pass arg2 - obj->klass
1426 PUSH eax // pass arg1 - checked class
Mathieu Chartier9fd8c602016-11-14 14:38:53 -08001427 call SYMBOL(artInstanceOfFromCode) // (Object* obj, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001428 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001429 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001430 ret
Mathieu Chartier9fd8c602016-11-14 14:38:53 -08001431END_FUNCTION art_quick_instance_of
Ian Rogers7caad772012-03-30 01:07:54 -07001432
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001433DEFINE_FUNCTION art_quick_check_instance_of
Andreas Gampe4360be22015-07-14 23:34:44 -07001434 PUSH eax // alignment padding
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001435 PUSH ecx // pass arg2 - checked class
1436 PUSH eax // pass arg1 - obj
1437 call SYMBOL(artInstanceOfFromCode) // (Object* obj, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001438 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001439 jz 1f // jump forward if not assignable
1440 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001441 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001442 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001443
Andreas Gampe4360be22015-07-14 23:34:44 -07001444 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070014451:
Andreas Gampe4360be22015-07-14 23:34:44 -07001446 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001447 POP ecx
1448 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001449 CFI_ADJUST_CFA_OFFSET(-4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001450 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001451 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001452 PUSH eax // alignment padding
1453 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001454 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001455 PUSH ecx // pass arg2
1456 PUSH eax // pass arg1
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001457 call SYMBOL(artThrowClassCastExceptionForObject) // (Object* src, Class* dest, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001458 UNREACHABLE
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08001459END_FUNCTION art_quick_check_instance_of
Ian Rogersa9a82542013-10-04 11:17:26 -07001460
Man Cao1aee9002015-07-14 22:31:42 -07001461// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1462MACRO2(POP_REG_NE, reg, exclude_reg)
1463 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1464 addl MACRO_LITERAL(4), %esp
1465 CFI_ADJUST_CFA_OFFSET(-4)
1466 .else
1467 POP RAW_VAR(reg)
1468 .endif
1469END_MACRO
1470
1471 /*
1472 * Macro to insert read barrier, only used in art_quick_aput_obj.
1473 * obj_reg and dest_reg are registers, offset is a defined literal such as
1474 * MIRROR_OBJECT_CLASS_OFFSET.
1475 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1476 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1477 */
1478MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1479#ifdef USE_READ_BARRIER
1480 PUSH eax // save registers used in art_quick_aput_obj
1481 PUSH ebx
1482 PUSH edx
1483 PUSH ecx
1484 // Outgoing argument set up
1485 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1486 CFI_ADJUST_CFA_OFFSET(4)
1487 PUSH RAW_VAR(obj_reg) // pass obj_reg
1488 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1489 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1490 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1491 .ifnc RAW_VAR(dest_reg), eax
1492 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1493 .endif
1494 addl MACRO_LITERAL(12), %esp // pop arguments
1495 CFI_ADJUST_CFA_OFFSET(-12)
1496 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1497 POP_REG_NE edx, RAW_VAR(dest_reg)
1498 POP_REG_NE ebx, RAW_VAR(dest_reg)
1499 .ifc RAW_VAR(pop_eax), true
1500 POP_REG_NE eax, RAW_VAR(dest_reg)
1501 .endif
1502#else
1503 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1504 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1505#endif // USE_READ_BARRIER
1506END_MACRO
1507
Ian Rogersa9a82542013-10-04 11:17:26 -07001508DEFINE_FUNCTION art_quick_aput_obj
1509 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001510 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001511 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1512 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001513 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001514#if defined(USE_READ_BARRIER)
1515 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1516 cmpl %eax, %ebx
1517 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001518 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001519#elif defined(USE_HEAP_POISONING)
1520 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001521 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1522 UNPOISON_HEAP_REF eax
1523 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001524 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001525#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001526 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001527#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001528 jne .Lcheck_assignability
1529.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001530 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001531 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001532 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001533 shrl LITERAL(CARD_TABLE_CARD_SHIFT), %eax
Ian Rogersa9a82542013-10-04 11:17:26 -07001534 movb %dl, (%edx, %eax)
1535 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001536.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001537 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001538 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001539.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001540 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001541 PUSH ecx
1542 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001543#if defined(USE_READ_BARRIER)
1544 subl LITERAL(4), %esp // alignment padding
1545 CFI_ADJUST_CFA_OFFSET(4)
1546 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1547 subl LITERAL(4), %esp // alignment padding
1548 CFI_ADJUST_CFA_OFFSET(4)
1549 PUSH eax // pass arg2 - type of the value to be stored
1550#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001551 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001552 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001553 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001554 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001555 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001556#else
Man Cao63069212015-08-21 15:51:39 -07001557 subl LITERAL(8), %esp // alignment padding
1558 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001559 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001560 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001561#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001562 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001563 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001564 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001565 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001566 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001567 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001568 POP edx
1569 POP ecx
1570 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001571 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001572 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001573 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
Mathieu Chartierafdcbcb2017-04-26 16:43:35 -07001574 shrl LITERAL(CARD_TABLE_CARD_SHIFT), %eax
Ian Rogersa9a82542013-10-04 11:17:26 -07001575 movb %dl, (%edx, %eax)
1576 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001577 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001578.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001579 POP edx
1580 POP ecx
1581 POP eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001582 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001583 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001584 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001585 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001586 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001587 PUSH edx // pass arg2 - value
1588 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001589 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001590 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001591END_FUNCTION art_quick_aput_obj
1592
Logan Chien8dbb7082013-01-25 20:31:17 +08001593DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001594 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001595 PUSH edx // pass arg3
1596 PUSH ecx // pass arg2
1597 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001598 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001599 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001600 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001601 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001602END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001603
Vladimir Marko952dbb12016-07-28 12:01:51 +01001604DEFINE_FUNCTION art_quick_test_suspend
Mingyao Yang0a87a652017-04-12 13:43:15 -07001605 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx, RUNTIME_SAVE_EVERYTHING_FOR_SUSPEND_CHECK_METHOD_OFFSET // save everything for GC
Vladimir Marko952dbb12016-07-28 12:01:51 +01001606 // Outgoing argument set up
1607 subl MACRO_LITERAL(12), %esp // push padding
1608 CFI_ADJUST_CFA_OFFSET(12)
1609 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1610 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko603b7ca2016-08-04 16:46:51 +01001611 call SYMBOL(artTestSuspendFromCode) // (Thread*)
Vladimir Marko952dbb12016-07-28 12:01:51 +01001612 addl MACRO_LITERAL(16), %esp // pop arguments
1613 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001614 RESTORE_SAVE_EVERYTHING_FRAME // restore frame up to return address
Vladimir Marko952dbb12016-07-28 12:01:51 +01001615 ret // return
1616END_FUNCTION art_quick_test_suspend
Ian Rogers7caad772012-03-30 01:07:54 -07001617
Ian Rogers468532e2013-08-05 10:56:33 -07001618DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001619 subl LITERAL(12), %esp // alignment padding, room for argument
1620 CFI_ADJUST_CFA_OFFSET(12)
1621 movsd %xmm0, 0(%esp) // arg a
1622 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001623 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001624 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001625 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001626END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001627
Ian Rogers468532e2013-08-05 10:56:33 -07001628DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001629 subl LITERAL(12), %esp // alignment padding
1630 CFI_ADJUST_CFA_OFFSET(12)
1631 movss %xmm0, 0(%esp) // arg a
1632 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001633 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001634 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001635 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001636END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001637
Ian Rogers468532e2013-08-05 10:56:33 -07001638DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001639 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001640 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001641 PUSH ebx // pass arg4 b.hi
1642 PUSH edx // pass arg3 b.lo
1643 PUSH ecx // pass arg2 a.hi
1644 PUSH eax // pass arg1 a.lo
1645 call SYMBOL(artLdiv) // (jlong a, jlong b)
1646 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001647 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001648 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001649END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001650
Ian Rogersa9a82542013-10-04 11:17:26 -07001651DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001652 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001653 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001654 PUSH ebx // pass arg4 b.hi
1655 PUSH edx // pass arg3 b.lo
1656 PUSH ecx // pass arg2 a.hi
1657 PUSH eax // pass arg1 a.lo
1658 call SYMBOL(artLmod) // (jlong a, jlong b)
1659 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001660 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001661 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001662END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001663
Ian Rogers468532e2013-08-05 10:56:33 -07001664DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001665 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1666 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1667 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001668 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001669 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001670 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001671END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001672
Ian Rogers468532e2013-08-05 10:56:33 -07001673DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001674 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001675 xchg %edx, %ecx
1676 shld %cl,%eax,%edx
1677 shl %cl,%eax
1678 test LITERAL(32), %cl
1679 jz 1f
1680 mov %eax, %edx
1681 xor %eax, %eax
16821:
1683 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001684END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001685
Ian Rogers468532e2013-08-05 10:56:33 -07001686DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001687 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001688 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001689 shrd %cl,%edx,%eax
1690 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001691 test LITERAL(32),%cl
1692 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001693 mov %edx, %eax
1694 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070016951:
1696 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001697END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001698
Ian Rogers468532e2013-08-05 10:56:33 -07001699DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001700 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001701 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001702 shrd %cl,%edx,%eax
1703 shr %cl,%edx
1704 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001705 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001706 mov %edx, %eax
1707 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070017081:
1709 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001710END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001711
Roland Levillain809f5b12018-01-04 14:05:59 +00001712// Note: Functions `art{Get,Set}<Kind>{Static,Instance}FromCompiledCode` are
1713// defined with a macro in runtime/entrypoints/quick/quick_field_entrypoints.cc.
1714
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001715ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1716ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1717ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1718ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1719ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1720ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1721ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001722
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001723TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1724TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1725TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1726TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1727TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1728TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1729TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCompiledCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001730
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001731TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCompiledCode, RETURN_IF_EAX_ZERO
1732TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCompiledCode, RETURN_IF_EAX_ZERO
1733TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCompiledCode, RETURN_IF_EAX_ZERO
1734TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCompiledCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001735
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001736THREE_ARG_REF_DOWNCALL art_quick_set64_static, artSet64StaticFromCompiledCode, RETURN_IF_EAX_ZERO
1737THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCompiledCode, RETURN_IF_EAX_ZERO
1738THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCompiledCode, RETURN_IF_EAX_ZERO
1739THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCompiledCode, RETURN_IF_EAX_ZERO
1740THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCompiledCode, RETURN_IF_EAX_ZERO
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001741
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +00001742// Call artSet64InstanceFromCode with 4 word size arguments.
Ian Rogers468532e2013-08-05 10:56:33 -07001743DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001744 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001745 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001746 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001747 // Outgoing argument set up
Nicolas Geoffray79da1382017-01-26 16:24:32 +00001748 subl LITERAL(12), %esp // alignment padding
1749 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001750 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001751 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001752 PUSH ebx // pass high half of new_val
1753 PUSH edx // pass low half of new_val
1754 PUSH ecx // pass object
1755 PUSH eax // pass field_idx
Nicolas Geoffray6ebb7cc2017-01-26 15:18:52 +00001756 call SYMBOL(artSet64InstanceFromCompiledCode) // (field_idx, Object*, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001757 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001758 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001759 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001760 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001761END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001762
Logan Chien8dbb7082013-01-25 20:31:17 +08001763DEFINE_FUNCTION art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001764 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001765 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001766 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001767 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001768 PUSH ecx // pass receiver
1769 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001770 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001771 movd %eax, %xmm0 // place return value also into floating point return value
1772 movd %edx, %xmm1
1773 punpckldq %xmm1, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001774 addl LITERAL(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY), %esp
1775 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY))
1776 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001777 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001778END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001779
Jeff Hao88474b42013-10-23 16:24:40 -07001780 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001781 * Called to resolve an imt conflict.
1782 * eax is the conflict ArtMethod.
1783 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1784 *
1785 * Note that this stub writes to eax.
1786 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001787 */
1788DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001789 PUSH EDI
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001790 PUSH ESI
1791 PUSH EDX
1792 movl 16(%esp), %edi // Load referrer.
Vladimir Marko5122e6b2017-08-17 16:10:09 +01001793 // If the method is obsolete, just go through the dex cache miss slow path.
1794 // The obsolete flag is set with suspended threads, so we do not need an acquire operation here.
1795 testl LITERAL(ACC_OBSOLETE_METHOD), ART_METHOD_ACCESS_FLAGS_OFFSET(%edi)
1796 jnz .Limt_conflict_trampoline_dex_cache_miss
1797 movl ART_METHOD_DECLARING_CLASS_OFFSET(%edi), %edi // Load declaring class (no read barrier).
1798 movl MIRROR_CLASS_DEX_CACHE_OFFSET(%edi), %edi // Load the DexCache (without read barrier).
1799 UNPOISON_HEAP_REF edi
1800 movl MIRROR_DEX_CACHE_RESOLVED_METHODS_OFFSET(%edi), %edi // Load the resolved methods.
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001801 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1802 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001803 movd %xmm7, %eax // Get target method index stored in xmm7.
1804 movl %eax, %esi // Remember method index in ESI.
1805 andl LITERAL(METHOD_DEX_CACHE_SIZE_MINUS_ONE), %eax // Calculate DexCache method slot index.
1806 leal 0(%edi, %eax, 2 * __SIZEOF_POINTER__), %edi // Load DexCache method slot address.
1807 mov %ecx, %edx // Make EDX:EAX == ECX:EBX so that LOCK CMPXCHG8B makes no changes.
1808 mov %ebx, %eax // (The actual value does not matter.)
1809 lock cmpxchg8b (%edi) // Relaxed atomic load EDX:EAX from the dex cache slot.
1810 popl %edi // Pop ImtConflictTable.
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001811 CFI_ADJUST_CFA_OFFSET(-4)
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001812 cmp %edx, %esi // Compare method index to see if we had a DexCache method hit.
1813 jne .Limt_conflict_trampoline_dex_cache_miss
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001814.Limt_table_iterate:
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001815 cmpl %eax, 0(%edi)
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001816 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001817 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001818 // and jump to it.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001819 movl __SIZEOF_POINTER__(%edi), %eax
1820 CFI_REMEMBER_STATE
1821 POP EDX
1822 POP ESI
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001823 POP EDI
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001824 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001825 CFI_RESTORE_STATE
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001826.Limt_table_next_entry:
1827 // If the entry is null, the interface method is not in the ImtConflictTable.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001828 cmpl LITERAL(0), 0(%edi)
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001829 jz .Lconflict_trampoline
1830 // Iterate over the entries of the ImtConflictTable.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001831 addl LITERAL(2 * __SIZEOF_POINTER__), %edi
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001832 jmp .Limt_table_iterate
1833.Lconflict_trampoline:
1834 // Call the runtime stub to populate the ImtConflictTable and jump to the
1835 // resolved method.
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001836 CFI_REMEMBER_STATE
1837 POP EDX
1838 POP ESI
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001839 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001840 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Vladimir Marko07bfbac2017-07-06 14:55:02 +01001841 CFI_RESTORE_STATE
1842.Limt_conflict_trampoline_dex_cache_miss:
1843 // We're not creating a proper runtime method frame here,
1844 // artLookupResolvedMethod() is not allowed to walk the stack.
1845
1846 // Save core register args; EDX is already saved.
1847 PUSH ebx
1848 PUSH ecx
1849
1850 // Save FPR args.
1851 subl MACRO_LITERAL(32), %esp
1852 CFI_ADJUST_CFA_OFFSET(32)
1853 movsd %xmm0, 0(%esp)
1854 movsd %xmm1, 8(%esp)
1855 movsd %xmm2, 16(%esp)
1856 movsd %xmm3, 24(%esp)
1857
1858 pushl 32+8+16(%esp) // Pass referrer.
1859 CFI_ADJUST_CFA_OFFSET(4)
1860 pushl %esi // Pass method index.
1861 CFI_ADJUST_CFA_OFFSET(4)
1862 call SYMBOL(artLookupResolvedMethod) // (uint32_t method_index, ArtMethod* referrer)
1863 addl LITERAL(8), %esp // Pop arguments.
1864 CFI_ADJUST_CFA_OFFSET(-8)
1865
1866 // Restore FPR args.
1867 movsd 0(%esp), %xmm0
1868 movsd 8(%esp), %xmm1
1869 movsd 16(%esp), %xmm2
1870 movsd 24(%esp), %xmm3
1871 addl MACRO_LITERAL(32), %esp
1872 CFI_ADJUST_CFA_OFFSET(-32)
1873
1874 // Restore core register args.
1875 POP ecx
1876 POP ebx
1877
1878 cmp LITERAL(0), %eax // If the method wasn't resolved,
1879 je .Lconflict_trampoline // skip the lookup and go to artInvokeInterfaceTrampoline().
1880 jmp .Limt_table_iterate
Jeff Hao88474b42013-10-23 16:24:40 -07001881END_FUNCTION art_quick_imt_conflict_trampoline
1882
Ian Rogers468532e2013-08-05 10:56:33 -07001883DEFINE_FUNCTION art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001884 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001885 movl %esp, %edi
1886 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001887 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001888 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001889 PUSH ecx // pass receiver
1890 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001891 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001892 movl %eax, %edi // remember code pointer in EDI
1893 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001894 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001895 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001896 jz 1f
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001897 RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070018981:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001899 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001900 DELIVER_PENDING_EXCEPTION
1901END_FUNCTION art_quick_resolution_trampoline
1902
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001903DEFINE_FUNCTION art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001904 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001905 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001906 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001907 subl LITERAL(5120), %esp
1908 // prepare for artQuickGenericJniTrampoline call
1909 // (Thread*, SP)
1910 // (esp) 4(esp) <= C calling convention
1911 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001912
1913 subl LITERAL(8), %esp // Padding for 16B alignment.
1914 pushl %ebp // Pass SP (to ArtMethod).
1915 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001916 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001917
Andreas Gampec200a4a2014-06-16 18:39:09 -07001918 // The C call will have registered the complete save-frame on success.
1919 // The result of the call is:
1920 // eax: pointer to native code, 0 on error.
1921 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001922
Andreas Gampec200a4a2014-06-16 18:39:09 -07001923 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001924 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001925 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001926
Andreas Gampec200a4a2014-06-16 18:39:09 -07001927 // Release part of the alloca.
1928 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001929
1930 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001931 // Native call.
1932 call *%eax
1933
Andreas Gampe779f8c92014-06-09 18:29:38 -07001934 // result sign extension is handled in C code
1935 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001936 // (Thread*, result, result_f)
1937 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001938 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001939
Andreas Gampe4360be22015-07-14 23:34:44 -07001940 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001941 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001942 pushl %edx // Pass int result.
1943 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001944 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001945 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001946
Andreas Gampe779f8c92014-06-09 18:29:38 -07001947 // Pending exceptions possible.
1948 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1949 testl %ebx, %ebx
1950 jnz .Lexception_in_native
1951
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001952 // Tear down the alloca.
1953 movl %ebp, %esp
1954 CFI_DEF_CFA_REGISTER(esp)
1955
1956
Andreas Gampe779f8c92014-06-09 18:29:38 -07001957 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001958 // Remove space for FPR args and EAX
1959 addl LITERAL(4 + 4 * 8), %esp
1960 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1961
Andreas Gampe779f8c92014-06-09 18:29:38 -07001962 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001963 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001964 CFI_ADJUST_CFA_OFFSET(-4)
1965 POP ebx
1966 POP ebp // Restore callee saves
1967 POP esi
1968 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001969 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001970 movd %eax, %xmm0
1971 movd %edx, %xmm1
1972 punpckldq %xmm1, %xmm0
1973 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001974.Lexception_in_native:
Vladimir Marko2196c652017-11-30 16:16:07 +00001975 pushl %fs:THREAD_TOP_QUICK_FRAME_OFFSET
1976 addl LITERAL(-1), (%esp) // Remove the GenericJNI tag.
1977 movl (%esp), %esp
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001978 // Do a call to push a new save-all frame required by the runtime.
1979 call .Lexception_call
1980.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001981 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001982END_FUNCTION art_quick_generic_jni_trampoline
1983
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001984DEFINE_FUNCTION art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001985 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001986 mov %esp, %edx // remember SP
1987 PUSH eax // alignment padding
1988 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001989 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001990 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001991 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001992 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001993 addl LITERAL(16), %esp // pop arguments
1994 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001995
1996 // Return eax:edx in xmm0 also.
1997 movd %eax, %xmm0
1998 movd %edx, %xmm1
1999 punpckldq %xmm1, %xmm0
2000
2001 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
2002 CFI_ADJUST_CFA_OFFSET(-48)
2003
Andreas Gampe4360be22015-07-14 23:34:44 -07002004 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00002005 POP esi
2006 POP edi
2007
Ian Rogers7db619b2013-01-16 18:35:48 -08002008 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07002009END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08002010
jeffhao7e4fcb82013-01-10 18:11:08 -08002011 /*
Alex Lightdb01a092017-04-03 15:39:55 -07002012 * Called by managed code, saves callee saves and then calls artInvokeObsoleteMethod
2013 */
2014ONE_ARG_RUNTIME_EXCEPTION art_invoke_obsolete_method_stub, artInvokeObsoleteMethod
2015
2016 /*
jeffhao7e4fcb82013-01-10 18:11:08 -08002017 * Routine that intercepts method calls and returns.
2018 */
Ian Rogers468532e2013-08-05 10:56:33 -07002019DEFINE_FUNCTION art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002020 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08002021 PUSH eax // Save eax which will be clobbered by the callee-save method.
Alex Lightb7edcda2017-04-27 13:20:31 -07002022 subl LITERAL(16), %esp // Align stack (12 bytes) and reserve space for the SP argument
2023 CFI_ADJUST_CFA_OFFSET(16) // (4 bytes). We lack the scratch registers to calculate the SP
2024 // right now, so we will just fill it in later.
Ian Rogers62d6c772013-02-27 08:32:07 -08002025 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08002026 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08002027 PUSH ecx // Pass receiver.
2028 PUSH eax // Pass Method*.
Alex Lightb7edcda2017-04-27 13:20:31 -07002029 leal 32(%esp), %eax // Put original SP into eax
2030 movl %eax, 12(%esp) // set SP
2031 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP)
2032
Elliott Hughes7ac7e322014-06-27 17:20:59 -07002033 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002034 CFI_ADJUST_CFA_OFFSET(-28)
Alex Lightb7edcda2017-04-27 13:20:31 -07002035
2036 testl %eax, %eax
2037 jz 1f // Test for null return (indicating exception) and handle it.
2038
Mark P Mendell966c3ae2015-01-27 15:45:27 +00002039 movl 60(%esp), %edi // Restore edi.
2040 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07002041 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002042 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00002043 movl %ebx, 64(%esp)
2044 movl 0(%esp), %eax // Restore eax.
2045 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
2046 movsd 8(%esp), %xmm0
2047 movsd 16(%esp), %xmm1
2048 movsd 24(%esp), %xmm2
2049 movsd 32(%esp), %xmm3
2050
2051 // Restore GPRs.
2052 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01002053 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00002054 movl 48(%esp), %ebx // Restore ebx.
2055 movl 52(%esp), %ebp // Restore ebp.
2056 movl 56(%esp), %esi // Restore esi.
2057 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002058 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08002059 ret // Call method (and pop).
Alex Lightb7edcda2017-04-27 13:20:31 -070020601:
2061 // Make caller handle exception
2062 addl LITERAL(4), %esp
2063 CFI_ADJUST_CFA_OFFSET(-4)
2064 RESTORE_SAVE_REFS_AND_ARGS_FRAME
2065 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07002066END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08002067
Vladimir Marko98778552017-06-12 14:04:52 +01002068DEFINE_FUNCTION_CUSTOM_CFA art_quick_instrumentation_exit, 0
Ian Rogers62d6c772013-02-27 08:32:07 -08002069 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002070 CFI_ADJUST_CFA_OFFSET(4)
Mingyao Yang2ee17902017-08-30 11:37:08 -07002071 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
2072
2073 movl %esp, %ecx // Remember SP
2074 subl LITERAL(8), %esp // Align stack.
Mark Mendell3f2d0312014-01-20 17:20:27 -08002075 CFI_ADJUST_CFA_OFFSET(8)
Mingyao Yang2ee17902017-08-30 11:37:08 -07002076 PUSH edx // Save gpr return value. edx and eax need to be together,
2077 // which isn't the case in kSaveEverything frame.
Ian Rogers62d6c772013-02-27 08:32:07 -08002078 PUSH eax
Mingyao Yang2ee17902017-08-30 11:37:08 -07002079 leal 32(%esp), %eax // Get pointer to fpr_result, in kSaveEverything frame
Alex Lightb7edcda2017-04-27 13:20:31 -07002080 movl %esp, %edx // Get pointer to gpr_result
2081 PUSH eax // Pass fpr_result
2082 PUSH edx // Pass gpr_result
Mingyao Yang2ee17902017-08-30 11:37:08 -07002083 PUSH ecx // Pass SP
Ian Rogers62d6c772013-02-27 08:32:07 -08002084 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08002085 CFI_ADJUST_CFA_OFFSET(4)
Mingyao Yang2ee17902017-08-30 11:37:08 -07002086
Alex Lightb7edcda2017-04-27 13:20:31 -07002087 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result*, fpr_result*)
Mingyao Yang2ee17902017-08-30 11:37:08 -07002088 // Return result could have been changed if it's a reference.
2089 movl 16(%esp), %ecx
2090 movl %ecx, (80+32)(%esp)
2091 addl LITERAL(32), %esp // Pop arguments and grp_result.
Nicolas Geoffray07c70282017-08-30 08:09:42 +00002092 CFI_ADJUST_CFA_OFFSET(-32)
Mingyao Yang2ee17902017-08-30 11:37:08 -07002093
2094 testl %eax, %eax // Check if we returned error.
2095 jz .Ldo_deliver_instrumentation_exception
2096 testl %edx, %edx
2097 jnz .Ldeoptimize
2098 // Normal return.
2099 movl %eax, FRAME_SIZE_SAVE_EVERYTHING-4(%esp) // Set return pc.
2100 RESTORE_SAVE_EVERYTHING_FRAME
2101 ret
2102.Ldeoptimize:
2103 mov %edx, (FRAME_SIZE_SAVE_EVERYTHING-4)(%esp) // Set return pc.
2104 RESTORE_SAVE_EVERYTHING_FRAME
2105 jmp SYMBOL(art_quick_deoptimize)
2106.Ldo_deliver_instrumentation_exception:
2107 DELIVER_PENDING_EXCEPTION_FRAME_READY
Ian Rogers468532e2013-08-05 10:56:33 -07002108END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08002109
jeffhao7e4fcb82013-01-10 18:11:08 -08002110 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08002111 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2112 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08002113 */
Logan Chien8dbb7082013-01-25 20:31:17 +08002114DEFINE_FUNCTION art_quick_deoptimize
Mingyao Yang2ee17902017-08-30 11:37:08 -07002115 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002116 subl LITERAL(12), %esp // Align stack.
2117 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08002118 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08002119 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002120 call SYMBOL(artDeoptimize) // (Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07002121 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08002122END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08002123
jeffhao86e46712012-08-08 17:30:59 -07002124 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00002125 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07002126 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00002127 */
2128DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002129 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002130 subl LITERAL(8), %esp // Align stack.
2131 CFI_ADJUST_CFA_OFFSET(8)
Sebastien Hertz07474662015-08-25 15:12:33 +00002132 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
2133 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +01002134 PUSH eax
2135 call SYMBOL(artDeoptimizeFromCompiledCode) // (DeoptimizationKind, Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002136 UNREACHABLE
2137END_FUNCTION art_quick_deoptimize_from_compiled_code
2138
2139 /*
jeffhao86e46712012-08-08 17:30:59 -07002140 * String's compareTo.
2141 *
2142 * On entry:
2143 * eax: this string object (known non-null)
2144 * ecx: comp string object (known non-null)
2145 */
Logan Chien8dbb7082013-01-25 20:31:17 +08002146DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07002147 PUSH esi // push callee save reg
2148 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002149 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
2150 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08002151 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
2152 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jessicahandojo4877b792016-09-08 19:49:13 -07002153#if (STRING_COMPRESSION_FEATURE)
2154 /* Differ cases */
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002155 shrl LITERAL(1), %edx
2156 jnc .Lstring_compareto_this_is_compressed
2157 shrl LITERAL(1), %ebx
2158 jnc .Lstring_compareto_that_is_compressed
jessicahandojo4877b792016-09-08 19:49:13 -07002159 jmp .Lstring_compareto_both_not_compressed
2160.Lstring_compareto_this_is_compressed:
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002161 shrl LITERAL(1), %ebx
2162 jnc .Lstring_compareto_both_compressed
jessicahandojo4877b792016-09-08 19:49:13 -07002163 /* If (this->IsCompressed() && that->IsCompressed() == false) */
2164 mov %edx, %eax
2165 subl %ebx, %eax
2166 mov %edx, %ecx
2167 cmovg %ebx, %ecx
2168 /* Going into loop to compare each character */
2169 jecxz .Lstring_compareto_keep_length // check loop counter (if 0, don't compare)
2170.Lstring_compareto_loop_comparison_this_compressed:
2171 movzbl (%esi), %edx // move *(this_cur_char) byte to long
2172 movzwl (%edi), %ebx // move *(that_cur_char) word to long
2173 addl LITERAL(1), %esi // ++this_cur_char (8-bit)
2174 addl LITERAL(2), %edi // ++that_cur_char (16-bit)
2175 subl %ebx, %edx
2176 loope .Lstring_compareto_loop_comparison_this_compressed
2177 cmovne %edx, %eax // return eax = *(this_cur_char) - *(that_cur_char)
2178 jmp .Lstring_compareto_return
2179.Lstring_compareto_that_is_compressed:
jessicahandojo4877b792016-09-08 19:49:13 -07002180 mov %edx, %eax
2181 subl %ebx, %eax
2182 mov %edx, %ecx
2183 cmovg %ebx, %ecx
2184 /* If (this->IsCompressed() == false && that->IsCompressed()) */
2185 jecxz .Lstring_compareto_keep_length // check loop counter, if 0, don't compare
2186.Lstring_compareto_loop_comparison_that_compressed:
2187 movzwl (%esi), %edx // move *(this_cur_char) word to long
2188 movzbl (%edi), %ebx // move *(that_cur_char) byte to long
2189 addl LITERAL(2), %esi // ++this_cur_char (16-bit)
2190 addl LITERAL(1), %edi // ++that_cur_char (8-bit)
2191 subl %ebx, %edx
2192 loope .Lstring_compareto_loop_comparison_that_compressed
2193 cmovne %edx, %eax
2194 jmp .Lstring_compareto_return // return eax = *(this_cur_char) - *(that_cur_char)
2195.Lstring_compareto_both_compressed:
jeffhao86e46712012-08-08 17:30:59 -07002196 /* Calculate min length and count diff */
jessicahandojo4877b792016-09-08 19:49:13 -07002197 mov %edx, %ecx
2198 mov %edx, %eax
2199 subl %ebx, %eax
2200 cmovg %ebx, %ecx
2201 jecxz .Lstring_compareto_keep_length
2202 repe cmpsb
2203 je .Lstring_compareto_keep_length
2204 movzbl -1(%esi), %eax // get last compared char from this string (8-bit)
2205 movzbl -1(%edi), %ecx // get last compared char from comp string (8-bit)
2206 jmp .Lstring_compareto_count_difference
2207#endif // STRING_COMPRESSION_FEATURE
2208.Lstring_compareto_both_not_compressed:
2209 /* Calculate min length and count diff */
2210 mov %edx, %ecx
2211 mov %edx, %eax
2212 subl %ebx, %eax
2213 cmovg %ebx, %ecx
jeffhao86e46712012-08-08 17:30:59 -07002214 /*
2215 * At this point we have:
2216 * eax: value to return if first part of strings are equal
2217 * ecx: minimum among the lengths of the two strings
2218 * esi: pointer to this string data
2219 * edi: pointer to comp string data
2220 */
jessicahandojo4877b792016-09-08 19:49:13 -07002221 jecxz .Lstring_compareto_keep_length
2222 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
2223 je .Lstring_compareto_keep_length
2224 movzwl -2(%esi), %eax // get last compared char from this string (16-bit)
2225 movzwl -2(%edi), %ecx // get last compared char from comp string (16-bit)
2226.Lstring_compareto_count_difference:
2227 subl %ecx, %eax
2228.Lstring_compareto_keep_length:
2229.Lstring_compareto_return:
Ian Rogersaeeada42013-02-13 11:28:34 -08002230 POP edi // pop callee save reg
2231 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07002232 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08002233END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07002234
Roland Levillain02b75802016-07-13 11:54:35 +01002235// Create a function `name` calling the ReadBarrier::Mark routine,
2236// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01002237// `reg`, saving and restoring all caller-save registers.
2238//
2239// If `reg` is different from `eax`, the generated function follows a
2240// non-standard runtime calling convention:
2241// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002242// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01002243// - register `reg` is used to return the result of this function
2244// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01002245// - EAX is treated like a normal (non-argument) caller-save register;
2246// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002247// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002248MACRO2(READ_BARRIER_MARK_REG, name, reg)
2249 DEFINE_FUNCTION VAR(name)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002250 // Null check so that we can load the lock word.
2251 test REG_VAR(reg), REG_VAR(reg)
2252 jz .Lret_rb_\name
Vladimir Marko94ce9c22016-09-30 14:50:51 +01002253.Lnot_null_\name:
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002254 // Check the mark bit, if it is 1 return.
2255 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg))
2256 jz .Lslow_rb_\name
2257 ret
2258.Lslow_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002259 PUSH eax
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002260 mov MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg)), %eax
2261 add LITERAL(LOCK_WORD_STATE_FORWARDING_ADDRESS_OVERFLOW), %eax
2262 // Jump if overflow, the only case where it overflows should be the forwarding address one.
2263 // Taken ~25% of the time.
2264 jnae .Lret_forwarding_address\name
2265
2266 // Save all potentially live caller-save core registers.
2267 mov 0(%esp), %eax
Roland Levillain4359e612016-07-20 11:32:19 +01002268 PUSH ecx
2269 PUSH edx
2270 PUSH ebx
2271 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
2272 // and create space for caller-save floating-point registers.
2273 subl MACRO_LITERAL(4 + 8 * 8), %esp
2274 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
2275 // Save all potentially live caller-save floating-point registers.
2276 movsd %xmm0, 0(%esp)
2277 movsd %xmm1, 8(%esp)
2278 movsd %xmm2, 16(%esp)
2279 movsd %xmm3, 24(%esp)
2280 movsd %xmm4, 32(%esp)
2281 movsd %xmm5, 40(%esp)
2282 movsd %xmm6, 48(%esp)
2283 movsd %xmm7, 56(%esp)
2284
2285 subl LITERAL(4), %esp // alignment padding
2286 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01002287 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
2288 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002289 .ifnc RAW_VAR(reg), eax
2290 movl %eax, REG_VAR(reg) // return result into `reg`
2291 .endif
2292 addl LITERAL(8), %esp // pop argument and remove padding
2293 CFI_ADJUST_CFA_OFFSET(-8)
2294
2295 // Restore floating-point registers.
2296 movsd 0(%esp), %xmm0
2297 movsd 8(%esp), %xmm1
2298 movsd 16(%esp), %xmm2
2299 movsd 24(%esp), %xmm3
2300 movsd 32(%esp), %xmm4
2301 movsd 40(%esp), %xmm5
2302 movsd 48(%esp), %xmm6
2303 movsd 56(%esp), %xmm7
2304 // Remove floating-point registers and padding.
2305 addl MACRO_LITERAL(8 * 8 + 4), %esp
2306 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
2307 // Restore core regs, except `reg`, as it is used to return the
2308 // result of this function (simply remove it from the stack instead).
2309 POP_REG_NE ebx, RAW_VAR(reg)
2310 POP_REG_NE edx, RAW_VAR(reg)
2311 POP_REG_NE ecx, RAW_VAR(reg)
2312 POP_REG_NE eax, RAW_VAR(reg)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002313.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002314 ret
Mathieu Chartier6f198e32016-11-03 11:15:04 -07002315.Lret_forwarding_address\name:
2316 // The overflow cleared the top bits.
2317 sall LITERAL(LOCK_WORD_STATE_FORWARDING_ADDRESS_SHIFT), %eax
2318 mov %eax, REG_VAR(reg)
2319 POP_REG_NE eax, RAW_VAR(reg)
2320 ret
Roland Levillain02b75802016-07-13 11:54:35 +01002321 END_FUNCTION VAR(name)
2322END_MACRO
2323
Roland Levillain4359e612016-07-20 11:32:19 +01002324READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01002325READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
2326READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
2327READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
2328READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
2329// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
2330// cannot be used to pass arguments.
2331READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
2332READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00002333
Man Cao1aee9002015-07-14 22:31:42 -07002334DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00002335 PUSH edx // pass arg3 - offset
2336 PUSH ecx // pass arg2 - obj
2337 PUSH eax // pass arg1 - ref
2338 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
2339 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07002340 CFI_ADJUST_CFA_OFFSET(-12)
2341 ret
2342END_FUNCTION art_quick_read_barrier_slow
2343
Roland Levillain0d5a2812015-11-13 10:07:31 +00002344DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01002345 subl LITERAL(8), %esp // alignment padding
2346 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002347 PUSH eax // pass arg1 - root
2348 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002349 addl LITERAL(12), %esp // pop argument and remove padding
2350 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002351 ret
2352END_FUNCTION art_quick_read_barrier_for_root_slow
2353
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002354 /*
2355 * On stack replacement stub.
2356 * On entry:
2357 * [sp] = return address
2358 * [sp + 4] = stack to copy
2359 * [sp + 8] = size of stack
2360 * [sp + 12] = pc to call
2361 * [sp + 16] = JValue* result
2362 * [sp + 20] = shorty
2363 * [sp + 24] = thread
2364 */
2365DEFINE_FUNCTION art_quick_osr_stub
2366 // Save native callee saves.
2367 PUSH ebp
2368 PUSH ebx
2369 PUSH esi
2370 PUSH edi
2371 mov 4+16(%esp), %esi // ESI = argument array
2372 mov 8+16(%esp), %ecx // ECX = size of args
2373 mov 12+16(%esp), %ebx // EBX = pc to call
2374 mov %esp, %ebp // Save stack pointer
2375 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2376 PUSH ebp // Save old stack pointer
2377 subl LITERAL(12), %esp // Align stack
2378 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2379 call .Losr_entry
2380
2381 // Restore stack pointer.
2382 addl LITERAL(12), %esp
2383 POP ebp
2384 mov %ebp, %esp
2385
2386 // Restore callee saves.
2387 POP edi
2388 POP esi
2389 POP ebx
2390 POP ebp
2391 mov 16(%esp), %ecx // Get JValue result
2392 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2393 mov %edx, 4(%ecx) // Store the other half of the result
2394 mov 20(%esp), %edx // Get the shorty
2395 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2396 je .Losr_return_double_quick
2397 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2398 je .Losr_return_float_quick
2399 ret
2400.Losr_return_double_quick:
2401 movsd %xmm0, (%ecx) // Store the floating point result
2402 ret
2403.Losr_return_float_quick:
2404 movss %xmm0, (%ecx) // Store the floating point result
2405 ret
2406.Losr_entry:
2407 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2408 subl %ecx, %esp
2409 mov %esp, %edi // EDI = beginning of stack
2410 rep movsb // while (ecx--) { *edi++ = *esi++ }
2411 jmp *%ebx
2412END_FUNCTION art_quick_osr_stub
2413
Orion Hodsonac141392017-01-13 11:53:47 +00002414DEFINE_FUNCTION art_quick_invoke_polymorphic
2415 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx // Save frame.
2416 mov %esp, %edx // Remember SP.
2417 subl LITERAL(16), %esp // Make space for JValue result.
2418 CFI_ADJUST_CFA_OFFSET(16)
2419 movl LITERAL(0), (%esp) // Initialize result to zero.
2420 movl LITERAL(0), 4(%esp)
2421 mov %esp, %eax // Store pointer to JValue result in eax.
2422 PUSH edx // pass SP
2423 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
2424 CFI_ADJUST_CFA_OFFSET(4)
2425 PUSH ecx // pass receiver (method handle)
2426 PUSH eax // pass JResult
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002427 call SYMBOL(artInvokePolymorphic) // artInvokePolymorphic(result, receiver, Thread*, SP)
Orion Hodsonac141392017-01-13 11:53:47 +00002428 subl LITERAL('A'), %eax // Eliminate out of bounds options
2429 cmpb LITERAL('Z' - 'A'), %al
2430 ja .Lcleanup_and_return
2431 movzbl %al, %eax
2432 call .Lput_eip_in_ecx
2433.Lbranch_start:
2434 movl %ecx, %edx
2435 add $(.Lhandler_table - .Lbranch_start), %edx // Make EDX point to handler_table.
2436 leal (%edx, %eax, 2), %eax // Calculate address of entry in table.
2437 movzwl (%eax), %eax // Lookup relative branch in table.
2438 addl %ecx, %eax // Add EIP relative offset.
2439 jmp *%eax // Branch to handler.
2440
2441 // Handlers for different return types.
2442.Lstore_boolean_result:
2443 movzbl 16(%esp), %eax // Copy boolean result to the accumulator.
2444 jmp .Lcleanup_and_return
2445.Lstore_char_result:
2446 movzwl 16(%esp), %eax // Copy char result to the accumulator.
2447 jmp .Lcleanup_and_return
2448.Lstore_float_result:
2449 movd 16(%esp), %xmm0 // Copy float result to the context restored by
2450 movd %xmm0, 36(%esp) // RESTORE_SAVE_REFS_ONLY_FRAME.
2451 jmp .Lcleanup_and_return
2452.Lstore_double_result:
2453 movsd 16(%esp), %xmm0 // Copy double result to the context restored by
2454 movsd %xmm0, 36(%esp) // RESTORE_SAVE_REFS_ONLY_FRAME.
2455 jmp .Lcleanup_and_return
2456.Lstore_long_result:
2457 movl 20(%esp), %edx // Copy upper-word of result to the context restored by
2458 movl %edx, 72(%esp) // RESTORE_SAVE_REFS_ONLY_FRAME.
2459 // Fall-through for lower bits.
2460.Lstore_int_result:
2461 movl 16(%esp), %eax // Copy int result to the accumulator.
2462 // Fall-through to clean up and return.
2463.Lcleanup_and_return:
2464 addl LITERAL(32), %esp // Pop arguments and stack allocated JValue result.
2465 CFI_ADJUST_CFA_OFFSET(-32)
2466 RESTORE_SAVE_REFS_AND_ARGS_FRAME
2467 RETURN_OR_DELIVER_PENDING_EXCEPTION
2468
2469.Lput_eip_in_ecx: // Internal function that puts address of
2470 movl 0(%esp), %ecx // next instruction into ECX when CALL
2471 ret
2472
2473 // Handler table to handlers for given type.
2474.Lhandler_table:
2475MACRO1(HANDLER_TABLE_ENTRY, handler_label)
2476 // NB some tools require 16-bits for relocations. Shouldn't need adjusting.
2477 .word RAW_VAR(handler_label) - .Lbranch_start
2478END_MACRO
2479 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // A
2480 HANDLER_TABLE_ENTRY(.Lstore_int_result) // B (byte)
2481 HANDLER_TABLE_ENTRY(.Lstore_char_result) // C (char)
2482 HANDLER_TABLE_ENTRY(.Lstore_double_result) // D (double)
2483 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // E
2484 HANDLER_TABLE_ENTRY(.Lstore_float_result) // F (float)
2485 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // G
2486 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // H
2487 HANDLER_TABLE_ENTRY(.Lstore_int_result) // I (int)
2488 HANDLER_TABLE_ENTRY(.Lstore_long_result) // J (long)
2489 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // K
2490 HANDLER_TABLE_ENTRY(.Lstore_int_result) // L (object)
2491 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // M
2492 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // N
2493 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // O
2494 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // P
2495 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // Q
2496 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // R
2497 HANDLER_TABLE_ENTRY(.Lstore_int_result) // S (short)
2498 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // T
2499 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // U
2500 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // V (void)
2501 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // W
2502 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // X
2503 HANDLER_TABLE_ENTRY(.Lcleanup_and_return) // Y
2504 HANDLER_TABLE_ENTRY(.Lstore_boolean_result) // Z (boolean)
2505
2506END_FUNCTION art_quick_invoke_polymorphic
2507
Elliott Hughes787ec202012-03-29 17:14:15 -07002508 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002509UNIMPLEMENTED art_quick_memcmp16