quick_entrypoints_arm64.S revision e460d1df1f789c7c8bb97024a8efbd713ac175e9
1/* 2 * Copyright (C) 2014 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_arm64.S" 18 19#include "arch/quick_alloc_entrypoints.S" 20 21 22 /* 23 * Macro that sets up the callee save frame to conform with 24 * Runtime::CreateCalleeSaveMethod(kSaveAll) 25 */ 26.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 27 adrp xIP0, :got:_ZN3art7Runtime9instance_E 28 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 29 30 // Our registers aren't intermixed - just spill in order. 31 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 32 33 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . 34 // Loads appropriate callee-save-method. 35 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ] 36 37 sub sp, sp, #176 38 .cfi_adjust_cfa_offset 176 39 40 // Ugly compile-time check, but we only have the preprocessor. 41#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176) 42#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected." 43#endif 44 45 // Stack alignment filler [sp, #8]. 46 // FP callee-saves. 47 stp d8, d9, [sp, #16] 48 stp d10, d11, [sp, #32] 49 stp d12, d13, [sp, #48] 50 stp d14, d15, [sp, #64] 51 52 // GP callee-saves 53 stp x19, x20, [sp, #80] 54 .cfi_rel_offset x19, 80 55 .cfi_rel_offset x20, 88 56 57 stp x21, x22, [sp, #96] 58 .cfi_rel_offset x21, 96 59 .cfi_rel_offset x22, 104 60 61 stp x23, x24, [sp, #112] 62 .cfi_rel_offset x23, 112 63 .cfi_rel_offset x24, 120 64 65 stp x25, x26, [sp, #128] 66 .cfi_rel_offset x25, 128 67 .cfi_rel_offset x26, 136 68 69 stp x27, x28, [sp, #144] 70 .cfi_rel_offset x27, 144 71 .cfi_rel_offset x28, 152 72 73 stp x29, xLR, [sp, #160] 74 .cfi_rel_offset x29, 160 75 .cfi_rel_offset x30, 168 76 77 // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]. 78 str xIP0, [sp] 79 // Place sp in Thread::Current()->top_quick_frame. 80 mov xIP0, sp 81 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 82.endm 83 84 /* 85 * Macro that sets up the callee save frame to conform with 86 * Runtime::CreateCalleeSaveMethod(kRefsOnly). 87 */ 88.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 89 adrp xIP0, :got:_ZN3art7Runtime9instance_E 90 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 91 92 // Our registers aren't intermixed - just spill in order. 93 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 94 95 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefOnly] . 96 // Loads appropriate callee-save-method. 97 ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ] 98 99 sub sp, sp, #96 100 .cfi_adjust_cfa_offset 96 101 102 // Ugly compile-time check, but we only have the preprocessor. 103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96) 104#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected." 105#endif 106 107 // GP callee-saves. 108 // x20 paired with ArtMethod* - see below. 109 stp x21, x22, [sp, #16] 110 .cfi_rel_offset x21, 16 111 .cfi_rel_offset x22, 24 112 113 stp x23, x24, [sp, #32] 114 .cfi_rel_offset x23, 32 115 .cfi_rel_offset x24, 40 116 117 stp x25, x26, [sp, #48] 118 .cfi_rel_offset x25, 48 119 .cfi_rel_offset x26, 56 120 121 stp x27, x28, [sp, #64] 122 .cfi_rel_offset x27, 64 123 .cfi_rel_offset x28, 72 124 125 stp x29, xLR, [sp, #80] 126 .cfi_rel_offset x29, 80 127 .cfi_rel_offset x30, 88 128 129 // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly]. 130 stp xIP0, x20, [sp] 131 .cfi_rel_offset x20, 8 132 133 // Place sp in Thread::Current()->top_quick_frame. 134 mov xIP0, sp 135 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 136.endm 137 138// TODO: Probably no need to restore registers preserved by aapcs64. 139.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 140 // Callee-saves. 141 ldr x20, [sp, #8] 142 .cfi_restore x20 143 144 ldp x21, x22, [sp, #16] 145 .cfi_restore x21 146 .cfi_restore x22 147 148 ldp x23, x24, [sp, #32] 149 .cfi_restore x23 150 .cfi_restore x24 151 152 ldp x25, x26, [sp, #48] 153 .cfi_restore x25 154 .cfi_restore x26 155 156 ldp x27, x28, [sp, #64] 157 .cfi_restore x27 158 .cfi_restore x28 159 160 ldp x29, xLR, [sp, #80] 161 .cfi_restore x29 162 .cfi_restore x30 163 164 add sp, sp, #96 165 .cfi_adjust_cfa_offset -96 166.endm 167 168.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME 169 add sp, sp, #96 170 .cfi_adjust_cfa_offset - 96 171.endm 172 173.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 174 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 175 ret 176.endm 177 178 179.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 180 sub sp, sp, #224 181 .cfi_adjust_cfa_offset 224 182 183 // Ugly compile-time check, but we only have the preprocessor. 184#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224) 185#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected." 186#endif 187 188 // Stack alignment filler [sp, #8]. 189 // FP args. 190 stp d0, d1, [sp, #16] 191 stp d2, d3, [sp, #32] 192 stp d4, d5, [sp, #48] 193 stp d6, d7, [sp, #64] 194 195 // Core args. 196 stp x1, x2, [sp, #80] 197 .cfi_rel_offset x1, 80 198 .cfi_rel_offset x2, 88 199 200 stp x3, x4, [sp, #96] 201 .cfi_rel_offset x3, 96 202 .cfi_rel_offset x4, 104 203 204 stp x5, x6, [sp, #112] 205 .cfi_rel_offset x5, 112 206 .cfi_rel_offset x6, 120 207 208 // x7, Callee-saves. 209 stp x7, x20, [sp, #128] 210 .cfi_rel_offset x7, 128 211 .cfi_rel_offset x20, 136 212 213 stp x21, x22, [sp, #144] 214 .cfi_rel_offset x21, 144 215 .cfi_rel_offset x22, 152 216 217 stp x23, x24, [sp, #160] 218 .cfi_rel_offset x23, 160 219 .cfi_rel_offset x24, 168 220 221 stp x25, x26, [sp, #176] 222 .cfi_rel_offset x25, 176 223 .cfi_rel_offset x26, 184 224 225 stp x27, x28, [sp, #192] 226 .cfi_rel_offset x27, 192 227 .cfi_rel_offset x28, 200 228 229 // x29(callee-save) and LR. 230 stp x29, xLR, [sp, #208] 231 .cfi_rel_offset x29, 208 232 .cfi_rel_offset x30, 216 233 234.endm 235 236 /* 237 * Macro that sets up the callee save frame to conform with 238 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). 239 * 240 * TODO This is probably too conservative - saving FP & LR. 241 */ 242.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 243 adrp xIP0, :got:_ZN3art7Runtime9instance_E 244 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] 245 246 // Our registers aren't intermixed - just spill in order. 247 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) . 248 249 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . 250 ldr xIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ] 251 252 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 253 254 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] 255 // Place sp in Thread::Current()->top_quick_frame. 256 mov xIP0, sp 257 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 258.endm 259 260.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 261 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 262 str x0, [sp, #0] // Store ArtMethod* to bottom of stack. 263 // Place sp in Thread::Current()->top_quick_frame. 264 mov xIP0, sp 265 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 266.endm 267 268// TODO: Probably no need to restore registers preserved by aapcs64. 269.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 270 // FP args. 271 ldp d0, d1, [sp, #16] 272 ldp d2, d3, [sp, #32] 273 ldp d4, d5, [sp, #48] 274 ldp d6, d7, [sp, #64] 275 276 // Core args. 277 ldp x1, x2, [sp, #80] 278 .cfi_restore x1 279 .cfi_restore x2 280 281 ldp x3, x4, [sp, #96] 282 .cfi_restore x3 283 .cfi_restore x4 284 285 ldp x5, x6, [sp, #112] 286 .cfi_restore x5 287 .cfi_restore x6 288 289 // x7, Callee-saves. 290 ldp x7, x20, [sp, #128] 291 .cfi_restore x7 292 .cfi_restore x20 293 294 ldp x21, x22, [sp, #144] 295 .cfi_restore x21 296 .cfi_restore x22 297 298 ldp x23, x24, [sp, #160] 299 .cfi_restore x23 300 .cfi_restore x24 301 302 ldp x25, x26, [sp, #176] 303 .cfi_restore x25 304 .cfi_restore x26 305 306 ldp x27, x28, [sp, #192] 307 .cfi_restore x27 308 .cfi_restore x28 309 310 // x29(callee-save) and LR. 311 ldp x29, xLR, [sp, #208] 312 .cfi_restore x29 313 .cfi_restore x30 314 315 add sp, sp, #224 316 .cfi_adjust_cfa_offset -224 317.endm 318 319.macro RETURN_IF_RESULT_IS_ZERO 320 cbnz x0, 1f // result non-zero branch over 321 ret // return 3221: 323.endm 324 325.macro RETURN_IF_RESULT_IS_NON_ZERO 326 cbz x0, 1f // result zero branch over 327 ret // return 3281: 329.endm 330 331 /* 332 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending 333 * exception is Thread::Current()->exception_ 334 */ 335.macro DELIVER_PENDING_EXCEPTION 336 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 337 mov x0, xSELF 338 339 // Point of no return. 340 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*) 341 brk 0 // Unreached 342.endm 343 344.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg 345 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field. 346 cbnz \reg, 1f 347 ret 3481: 349 DELIVER_PENDING_EXCEPTION 350.endm 351 352.macro RETURN_OR_DELIVER_PENDING_EXCEPTION 353 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0 354.endm 355 356// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register. 357.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 358 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1 359.endm 360 361.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER 362 cbnz w0, 1f // result non-zero branch over 363 ret // return 3641: 365 DELIVER_PENDING_EXCEPTION 366.endm 367 368.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 369 .extern \cxx_name 370ENTRY \c_name 371 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 372 mov x0, xSELF // pass Thread::Current 373 b \cxx_name // \cxx_name(Thread*) 374END \c_name 375.endm 376 377.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name 378 .extern \cxx_name 379ENTRY \c_name 380 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context. 381 mov x1, xSELF // pass Thread::Current. 382 b \cxx_name // \cxx_name(arg, Thread*). 383 brk 0 384END \c_name 385.endm 386 387.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 388 .extern \cxx_name 389ENTRY \c_name 390 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 391 mov x2, xSELF // pass Thread::Current 392 b \cxx_name // \cxx_name(arg1, arg2, Thread*) 393 brk 0 394END \c_name 395.endm 396 397 /* 398 * Called by managed code, saves callee saves and then calls artThrowException 399 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. 400 */ 401ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode 402 403 /* 404 * Called by managed code to create and deliver a NullPointerException. 405 */ 406NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode 407 408 /* 409 * Called by managed code to create and deliver an ArithmeticException. 410 */ 411NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode 412 413 /* 414 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds 415 * index, arg2 holds limit. 416 */ 417TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode 418 419 /* 420 * Called by managed code to create and deliver a StackOverflowError. 421 */ 422NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode 423 424 /* 425 * Called by managed code to create and deliver a NoSuchMethodError. 426 */ 427ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode 428 429 /* 430 * All generated callsites for interface invokes and invocation slow paths will load arguments 431 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain 432 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper. 433 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1. 434 * 435 * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting 436 * of the target Method* in x0 and method->code_ in x1. 437 * 438 * If unsuccessful, the helper will return null/????. There will be a pending exception in the 439 * thread and we branch to another stub to deliver it. 440 * 441 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr 442 * pointing back to the original caller. 443 * 444 * Adapted from ARM32 code. 445 * 446 * Clobbers xIP0. 447 */ 448.macro INVOKE_TRAMPOLINE_BODY cxx_name 449 .extern \cxx_name 450 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC 451 // Helper signature is always 452 // (method_idx, *this_object, *caller_method, *self, sp) 453 454 mov x2, xSELF // pass Thread::Current 455 mov x3, sp 456 bl \cxx_name // (method_idx, this, Thread*, SP) 457 mov xIP0, x1 // save Method*->code_ 458 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 459 cbz x0, 1f // did we find the target? if not go to exception delivery 460 br xIP0 // tail call to target 4611: 462 DELIVER_PENDING_EXCEPTION 463.endm 464.macro INVOKE_TRAMPOLINE c_name, cxx_name 465ENTRY \c_name 466 INVOKE_TRAMPOLINE_BODY \cxx_name 467END \c_name 468.endm 469 470INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck 471 472INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck 473INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck 474INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck 475INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck 476 477 478.macro INVOKE_STUB_CREATE_FRAME 479 480SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved. 481SAVE_SIZE_AND_METHOD=SAVE_SIZE+8 482 483 484 mov x9, sp // Save stack pointer. 485 .cfi_register sp,x9 486 487 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame. 488 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args 489 and x10, x10, # ~0xf // Enforce 16 byte stack alignment. 490 mov sp, x10 // Set new SP. 491 492 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP 493 .cfi_def_cfa_register x10 // before this. 494 .cfi_adjust_cfa_offset SAVE_SIZE 495 496 str x28, [x10, #112] 497 .cfi_rel_offset x28, 112 498 499 stp x26, x27, [x10, #96] 500 .cfi_rel_offset x26, 96 501 .cfi_rel_offset x27, 104 502 503 stp x24, x25, [x10, #80] 504 .cfi_rel_offset x24, 80 505 .cfi_rel_offset x25, 88 506 507 stp x22, x23, [x10, #64] 508 .cfi_rel_offset x22, 64 509 .cfi_rel_offset x23, 72 510 511 stp x20, x21, [x10, #48] 512 .cfi_rel_offset x20, 48 513 .cfi_rel_offset x21, 56 514 515 stp x9, x19, [x10, #32] // Save old stack pointer and x19. 516 .cfi_rel_offset sp, 32 517 .cfi_rel_offset x19, 40 518 519 stp x4, x5, [x10, #16] // Save result and shorty addresses. 520 .cfi_rel_offset x4, 16 521 .cfi_rel_offset x5, 24 522 523 stp xFP, xLR, [x10] // Store LR & FP. 524 .cfi_rel_offset x29, 0 525 .cfi_rel_offset x30, 8 526 527 mov xFP, x10 // Use xFP now, as it's callee-saved. 528 .cfi_def_cfa_register x29 529 mov xSELF, x3 // Move thread pointer into SELF register. 530 531 // Copy arguments into stack frame. 532 // Use simple copy routine for now. 533 // 4 bytes per slot. 534 // X1 - source address 535 // W2 - args length 536 // X9 - destination address. 537 // W10 - temporary 538 add x9, sp, #8 // Destination address is bottom of stack + null. 539 540 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler 541 // does not have unique-id variables. 5421: 543 cmp w2, #0 544 beq 2f 545 sub w2, w2, #4 // Need 65536 bytes of range. 546 ldr w10, [x1, x2] 547 str w10, [x9, x2] 548 549 b 1b 550 5512: 552 // Store null into ArtMethod* at bottom of frame. 553 str xzr, [sp] 554.endm 555 556.macro INVOKE_STUB_CALL_AND_RETURN 557 558 // load method-> METHOD_QUICK_CODE_OFFSET 559 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64] 560 // Branch to method. 561 blr x9 562 563 // Restore return value address and shorty address. 564 ldp x4,x5, [xFP, #16] 565 .cfi_restore x4 566 .cfi_restore x5 567 568 ldr x28, [xFP, #112] 569 .cfi_restore x28 570 571 ldp x26, x27, [xFP, #96] 572 .cfi_restore x26 573 .cfi_restore x27 574 575 ldp x24, x25, [xFP, #80] 576 .cfi_restore x24 577 .cfi_restore x25 578 579 ldp x22, x23, [xFP, #64] 580 .cfi_restore x22 581 .cfi_restore x23 582 583 ldp x20, x21, [xFP, #48] 584 .cfi_restore x20 585 .cfi_restore x21 586 587 // Store result (w0/x0/s0/d0) appropriately, depending on resultType. 588 ldrb w10, [x5] 589 590 // Check the return type and store the correct register into the jvalue in memory. 591 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables. 592 593 // Don't set anything for a void type. 594 cmp w10, #'V' 595 beq 3f 596 597 // Is it a double? 598 cmp w10, #'D' 599 bne 1f 600 str d0, [x4] 601 b 3f 602 6031: // Is it a float? 604 cmp w10, #'F' 605 bne 2f 606 str s0, [x4] 607 b 3f 608 6092: // Just store x0. Doesn't matter if it is 64 or 32 bits. 610 str x0, [x4] 611 6123: // Finish up. 613 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19. 614 .cfi_restore x19 615 mov sp, x2 616 .cfi_restore sp 617 618 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register. 619 .cfi_restore x29 620 .cfi_restore x30 621 622 ret 623 624.endm 625 626 627/* 628 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0 629 * uint32_t *args, x1 630 * uint32_t argsize, w2 631 * Thread *self, x3 632 * JValue *result, x4 633 * char *shorty); x5 634 * +----------------------+ 635 * | | 636 * | C/C++ frame | 637 * | LR'' | 638 * | FP'' | <- SP' 639 * +----------------------+ 640 * +----------------------+ 641 * | x28 | <- TODO: Remove callee-saves. 642 * | : | 643 * | x19 | 644 * | SP' | 645 * | X5 | 646 * | X4 | Saved registers 647 * | LR' | 648 * | FP' | <- FP 649 * +----------------------+ 650 * | uint32_t out[n-1] | 651 * | : : | Outs 652 * | uint32_t out[0] | 653 * | ArtMethod* | <- SP value=null 654 * +----------------------+ 655 * 656 * Outgoing registers: 657 * x0 - Method* 658 * x1-x7 - integer parameters. 659 * d0-d7 - Floating point parameters. 660 * xSELF = self 661 * SP = & of ArtMethod* 662 * x1 = "this" pointer. 663 * 664 */ 665ENTRY art_quick_invoke_stub 666 // Spill registers as per AACPS64 calling convention. 667 INVOKE_STUB_CREATE_FRAME 668 669 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 670 // Parse the passed shorty to determine which register to load. 671 // Load addresses for routines that load WXSD registers. 672 adr x11, .LstoreW2 673 adr x12, .LstoreX2 674 adr x13, .LstoreS0 675 adr x14, .LstoreD0 676 677 // Initialize routine offsets to 0 for integers and floats. 678 // x8 for integers, x15 for floating point. 679 mov x8, #0 680 mov x15, #0 681 682 add x10, x5, #1 // Load shorty address, plus one to skip return value. 683 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer. 684 685 // Loop to fill registers. 686.LfillRegisters: 687 ldrb w17, [x10], #1 // Load next character in signature, and increment. 688 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated. 689 690 cmp w17, #'F' // is this a float? 691 bne .LisDouble 692 693 cmp x15, # 8*12 // Skip this load if all registers full. 694 beq .Ladvance4 695 696 add x17, x13, x15 // Calculate subroutine to jump to. 697 br x17 698 699.LisDouble: 700 cmp w17, #'D' // is this a double? 701 bne .LisLong 702 703 cmp x15, # 8*12 // Skip this load if all registers full. 704 beq .Ladvance8 705 706 add x17, x14, x15 // Calculate subroutine to jump to. 707 br x17 708 709.LisLong: 710 cmp w17, #'J' // is this a long? 711 bne .LisOther 712 713 cmp x8, # 6*12 // Skip this load if all registers full. 714 beq .Ladvance8 715 716 add x17, x12, x8 // Calculate subroutine to jump to. 717 br x17 718 719.LisOther: // Everything else takes one vReg. 720 cmp x8, # 6*12 // Skip this load if all registers full. 721 beq .Ladvance4 722 723 add x17, x11, x8 // Calculate subroutine to jump to. 724 br x17 725 726.Ladvance4: 727 add x9, x9, #4 728 b .LfillRegisters 729 730.Ladvance8: 731 add x9, x9, #8 732 b .LfillRegisters 733 734// Macro for loading a parameter into a register. 735// counter - the register with offset into these tables 736// size - the size of the register - 4 or 8 bytes. 737// register - the name of the register to be loaded. 738.macro LOADREG counter size register return 739 ldr \register , [x9], #\size 740 add \counter, \counter, 12 741 b \return 742.endm 743 744// Store ints. 745.LstoreW2: 746 LOADREG x8 4 w2 .LfillRegisters 747 LOADREG x8 4 w3 .LfillRegisters 748 LOADREG x8 4 w4 .LfillRegisters 749 LOADREG x8 4 w5 .LfillRegisters 750 LOADREG x8 4 w6 .LfillRegisters 751 LOADREG x8 4 w7 .LfillRegisters 752 753// Store longs. 754.LstoreX2: 755 LOADREG x8 8 x2 .LfillRegisters 756 LOADREG x8 8 x3 .LfillRegisters 757 LOADREG x8 8 x4 .LfillRegisters 758 LOADREG x8 8 x5 .LfillRegisters 759 LOADREG x8 8 x6 .LfillRegisters 760 LOADREG x8 8 x7 .LfillRegisters 761 762// Store singles. 763.LstoreS0: 764 LOADREG x15 4 s0 .LfillRegisters 765 LOADREG x15 4 s1 .LfillRegisters 766 LOADREG x15 4 s2 .LfillRegisters 767 LOADREG x15 4 s3 .LfillRegisters 768 LOADREG x15 4 s4 .LfillRegisters 769 LOADREG x15 4 s5 .LfillRegisters 770 LOADREG x15 4 s6 .LfillRegisters 771 LOADREG x15 4 s7 .LfillRegisters 772 773// Store doubles. 774.LstoreD0: 775 LOADREG x15 8 d0 .LfillRegisters 776 LOADREG x15 8 d1 .LfillRegisters 777 LOADREG x15 8 d2 .LfillRegisters 778 LOADREG x15 8 d3 .LfillRegisters 779 LOADREG x15 8 d4 .LfillRegisters 780 LOADREG x15 8 d5 .LfillRegisters 781 LOADREG x15 8 d6 .LfillRegisters 782 LOADREG x15 8 d7 .LfillRegisters 783 784 785.LcallFunction: 786 787 INVOKE_STUB_CALL_AND_RETURN 788 789END art_quick_invoke_stub 790 791/* extern"C" 792 * void art_quick_invoke_static_stub(ArtMethod *method, x0 793 * uint32_t *args, x1 794 * uint32_t argsize, w2 795 * Thread *self, x3 796 * JValue *result, x4 797 * char *shorty); x5 798 */ 799ENTRY art_quick_invoke_static_stub 800 // Spill registers as per AACPS64 calling convention. 801 INVOKE_STUB_CREATE_FRAME 802 803 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 804 // Parse the passed shorty to determine which register to load. 805 // Load addresses for routines that load WXSD registers. 806 adr x11, .LstoreW1_2 807 adr x12, .LstoreX1_2 808 adr x13, .LstoreS0_2 809 adr x14, .LstoreD0_2 810 811 // Initialize routine offsets to 0 for integers and floats. 812 // x8 for integers, x15 for floating point. 813 mov x8, #0 814 mov x15, #0 815 816 add x10, x5, #1 // Load shorty address, plus one to skip return value. 817 818 // Loop to fill registers. 819.LfillRegisters2: 820 ldrb w17, [x10], #1 // Load next character in signature, and increment. 821 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated. 822 823 cmp w17, #'F' // is this a float? 824 bne .LisDouble2 825 826 cmp x15, # 8*12 // Skip this load if all registers full. 827 beq .Ladvance4_2 828 829 add x17, x13, x15 // Calculate subroutine to jump to. 830 br x17 831 832.LisDouble2: 833 cmp w17, #'D' // is this a double? 834 bne .LisLong2 835 836 cmp x15, # 8*12 // Skip this load if all registers full. 837 beq .Ladvance8_2 838 839 add x17, x14, x15 // Calculate subroutine to jump to. 840 br x17 841 842.LisLong2: 843 cmp w17, #'J' // is this a long? 844 bne .LisOther2 845 846 cmp x8, # 7*12 // Skip this load if all registers full. 847 beq .Ladvance8_2 848 849 add x17, x12, x8 // Calculate subroutine to jump to. 850 br x17 851 852.LisOther2: // Everything else takes one vReg. 853 cmp x8, # 7*12 // Skip this load if all registers full. 854 beq .Ladvance4_2 855 856 add x17, x11, x8 // Calculate subroutine to jump to. 857 br x17 858 859.Ladvance4_2: 860 add x9, x9, #4 861 b .LfillRegisters2 862 863.Ladvance8_2: 864 add x9, x9, #8 865 b .LfillRegisters2 866 867// Store ints. 868.LstoreW1_2: 869 LOADREG x8 4 w1 .LfillRegisters2 870 LOADREG x8 4 w2 .LfillRegisters2 871 LOADREG x8 4 w3 .LfillRegisters2 872 LOADREG x8 4 w4 .LfillRegisters2 873 LOADREG x8 4 w5 .LfillRegisters2 874 LOADREG x8 4 w6 .LfillRegisters2 875 LOADREG x8 4 w7 .LfillRegisters2 876 877// Store longs. 878.LstoreX1_2: 879 LOADREG x8 8 x1 .LfillRegisters2 880 LOADREG x8 8 x2 .LfillRegisters2 881 LOADREG x8 8 x3 .LfillRegisters2 882 LOADREG x8 8 x4 .LfillRegisters2 883 LOADREG x8 8 x5 .LfillRegisters2 884 LOADREG x8 8 x6 .LfillRegisters2 885 LOADREG x8 8 x7 .LfillRegisters2 886 887// Store singles. 888.LstoreS0_2: 889 LOADREG x15 4 s0 .LfillRegisters2 890 LOADREG x15 4 s1 .LfillRegisters2 891 LOADREG x15 4 s2 .LfillRegisters2 892 LOADREG x15 4 s3 .LfillRegisters2 893 LOADREG x15 4 s4 .LfillRegisters2 894 LOADREG x15 4 s5 .LfillRegisters2 895 LOADREG x15 4 s6 .LfillRegisters2 896 LOADREG x15 4 s7 .LfillRegisters2 897 898// Store doubles. 899.LstoreD0_2: 900 LOADREG x15 8 d0 .LfillRegisters2 901 LOADREG x15 8 d1 .LfillRegisters2 902 LOADREG x15 8 d2 .LfillRegisters2 903 LOADREG x15 8 d3 .LfillRegisters2 904 LOADREG x15 8 d4 .LfillRegisters2 905 LOADREG x15 8 d5 .LfillRegisters2 906 LOADREG x15 8 d6 .LfillRegisters2 907 LOADREG x15 8 d7 .LfillRegisters2 908 909 910.LcallFunction2: 911 912 INVOKE_STUB_CALL_AND_RETURN 913 914END art_quick_invoke_static_stub 915 916 917 918 /* 919 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_ 920 */ 921 922ENTRY art_quick_do_long_jump 923 // Load FPRs 924 ldp d0, d1, [x1], #16 925 ldp d2, d3, [x1], #16 926 ldp d4, d5, [x1], #16 927 ldp d6, d7, [x1], #16 928 ldp d8, d9, [x1], #16 929 ldp d10, d11, [x1], #16 930 ldp d12, d13, [x1], #16 931 ldp d14, d15, [x1], #16 932 ldp d16, d17, [x1], #16 933 ldp d18, d19, [x1], #16 934 ldp d20, d21, [x1], #16 935 ldp d22, d23, [x1], #16 936 ldp d24, d25, [x1], #16 937 ldp d26, d27, [x1], #16 938 ldp d28, d29, [x1], #16 939 ldp d30, d31, [x1] 940 941 // Load GPRs 942 // TODO: lots of those are smashed, could optimize. 943 add x0, x0, #30*8 944 ldp x30, x1, [x0], #-16 // LR & SP 945 ldp x28, x29, [x0], #-16 946 ldp x26, x27, [x0], #-16 947 ldp x24, x25, [x0], #-16 948 ldp x22, x23, [x0], #-16 949 ldp x20, x21, [x0], #-16 950 ldp x18, x19, [x0], #-16 951 ldp x16, x17, [x0], #-16 952 ldp x14, x15, [x0], #-16 953 ldp x12, x13, [x0], #-16 954 ldp x10, x11, [x0], #-16 955 ldp x8, x9, [x0], #-16 956 ldp x6, x7, [x0], #-16 957 ldp x4, x5, [x0], #-16 958 ldp x2, x3, [x0], #-16 959 mov sp, x1 960 961 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1. 962 ldr x1, [x0, #33*8] 963 // And the value of x0. 964 ldr x0, [x0] 965 966 br x1 967END art_quick_do_long_jump 968 969 /* 970 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the 971 * possibly null object to lock. 972 * 973 * Derived from arm32 code. 974 */ 975 .extern artLockObjectFromCode 976ENTRY art_quick_lock_object 977 cbz w0, .Lslow_lock 978 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore 979.Lretry_lock: 980 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop? 981 ldxr w1, [x4] 982 mov x3, x1 983 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 984 cbnz w3, .Lnot_unlocked // already thin locked 985 // unlocked case - x1: original lock word that's zero except for the read barrier bits. 986 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits 987 stxr w3, w2, [x4] 988 cbnz w3, .Llock_stxr_fail // store failed, retry 989 dmb ishld // full (LoadLoad|LoadStore) memory barrier 990 ret 991.Lnot_unlocked: // x1: original lock word 992 lsr w3, w1, LOCK_WORD_STATE_SHIFT 993 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path 994 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() 995 uxth w2, w2 // zero top 16 bits 996 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock 997 // else contention, go to slow path 998 mov x3, x1 // copy the lock word to check count overflow. 999 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits. 1000 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow 1001 lsr w3, w2, LOCK_WORD_READ_BARRIER_STATE_SHIFT // if either of the upper two bits (28-29) are set, we overflowed. 1002 cbnz w3, .Lslow_lock // if we overflow the count go slow path 1003 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real 1004 stxr w3, w2, [x4] 1005 cbnz w3, .Llock_stxr_fail // store failed, retry 1006 ret 1007.Llock_stxr_fail: 1008 b .Lretry_lock // retry 1009.Lslow_lock: 1010 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block 1011 mov x1, xSELF // pass Thread::Current 1012 bl artLockObjectFromCode // (Object* obj, Thread*) 1013 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1014 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1015END art_quick_lock_object 1016 1017 /* 1018 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. 1019 * x0 holds the possibly null object to lock. 1020 * 1021 * Derived from arm32 code. 1022 */ 1023 .extern artUnlockObjectFromCode 1024ENTRY art_quick_unlock_object 1025 cbz x0, .Lslow_unlock 1026 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore 1027.Lretry_unlock: 1028#ifndef USE_READ_BARRIER 1029 ldr w1, [x4] 1030#else 1031 ldxr w1, [x4] // Need to use atomic instructions for read barrier 1032#endif 1033 lsr w2, w1, LOCK_WORD_STATE_SHIFT 1034 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path 1035 ldr w2, [xSELF, #THREAD_ID_OFFSET] 1036 mov x3, x1 // copy lock word to check thread id equality 1037 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 1038 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId() 1039 uxth w3, w3 // zero top 16 bits 1040 cbnz w3, .Lslow_unlock // do lock word and self thread id's match? 1041 mov x3, x1 // copy lock word to detect transition to unlocked 1042 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits 1043 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE 1044 bpl .Lrecursive_thin_unlock 1045 // transition to unlocked 1046 mov x3, x1 1047 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK // w3: zero except for the preserved read barrier bits 1048 dmb ish // full (LoadStore|StoreStore) memory barrier 1049#ifndef USE_READ_BARRIER 1050 str w3, [x4] 1051#else 1052 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier 1053 cbnz w2, .Lunlock_stxr_fail // store failed, retry 1054#endif 1055 ret 1056.Lrecursive_thin_unlock: // w1: original lock word 1057 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count 1058#ifndef USE_READ_BARRIER 1059 str w1, [x4] 1060#else 1061 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier 1062 cbnz w2, .Lunlock_stxr_fail // store failed, retry 1063#endif 1064 ret 1065.Lunlock_stxr_fail: 1066 b .Lretry_unlock // retry 1067.Lslow_unlock: 1068 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC 1069 mov x1, xSELF // pass Thread::Current 1070 bl artUnlockObjectFromCode // (Object* obj, Thread*) 1071 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1072 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1073END art_quick_unlock_object 1074 1075 /* 1076 * Entry from managed code that calls artIsAssignableFromCode and on failure calls 1077 * artThrowClassCastException. 1078 */ 1079 .extern artThrowClassCastException 1080ENTRY art_quick_check_cast 1081 // Store arguments and link register 1082 // Stack needs to be 16B aligned on calls. 1083 stp x0, x1, [sp,#-32]! 1084 .cfi_adjust_cfa_offset 32 1085 .cfi_rel_offset x0, 0 1086 .cfi_rel_offset x1, 8 1087 str xLR, [sp, #24] 1088 .cfi_rel_offset x30, 24 1089 1090 // Call runtime code 1091 bl artIsAssignableFromCode 1092 1093 // Check for exception 1094 cbz x0, .Lthrow_class_cast_exception 1095 1096 // Restore and return 1097 ldr xLR, [sp, #24] 1098 .cfi_restore x30 1099 ldp x0, x1, [sp], #32 1100 .cfi_restore x0 1101 .cfi_restore x1 1102 .cfi_adjust_cfa_offset -32 1103 ret 1104 1105 .cfi_adjust_cfa_offset 32 // Reset unwind info so following code unwinds. 1106 1107.Lthrow_class_cast_exception: 1108 // Restore 1109 ldr xLR, [sp, #24] 1110 .cfi_restore x30 1111 ldp x0, x1, [sp], #32 1112 .cfi_restore x0 1113 .cfi_restore x1 1114 .cfi_adjust_cfa_offset -32 1115 1116 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 1117 mov x2, xSELF // pass Thread::Current 1118 b artThrowClassCastException // (Class*, Class*, Thread*) 1119 brk 0 // We should not return here... 1120END art_quick_check_cast 1121 1122// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude. 1123.macro POP_REG_NE xReg, offset, xExclude 1124 .ifnc \xReg, \xExclude 1125 ldr \xReg, [sp, #\offset] // restore xReg 1126 .cfi_restore \xReg 1127 .endif 1128.endm 1129 1130 /* 1131 * Macro to insert read barrier, only used in art_quick_aput_obj. 1132 * xDest, wDest and xObj are registers, offset is a defined literal such as 1133 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle 1134 * name mismatch between instructions. This macro uses the lower 32b of register when possible. 1135 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path. 1136 */ 1137.macro READ_BARRIER xDest, wDest, xObj, offset 1138#ifdef USE_READ_BARRIER 1139 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned. 1140 stp x0, x1, [sp, #-48]! 1141 .cfi_adjust_cfa_offset 48 1142 .cfi_rel_offset x0, 0 1143 .cfi_rel_offset x1, 8 1144 stp x2, x3, [sp, #16] 1145 .cfi_rel_offset x2, 16 1146 .cfi_rel_offset x3, 24 1147 stp x4, xLR, [sp, #32] 1148 .cfi_rel_offset x4, 32 1149 .cfi_rel_offset x30, 40 1150 1151 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused) 1152 .ifnc \xObj, x1 1153 mov x1, \xObj // pass xObj 1154 .endif 1155 mov w2, #\offset // pass offset 1156 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset) 1157 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning. 1158 .ifnc \wDest, w0 1159 mov \wDest, w0 // save return value in wDest 1160 .endif 1161 1162 // Conditionally restore saved registers 1163 POP_REG_NE x0, 0, \xDest 1164 POP_REG_NE x1, 8, \xDest 1165 POP_REG_NE x2, 16, \xDest 1166 POP_REG_NE x3, 24, \xDest 1167 POP_REG_NE x4, 32, \xDest 1168 ldr xLR, [sp, #40] 1169 .cfi_restore x30 1170 add sp, sp, #48 1171 .cfi_adjust_cfa_offset -48 1172#else 1173 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest. 1174 UNPOISON_HEAP_REF \wDest 1175#endif // USE_READ_BARRIER 1176.endm 1177 1178 /* 1179 * Entry from managed code for array put operations of objects where the value being stored 1180 * needs to be checked for compatibility. 1181 * x0 = array, x1 = index, x2 = value 1182 * 1183 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We 1184 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by 1185 * using index-zero-extension in load/stores. 1186 * 1187 * Temporaries: x3, x4 1188 * TODO: x4 OK? ip seems wrong here. 1189 */ 1190ENTRY art_quick_aput_obj_with_null_and_bound_check 1191 tst x0, x0 1192 bne art_quick_aput_obj_with_bound_check 1193 b art_quick_throw_null_pointer_exception 1194END art_quick_aput_obj_with_null_and_bound_check 1195 1196ENTRY art_quick_aput_obj_with_bound_check 1197 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] 1198 cmp w3, w1 1199 bhi art_quick_aput_obj 1200 mov x0, x1 1201 mov x1, x3 1202 b art_quick_throw_array_bounds 1203END art_quick_aput_obj_with_bound_check 1204 1205#ifdef USE_READ_BARRIER 1206 .extern artReadBarrierSlow 1207#endif 1208ENTRY art_quick_aput_obj 1209 cbz x2, .Ldo_aput_null 1210 READ_BARRIER x3, w3, x0, MIRROR_OBJECT_CLASS_OFFSET // Heap reference = 32b 1211 // This also zero-extends to x3 1212 READ_BARRIER x4, w4, x2, MIRROR_OBJECT_CLASS_OFFSET // Heap reference = 32b 1213 // This also zero-extends to x4 1214 READ_BARRIER x3, w3, x3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET // Heap reference = 32b 1215 // This also zero-extends to x3 1216 cmp w3, w4 // value's type == array's component type - trivial assignability 1217 bne .Lcheck_assignability 1218.Ldo_aput: 1219 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1220 // "Compress" = do nothing 1221 POISON_HEAP_REF w2 1222 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1223 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1224 lsr x0, x0, #7 1225 strb w3, [x3, x0] 1226 ret 1227.Ldo_aput_null: 1228 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1229 // "Compress" = do nothing 1230 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1231 ret 1232.Lcheck_assignability: 1233 // Store arguments and link register 1234 stp x0, x1, [sp,#-32]! 1235 .cfi_adjust_cfa_offset 32 1236 .cfi_rel_offset x0, 0 1237 .cfi_rel_offset x1, 8 1238 stp x2, xLR, [sp, #16] 1239 .cfi_rel_offset x2, 16 1240 .cfi_rel_offset x30, 24 1241 1242 // Call runtime code 1243 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1244 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1245 bl artIsAssignableFromCode 1246 1247 // Check for exception 1248 cbz x0, .Lthrow_array_store_exception 1249 1250 // Restore 1251 ldp x2, x30, [sp, #16] 1252 .cfi_restore x2 1253 .cfi_restore x30 1254 ldp x0, x1, [sp], #32 1255 .cfi_restore x0 1256 .cfi_restore x1 1257 .cfi_adjust_cfa_offset -32 1258 1259 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET 1260 // "Compress" = do nothing 1261 POISON_HEAP_REF w2 1262 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1263 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1264 lsr x0, x0, #7 1265 strb w3, [x3, x0] 1266 ret 1267 .cfi_adjust_cfa_offset 32 // 4 restores after cbz for unwinding. 1268.Lthrow_array_store_exception: 1269 ldp x2, x30, [sp, #16] 1270 .cfi_restore x2 1271 .cfi_restore x30 1272 ldp x0, x1, [sp], #32 1273 .cfi_restore x0 1274 .cfi_restore x1 1275 .cfi_adjust_cfa_offset -32 1276 1277 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1278 mov x1, x2 // Pass value. 1279 mov x2, xSELF // Pass Thread::Current. 1280 b artThrowArrayStoreException // (Object*, Object*, Thread*). 1281 brk 0 // Unreached. 1282END art_quick_aput_obj 1283 1284// Macro to facilitate adding new allocation entrypoints. 1285.macro ONE_ARG_DOWNCALL name, entrypoint, return 1286 .extern \entrypoint 1287ENTRY \name 1288 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1289 mov x1, xSELF // pass Thread::Current 1290 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) 1291 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1292 \return 1293END \name 1294.endm 1295 1296// Macro to facilitate adding new allocation entrypoints. 1297.macro TWO_ARG_DOWNCALL name, entrypoint, return 1298 .extern \entrypoint 1299ENTRY \name 1300 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1301 mov x2, xSELF // pass Thread::Current 1302 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) 1303 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1304 \return 1305END \name 1306.endm 1307 1308// Macro to facilitate adding new allocation entrypoints. 1309.macro THREE_ARG_DOWNCALL name, entrypoint, return 1310 .extern \entrypoint 1311ENTRY \name 1312 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1313 mov x3, xSELF // pass Thread::Current 1314 bl \entrypoint 1315 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1316 \return 1317END \name 1318.endm 1319 1320// Macro to facilitate adding new allocation entrypoints. 1321.macro FOUR_ARG_DOWNCALL name, entrypoint, return 1322 .extern \entrypoint 1323ENTRY \name 1324 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1325 mov x4, xSELF // pass Thread::Current 1326 bl \entrypoint // 1327 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1328 \return 1329 DELIVER_PENDING_EXCEPTION 1330END \name 1331.endm 1332 1333// Macros taking opportunity of code similarities for downcalls with referrer. 1334.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return 1335 .extern \entrypoint 1336ENTRY \name 1337 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1338 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1339 mov x2, xSELF // pass Thread::Current 1340 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) 1341 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1342 \return 1343END \name 1344.endm 1345 1346.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return 1347 .extern \entrypoint 1348ENTRY \name 1349 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1350 ldr x2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1351 mov x3, xSELF // pass Thread::Current 1352 bl \entrypoint 1353 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1354 \return 1355END \name 1356.endm 1357 1358.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return 1359 .extern \entrypoint 1360ENTRY \name 1361 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1362 ldr x3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1363 mov x4, xSELF // pass Thread::Current 1364 bl \entrypoint 1365 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1366 \return 1367END \name 1368.endm 1369 1370.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1371 cbz w0, 1f // result zero branch over 1372 ret // return 13731: 1374 DELIVER_PENDING_EXCEPTION 1375.endm 1376 1377 /* 1378 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on 1379 * failure. 1380 */ 1381TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1382 1383 /* 1384 * Entry from managed code when uninitialized static storage, this stub will run the class 1385 * initializer and deliver the exception on error. On success the static storage base is 1386 * returned. 1387 */ 1388ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1389 1390ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1391ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1392 1393ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1394ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1395ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1396ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1397ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1398ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1399ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1400 1401TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1402TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1403TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1404TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1405TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1406TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1407TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1408 1409TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1410TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1411TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1412TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1413 1414THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1415THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1416THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1417THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1418THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1419 1420// This is separated out as the argument order is different. 1421 .extern artSet64StaticFromCode 1422ENTRY art_quick_set64_static 1423 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1424 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1425 // x2 contains the parameter 1426 mov x3, xSELF // pass Thread::Current 1427 bl artSet64StaticFromCode 1428 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 1429 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1430END art_quick_set64_static 1431 1432 /* 1433 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an 1434 * exception on error. On success the String is returned. w0 holds the string index. The fast 1435 * path check for hit in strings cache has already been performed. 1436 */ 1437ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1438 1439// Generate the allocation entrypoints for each allocator. 1440GENERATE_ALL_ALLOC_ENTRYPOINTS 1441 1442 /* 1443 * Called by managed code when the thread has been asked to suspend. 1444 */ 1445 .extern artTestSuspendFromCode 1446ENTRY art_quick_test_suspend 1447 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags 1448 cbnz w0, .Lneed_suspend // check flags == 0 1449 ret // return if flags == 0 1450.Lneed_suspend: 1451 mov x0, xSELF 1452 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl 1453 bl artTestSuspendFromCode // (Thread*) 1454 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1455END art_quick_test_suspend 1456 1457ENTRY art_quick_implicit_suspend 1458 mov x0, xSELF 1459 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl 1460 bl artTestSuspendFromCode // (Thread*) 1461 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1462END art_quick_implicit_suspend 1463 1464 /* 1465 * Called by managed code that is attempting to call a method on a proxy class. On entry 1466 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy 1467 * method agrees with a ref and args callee save frame. 1468 */ 1469 .extern artQuickProxyInvokeHandler 1470ENTRY art_quick_proxy_invoke_handler 1471 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 1472 mov x2, xSELF // pass Thread::Current 1473 mov x3, sp // pass SP 1474 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP) 1475 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] 1476 cbnz x2, .Lexception_in_proxy // success if no exception is pending 1477 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame 1478 fmov d0, x0 // Store result in d0 in case it was float or double 1479 ret // return on success 1480.Lexception_in_proxy: 1481 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1482 DELIVER_PENDING_EXCEPTION 1483END art_quick_proxy_invoke_handler 1484 1485 /* 1486 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's 1487 * dex method index. 1488 */ 1489 .extern artInvokeInterfaceTrampoline 1490ENTRY art_quick_imt_conflict_trampoline 1491 mov x0, xIP1 1492 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline 1493END art_quick_imt_conflict_trampoline 1494 1495ENTRY art_quick_resolution_trampoline 1496 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1497 mov x2, xSELF 1498 mov x3, sp 1499 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP) 1500 cbz x0, 1f 1501 mov xIP0, x0 // Remember returned code pointer in xIP0. 1502 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP. 1503 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1504 br xIP0 15051: 1506 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1507 DELIVER_PENDING_EXCEPTION 1508END art_quick_resolution_trampoline 1509 1510/* 1511 * Generic JNI frame layout: 1512 * 1513 * #-------------------# 1514 * | | 1515 * | caller method... | 1516 * #-------------------# <--- SP on entry 1517 * | Return X30/LR | 1518 * | X29/FP | callee save 1519 * | X28 | callee save 1520 * | X27 | callee save 1521 * | X26 | callee save 1522 * | X25 | callee save 1523 * | X24 | callee save 1524 * | X23 | callee save 1525 * | X22 | callee save 1526 * | X21 | callee save 1527 * | X20 | callee save 1528 * | X19 | callee save 1529 * | X7 | arg7 1530 * | X6 | arg6 1531 * | X5 | arg5 1532 * | X4 | arg4 1533 * | X3 | arg3 1534 * | X2 | arg2 1535 * | X1 | arg1 1536 * | D7 | float arg 8 1537 * | D6 | float arg 7 1538 * | D5 | float arg 6 1539 * | D4 | float arg 5 1540 * | D3 | float arg 4 1541 * | D2 | float arg 3 1542 * | D1 | float arg 2 1543 * | D0 | float arg 1 1544 * | Method* | <- X0 1545 * #-------------------# 1546 * | local ref cookie | // 4B 1547 * | handle scope size | // 4B 1548 * #-------------------# 1549 * | JNI Call Stack | 1550 * #-------------------# <--- SP on native call 1551 * | | 1552 * | Stack for Regs | The trampoline assembly will pop these values 1553 * | | into registers for native call 1554 * #-------------------# 1555 * | Native code ptr | 1556 * #-------------------# 1557 * | Free scratch | 1558 * #-------------------# 1559 * | Ptr to (1) | <--- SP 1560 * #-------------------# 1561 */ 1562 /* 1563 * Called to do a generic JNI down-call 1564 */ 1565ENTRY art_quick_generic_jni_trampoline 1566 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0 1567 1568 // Save SP , so we can have static CFI info. 1569 mov x28, sp 1570 .cfi_def_cfa_register x28 1571 1572 // This looks the same, but is different: this will be updated to point to the bottom 1573 // of the frame when the handle scope is inserted. 1574 mov xFP, sp 1575 1576 mov xIP0, #5120 1577 sub sp, sp, xIP0 1578 1579 // prepare for artQuickGenericJniTrampoline call 1580 // (Thread*, SP) 1581 // x0 x1 <= C calling convention 1582 // xSELF xFP <= where they are 1583 1584 mov x0, xSELF // Thread* 1585 mov x1, xFP 1586 bl artQuickGenericJniTrampoline // (Thread*, sp) 1587 1588 // The C call will have registered the complete save-frame on success. 1589 // The result of the call is: 1590 // x0: pointer to native code, 0 on error. 1591 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there. 1592 1593 // Check for error = 0. 1594 cbz x0, .Lexception_in_native 1595 1596 // Release part of the alloca. 1597 mov sp, x1 1598 1599 // Save the code pointer 1600 mov xIP0, x0 1601 1602 // Load parameters from frame into registers. 1603 // TODO Check with artQuickGenericJniTrampoline. 1604 // Also, check again APPCS64 - the stack arguments are interleaved. 1605 ldp x0, x1, [sp] 1606 ldp x2, x3, [sp, #16] 1607 ldp x4, x5, [sp, #32] 1608 ldp x6, x7, [sp, #48] 1609 1610 ldp d0, d1, [sp, #64] 1611 ldp d2, d3, [sp, #80] 1612 ldp d4, d5, [sp, #96] 1613 ldp d6, d7, [sp, #112] 1614 1615 add sp, sp, #128 1616 1617 blr xIP0 // native call. 1618 1619 // result sign extension is handled in C code 1620 // prepare for artQuickGenericJniEndTrampoline call 1621 // (Thread*, result, result_f) 1622 // x0 x1 x2 <= C calling convention 1623 mov x1, x0 // Result (from saved). 1624 mov x0, xSELF // Thread register. 1625 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2 1626 1627 bl artQuickGenericJniEndTrampoline 1628 1629 // Pending exceptions possible. 1630 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] 1631 cbnz x2, .Lexception_in_native 1632 1633 // Tear down the alloca. 1634 mov sp, x28 1635 .cfi_def_cfa_register sp 1636 1637 // Tear down the callee-save frame. 1638 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1639 1640 // store into fpr, for when it's a fpr return... 1641 fmov d0, x0 1642 ret 1643 1644.Lexception_in_native: 1645 // Move to x1 then sp to please assembler. 1646 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] 1647 mov sp, x1 1648 .cfi_def_cfa_register sp 1649 # This will create a new save-all frame, required by the runtime. 1650 DELIVER_PENDING_EXCEPTION 1651END art_quick_generic_jni_trampoline 1652 1653/* 1654 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those 1655 * of a quick call: 1656 * x0 = method being called/to bridge to. 1657 * x1..x7, d0..d7 = arguments to that method. 1658 */ 1659ENTRY art_quick_to_interpreter_bridge 1660 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments. 1661 1662 // x0 will contain mirror::ArtMethod* method. 1663 mov x1, xSELF // How to get Thread::Current() ??? 1664 mov x2, sp 1665 1666 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self, 1667 // mirror::ArtMethod** sp) 1668 bl artQuickToInterpreterBridge 1669 1670 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case. 1671 1672 fmov d0, x0 1673 1674 RETURN_OR_DELIVER_PENDING_EXCEPTION 1675END art_quick_to_interpreter_bridge 1676 1677 1678// 1679// Instrumentation-related stubs 1680// 1681 .extern artInstrumentationMethodEntryFromCode 1682ENTRY art_quick_instrumentation_entry 1683 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1684 1685 mov x20, x0 // Preserve method reference in a callee-save. 1686 1687 mov x2, xSELF 1688 mov x3, xLR 1689 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR) 1690 1691 mov xIP0, x0 // x0 = result of call. 1692 mov x0, x20 // Reload method reference. 1693 1694 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF 1695 adr xLR, art_quick_instrumentation_exit 1696 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit. 1697END art_quick_instrumentation_entry 1698 1699 .extern artInstrumentationMethodExitFromCode 1700ENTRY art_quick_instrumentation_exit 1701 mov xLR, #0 // Clobber LR for later checks. 1702 1703 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 1704 1705 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then 1706 // we would need to fully restore it. As there are a lot of callee-save registers, it seems 1707 // easier to have an extra small stack area. 1708 1709 str x0, [sp, #-16]! // Save integer result. 1710 .cfi_adjust_cfa_offset 16 1711 str d0, [sp, #8] // Save floating-point result. 1712 1713 add x1, sp, #16 // Pass SP. 1714 mov x2, x0 // Pass integer result. 1715 fmov x3, d0 // Pass floating-point result. 1716 mov x0, xSELF // Pass Thread. 1717 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res) 1718 1719 mov xIP0, x0 // Return address from instrumentation call. 1720 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize 1721 1722 ldr d0, [sp, #8] // Restore floating-point result. 1723 ldr x0, [sp], 16 // Restore integer result, and drop stack area. 1724 .cfi_adjust_cfa_offset 16 1725 1726 POP_REFS_ONLY_CALLEE_SAVE_FRAME 1727 1728 br xIP0 // Tail-call out. 1729END art_quick_instrumentation_exit 1730 1731 /* 1732 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization 1733 * will long jump to the upcall with a special exception of -1. 1734 */ 1735 .extern artDeoptimize 1736ENTRY art_quick_deoptimize 1737 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1738 mov x0, xSELF // Pass thread. 1739 bl artDeoptimize // artDeoptimize(Thread*) 1740 brk 0 1741END art_quick_deoptimize 1742 1743 /* 1744 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization 1745 * will long jump to the upcall with a special exception of -1. 1746 */ 1747 .extern artDeoptimizeFromCompiledCode 1748ENTRY art_quick_deoptimize_from_compiled_code 1749 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1750 mov x0, xSELF // Pass thread. 1751 bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*) 1752 brk 0 1753END art_quick_deoptimize_from_compiled_code 1754 1755 1756 /* 1757 * String's indexOf. 1758 * 1759 * TODO: Not very optimized. 1760 * On entry: 1761 * x0: string object (known non-null) 1762 * w1: char to match (known <= 0xFFFF) 1763 * w2: Starting offset in string data 1764 */ 1765ENTRY art_quick_indexof 1766 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET] 1767 add x0, x0, #MIRROR_STRING_VALUE_OFFSET 1768 1769 /* Clamp start to [0..count] */ 1770 cmp w2, #0 1771 csel w2, wzr, w2, lt 1772 cmp w2, w3 1773 csel w2, w3, w2, gt 1774 1775 /* Save a copy to compute result */ 1776 mov x5, x0 1777 1778 /* Build pointer to start of data to compare and pre-bias */ 1779 add x0, x0, x2, lsl #1 1780 sub x0, x0, #2 1781 1782 /* Compute iteration count */ 1783 sub w2, w3, w2 1784 1785 /* 1786 * At this point we have: 1787 * x0: start of the data to test 1788 * w1: char to compare 1789 * w2: iteration count 1790 * x5: original start of string data 1791 */ 1792 1793 subs w2, w2, #4 1794 b.lt .Lindexof_remainder 1795 1796.Lindexof_loop4: 1797 ldrh w6, [x0, #2]! 1798 ldrh w7, [x0, #2]! 1799 ldrh wIP0, [x0, #2]! 1800 ldrh wIP1, [x0, #2]! 1801 cmp w6, w1 1802 b.eq .Lmatch_0 1803 cmp w7, w1 1804 b.eq .Lmatch_1 1805 cmp wIP0, w1 1806 b.eq .Lmatch_2 1807 cmp wIP1, w1 1808 b.eq .Lmatch_3 1809 subs w2, w2, #4 1810 b.ge .Lindexof_loop4 1811 1812.Lindexof_remainder: 1813 adds w2, w2, #4 1814 b.eq .Lindexof_nomatch 1815 1816.Lindexof_loop1: 1817 ldrh w6, [x0, #2]! 1818 cmp w6, w1 1819 b.eq .Lmatch_3 1820 subs w2, w2, #1 1821 b.ne .Lindexof_loop1 1822 1823.Lindexof_nomatch: 1824 mov x0, #-1 1825 ret 1826 1827.Lmatch_0: 1828 sub x0, x0, #6 1829 sub x0, x0, x5 1830 asr x0, x0, #1 1831 ret 1832.Lmatch_1: 1833 sub x0, x0, #4 1834 sub x0, x0, x5 1835 asr x0, x0, #1 1836 ret 1837.Lmatch_2: 1838 sub x0, x0, #2 1839 sub x0, x0, x5 1840 asr x0, x0, #1 1841 ret 1842.Lmatch_3: 1843 sub x0, x0, x5 1844 asr x0, x0, #1 1845 ret 1846END art_quick_indexof 1847 1848 /* 1849 * String's compareTo. 1850 * 1851 * TODO: Not very optimized. 1852 * 1853 * On entry: 1854 * x0: this object pointer 1855 * x1: comp object pointer 1856 * 1857 */ 1858 .extern __memcmp16 1859ENTRY art_quick_string_compareto 1860 mov x2, x0 // x0 is return, use x2 for first input. 1861 sub x0, x2, x1 // Same string object? 1862 cbnz x0,1f 1863 ret 18641: // Different string objects. 1865 1866 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET] 1867 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET] 1868 add x2, x2, #MIRROR_STRING_VALUE_OFFSET 1869 add x1, x1, #MIRROR_STRING_VALUE_OFFSET 1870 1871 /* 1872 * Now: Data* Count 1873 * first arg x2 w4 1874 * second arg x1 w3 1875 */ 1876 1877 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4. 1878 subs x0, x4, x3 1879 // Min(count1, count2) into w3. 1880 csel x3, x3, x4, ge 1881 1882 // TODO: Tune this value. 1883 // Check for long string, do memcmp16 for them. 1884 cmp w3, #28 // Constant from arm32. 1885 bgt .Ldo_memcmp16 1886 1887 /* 1888 * Now: 1889 * x2: *first string data 1890 * x1: *second string data 1891 * w3: iteration count 1892 * x0: return value if comparison equal 1893 * x4, x5, x6, x7: free 1894 */ 1895 1896 // Do a simple unrolled loop. 1897.Lloop: 1898 // At least two more elements? 1899 subs w3, w3, #2 1900 b.lt .Lremainder_or_done 1901 1902 ldrh w4, [x2], #2 1903 ldrh w5, [x1], #2 1904 1905 ldrh w6, [x2], #2 1906 ldrh w7, [x1], #2 1907 1908 subs w4, w4, w5 1909 b.ne .Lw4_result 1910 1911 subs w6, w6, w7 1912 b.ne .Lw6_result 1913 1914 b .Lloop 1915 1916.Lremainder_or_done: 1917 adds w3, w3, #1 1918 b.eq .Lremainder 1919 ret 1920 1921.Lremainder: 1922 ldrh w4, [x2], #2 1923 ldrh w5, [x1], #2 1924 subs w4, w4, w5 1925 b.ne .Lw4_result 1926 ret 1927 1928// Result is in w4 1929.Lw4_result: 1930 sxtw x0, w4 1931 ret 1932 1933// Result is in w6 1934.Lw6_result: 1935 sxtw x0, w6 1936 ret 1937 1938.Ldo_memcmp16: 1939 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps. 1940 mov x15, xLR // TODO: Codify and check that? 1941 1942 mov x0, x2 1943 uxtw x2, w3 1944 bl __memcmp16 1945 1946 mov xLR, x15 // Restore LR. 1947 1948 cmp x0, #0 // Check the memcmp difference. 1949 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1. 1950 ret 1951END art_quick_string_compareto 1952