quick_entrypoints_x86.S revision 2cd334ae2d4287216523882f0d298cf3901b7ab1
1/* 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 17#include "asm_support_x86.S" 18 19// For x86, the CFA is esp+4, the address above the pushed return address on the stack. 20 21 /* 22 * Macro that sets up the callee save frame to conform with 23 * Runtime::CreateCalleeSaveMethod(kSaveAll) 24 */ 25MACRO2(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME, got_reg, temp_reg) 26 PUSH edi // Save callee saves (ebx is saved/restored by the upcall) 27 PUSH esi 28 PUSH ebp 29 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words. 30 CFI_ADJUST_CFA_OFFSET(12) 31 SETUP_GOT_NOSAVE RAW_VAR(got_reg, 0) 32 // Load Runtime::instance_ from GOT. 33 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg, 0)), REG_VAR(temp_reg, 1) 34 movl (REG_VAR(temp_reg, 1)), REG_VAR(temp_reg, 1) 35 // Push save all callee-save method. 36 pushl RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg, 1)) 37 CFI_ADJUST_CFA_OFFSET(4) 38 // Store esp as the top quick frame. 39 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET 40 // Ugly compile-time check, but we only have the preprocessor. 41 // Last +4: implicit return address pushed on stack when caller made call. 42#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 3*4 + 16 + 4) 43#error "SAVE_ALL_CALLEE_SAVE_FRAME(X86) size not as expected." 44#endif 45END_MACRO 46 47 /* 48 * Macro that sets up the callee save frame to conform with 49 * Runtime::CreateCalleeSaveMethod(kRefsOnly) 50 */ 51MACRO2(SETUP_REFS_ONLY_CALLEE_SAVE_FRAME, got_reg, temp_reg) 52 PUSH edi // Save callee saves (ebx is saved/restored by the upcall) 53 PUSH esi 54 PUSH ebp 55 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words. 56 CFI_ADJUST_CFA_OFFSET(12) 57 SETUP_GOT_NOSAVE VAR(got_reg, 0) 58 // Load Runtime::instance_ from GOT. 59 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg, 0)), REG_VAR(temp_reg, 1) 60 movl (REG_VAR(temp_reg, 1)), REG_VAR(temp_reg, 1) 61 // Push save all callee-save method. 62 pushl RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg, 1)) 63 CFI_ADJUST_CFA_OFFSET(4) 64 // Store esp as the top quick frame. 65 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET 66 67 // Ugly compile-time check, but we only have the preprocessor. 68 // Last +4: implicit return address pushed on stack when caller made call. 69#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4) 70#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected." 71#endif 72END_MACRO 73 74MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME) 75 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values 76 CFI_ADJUST_CFA_OFFSET(-16) 77 POP ebp // Restore callee saves (ebx is saved/restored by the upcall) 78 POP esi 79 POP edi 80END_MACRO 81 82 /* 83 * Macro that sets up the callee save frame to conform with 84 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) 85 */ 86MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg) 87 PUSH edi // Save callee saves 88 PUSH esi 89 PUSH ebp 90 PUSH ebx // Save args 91 PUSH edx 92 PUSH ecx 93 SETUP_GOT_NOSAVE VAR(got_reg, 0) 94 // Load Runtime::instance_ from GOT. 95 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg, 0)), REG_VAR(temp_reg, 1) 96 movl (REG_VAR(temp_reg, 1)), REG_VAR(temp_reg, 1) 97 // Push save all callee-save method. 98 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg, 1)) 99 CFI_ADJUST_CFA_OFFSET(4) 100 // Store esp as the stop quick frame. 101 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET 102 103 // Ugly compile-time check, but we only have the preprocessor. 104 // Last +4: implicit return address pushed on stack when caller made call. 105#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4) 106#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected." 107#endif 108END_MACRO 109 110 /* 111 * Macro that sets up the callee save frame to conform with 112 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX. 113 */ 114MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX) 115 PUSH edi // Save callee saves 116 PUSH esi 117 PUSH ebp 118 PUSH ebx // Save args 119 PUSH edx 120 PUSH ecx 121 PUSH eax // Store the ArtMethod reference at the bottom of the stack. 122 // Store esp as the stop quick frame. 123 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET 124END_MACRO 125 126MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME) 127 addl MACRO_LITERAL(4), %esp // Remove padding 128 CFI_ADJUST_CFA_OFFSET(-4) 129 POP ecx // Restore args except eax 130 POP edx 131 POP ebx 132 POP ebp // Restore callee saves 133 POP esi 134 POP edi 135END_MACRO 136 137 /* 138 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending 139 * exception is Thread::Current()->exception_. 140 */ 141MACRO0(DELIVER_PENDING_EXCEPTION) 142 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw 143 // Outgoing argument set up 144 subl MACRO_LITERAL(12), %esp // Alignment padding 145 CFI_ADJUST_CFA_OFFSET(12) 146 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 147 CFI_ADJUST_CFA_OFFSET(4) 148 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*) 149 int3 // unreached 150END_MACRO 151 152MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) 153 DEFINE_FUNCTION RAW_VAR(c_name, 0) 154 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context 155 // Outgoing argument set up 156 subl MACRO_LITERAL(12), %esp // alignment padding 157 CFI_ADJUST_CFA_OFFSET(12) 158 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 159 CFI_ADJUST_CFA_OFFSET(4) 160 call VAR(cxx_name, 1) // cxx_name(Thread*) 161 int3 // unreached 162 END_FUNCTION RAW_VAR(c_name, 0) 163END_MACRO 164 165MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) 166 DEFINE_FUNCTION RAW_VAR(c_name, 0) 167 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context 168 mov %esp, %ecx 169 // Outgoing argument set up 170 subl MACRO_LITERAL(8), %esp // alignment padding 171 CFI_ADJUST_CFA_OFFSET(8) 172 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 173 CFI_ADJUST_CFA_OFFSET(4) 174 PUSH eax // pass arg1 175 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*) 176 int3 // unreached 177 END_FUNCTION RAW_VAR(c_name, 0) 178END_MACRO 179 180MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) 181 DEFINE_FUNCTION RAW_VAR(c_name, 0) 182 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context 183 // Outgoing argument set up 184 PUSH eax // alignment padding 185 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 186 CFI_ADJUST_CFA_OFFSET(4) 187 PUSH ecx // pass arg2 188 PUSH eax // pass arg1 189 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*) 190 int3 // unreached 191 END_FUNCTION RAW_VAR(c_name, 0) 192END_MACRO 193 194 /* 195 * Called by managed code to create and deliver a NullPointerException. 196 */ 197NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode 198 199 /* 200 * Called by managed code to create and deliver an ArithmeticException. 201 */ 202NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode 203 204 /* 205 * Called by managed code to create and deliver a StackOverflowError. 206 */ 207NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode 208 209 /* 210 * Called by managed code, saves callee saves and then calls artThrowException 211 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. 212 */ 213ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode 214 215 /* 216 * Called by managed code to create and deliver a NoSuchMethodError. 217 */ 218ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode 219 220 /* 221 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds 222 * index, arg2 holds limit. 223 */ 224TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode 225 226 /* 227 * All generated callsites for interface invokes and invocation slow paths will load arguments 228 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain 229 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the 230 * stack and call the appropriate C helper. 231 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1. 232 * 233 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting 234 * of the target Method* in r0 and method->code_ in r1. 235 * 236 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the 237 * thread and we branch to another stub to deliver it. 238 * 239 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr 240 * pointing back to the original caller. 241 */ 242MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name) 243 DEFINE_FUNCTION RAW_VAR(c_name, 0) 244 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx 245 movl %esp, %edx // remember SP 246 // Outgoing argument set up 247 subl MACRO_LITERAL(12), %esp // alignment padding 248 CFI_ADJUST_CFA_OFFSET(12) 249 PUSH edx // pass SP 250 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 251 CFI_ADJUST_CFA_OFFSET(4) 252 pushl 32(%edx) // pass caller Method* 253 CFI_ADJUST_CFA_OFFSET(4) 254 PUSH ecx // pass arg2 255 PUSH eax // pass arg1 256 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP) 257 movl %edx, %edi // save code pointer in EDI 258 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax 259 CFI_ADJUST_CFA_OFFSET(-36) 260 POP ecx // Restore args except eax 261 POP edx 262 POP ebx 263 POP ebp // Restore callee saves 264 POP esi 265 // Swap EDI callee save with code pointer. 266 xchgl %edi, (%esp) 267 testl %eax, %eax // Branch forward if exception pending. 268 jz 1f 269 // Tail call to intended method. 270 ret 2711: 272 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack 273 CFI_ADJUST_CFA_OFFSET(-4) 274 DELIVER_PENDING_EXCEPTION 275 END_FUNCTION RAW_VAR(c_name, 0) 276END_MACRO 277 278INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline 279INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck 280 281INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck 282INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck 283INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck 284INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck 285 286 /* 287 * Quick invocation stub. 288 * On entry: 289 * [sp] = return address 290 * [sp + 4] = method pointer 291 * [sp + 8] = argument array or NULL for no argument methods 292 * [sp + 12] = size of argument array in bytes 293 * [sp + 16] = (managed) thread pointer 294 * [sp + 20] = JValue* result 295 * [sp + 24] = shorty 296 */ 297DEFINE_FUNCTION art_quick_invoke_stub 298 PUSH ebp // save ebp 299 PUSH ebx // save ebx 300 PUSH esi // save esi 301 PUSH edi // save edi 302 mov %esp, %ebp // copy value of stack pointer into base pointer 303 CFI_DEF_CFA_REGISTER(ebp) 304 mov 28(%ebp), %ebx // get arg array size 305 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame 306 addl LITERAL(36), %ebx 307 // align frame size to 16 bytes 308 andl LITERAL(0xFFFFFFF0), %ebx 309 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi 310 subl %ebx, %esp // reserve stack space for argument array 311 SETUP_GOT_NOSAVE ebx // clobbers ebx (harmless here) 312 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy 313 pushl 28(%ebp) // push size of region to memcpy 314 pushl 24(%ebp) // push arg array as source of memcpy 315 pushl %eax // push stack pointer as destination of memcpy 316 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t) 317 addl LITERAL(12), %esp // pop arguments to memcpy 318 movl LITERAL(0), (%esp) // store NULL for method* 319 mov 20(%ebp), %eax // move method pointer into eax 320 mov 4(%esp), %ecx // copy arg1 into ecx 321 mov 8(%esp), %edx // copy arg2 into edx 322 mov 12(%esp), %ebx // copy arg3 into ebx 323 call *MIRROR_ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method 324 mov %ebp, %esp // restore stack pointer 325 CFI_DEF_CFA_REGISTER(esp) 326 POP edi // pop edi 327 POP esi // pop esi 328 POP ebx // pop ebx 329 POP ebp // pop ebp 330 mov 20(%esp), %ecx // get result pointer 331 mov %eax, (%ecx) // store the result assuming its a long, int or Object* 332 mov %edx, 4(%ecx) // store the other half of the result 333 mov 24(%esp), %edx // get the shorty 334 cmpb LITERAL(68), (%edx) // test if result type char == 'D' 335 je .Lreturn_double_quick 336 cmpb LITERAL(70), (%edx) // test if result type char == 'F' 337 je .Lreturn_float_quick 338 ret 339.Lreturn_double_quick: 340 movsd %xmm0, (%ecx) // store the floating point result 341 ret 342.Lreturn_float_quick: 343 movss %xmm0, (%ecx) // store the floating point result 344 ret 345END_FUNCTION art_quick_invoke_stub 346 347MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro) 348 DEFINE_FUNCTION RAW_VAR(c_name, 0) 349 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 350 // Outgoing argument set up 351 subl MACRO_LITERAL(12), %esp // push padding 352 CFI_ADJUST_CFA_OFFSET(12) 353 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 354 CFI_ADJUST_CFA_OFFSET(4) 355 call VAR(cxx_name, 1) // cxx_name(Thread*) 356 addl MACRO_LITERAL(16), %esp // pop arguments 357 CFI_ADJUST_CFA_OFFSET(-16) 358 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 359 CALL_MACRO(return_macro, 2) // return or deliver exception 360 END_FUNCTION RAW_VAR(c_name, 0) 361END_MACRO 362 363MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro) 364 DEFINE_FUNCTION RAW_VAR(c_name, 0) 365 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 366 // Outgoing argument set up 367 subl MACRO_LITERAL(8), %esp // push padding 368 CFI_ADJUST_CFA_OFFSET(8) 369 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 370 CFI_ADJUST_CFA_OFFSET(4) 371 PUSH eax // pass arg1 372 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*) 373 addl MACRO_LITERAL(16), %esp // pop arguments 374 CFI_ADJUST_CFA_OFFSET(-16) 375 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 376 CALL_MACRO(return_macro, 2) // return or deliver exception 377 END_FUNCTION RAW_VAR(c_name, 0) 378END_MACRO 379 380MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro) 381 DEFINE_FUNCTION RAW_VAR(c_name, 0) 382 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 383 // Outgoing argument set up 384 PUSH eax // push padding 385 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 386 CFI_ADJUST_CFA_OFFSET(4) 387 PUSH ecx // pass arg2 388 PUSH eax // pass arg1 389 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*) 390 addl MACRO_LITERAL(16), %esp // pop arguments 391 CFI_ADJUST_CFA_OFFSET(-16) 392 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 393 CALL_MACRO(return_macro, 2) // return or deliver exception 394 END_FUNCTION RAW_VAR(c_name, 0) 395END_MACRO 396 397MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro) 398 DEFINE_FUNCTION RAW_VAR(c_name, 0) 399 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 400 // Outgoing argument set up 401 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 402 CFI_ADJUST_CFA_OFFSET(4) 403 PUSH edx // pass arg3 404 PUSH ecx // pass arg2 405 PUSH eax // pass arg1 406 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*) 407 addl MACRO_LITERAL(16), %esp // pop arguments 408 CFI_ADJUST_CFA_OFFSET(-16) 409 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 410 CALL_MACRO(return_macro, 2) // return or deliver exception 411 END_FUNCTION RAW_VAR(c_name, 0) 412END_MACRO 413 414MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro) 415 DEFINE_FUNCTION RAW_VAR(c_name, 0) 416 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 417 // Outgoing argument set up 418 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer 419 PUSH eax // push padding 420 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 421 CFI_ADJUST_CFA_OFFSET(4) 422 PUSH ecx // pass referrer 423 PUSH eax // pass arg1 424 call VAR(cxx_name, 1) // cxx_name(arg1, referrer, Thread*) 425 addl MACRO_LITERAL(16), %esp // pop arguments 426 CFI_ADJUST_CFA_OFFSET(-16) 427 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 428 CALL_MACRO(return_macro, 2) // return or deliver exception 429 END_FUNCTION RAW_VAR(c_name, 0) 430END_MACRO 431 432MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro) 433 DEFINE_FUNCTION RAW_VAR(c_name, 0) 434 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 435 // Outgoing argument set up 436 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer 437 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 438 CFI_ADJUST_CFA_OFFSET(4) 439 PUSH edx // pass referrer 440 PUSH ecx // pass arg2 441 PUSH eax // pass arg1 442 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, referrer, Thread*) 443 addl MACRO_LITERAL(16), %esp // pop arguments 444 CFI_ADJUST_CFA_OFFSET(-16) 445 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 446 CALL_MACRO(return_macro, 2) // return or deliver exception 447 END_FUNCTION RAW_VAR(c_name, 0) 448END_MACRO 449 450MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro) 451 DEFINE_FUNCTION RAW_VAR(c_name, 0) 452 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 453 // Outgoing argument set up 454 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer 455 subl MACRO_LITERAL(12), %esp // alignment padding 456 CFI_ADJUST_CFA_OFFSET(12) 457 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 458 CFI_ADJUST_CFA_OFFSET(4) 459 PUSH ebx // pass referrer 460 PUSH edx // pass arg3 461 PUSH ecx // pass arg2 462 PUSH eax // pass arg1 463 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, referrer, Thread*) 464 addl LITERAL(32), %esp // pop arguments 465 CFI_ADJUST_CFA_OFFSET(-32) 466 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 467 CALL_MACRO(return_macro, 2) // return or deliver exception 468 END_FUNCTION RAW_VAR(c_name, 0) 469END_MACRO 470 471MACRO0(RETURN_IF_RESULT_IS_NON_ZERO) 472 testl %eax, %eax // eax == 0 ? 473 jz 1f // if eax == 0 goto 1 474 ret // return 4751: // deliver exception on current thread 476 DELIVER_PENDING_EXCEPTION 477END_MACRO 478 479MACRO0(RETURN_IF_EAX_ZERO) 480 testl %eax, %eax // eax == 0 ? 481 jnz 1f // if eax != 0 goto 1 482 ret // return 4831: // deliver exception on current thread 484 DELIVER_PENDING_EXCEPTION 485END_MACRO 486 487MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION) 488 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ? 489 jne 1f // if exception field != 0 goto 1 490 ret // return 4911: // deliver exception on current thread 492 DELIVER_PENDING_EXCEPTION 493END_MACRO 494 495// Generate the allocation entrypoints for each allocator. 496// TODO: use arch/quick_alloc_entrypoints.S. Currently we don't as we need to use concatenation 497// macros to work around differences between OS/X's as and binutils as (OS/X lacks named arguments 498// to macros and the VAR macro won't concatenate arguments properly), this also breaks having 499// multi-line macros that use each other (hence using 1 macro per newline below). 500#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(c_suffix, cxx_suffix) \ 501 TWO_ARG_DOWNCALL art_quick_alloc_object ## c_suffix, artAllocObjectFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 502#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(c_suffix, cxx_suffix) \ 503 TWO_ARG_DOWNCALL art_quick_alloc_object_resolved ## c_suffix, artAllocObjectFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 504#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(c_suffix, cxx_suffix) \ 505 TWO_ARG_DOWNCALL art_quick_alloc_object_initialized ## c_suffix, artAllocObjectFromCodeInitialized ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 506#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \ 507 TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check ## c_suffix, artAllocObjectFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 508#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(c_suffix, cxx_suffix) \ 509 THREE_ARG_DOWNCALL art_quick_alloc_array ## c_suffix, artAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 510#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(c_suffix, cxx_suffix) \ 511 THREE_ARG_DOWNCALL art_quick_alloc_array_resolved ## c_suffix, artAllocArrayFromCodeResolved ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 512#define GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \ 513 THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check ## c_suffix, artAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 514#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(c_suffix, cxx_suffix) \ 515 THREE_ARG_DOWNCALL art_quick_check_and_alloc_array ## c_suffix, artCheckAndAllocArrayFromCode ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 516#define GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(c_suffix, cxx_suffix) \ 517 THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check ## c_suffix, artCheckAndAllocArrayFromCodeWithAccessCheck ## cxx_suffix, RETURN_IF_RESULT_IS_NON_ZERO 518 519GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc, DlMalloc) 520GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc, DlMalloc) 521GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc, DlMalloc) 522GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc) 523GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc, DlMalloc) 524GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc, DlMalloc) 525GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc) 526GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc, DlMalloc) 527GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc, DlMalloc) 528 529GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_dlmalloc_instrumented, DlMallocInstrumented) 530GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented) 531GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_dlmalloc_instrumented, DlMallocInstrumented) 532GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented) 533GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented) 534GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_dlmalloc_instrumented, DlMallocInstrumented) 535GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented) 536GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_dlmalloc_instrumented, DlMallocInstrumented) 537GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_dlmalloc_instrumented, DlMallocInstrumented) 538 539GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc) 540GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc, RosAlloc) 541GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc, RosAlloc) 542GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc, RosAlloc) 543GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc, RosAlloc) 544GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc, RosAlloc) 545GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc) 546GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc, RosAlloc) 547GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc, RosAlloc) 548 549GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc_instrumented, RosAllocInstrumented) 550GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented) 551GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_rosalloc_instrumented, RosAllocInstrumented) 552GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented) 553GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented) 554GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_rosalloc_instrumented, RosAllocInstrumented) 555GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented) 556GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_rosalloc_instrumented, RosAllocInstrumented) 557GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_rosalloc_instrumented, RosAllocInstrumented) 558 559GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer, BumpPointer) 560GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer, BumpPointer) 561GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer, BumpPointer) 562GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer) 563GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer, BumpPointer) 564GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer, BumpPointer) 565GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer) 566GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer, BumpPointer) 567GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer, BumpPointer) 568 569GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_bump_pointer_instrumented, BumpPointerInstrumented) 570GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented) 571GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_bump_pointer_instrumented, BumpPointerInstrumented) 572GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented) 573GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented) 574GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_bump_pointer_instrumented, BumpPointerInstrumented) 575GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented) 576GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_bump_pointer_instrumented, BumpPointerInstrumented) 577GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_bump_pointer_instrumented, BumpPointerInstrumented) 578 579GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB) 580GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab, TLAB) 581GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab, TLAB) 582GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab, TLAB) 583GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab, TLAB) 584GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab, TLAB) 585GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB) 586GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab, TLAB) 587GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab, TLAB) 588 589GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab_instrumented, TLABInstrumented) 590GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_tlab_instrumented, TLABInstrumented) 591GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_tlab_instrumented, TLABInstrumented) 592GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented) 593GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented) 594GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_tlab_instrumented, TLABInstrumented) 595GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented) 596GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_tlab_instrumented, TLABInstrumented) 597GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_tlab_instrumented, TLABInstrumented) 598 599GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region, Region) 600GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region, Region) 601GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region, Region) 602GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region, Region) 603GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region, Region) 604GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region, Region) 605GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region, Region) 606GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region, Region) 607GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region, Region) 608 609GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_instrumented, RegionInstrumented) 610GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_instrumented, RegionInstrumented) 611GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_instrumented, RegionInstrumented) 612GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_instrumented, RegionInstrumented) 613GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_instrumented, RegionInstrumented) 614GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_instrumented, RegionInstrumented) 615GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_instrumented, RegionInstrumented) 616GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_instrumented, RegionInstrumented) 617GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_instrumented, RegionInstrumented) 618 619GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) 620GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB) 621GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB) 622GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) 623GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) 624GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB) 625GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) 626GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB) 627GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) 628 629GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab_instrumented, RegionTLABInstrumented) 630GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab_instrumented, RegionTLABInstrumented) 631GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab_instrumented, RegionTLABInstrumented) 632GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab_instrumented, RegionTLABInstrumented) 633GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab_instrumented, RegionTLABInstrumented) 634GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab_instrumented, RegionTLABInstrumented) 635GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab_instrumented, RegionTLABInstrumented) 636GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab_instrumented, RegionTLABInstrumented) 637GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab_instrumented, RegionTLABInstrumented) 638 639TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO 640TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO 641TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO 642TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO 643 644TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO 645 646DEFINE_FUNCTION art_quick_lock_object 647 testl %eax, %eax // null check object/eax 648 jz .Lslow_lock 649.Lretry_lock: 650 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word 651 test LITERAL(0xC0000000), %ecx // test the 2 high bits. 652 jne .Lslow_lock // slow path if either of the two high bits are set. 653 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id 654 test %ecx, %ecx 655 jnz .Lalready_thin // lock word contains a thin lock 656 // unlocked case - %edx holds thread id with count of 0 657 movl %eax, %ecx // remember object in case of retry 658 xor %eax, %eax // eax == 0 for comparison with lock word in cmpxchg 659 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) 660 jnz .Lcmpxchg_fail // cmpxchg failed retry 661 ret 662.Lcmpxchg_fail: 663 movl %ecx, %eax // restore eax 664 jmp .Lretry_lock 665.Lalready_thin: 666 cmpw %cx, %dx // do we hold the lock already? 667 jne .Lslow_lock 668 addl LITERAL(65536), %ecx // increment recursion count 669 test LITERAL(0xC0000000), %ecx // overflowed if either of top two bits are set 670 jne .Lslow_lock // count overflowed so go slow 671 // update lockword, cmpxchg not necessary as we hold lock 672 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax) 673 ret 674.Lslow_lock: 675 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 676 // Outgoing argument set up 677 subl LITERAL(8), %esp // alignment padding 678 CFI_ADJUST_CFA_OFFSET(8) 679 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 680 CFI_ADJUST_CFA_OFFSET(4) 681 PUSH eax // pass object 682 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*) 683 addl LITERAL(16), %esp // pop arguments 684 CFI_ADJUST_CFA_OFFSET(-16) 685 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 686 RETURN_IF_EAX_ZERO 687END_FUNCTION art_quick_lock_object 688 689DEFINE_FUNCTION art_quick_unlock_object 690 testl %eax, %eax // null check object/eax 691 jz .Lslow_unlock 692 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word 693 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id 694 test LITERAL(0xC0000000), %ecx 695 jnz .Lslow_unlock // lock word contains a monitor 696 cmpw %cx, %dx // does the thread id match? 697 jne .Lslow_unlock 698 cmpl LITERAL(65536), %ecx 699 jae .Lrecursive_thin_unlock 700 movl LITERAL(0), MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax) 701 ret 702.Lrecursive_thin_unlock: 703 subl LITERAL(65536), %ecx 704 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax) 705 ret 706.Lslow_unlock: 707 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 708 // Outgoing argument set up 709 subl LITERAL(8), %esp // alignment padding 710 CFI_ADJUST_CFA_OFFSET(8) 711 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 712 CFI_ADJUST_CFA_OFFSET(4) 713 PUSH eax // pass object 714 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*) 715 addl LITERAL(16), %esp // pop arguments 716 CFI_ADJUST_CFA_OFFSET(-16) 717 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 718 RETURN_IF_EAX_ZERO 719END_FUNCTION art_quick_unlock_object 720 721DEFINE_FUNCTION art_quick_is_assignable 722 PUSH eax // alignment padding 723 PUSH ecx // pass arg2 - obj->klass 724 PUSH eax // pass arg1 - checked class 725 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass) 726 addl LITERAL(12), %esp // pop arguments 727 CFI_ADJUST_CFA_OFFSET(-12) 728 ret 729END_FUNCTION art_quick_is_assignable 730 731DEFINE_FUNCTION art_quick_check_cast 732 PUSH eax // alignment padding 733 PUSH ecx // pass arg2 - obj->klass 734 PUSH eax // pass arg1 - checked class 735 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass) 736 testl %eax, %eax 737 jz 1f // jump forward if not assignable 738 addl LITERAL(12), %esp // pop arguments 739 CFI_ADJUST_CFA_OFFSET(-12) 740 ret 7411: 742 POP eax // pop arguments 743 POP ecx 744 addl LITERAL(4), %esp 745 CFI_ADJUST_CFA_OFFSET(-12) 746 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context 747 // Outgoing argument set up 748 PUSH eax // alignment padding 749 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 750 CFI_ADJUST_CFA_OFFSET(4) 751 PUSH ecx // pass arg2 752 PUSH eax // pass arg1 753 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*) 754 int3 // unreached 755END_FUNCTION art_quick_check_cast 756 757 /* 758 * Entry from managed code for array put operations of objects where the value being stored 759 * needs to be checked for compatibility. 760 * eax = array, ecx = index, edx = value 761 */ 762DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check 763 testl %eax, %eax 764 jnz SYMBOL(art_quick_aput_obj_with_bound_check) 765 jmp SYMBOL(art_quick_throw_null_pointer_exception) 766END_FUNCTION art_quick_aput_obj_with_null_and_bound_check 767 768DEFINE_FUNCTION art_quick_aput_obj_with_bound_check 769 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx 770 cmpl %ebx, %ecx 771 jb SYMBOL(art_quick_aput_obj) 772 mov %ecx, %eax 773 mov %ebx, %ecx 774 jmp SYMBOL(art_quick_throw_array_bounds) 775END_FUNCTION art_quick_aput_obj_with_bound_check 776 777DEFINE_FUNCTION art_quick_aput_obj 778 test %edx, %edx // store of null 779 jz .Ldo_aput_null 780 movl MIRROR_OBJECT_CLASS_OFFSET(%eax), %ebx 781 movl MIRROR_CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx 782 // value's type == array's component type - trivial assignability 783 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx 784 jne .Lcheck_assignability 785.Ldo_aput: 786 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) 787 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx 788 shrl LITERAL(7), %eax 789 movb %dl, (%edx, %eax) 790 ret 791.Ldo_aput_null: 792 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) 793 ret 794.Lcheck_assignability: 795 PUSH eax // save arguments 796 PUSH ecx 797 PUSH edx 798 subl LITERAL(8), %esp // alignment padding 799 CFI_ADJUST_CFA_OFFSET(8) 800 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored 801 CFI_ADJUST_CFA_OFFSET(4) 802 PUSH ebx // pass arg1 - component type of the array 803 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b) 804 addl LITERAL(16), %esp // pop arguments 805 CFI_ADJUST_CFA_OFFSET(-16) 806 testl %eax, %eax 807 jz .Lthrow_array_store_exception 808 POP edx 809 POP ecx 810 POP eax 811 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput 812 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx 813 shrl LITERAL(7), %eax 814 movb %dl, (%edx, %eax) 815 ret 816.Lthrow_array_store_exception: 817 POP edx 818 POP ecx 819 POP eax 820 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context 821 // Outgoing argument set up 822 PUSH eax // alignment padding 823 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 824 CFI_ADJUST_CFA_OFFSET(4) 825 PUSH edx // pass arg2 - value 826 PUSH eax // pass arg1 - array 827 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*) 828 int3 // unreached 829END_FUNCTION art_quick_aput_obj 830 831DEFINE_FUNCTION art_quick_memcpy 832 SETUP_GOT_NOSAVE ebx // clobbers EBX 833 PUSH edx // pass arg3 834 PUSH ecx // pass arg2 835 PUSH eax // pass arg1 836 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t) 837 addl LITERAL(12), %esp // pop arguments 838 CFI_ADJUST_CFA_OFFSET(-12) 839 ret 840END_FUNCTION art_quick_memcpy 841 842NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret 843 844DEFINE_FUNCTION art_quick_d2l 845 PUSH eax // alignment padding 846 PUSH ecx // pass arg2 a.hi 847 PUSH eax // pass arg1 a.lo 848 call SYMBOL(art_d2l) // (jdouble a) 849 addl LITERAL(12), %esp // pop arguments 850 CFI_ADJUST_CFA_OFFSET(-12) 851 ret 852END_FUNCTION art_quick_d2l 853 854DEFINE_FUNCTION art_quick_f2l 855 subl LITERAL(8), %esp // alignment padding 856 CFI_ADJUST_CFA_OFFSET(8) 857 PUSH eax // pass arg1 a 858 call SYMBOL(art_f2l) // (jfloat a) 859 addl LITERAL(12), %esp // pop arguments 860 CFI_ADJUST_CFA_OFFSET(-12) 861 ret 862END_FUNCTION art_quick_f2l 863 864DEFINE_FUNCTION art_quick_ldiv 865 subl LITERAL(12), %esp // alignment padding 866 CFI_ADJUST_CFA_OFFSET(12) 867 PUSH ebx // pass arg4 b.hi 868 PUSH edx // pass arg3 b.lo 869 PUSH ecx // pass arg2 a.hi 870 PUSH eax // pass arg1 a.lo 871 call SYMBOL(artLdiv) // (jlong a, jlong b) 872 addl LITERAL(28), %esp // pop arguments 873 CFI_ADJUST_CFA_OFFSET(-28) 874 ret 875END_FUNCTION art_quick_ldiv 876 877DEFINE_FUNCTION art_quick_lmod 878 subl LITERAL(12), %esp // alignment padding 879 CFI_ADJUST_CFA_OFFSET(12) 880 PUSH ebx // pass arg4 b.hi 881 PUSH edx // pass arg3 b.lo 882 PUSH ecx // pass arg2 a.hi 883 PUSH eax // pass arg1 a.lo 884 call SYMBOL(artLmod) // (jlong a, jlong b) 885 addl LITERAL(28), %esp // pop arguments 886 CFI_ADJUST_CFA_OFFSET(-28) 887 ret 888END_FUNCTION art_quick_lmod 889 890DEFINE_FUNCTION art_quick_lmul 891 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx) 892 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx) 893 mul %edx // edx:eax = a.lo(eax) * b.lo(edx) 894 add %ebx, %ecx 895 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi) 896 ret 897END_FUNCTION art_quick_lmul 898 899DEFINE_FUNCTION art_quick_lshl 900 // ecx:eax << edx 901 xchg %edx, %ecx 902 shld %cl,%eax,%edx 903 shl %cl,%eax 904 test LITERAL(32), %cl 905 jz 1f 906 mov %eax, %edx 907 xor %eax, %eax 9081: 909 ret 910END_FUNCTION art_quick_lshl 911 912DEFINE_FUNCTION art_quick_lshr 913 // ecx:eax >> edx 914 xchg %edx, %ecx 915 shrd %cl,%edx,%eax 916 sar %cl,%edx 917 test LITERAL(32),%cl 918 jz 1f 919 mov %edx, %eax 920 sar LITERAL(31), %edx 9211: 922 ret 923END_FUNCTION art_quick_lshr 924 925DEFINE_FUNCTION art_quick_lushr 926 // ecx:eax >>> edx 927 xchg %edx, %ecx 928 shrd %cl,%edx,%eax 929 shr %cl,%edx 930 test LITERAL(32),%cl 931 jz 1f 932 mov %edx, %eax 933 xor %edx, %edx 9341: 935 ret 936END_FUNCTION art_quick_lushr 937 938ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 939ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 940ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 941ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 942ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 943ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 944ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 945 946TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 947TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 948TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 949TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 950TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 951TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 952TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION 953 954TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO 955TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO 956TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO 957TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO 958 959THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO 960THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO 961THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO 962THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO 963 964// Call artSet64InstanceFromCode with 4 word size arguments and the referrer. 965DEFINE_FUNCTION art_quick_set64_instance 966 movd %ebx, %xmm0 967 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 968 movd %xmm0, %ebx 969 // Outgoing argument set up 970 subl LITERAL(8), %esp // alignment padding 971 CFI_ADJUST_CFA_OFFSET(8) 972 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 973 CFI_ADJUST_CFA_OFFSET(4) 974 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer 975 CFI_ADJUST_CFA_OFFSET(4) 976 PUSH ebx // pass high half of new_val 977 PUSH edx // pass low half of new_val 978 PUSH ecx // pass object 979 PUSH eax // pass field_idx 980 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*) 981 addl LITERAL(32), %esp // pop arguments 982 CFI_ADJUST_CFA_OFFSET(-32) 983 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 984 RETURN_IF_EAX_ZERO // return or deliver exception 985END_FUNCTION art_quick_set64_instance 986 987// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position 988// so that new_val is aligned on even registers were we passing arguments in registers. 989DEFINE_FUNCTION art_quick_set64_static 990 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC 991 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer 992 subl LITERAL(12), %esp // alignment padding 993 CFI_ADJUST_CFA_OFFSET(12) 994 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 995 CFI_ADJUST_CFA_OFFSET(4) 996 PUSH edx // pass high half of new_val 997 PUSH ecx // pass low half of new_val 998 PUSH ebx // pass referrer 999 PUSH eax // pass field_idx 1000 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*) 1001 addl LITERAL(32), %esp // pop arguments 1002 CFI_ADJUST_CFA_OFFSET(-32) 1003 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address 1004 RETURN_IF_EAX_ZERO // return or deliver exception 1005END_FUNCTION art_quick_set64_static 1006 1007DEFINE_FUNCTION art_quick_proxy_invoke_handler 1008 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX 1009 PUSH esp // pass SP 1010 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 1011 CFI_ADJUST_CFA_OFFSET(4) 1012 PUSH ecx // pass receiver 1013 PUSH eax // pass proxy method 1014 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP) 1015 movd %eax, %xmm0 // place return value also into floating point return value 1016 movd %edx, %xmm1 1017 punpckldq %xmm1, %xmm0 1018 addl LITERAL(44), %esp // pop arguments 1019 CFI_ADJUST_CFA_OFFSET(-44) 1020 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception 1021END_FUNCTION art_quick_proxy_invoke_handler 1022 1023 /* 1024 * Called to resolve an imt conflict. xmm0 is a hidden argument that holds the target method's 1025 * dex method index. 1026 */ 1027DEFINE_FUNCTION art_quick_imt_conflict_trampoline 1028 PUSH ecx 1029 movl 8(%esp), %eax // load caller Method* 1030 movl MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET(%eax), %eax // load dex_cache_resolved_methods 1031 movd %xmm0, %ecx // get target method index stored in xmm0 1032 movl MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4), %eax // load the target method 1033 POP ecx 1034 jmp SYMBOL(art_quick_invoke_interface_trampoline) 1035END_FUNCTION art_quick_imt_conflict_trampoline 1036 1037DEFINE_FUNCTION art_quick_resolution_trampoline 1038 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx 1039 movl %esp, %edi 1040 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding 1041 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 1042 CFI_ADJUST_CFA_OFFSET(4) 1043 PUSH ecx // pass receiver 1044 PUSH eax // pass method 1045 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP) 1046 movl %eax, %edi // remember code pointer in EDI 1047 addl LITERAL(16), %esp // pop arguments 1048 test %eax, %eax // if code pointer is NULL goto deliver pending exception 1049 jz 1f 1050 POP eax // called method 1051 POP ecx // restore args 1052 POP edx 1053 POP ebx 1054 POP ebp // restore callee saves except EDI 1055 POP esi 1056 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack 1057 ret // tail call into method 10581: 1059 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1060 DELIVER_PENDING_EXCEPTION 1061END_FUNCTION art_quick_resolution_trampoline 1062 1063DEFINE_FUNCTION art_quick_generic_jni_trampoline 1064 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX 1065 movl %esp, %ebp // save SP at callee-save frame 1066 CFI_DEF_CFA_REGISTER(ebp) 1067 subl LITERAL(5120), %esp 1068 // prepare for artQuickGenericJniTrampoline call 1069 // (Thread*, SP) 1070 // (esp) 4(esp) <= C calling convention 1071 // fs:... ebp <= where they are 1072 1073 subl LITERAL(8), %esp // Padding for 16B alignment. 1074 pushl %ebp // Pass SP (to ArtMethod). 1075 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current(). 1076 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp) 1077 1078 // The C call will have registered the complete save-frame on success. 1079 // The result of the call is: 1080 // eax: pointer to native code, 0 on error. 1081 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there. 1082 1083 // Check for error = 0. 1084 test %eax, %eax 1085 jz .Lentry_error 1086 1087 // Release part of the alloca. 1088 movl %edx, %esp 1089 1090 // On x86 there are no registers passed, so nothing to pop here. 1091 1092 // Native call. 1093 call *%eax 1094 1095 // result sign extension is handled in C code 1096 // prepare for artQuickGenericJniEndTrampoline call 1097 // (Thread*, result, result_f) 1098 // (esp) 4(esp) 12(esp) <= C calling convention 1099 // fs:... eax:edx fp0 <= where they are 1100 1101 subl LITERAL(20), %esp // Padding & pass float result. 1102 fstpl (%esp) 1103 pushl %edx // Pass int result. 1104 pushl %eax 1105 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current(). 1106 call SYMBOL(artQuickGenericJniEndTrampoline) 1107 1108 // Tear down the alloca. 1109 movl %ebp, %esp 1110 CFI_DEF_CFA_REGISTER(esp) 1111 1112 // Pending exceptions possible. 1113 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx 1114 testl %ebx, %ebx 1115 jnz .Lexception_in_native 1116 1117 // Tear down the callee-save frame. 1118 addl LITERAL(4), %esp // Remove padding 1119 CFI_ADJUST_CFA_OFFSET(-4) 1120 POP ecx 1121 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result. 1122 CFI_ADJUST_CFA_OFFSET(-4) 1123 POP ebx 1124 POP ebp // Restore callee saves 1125 POP esi 1126 POP edi 1127 // Quick expects the return value to be in xmm0. 1128 movd %eax, %xmm0 1129 movd %edx, %xmm1 1130 punpckldq %xmm1, %xmm0 1131 ret 1132.Lentry_error: 1133 movl %ebp, %esp 1134 CFI_DEF_CFA_REGISTER(esp) 1135.Lexception_in_native: 1136 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1137 DELIVER_PENDING_EXCEPTION 1138END_FUNCTION art_quick_generic_jni_trampoline 1139 1140DEFINE_FUNCTION art_quick_to_interpreter_bridge 1141 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame 1142 mov %esp, %edx // remember SP 1143 PUSH eax // alignment padding 1144 PUSH edx // pass SP 1145 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() 1146 CFI_ADJUST_CFA_OFFSET(4) 1147 PUSH eax // pass method 1148 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP) 1149 movd %eax, %xmm0 // place return value also into floating point return value 1150 movd %edx, %xmm1 1151 punpckldq %xmm1, %xmm0 1152 addl LITERAL(16), %esp // pop arguments 1153 CFI_ADJUST_CFA_OFFSET(-16) 1154 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1155 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception 1156END_FUNCTION art_quick_to_interpreter_bridge 1157 1158 /* 1159 * Routine that intercepts method calls and returns. 1160 */ 1161DEFINE_FUNCTION art_quick_instrumentation_entry 1162 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx 1163 PUSH eax // Save eax which will be clobbered by the callee-save method. 1164 subl LITERAL(12), %esp // Align stack. 1165 CFI_ADJUST_CFA_OFFSET(12) 1166 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR. 1167 CFI_ADJUST_CFA_OFFSET(4) 1168 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current(). 1169 CFI_ADJUST_CFA_OFFSET(4) 1170 PUSH ecx // Pass receiver. 1171 PUSH eax // Pass Method*. 1172 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR) 1173 addl LITERAL(28), %esp // Pop arguments upto saved Method*. 1174 movl 28(%esp), %edi // Restore edi. 1175 movl %eax, 28(%esp) // Place code* over edi, just under return pc. 1176 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx 1177 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry. 1178 movl %ebx, 32(%esp) 1179 movl (%esp), %eax // Restore eax. 1180 movl 8(%esp), %ecx // Restore ecx. 1181 movl 12(%esp), %edx // Restore edx. 1182 movl 16(%esp), %ebx // Restore ebx. 1183 movl 20(%esp), %ebp // Restore ebp. 1184 movl 24(%esp), %esi // Restore esi. 1185 addl LITERAL(28), %esp // Wind stack back upto code*. 1186 ret // Call method (and pop). 1187END_FUNCTION art_quick_instrumentation_entry 1188 1189DEFINE_FUNCTION art_quick_instrumentation_exit 1190 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack. 1191 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx 1192 mov %esp, %ecx // Remember SP 1193 subl LITERAL(8), %esp // Save float return value. 1194 CFI_ADJUST_CFA_OFFSET(8) 1195 movq %xmm0, (%esp) 1196 PUSH edx // Save gpr return value. 1197 PUSH eax 1198 subl LITERAL(16), %esp // Align stack 1199 CFI_ADJUST_CFA_OFFSET(16) 1200 movq %xmm0, (%esp) // Pass float return value. 1201 PUSH edx // Pass gpr return value. 1202 PUSH eax 1203 PUSH ecx // Pass SP. 1204 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current. 1205 CFI_ADJUST_CFA_OFFSET(4) 1206 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result) 1207 mov %eax, %ecx // Move returned link register. 1208 addl LITERAL(32), %esp // Pop arguments. 1209 CFI_ADJUST_CFA_OFFSET(-32) 1210 movl %edx, %ebx // Move returned link register for deopt 1211 // (ebx is pretending to be our LR). 1212 POP eax // Restore gpr return value. 1213 POP edx 1214 movq (%esp), %xmm0 // Restore fpr return value. 1215 addl LITERAL(8), %esp 1216 CFI_ADJUST_CFA_OFFSET(-8) 1217 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1218 addl LITERAL(4), %esp // Remove fake return pc. 1219 jmp *%ecx // Return. 1220END_FUNCTION art_quick_instrumentation_exit 1221 1222 /* 1223 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization 1224 * will long jump to the upcall with a special exception of -1. 1225 */ 1226DEFINE_FUNCTION art_quick_deoptimize 1227 pushl %ebx // Fake that we were called. 1228 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx 1229 subl LITERAL(12), %esp // Align stack. 1230 CFI_ADJUST_CFA_OFFSET(12) 1231 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current(). 1232 CFI_ADJUST_CFA_OFFSET(4) 1233 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*) 1234 int3 // Unreachable. 1235END_FUNCTION art_quick_deoptimize 1236 1237 /* 1238 * String's compareTo. 1239 * 1240 * On entry: 1241 * eax: this string object (known non-null) 1242 * ecx: comp string object (known non-null) 1243 */ 1244DEFINE_FUNCTION art_quick_string_compareto 1245 PUSH esi // push callee save reg 1246 PUSH edi // push callee save reg 1247 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx 1248 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx 1249 mov MIRROR_STRING_VALUE_OFFSET(%eax), %esi 1250 mov MIRROR_STRING_VALUE_OFFSET(%ecx), %edi 1251 mov MIRROR_STRING_OFFSET_OFFSET(%eax), %eax 1252 mov MIRROR_STRING_OFFSET_OFFSET(%ecx), %ecx 1253 /* Build pointers to the start of string data */ 1254 lea MIRROR_CHAR_ARRAY_DATA_OFFSET(%esi, %eax, 2), %esi 1255 lea MIRROR_CHAR_ARRAY_DATA_OFFSET(%edi, %ecx, 2), %edi 1256 /* Calculate min length and count diff */ 1257 mov %edx, %ecx 1258 mov %edx, %eax 1259 subl %ebx, %eax 1260 cmovg %ebx, %ecx 1261 /* 1262 * At this point we have: 1263 * eax: value to return if first part of strings are equal 1264 * ecx: minimum among the lengths of the two strings 1265 * esi: pointer to this string data 1266 * edi: pointer to comp string data 1267 */ 1268 jecxz .Lkeep_length 1269 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx 1270 jne .Lnot_equal 1271.Lkeep_length: 1272 POP edi // pop callee save reg 1273 POP esi // pop callee save reg 1274 ret 1275 .balign 16 1276.Lnot_equal: 1277 movzwl -2(%esi), %eax // get last compared char from this string 1278 movzwl -2(%edi), %ecx // get last compared char from comp string 1279 subl %ecx, %eax // return the difference 1280 POP edi // pop callee save reg 1281 POP esi // pop callee save reg 1282 ret 1283END_FUNCTION art_quick_string_compareto 1284 1285// Return from a nested signal: 1286// Entry: 1287// eax: address of jmp_buf in TLS 1288 1289DEFINE_FUNCTION art_nested_signal_return 1290 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT 1291 movl LITERAL(1), %ecx 1292 pushl %ecx // second arg to longjmp (1) 1293 pushl %eax // first arg to longjmp (jmp_buf) 1294 call PLT_SYMBOL(longjmp) 1295 int3 // won't get here. 1296END_FUNCTION art_nested_signal_return 1297 1298 // TODO: implement these! 1299UNIMPLEMENTED art_quick_memcmp16 1300