1 /* 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.hpp" 28 #include "gc/shared/barrierSetAssembler.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterRuntime.hpp" 31 #include "interpreter/interp_masm.hpp" 32 #include "interpreter/templateTable.hpp" 33 #include "memory/universe.hpp" 34 #include "oops/methodData.hpp" 35 #include "oops/method.hpp" 36 #include "oops/objArrayKlass.hpp" 37 #include "oops/oop.inline.hpp" 38 #include "prims/methodHandles.hpp" 39 #include "runtime/frame.inline.hpp" 40 #include "runtime/sharedRuntime.hpp" 41 #include "runtime/stubRoutines.hpp" 42 #include "runtime/synchronizer.hpp" 43 44 #define __ _masm-> 45 46 // Platform-dependent initialization 47 48 void TemplateTable::pd_initialize() { 49 // No aarch64 specific initialization 50 } 51 52 // Address computation: local variables 53 54 static inline Address iaddress(int n) { 55 return Address(rlocals, Interpreter::local_offset_in_bytes(n)); 56 } 57 58 static inline Address laddress(int n) { 59 return iaddress(n + 1); 60 } 61 62 static inline Address faddress(int n) { 63 return iaddress(n); 64 } 65 66 static inline Address daddress(int n) { 67 return laddress(n); 68 } 69 70 static inline Address aaddress(int n) { 71 return iaddress(n); 72 } 73 74 static inline Address iaddress(Register r) { 75 return Address(rlocals, r, Address::lsl(3)); 76 } 77 78 static inline Address laddress(Register r, Register scratch, 79 InterpreterMacroAssembler* _masm) { 80 __ lea(scratch, Address(rlocals, r, Address::lsl(3))); 81 return Address(scratch, Interpreter::local_offset_in_bytes(1)); 82 } 83 84 static inline Address faddress(Register r) { 85 return iaddress(r); 86 } 87 88 static inline Address daddress(Register r, Register scratch, 89 InterpreterMacroAssembler* _masm) { 90 return laddress(r, scratch, _masm); 91 } 92 93 static inline Address aaddress(Register r) { 94 return iaddress(r); 95 } 96 97 static inline Address at_rsp() { 98 return Address(esp, 0); 99 } 100 101 // At top of Java expression stack which may be different than esp(). It 102 // isn't for category 1 objects. 103 static inline Address at_tos () { 104 return Address(esp, Interpreter::expr_offset_in_bytes(0)); 105 } 106 107 static inline Address at_tos_p1() { 108 return Address(esp, Interpreter::expr_offset_in_bytes(1)); 109 } 110 111 static inline Address at_tos_p2() { 112 return Address(esp, Interpreter::expr_offset_in_bytes(2)); 113 } 114 115 static inline Address at_tos_p3() { 116 return Address(esp, Interpreter::expr_offset_in_bytes(3)); 117 } 118 119 static inline Address at_tos_p4() { 120 return Address(esp, Interpreter::expr_offset_in_bytes(4)); 121 } 122 123 static inline Address at_tos_p5() { 124 return Address(esp, Interpreter::expr_offset_in_bytes(5)); 125 } 126 127 // Condition conversion 128 static Assembler::Condition j_not(TemplateTable::Condition cc) { 129 switch (cc) { 130 case TemplateTable::equal : return Assembler::NE; 131 case TemplateTable::not_equal : return Assembler::EQ; 132 case TemplateTable::less : return Assembler::GE; 133 case TemplateTable::less_equal : return Assembler::GT; 134 case TemplateTable::greater : return Assembler::LE; 135 case TemplateTable::greater_equal: return Assembler::LT; 136 } 137 ShouldNotReachHere(); 138 return Assembler::EQ; 139 } 140 141 142 // Miscelaneous helper routines 143 // Store an oop (or NULL) at the Address described by obj. 144 // If val == noreg this means store a NULL 145 static void do_oop_store(InterpreterMacroAssembler* _masm, 146 Address dst, 147 Register val, 148 DecoratorSet decorators) { 149 assert(val == noreg || val == r0, "parameter is just for looks"); 150 BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler(); 151 bs->store_at(_masm, decorators, T_OBJECT, dst, val, /*tmp1*/ r10, /*tmp2*/ r1); 152 } 153 154 static void do_oop_load(InterpreterMacroAssembler* _masm, 155 Address src, 156 Register dst, 157 DecoratorSet decorators) { 158 BarrierSetAssembler *bs = BarrierSet::barrier_set()->barrier_set_assembler(); 159 bs->load_at(_masm, decorators, T_OBJECT, dst, src, /*tmp1*/ r10, /*tmp_thread*/ r1); 160 } 161 162 Address TemplateTable::at_bcp(int offset) { 163 assert(_desc->uses_bcp(), "inconsistent uses_bcp information"); 164 return Address(rbcp, offset); 165 } 166 167 void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg, 168 Register temp_reg, bool load_bc_into_bc_reg/*=true*/, 169 int byte_no) 170 { 171 if (!RewriteBytecodes) return; 172 Label L_patch_done; 173 174 switch (bc) { 175 case Bytecodes::_fast_aputfield: 176 case Bytecodes::_fast_bputfield: 177 case Bytecodes::_fast_zputfield: 178 case Bytecodes::_fast_cputfield: 179 case Bytecodes::_fast_dputfield: 180 case Bytecodes::_fast_fputfield: 181 case Bytecodes::_fast_iputfield: 182 case Bytecodes::_fast_lputfield: 183 case Bytecodes::_fast_sputfield: 184 { 185 // We skip bytecode quickening for putfield instructions when 186 // the put_code written to the constant pool cache is zero. 187 // This is required so that every execution of this instruction 188 // calls out to InterpreterRuntime::resolve_get_put to do 189 // additional, required work. 190 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 191 assert(load_bc_into_bc_reg, "we use bc_reg as temp"); 192 __ get_cache_and_index_and_bytecode_at_bcp(temp_reg, bc_reg, temp_reg, byte_no, 1); 193 __ movw(bc_reg, bc); 194 __ cbzw(temp_reg, L_patch_done); // don't patch 195 } 196 break; 197 default: 198 assert(byte_no == -1, "sanity"); 199 // the pair bytecodes have already done the load. 200 if (load_bc_into_bc_reg) { 201 __ movw(bc_reg, bc); 202 } 203 } 204 205 if (JvmtiExport::can_post_breakpoint()) { 206 Label L_fast_patch; 207 // if a breakpoint is present we can't rewrite the stream directly 208 __ load_unsigned_byte(temp_reg, at_bcp(0)); 209 __ cmpw(temp_reg, Bytecodes::_breakpoint); 210 __ br(Assembler::NE, L_fast_patch); 211 // Let breakpoint table handling rewrite to quicker bytecode 212 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), rmethod, rbcp, bc_reg); 213 __ b(L_patch_done); 214 __ bind(L_fast_patch); 215 } 216 217 #ifdef ASSERT 218 Label L_okay; 219 __ load_unsigned_byte(temp_reg, at_bcp(0)); 220 __ cmpw(temp_reg, (int) Bytecodes::java_code(bc)); 221 __ br(Assembler::EQ, L_okay); 222 __ cmpw(temp_reg, bc_reg); 223 __ br(Assembler::EQ, L_okay); 224 __ stop("patching the wrong bytecode"); 225 __ bind(L_okay); 226 #endif 227 228 // patch bytecode 229 __ strb(bc_reg, at_bcp(0)); 230 __ bind(L_patch_done); 231 } 232 233 234 // Individual instructions 235 236 void TemplateTable::nop() { 237 transition(vtos, vtos); 238 // nothing to do 239 } 240 241 void TemplateTable::shouldnotreachhere() { 242 transition(vtos, vtos); 243 __ stop("shouldnotreachhere bytecode"); 244 } 245 246 void TemplateTable::aconst_null() 247 { 248 transition(vtos, atos); 249 __ mov(r0, 0); 250 } 251 252 void TemplateTable::iconst(int value) 253 { 254 transition(vtos, itos); 255 __ mov(r0, value); 256 } 257 258 void TemplateTable::lconst(int value) 259 { 260 __ mov(r0, value); 261 } 262 263 void TemplateTable::fconst(int value) 264 { 265 transition(vtos, ftos); 266 switch (value) { 267 case 0: 268 __ fmovs(v0, zr); 269 break; 270 case 1: 271 __ fmovs(v0, 1.0); 272 break; 273 case 2: 274 __ fmovs(v0, 2.0); 275 break; 276 default: 277 ShouldNotReachHere(); 278 break; 279 } 280 } 281 282 void TemplateTable::dconst(int value) 283 { 284 transition(vtos, dtos); 285 switch (value) { 286 case 0: 287 __ fmovd(v0, zr); 288 break; 289 case 1: 290 __ fmovd(v0, 1.0); 291 break; 292 case 2: 293 __ fmovd(v0, 2.0); 294 break; 295 default: 296 ShouldNotReachHere(); 297 break; 298 } 299 } 300 301 void TemplateTable::bipush() 302 { 303 transition(vtos, itos); 304 __ load_signed_byte32(r0, at_bcp(1)); 305 } 306 307 void TemplateTable::sipush() 308 { 309 transition(vtos, itos); 310 __ load_unsigned_short(r0, at_bcp(1)); 311 __ revw(r0, r0); 312 __ asrw(r0, r0, 16); 313 } 314 315 void TemplateTable::ldc(bool wide) 316 { 317 transition(vtos, vtos); 318 Label call_ldc, notFloat, notClass, notInt, Done; 319 320 if (wide) { 321 __ get_unsigned_2_byte_index_at_bcp(r1, 1); 322 } else { 323 __ load_unsigned_byte(r1, at_bcp(1)); 324 } 325 __ get_cpool_and_tags(r2, r0); 326 327 const int base_offset = ConstantPool::header_size() * wordSize; 328 const int tags_offset = Array<u1>::base_offset_in_bytes(); 329 330 // get type 331 __ add(r3, r1, tags_offset); 332 __ lea(r3, Address(r0, r3)); 333 __ ldarb(r3, r3); 334 335 // unresolved class - get the resolved class 336 __ cmp(r3, JVM_CONSTANT_UnresolvedClass); 337 __ br(Assembler::EQ, call_ldc); 338 339 // unresolved class in error state - call into runtime to throw the error 340 // from the first resolution attempt 341 __ cmp(r3, JVM_CONSTANT_UnresolvedClassInError); 342 __ br(Assembler::EQ, call_ldc); 343 344 // resolved class - need to call vm to get java mirror of the class 345 __ cmp(r3, JVM_CONSTANT_Class); 346 __ br(Assembler::NE, notClass); 347 348 __ bind(call_ldc); 349 __ mov(c_rarg1, wide); 350 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), c_rarg1); 351 __ push_ptr(r0); 352 __ verify_oop(r0); 353 __ b(Done); 354 355 __ bind(notClass); 356 __ cmp(r3, JVM_CONSTANT_Float); 357 __ br(Assembler::NE, notFloat); 358 // ftos 359 __ adds(r1, r2, r1, Assembler::LSL, 3); 360 __ ldrs(v0, Address(r1, base_offset)); 361 __ push_f(); 362 __ b(Done); 363 364 __ bind(notFloat); 365 366 __ cmp(r3, JVM_CONSTANT_Integer); 367 __ br(Assembler::NE, notInt); 368 369 // itos 370 __ adds(r1, r2, r1, Assembler::LSL, 3); 371 __ ldrw(r0, Address(r1, base_offset)); 372 __ push_i(r0); 373 __ b(Done); 374 375 __ bind(notInt); 376 condy_helper(Done); 377 378 __ bind(Done); 379 } 380 381 // Fast path for caching oop constants. 382 void TemplateTable::fast_aldc(bool wide) 383 { 384 transition(vtos, atos); 385 386 Register result = r0; 387 Register tmp = r1; 388 Register rarg = r2; 389 390 int index_size = wide ? sizeof(u2) : sizeof(u1); 391 392 Label resolved; 393 394 // We are resolved if the resolved reference cache entry contains a 395 // non-null object (String, MethodType, etc.) 396 assert_different_registers(result, tmp); 397 __ get_cache_index_at_bcp(tmp, 1, index_size); 398 __ load_resolved_reference_at_index(result, tmp); 399 __ cbnz(result, resolved); 400 401 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); 402 403 // first time invocation - must resolve first 404 __ mov(rarg, (int)bytecode()); 405 __ call_VM(result, entry, rarg); 406 407 __ bind(resolved); 408 409 { // Check for the null sentinel. 410 // If we just called the VM, that already did the mapping for us, 411 // but it's harmless to retry. 412 Label notNull; 413 414 // Stash null_sentinel address to get its value later 415 __ movptr(rarg, (uintptr_t)Universe::the_null_sentinel_addr()); 416 __ ldr(tmp, Address(rarg)); 417 __ cmp(result, tmp); 418 __ br(Assembler::NE, notNull); 419 __ mov(result, 0); // NULL object reference 420 __ bind(notNull); 421 } 422 423 if (VerifyOops) { 424 // Safe to call with 0 result 425 __ verify_oop(result); 426 } 427 } 428 429 void TemplateTable::ldc2_w() 430 { 431 transition(vtos, vtos); 432 Label notDouble, notLong, Done; 433 __ get_unsigned_2_byte_index_at_bcp(r0, 1); 434 435 __ get_cpool_and_tags(r1, r2); 436 const int base_offset = ConstantPool::header_size() * wordSize; 437 const int tags_offset = Array<u1>::base_offset_in_bytes(); 438 439 // get type 440 __ lea(r2, Address(r2, r0, Address::lsl(0))); 441 __ load_unsigned_byte(r2, Address(r2, tags_offset)); 442 __ cmpw(r2, (int)JVM_CONSTANT_Double); 443 __ br(Assembler::NE, notDouble); 444 445 // dtos 446 __ lea (r2, Address(r1, r0, Address::lsl(3))); 447 __ ldrd(v0, Address(r2, base_offset)); 448 __ push_d(); 449 __ b(Done); 450 451 __ bind(notDouble); 452 __ cmpw(r2, (int)JVM_CONSTANT_Long); 453 __ br(Assembler::NE, notLong); 454 455 // ltos 456 __ lea(r0, Address(r1, r0, Address::lsl(3))); 457 __ ldr(r0, Address(r0, base_offset)); 458 __ push_l(); 459 __ b(Done); 460 461 __ bind(notLong); 462 condy_helper(Done); 463 464 __ bind(Done); 465 } 466 467 void TemplateTable::condy_helper(Label& Done) 468 { 469 Register obj = r0; 470 Register rarg = r1; 471 Register flags = r2; 472 Register off = r3; 473 474 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); 475 476 __ mov(rarg, (int) bytecode()); 477 __ call_VM(obj, entry, rarg); 478 479 __ get_vm_result_2(flags, rthread); 480 481 // VMr = obj = base address to find primitive value to push 482 // VMr2 = flags = (tos, off) using format of CPCE::_flags 483 __ mov(off, flags); 484 __ andw(off, off, ConstantPoolCacheEntry::field_index_mask); 485 486 const Address field(obj, off); 487 488 // What sort of thing are we loading? 489 // x86 uses a shift and mask or wings it with a shift plus assert 490 // the mask is not needed. aarch64 just uses bitfield extract 491 __ ubfxw(flags, flags, ConstantPoolCacheEntry::tos_state_shift, 492 ConstantPoolCacheEntry::tos_state_bits); 493 494 switch (bytecode()) { 495 case Bytecodes::_ldc: 496 case Bytecodes::_ldc_w: 497 { 498 // tos in (itos, ftos, stos, btos, ctos, ztos) 499 Label notInt, notFloat, notShort, notByte, notChar, notBool; 500 __ cmpw(flags, itos); 501 __ br(Assembler::NE, notInt); 502 // itos 503 __ ldrw(r0, field); 504 __ push(itos); 505 __ b(Done); 506 507 __ bind(notInt); 508 __ cmpw(flags, ftos); 509 __ br(Assembler::NE, notFloat); 510 // ftos 511 __ load_float(field); 512 __ push(ftos); 513 __ b(Done); 514 515 __ bind(notFloat); 516 __ cmpw(flags, stos); 517 __ br(Assembler::NE, notShort); 518 // stos 519 __ load_signed_short(r0, field); 520 __ push(stos); 521 __ b(Done); 522 523 __ bind(notShort); 524 __ cmpw(flags, btos); 525 __ br(Assembler::NE, notByte); 526 // btos 527 __ load_signed_byte(r0, field); 528 __ push(btos); 529 __ b(Done); 530 531 __ bind(notByte); 532 __ cmpw(flags, ctos); 533 __ br(Assembler::NE, notChar); 534 // ctos 535 __ load_unsigned_short(r0, field); 536 __ push(ctos); 537 __ b(Done); 538 539 __ bind(notChar); 540 __ cmpw(flags, ztos); 541 __ br(Assembler::NE, notBool); 542 // ztos 543 __ load_signed_byte(r0, field); 544 __ push(ztos); 545 __ b(Done); 546 547 __ bind(notBool); 548 break; 549 } 550 551 case Bytecodes::_ldc2_w: 552 { 553 Label notLong, notDouble; 554 __ cmpw(flags, ltos); 555 __ br(Assembler::NE, notLong); 556 // ltos 557 __ ldr(r0, field); 558 __ push(ltos); 559 __ b(Done); 560 561 __ bind(notLong); 562 __ cmpw(flags, dtos); 563 __ br(Assembler::NE, notDouble); 564 // dtos 565 __ load_double(field); 566 __ push(dtos); 567 __ b(Done); 568 569 __ bind(notDouble); 570 break; 571 } 572 573 default: 574 ShouldNotReachHere(); 575 } 576 577 __ stop("bad ldc/condy"); 578 } 579 580 void TemplateTable::locals_index(Register reg, int offset) 581 { 582 __ ldrb(reg, at_bcp(offset)); 583 __ neg(reg, reg); 584 } 585 586 void TemplateTable::iload() { 587 iload_internal(); 588 } 589 590 void TemplateTable::nofast_iload() { 591 iload_internal(may_not_rewrite); 592 } 593 594 void TemplateTable::iload_internal(RewriteControl rc) { 595 transition(vtos, itos); 596 if (RewriteFrequentPairs && rc == may_rewrite) { 597 Label rewrite, done; 598 Register bc = r4; 599 600 // get next bytecode 601 __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_iload))); 602 603 // if _iload, wait to rewrite to iload2. We only want to rewrite the 604 // last two iloads in a pair. Comparing against fast_iload means that 605 // the next bytecode is neither an iload or a caload, and therefore 606 // an iload pair. 607 __ cmpw(r1, Bytecodes::_iload); 608 __ br(Assembler::EQ, done); 609 610 // if _fast_iload rewrite to _fast_iload2 611 __ cmpw(r1, Bytecodes::_fast_iload); 612 __ movw(bc, Bytecodes::_fast_iload2); 613 __ br(Assembler::EQ, rewrite); 614 615 // if _caload rewrite to _fast_icaload 616 __ cmpw(r1, Bytecodes::_caload); 617 __ movw(bc, Bytecodes::_fast_icaload); 618 __ br(Assembler::EQ, rewrite); 619 620 // else rewrite to _fast_iload 621 __ movw(bc, Bytecodes::_fast_iload); 622 623 // rewrite 624 // bc: new bytecode 625 __ bind(rewrite); 626 patch_bytecode(Bytecodes::_iload, bc, r1, false); 627 __ bind(done); 628 629 } 630 631 // do iload, get the local value into tos 632 locals_index(r1); 633 __ ldr(r0, iaddress(r1)); 634 635 } 636 637 void TemplateTable::fast_iload2() 638 { 639 transition(vtos, itos); 640 locals_index(r1); 641 __ ldr(r0, iaddress(r1)); 642 __ push(itos); 643 locals_index(r1, 3); 644 __ ldr(r0, iaddress(r1)); 645 } 646 647 void TemplateTable::fast_iload() 648 { 649 transition(vtos, itos); 650 locals_index(r1); 651 __ ldr(r0, iaddress(r1)); 652 } 653 654 void TemplateTable::lload() 655 { 656 transition(vtos, ltos); 657 __ ldrb(r1, at_bcp(1)); 658 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord); 659 __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1))); 660 } 661 662 void TemplateTable::fload() 663 { 664 transition(vtos, ftos); 665 locals_index(r1); 666 // n.b. we use ldrd here because this is a 64 bit slot 667 // this is comparable to the iload case 668 __ ldrd(v0, faddress(r1)); 669 } 670 671 void TemplateTable::dload() 672 { 673 transition(vtos, dtos); 674 __ ldrb(r1, at_bcp(1)); 675 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord); 676 __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1))); 677 } 678 679 void TemplateTable::aload() 680 { 681 transition(vtos, atos); 682 locals_index(r1); 683 __ ldr(r0, iaddress(r1)); 684 } 685 686 void TemplateTable::locals_index_wide(Register reg) { 687 __ ldrh(reg, at_bcp(2)); 688 __ rev16w(reg, reg); 689 __ neg(reg, reg); 690 } 691 692 void TemplateTable::wide_iload() { 693 transition(vtos, itos); 694 locals_index_wide(r1); 695 __ ldr(r0, iaddress(r1)); 696 } 697 698 void TemplateTable::wide_lload() 699 { 700 transition(vtos, ltos); 701 __ ldrh(r1, at_bcp(2)); 702 __ rev16w(r1, r1); 703 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord); 704 __ ldr(r0, Address(r1, Interpreter::local_offset_in_bytes(1))); 705 } 706 707 void TemplateTable::wide_fload() 708 { 709 transition(vtos, ftos); 710 locals_index_wide(r1); 711 // n.b. we use ldrd here because this is a 64 bit slot 712 // this is comparable to the iload case 713 __ ldrd(v0, faddress(r1)); 714 } 715 716 void TemplateTable::wide_dload() 717 { 718 transition(vtos, dtos); 719 __ ldrh(r1, at_bcp(2)); 720 __ rev16w(r1, r1); 721 __ sub(r1, rlocals, r1, ext::uxtw, LogBytesPerWord); 722 __ ldrd(v0, Address(r1, Interpreter::local_offset_in_bytes(1))); 723 } 724 725 void TemplateTable::wide_aload() 726 { 727 transition(vtos, atos); 728 locals_index_wide(r1); 729 __ ldr(r0, aaddress(r1)); 730 } 731 732 void TemplateTable::index_check(Register array, Register index) 733 { 734 // destroys r1, rscratch1 735 // check array 736 __ null_check(array, arrayOopDesc::length_offset_in_bytes()); 737 // sign extend index for use by indexed load 738 // __ movl2ptr(index, index); 739 // check index 740 Register length = rscratch1; 741 __ ldrw(length, Address(array, arrayOopDesc::length_offset_in_bytes())); 742 __ cmpw(index, length); 743 if (index != r1) { 744 // ??? convention: move aberrant index into r1 for exception message 745 assert(r1 != array, "different registers"); 746 __ mov(r1, index); 747 } 748 Label ok; 749 __ br(Assembler::LO, ok); 750 // ??? convention: move array into r3 for exception message 751 __ mov(r3, array); 752 __ mov(rscratch1, Interpreter::_throw_ArrayIndexOutOfBoundsException_entry); 753 __ br(rscratch1); 754 __ bind(ok); 755 } 756 757 void TemplateTable::iaload() 758 { 759 transition(itos, itos); 760 __ mov(r1, r0); 761 __ pop_ptr(r0); 762 // r0: array 763 // r1: index 764 index_check(r0, r1); // leaves index in r1, kills rscratch1 765 __ lea(r1, Address(r0, r1, Address::uxtw(2))); 766 __ ldrw(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_INT))); 767 } 768 769 void TemplateTable::laload() 770 { 771 transition(itos, ltos); 772 __ mov(r1, r0); 773 __ pop_ptr(r0); 774 // r0: array 775 // r1: index 776 index_check(r0, r1); // leaves index in r1, kills rscratch1 777 __ lea(r1, Address(r0, r1, Address::uxtw(3))); 778 __ ldr(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_LONG))); 779 } 780 781 void TemplateTable::faload() 782 { 783 transition(itos, ftos); 784 __ mov(r1, r0); 785 __ pop_ptr(r0); 786 // r0: array 787 // r1: index 788 index_check(r0, r1); // leaves index in r1, kills rscratch1 789 __ lea(r1, Address(r0, r1, Address::uxtw(2))); 790 __ ldrs(v0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_FLOAT))); 791 } 792 793 void TemplateTable::daload() 794 { 795 transition(itos, dtos); 796 __ mov(r1, r0); 797 __ pop_ptr(r0); 798 // r0: array 799 // r1: index 800 index_check(r0, r1); // leaves index in r1, kills rscratch1 801 __ lea(r1, Address(r0, r1, Address::uxtw(3))); 802 __ ldrd(v0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); 803 } 804 805 void TemplateTable::aaload() 806 { 807 transition(itos, atos); 808 __ mov(r1, r0); 809 __ pop_ptr(r0); 810 // r0: array 811 // r1: index 812 index_check(r0, r1); // leaves index in r1, kills rscratch1 813 int s = (UseCompressedOops ? 2 : 3); 814 __ lea(r1, Address(r0, r1, Address::uxtw(s))); 815 do_oop_load(_masm, 816 Address(r1, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), 817 r0, 818 IN_HEAP | IN_HEAP_ARRAY); 819 } 820 821 void TemplateTable::baload() 822 { 823 transition(itos, itos); 824 __ mov(r1, r0); 825 __ pop_ptr(r0); 826 // r0: array 827 // r1: index 828 index_check(r0, r1); // leaves index in r1, kills rscratch1 829 __ lea(r1, Address(r0, r1, Address::uxtw(0))); 830 __ load_signed_byte(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_BYTE))); 831 } 832 833 void TemplateTable::caload() 834 { 835 transition(itos, itos); 836 __ mov(r1, r0); 837 __ pop_ptr(r0); 838 // r0: array 839 // r1: index 840 index_check(r0, r1); // leaves index in r1, kills rscratch1 841 __ lea(r1, Address(r0, r1, Address::uxtw(1))); 842 __ load_unsigned_short(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 843 } 844 845 // iload followed by caload frequent pair 846 void TemplateTable::fast_icaload() 847 { 848 transition(vtos, itos); 849 // load index out of locals 850 locals_index(r2); 851 __ ldr(r1, iaddress(r2)); 852 853 __ pop_ptr(r0); 854 855 // r0: array 856 // r1: index 857 index_check(r0, r1); // leaves index in r1, kills rscratch1 858 __ lea(r1, Address(r0, r1, Address::uxtw(1))); 859 __ load_unsigned_short(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 860 } 861 862 void TemplateTable::saload() 863 { 864 transition(itos, itos); 865 __ mov(r1, r0); 866 __ pop_ptr(r0); 867 // r0: array 868 // r1: index 869 index_check(r0, r1); // leaves index in r1, kills rscratch1 870 __ lea(r1, Address(r0, r1, Address::uxtw(1))); 871 __ load_signed_short(r0, Address(r1, arrayOopDesc::base_offset_in_bytes(T_SHORT))); 872 } 873 874 void TemplateTable::iload(int n) 875 { 876 transition(vtos, itos); 877 __ ldr(r0, iaddress(n)); 878 } 879 880 void TemplateTable::lload(int n) 881 { 882 transition(vtos, ltos); 883 __ ldr(r0, laddress(n)); 884 } 885 886 void TemplateTable::fload(int n) 887 { 888 transition(vtos, ftos); 889 __ ldrs(v0, faddress(n)); 890 } 891 892 void TemplateTable::dload(int n) 893 { 894 transition(vtos, dtos); 895 __ ldrd(v0, daddress(n)); 896 } 897 898 void TemplateTable::aload(int n) 899 { 900 transition(vtos, atos); 901 __ ldr(r0, iaddress(n)); 902 } 903 904 void TemplateTable::aload_0() { 905 aload_0_internal(); 906 } 907 908 void TemplateTable::nofast_aload_0() { 909 aload_0_internal(may_not_rewrite); 910 } 911 912 void TemplateTable::aload_0_internal(RewriteControl rc) { 913 // According to bytecode histograms, the pairs: 914 // 915 // _aload_0, _fast_igetfield 916 // _aload_0, _fast_agetfield 917 // _aload_0, _fast_fgetfield 918 // 919 // occur frequently. If RewriteFrequentPairs is set, the (slow) 920 // _aload_0 bytecode checks if the next bytecode is either 921 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then 922 // rewrites the current bytecode into a pair bytecode; otherwise it 923 // rewrites the current bytecode into _fast_aload_0 that doesn't do 924 // the pair check anymore. 925 // 926 // Note: If the next bytecode is _getfield, the rewrite must be 927 // delayed, otherwise we may miss an opportunity for a pair. 928 // 929 // Also rewrite frequent pairs 930 // aload_0, aload_1 931 // aload_0, iload_1 932 // These bytecodes with a small amount of code are most profitable 933 // to rewrite 934 if (RewriteFrequentPairs && rc == may_rewrite) { 935 Label rewrite, done; 936 const Register bc = r4; 937 938 // get next bytecode 939 __ load_unsigned_byte(r1, at_bcp(Bytecodes::length_for(Bytecodes::_aload_0))); 940 941 // if _getfield then wait with rewrite 942 __ cmpw(r1, Bytecodes::Bytecodes::_getfield); 943 __ br(Assembler::EQ, done); 944 945 // if _igetfield then rewrite to _fast_iaccess_0 946 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 947 __ cmpw(r1, Bytecodes::_fast_igetfield); 948 __ movw(bc, Bytecodes::_fast_iaccess_0); 949 __ br(Assembler::EQ, rewrite); 950 951 // if _agetfield then rewrite to _fast_aaccess_0 952 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 953 __ cmpw(r1, Bytecodes::_fast_agetfield); 954 __ movw(bc, Bytecodes::_fast_aaccess_0); 955 __ br(Assembler::EQ, rewrite); 956 957 // if _fgetfield then rewrite to _fast_faccess_0 958 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "fix bytecode definition"); 959 __ cmpw(r1, Bytecodes::_fast_fgetfield); 960 __ movw(bc, Bytecodes::_fast_faccess_0); 961 __ br(Assembler::EQ, rewrite); 962 963 // else rewrite to _fast_aload0 964 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "fix bytecode definition"); 965 __ movw(bc, Bytecodes::Bytecodes::_fast_aload_0); 966 967 // rewrite 968 // bc: new bytecode 969 __ bind(rewrite); 970 patch_bytecode(Bytecodes::_aload_0, bc, r1, false); 971 972 __ bind(done); 973 } 974 975 // Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop). 976 aload(0); 977 } 978 979 void TemplateTable::istore() 980 { 981 transition(itos, vtos); 982 locals_index(r1); 983 // FIXME: We're being very pernickerty here storing a jint in a 984 // local with strw, which costs an extra instruction over what we'd 985 // be able to do with a simple str. We should just store the whole 986 // word. 987 __ lea(rscratch1, iaddress(r1)); 988 __ strw(r0, Address(rscratch1)); 989 } 990 991 void TemplateTable::lstore() 992 { 993 transition(ltos, vtos); 994 locals_index(r1); 995 __ str(r0, laddress(r1, rscratch1, _masm)); 996 } 997 998 void TemplateTable::fstore() { 999 transition(ftos, vtos); 1000 locals_index(r1); 1001 __ lea(rscratch1, iaddress(r1)); 1002 __ strs(v0, Address(rscratch1)); 1003 } 1004 1005 void TemplateTable::dstore() { 1006 transition(dtos, vtos); 1007 locals_index(r1); 1008 __ strd(v0, daddress(r1, rscratch1, _masm)); 1009 } 1010 1011 void TemplateTable::astore() 1012 { 1013 transition(vtos, vtos); 1014 __ pop_ptr(r0); 1015 locals_index(r1); 1016 __ str(r0, aaddress(r1)); 1017 } 1018 1019 void TemplateTable::wide_istore() { 1020 transition(vtos, vtos); 1021 __ pop_i(); 1022 locals_index_wide(r1); 1023 __ lea(rscratch1, iaddress(r1)); 1024 __ strw(r0, Address(rscratch1)); 1025 } 1026 1027 void TemplateTable::wide_lstore() { 1028 transition(vtos, vtos); 1029 __ pop_l(); 1030 locals_index_wide(r1); 1031 __ str(r0, laddress(r1, rscratch1, _masm)); 1032 } 1033 1034 void TemplateTable::wide_fstore() { 1035 transition(vtos, vtos); 1036 __ pop_f(); 1037 locals_index_wide(r1); 1038 __ lea(rscratch1, faddress(r1)); 1039 __ strs(v0, rscratch1); 1040 } 1041 1042 void TemplateTable::wide_dstore() { 1043 transition(vtos, vtos); 1044 __ pop_d(); 1045 locals_index_wide(r1); 1046 __ strd(v0, daddress(r1, rscratch1, _masm)); 1047 } 1048 1049 void TemplateTable::wide_astore() { 1050 transition(vtos, vtos); 1051 __ pop_ptr(r0); 1052 locals_index_wide(r1); 1053 __ str(r0, aaddress(r1)); 1054 } 1055 1056 void TemplateTable::iastore() { 1057 transition(itos, vtos); 1058 __ pop_i(r1); 1059 __ pop_ptr(r3); 1060 // r0: value 1061 // r1: index 1062 // r3: array 1063 index_check(r3, r1); // prefer index in r1 1064 __ lea(rscratch1, Address(r3, r1, Address::uxtw(2))); 1065 __ strw(r0, Address(rscratch1, 1066 arrayOopDesc::base_offset_in_bytes(T_INT))); 1067 } 1068 1069 void TemplateTable::lastore() { 1070 transition(ltos, vtos); 1071 __ pop_i(r1); 1072 __ pop_ptr(r3); 1073 // r0: value 1074 // r1: index 1075 // r3: array 1076 index_check(r3, r1); // prefer index in r1 1077 __ lea(rscratch1, Address(r3, r1, Address::uxtw(3))); 1078 __ str(r0, Address(rscratch1, 1079 arrayOopDesc::base_offset_in_bytes(T_LONG))); 1080 } 1081 1082 void TemplateTable::fastore() { 1083 transition(ftos, vtos); 1084 __ pop_i(r1); 1085 __ pop_ptr(r3); 1086 // v0: value 1087 // r1: index 1088 // r3: array 1089 index_check(r3, r1); // prefer index in r1 1090 __ lea(rscratch1, Address(r3, r1, Address::uxtw(2))); 1091 __ strs(v0, Address(rscratch1, 1092 arrayOopDesc::base_offset_in_bytes(T_FLOAT))); 1093 } 1094 1095 void TemplateTable::dastore() { 1096 transition(dtos, vtos); 1097 __ pop_i(r1); 1098 __ pop_ptr(r3); 1099 // v0: value 1100 // r1: index 1101 // r3: array 1102 index_check(r3, r1); // prefer index in r1 1103 __ lea(rscratch1, Address(r3, r1, Address::uxtw(3))); 1104 __ strd(v0, Address(rscratch1, 1105 arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); 1106 } 1107 1108 void TemplateTable::aastore() { 1109 Label is_null, ok_is_subtype, done; 1110 transition(vtos, vtos); 1111 // stack: ..., array, index, value 1112 __ ldr(r0, at_tos()); // value 1113 __ ldr(r2, at_tos_p1()); // index 1114 __ ldr(r3, at_tos_p2()); // array 1115 1116 Address element_address(r4, arrayOopDesc::base_offset_in_bytes(T_OBJECT)); 1117 1118 index_check(r3, r2); // kills r1 1119 __ lea(r4, Address(r3, r2, Address::uxtw(UseCompressedOops? 2 : 3))); 1120 1121 // do array store check - check for NULL value first 1122 __ cbz(r0, is_null); 1123 1124 // Move subklass into r1 1125 __ load_klass(r1, r0); 1126 // Move superklass into r0 1127 __ load_klass(r0, r3); 1128 __ ldr(r0, Address(r0, 1129 ObjArrayKlass::element_klass_offset())); 1130 // Compress array + index*oopSize + 12 into a single register. Frees r2. 1131 1132 // Generate subtype check. Blows r2, r5 1133 // Superklass in r0. Subklass in r1. 1134 __ gen_subtype_check(r1, ok_is_subtype); 1135 1136 // Come here on failure 1137 // object is at TOS 1138 __ b(Interpreter::_throw_ArrayStoreException_entry); 1139 1140 // Come here on success 1141 __ bind(ok_is_subtype); 1142 1143 // Get the value we will store 1144 __ ldr(r0, at_tos()); 1145 // Now store using the appropriate barrier 1146 do_oop_store(_masm, element_address, r0, IN_HEAP | IN_HEAP_ARRAY); 1147 __ b(done); 1148 1149 // Have a NULL in r0, r3=array, r2=index. Store NULL at ary[idx] 1150 __ bind(is_null); 1151 __ profile_null_seen(r2); 1152 1153 // Store a NULL 1154 do_oop_store(_masm, element_address, noreg, IN_HEAP | IN_HEAP_ARRAY); 1155 1156 // Pop stack arguments 1157 __ bind(done); 1158 __ add(esp, esp, 3 * Interpreter::stackElementSize); 1159 } 1160 1161 void TemplateTable::bastore() 1162 { 1163 transition(itos, vtos); 1164 __ pop_i(r1); 1165 __ pop_ptr(r3); 1166 // r0: value 1167 // r1: index 1168 // r3: array 1169 index_check(r3, r1); // prefer index in r1 1170 1171 // Need to check whether array is boolean or byte 1172 // since both types share the bastore bytecode. 1173 __ load_klass(r2, r3); 1174 __ ldrw(r2, Address(r2, Klass::layout_helper_offset())); 1175 int diffbit_index = exact_log2(Klass::layout_helper_boolean_diffbit()); 1176 Label L_skip; 1177 __ tbz(r2, diffbit_index, L_skip); 1178 __ andw(r0, r0, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1 1179 __ bind(L_skip); 1180 1181 __ lea(rscratch1, Address(r3, r1, Address::uxtw(0))); 1182 __ strb(r0, Address(rscratch1, 1183 arrayOopDesc::base_offset_in_bytes(T_BYTE))); 1184 } 1185 1186 void TemplateTable::castore() 1187 { 1188 transition(itos, vtos); 1189 __ pop_i(r1); 1190 __ pop_ptr(r3); 1191 // r0: value 1192 // r1: index 1193 // r3: array 1194 index_check(r3, r1); // prefer index in r1 1195 __ lea(rscratch1, Address(r3, r1, Address::uxtw(1))); 1196 __ strh(r0, Address(rscratch1, 1197 arrayOopDesc::base_offset_in_bytes(T_CHAR))); 1198 } 1199 1200 void TemplateTable::sastore() 1201 { 1202 castore(); 1203 } 1204 1205 void TemplateTable::istore(int n) 1206 { 1207 transition(itos, vtos); 1208 __ str(r0, iaddress(n)); 1209 } 1210 1211 void TemplateTable::lstore(int n) 1212 { 1213 transition(ltos, vtos); 1214 __ str(r0, laddress(n)); 1215 } 1216 1217 void TemplateTable::fstore(int n) 1218 { 1219 transition(ftos, vtos); 1220 __ strs(v0, faddress(n)); 1221 } 1222 1223 void TemplateTable::dstore(int n) 1224 { 1225 transition(dtos, vtos); 1226 __ strd(v0, daddress(n)); 1227 } 1228 1229 void TemplateTable::astore(int n) 1230 { 1231 transition(vtos, vtos); 1232 __ pop_ptr(r0); 1233 __ str(r0, iaddress(n)); 1234 } 1235 1236 void TemplateTable::pop() 1237 { 1238 transition(vtos, vtos); 1239 __ add(esp, esp, Interpreter::stackElementSize); 1240 } 1241 1242 void TemplateTable::pop2() 1243 { 1244 transition(vtos, vtos); 1245 __ add(esp, esp, 2 * Interpreter::stackElementSize); 1246 } 1247 1248 void TemplateTable::dup() 1249 { 1250 transition(vtos, vtos); 1251 __ ldr(r0, Address(esp, 0)); 1252 __ push(r0); 1253 // stack: ..., a, a 1254 } 1255 1256 void TemplateTable::dup_x1() 1257 { 1258 transition(vtos, vtos); 1259 // stack: ..., a, b 1260 __ ldr(r0, at_tos()); // load b 1261 __ ldr(r2, at_tos_p1()); // load a 1262 __ str(r0, at_tos_p1()); // store b 1263 __ str(r2, at_tos()); // store a 1264 __ push(r0); // push b 1265 // stack: ..., b, a, b 1266 } 1267 1268 void TemplateTable::dup_x2() 1269 { 1270 transition(vtos, vtos); 1271 // stack: ..., a, b, c 1272 __ ldr(r0, at_tos()); // load c 1273 __ ldr(r2, at_tos_p2()); // load a 1274 __ str(r0, at_tos_p2()); // store c in a 1275 __ push(r0); // push c 1276 // stack: ..., c, b, c, c 1277 __ ldr(r0, at_tos_p2()); // load b 1278 __ str(r2, at_tos_p2()); // store a in b 1279 // stack: ..., c, a, c, c 1280 __ str(r0, at_tos_p1()); // store b in c 1281 // stack: ..., c, a, b, c 1282 } 1283 1284 void TemplateTable::dup2() 1285 { 1286 transition(vtos, vtos); 1287 // stack: ..., a, b 1288 __ ldr(r0, at_tos_p1()); // load a 1289 __ push(r0); // push a 1290 __ ldr(r0, at_tos_p1()); // load b 1291 __ push(r0); // push b 1292 // stack: ..., a, b, a, b 1293 } 1294 1295 void TemplateTable::dup2_x1() 1296 { 1297 transition(vtos, vtos); 1298 // stack: ..., a, b, c 1299 __ ldr(r2, at_tos()); // load c 1300 __ ldr(r0, at_tos_p1()); // load b 1301 __ push(r0); // push b 1302 __ push(r2); // push c 1303 // stack: ..., a, b, c, b, c 1304 __ str(r2, at_tos_p3()); // store c in b 1305 // stack: ..., a, c, c, b, c 1306 __ ldr(r2, at_tos_p4()); // load a 1307 __ str(r2, at_tos_p2()); // store a in 2nd c 1308 // stack: ..., a, c, a, b, c 1309 __ str(r0, at_tos_p4()); // store b in a 1310 // stack: ..., b, c, a, b, c 1311 } 1312 1313 void TemplateTable::dup2_x2() 1314 { 1315 transition(vtos, vtos); 1316 // stack: ..., a, b, c, d 1317 __ ldr(r2, at_tos()); // load d 1318 __ ldr(r0, at_tos_p1()); // load c 1319 __ push(r0) ; // push c 1320 __ push(r2); // push d 1321 // stack: ..., a, b, c, d, c, d 1322 __ ldr(r0, at_tos_p4()); // load b 1323 __ str(r0, at_tos_p2()); // store b in d 1324 __ str(r2, at_tos_p4()); // store d in b 1325 // stack: ..., a, d, c, b, c, d 1326 __ ldr(r2, at_tos_p5()); // load a 1327 __ ldr(r0, at_tos_p3()); // load c 1328 __ str(r2, at_tos_p3()); // store a in c 1329 __ str(r0, at_tos_p5()); // store c in a 1330 // stack: ..., c, d, a, b, c, d 1331 } 1332 1333 void TemplateTable::swap() 1334 { 1335 transition(vtos, vtos); 1336 // stack: ..., a, b 1337 __ ldr(r2, at_tos_p1()); // load a 1338 __ ldr(r0, at_tos()); // load b 1339 __ str(r2, at_tos()); // store a in b 1340 __ str(r0, at_tos_p1()); // store b in a 1341 // stack: ..., b, a 1342 } 1343 1344 void TemplateTable::iop2(Operation op) 1345 { 1346 transition(itos, itos); 1347 // r0 <== r1 op r0 1348 __ pop_i(r1); 1349 switch (op) { 1350 case add : __ addw(r0, r1, r0); break; 1351 case sub : __ subw(r0, r1, r0); break; 1352 case mul : __ mulw(r0, r1, r0); break; 1353 case _and : __ andw(r0, r1, r0); break; 1354 case _or : __ orrw(r0, r1, r0); break; 1355 case _xor : __ eorw(r0, r1, r0); break; 1356 case shl : __ lslvw(r0, r1, r0); break; 1357 case shr : __ asrvw(r0, r1, r0); break; 1358 case ushr : __ lsrvw(r0, r1, r0);break; 1359 default : ShouldNotReachHere(); 1360 } 1361 } 1362 1363 void TemplateTable::lop2(Operation op) 1364 { 1365 transition(ltos, ltos); 1366 // r0 <== r1 op r0 1367 __ pop_l(r1); 1368 switch (op) { 1369 case add : __ add(r0, r1, r0); break; 1370 case sub : __ sub(r0, r1, r0); break; 1371 case mul : __ mul(r0, r1, r0); break; 1372 case _and : __ andr(r0, r1, r0); break; 1373 case _or : __ orr(r0, r1, r0); break; 1374 case _xor : __ eor(r0, r1, r0); break; 1375 default : ShouldNotReachHere(); 1376 } 1377 } 1378 1379 void TemplateTable::idiv() 1380 { 1381 transition(itos, itos); 1382 // explicitly check for div0 1383 Label no_div0; 1384 __ cbnzw(r0, no_div0); 1385 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry); 1386 __ br(rscratch1); 1387 __ bind(no_div0); 1388 __ pop_i(r1); 1389 // r0 <== r1 idiv r0 1390 __ corrected_idivl(r0, r1, r0, /* want_remainder */ false); 1391 } 1392 1393 void TemplateTable::irem() 1394 { 1395 transition(itos, itos); 1396 // explicitly check for div0 1397 Label no_div0; 1398 __ cbnzw(r0, no_div0); 1399 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry); 1400 __ br(rscratch1); 1401 __ bind(no_div0); 1402 __ pop_i(r1); 1403 // r0 <== r1 irem r0 1404 __ corrected_idivl(r0, r1, r0, /* want_remainder */ true); 1405 } 1406 1407 void TemplateTable::lmul() 1408 { 1409 transition(ltos, ltos); 1410 __ pop_l(r1); 1411 __ mul(r0, r0, r1); 1412 } 1413 1414 void TemplateTable::ldiv() 1415 { 1416 transition(ltos, ltos); 1417 // explicitly check for div0 1418 Label no_div0; 1419 __ cbnz(r0, no_div0); 1420 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry); 1421 __ br(rscratch1); 1422 __ bind(no_div0); 1423 __ pop_l(r1); 1424 // r0 <== r1 ldiv r0 1425 __ corrected_idivq(r0, r1, r0, /* want_remainder */ false); 1426 } 1427 1428 void TemplateTable::lrem() 1429 { 1430 transition(ltos, ltos); 1431 // explicitly check for div0 1432 Label no_div0; 1433 __ cbnz(r0, no_div0); 1434 __ mov(rscratch1, Interpreter::_throw_ArithmeticException_entry); 1435 __ br(rscratch1); 1436 __ bind(no_div0); 1437 __ pop_l(r1); 1438 // r0 <== r1 lrem r0 1439 __ corrected_idivq(r0, r1, r0, /* want_remainder */ true); 1440 } 1441 1442 void TemplateTable::lshl() 1443 { 1444 transition(itos, ltos); 1445 // shift count is in r0 1446 __ pop_l(r1); 1447 __ lslv(r0, r1, r0); 1448 } 1449 1450 void TemplateTable::lshr() 1451 { 1452 transition(itos, ltos); 1453 // shift count is in r0 1454 __ pop_l(r1); 1455 __ asrv(r0, r1, r0); 1456 } 1457 1458 void TemplateTable::lushr() 1459 { 1460 transition(itos, ltos); 1461 // shift count is in r0 1462 __ pop_l(r1); 1463 __ lsrv(r0, r1, r0); 1464 } 1465 1466 void TemplateTable::fop2(Operation op) 1467 { 1468 transition(ftos, ftos); 1469 switch (op) { 1470 case add: 1471 // n.b. use ldrd because this is a 64 bit slot 1472 __ pop_f(v1); 1473 __ fadds(v0, v1, v0); 1474 break; 1475 case sub: 1476 __ pop_f(v1); 1477 __ fsubs(v0, v1, v0); 1478 break; 1479 case mul: 1480 __ pop_f(v1); 1481 __ fmuls(v0, v1, v0); 1482 break; 1483 case div: 1484 __ pop_f(v1); 1485 __ fdivs(v0, v1, v0); 1486 break; 1487 case rem: 1488 __ fmovs(v1, v0); 1489 __ pop_f(v0); 1490 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::frem), 1491 0, 2, MacroAssembler::ret_type_float); 1492 break; 1493 default: 1494 ShouldNotReachHere(); 1495 break; 1496 } 1497 } 1498 1499 void TemplateTable::dop2(Operation op) 1500 { 1501 transition(dtos, dtos); 1502 switch (op) { 1503 case add: 1504 // n.b. use ldrd because this is a 64 bit slot 1505 __ pop_d(v1); 1506 __ faddd(v0, v1, v0); 1507 break; 1508 case sub: 1509 __ pop_d(v1); 1510 __ fsubd(v0, v1, v0); 1511 break; 1512 case mul: 1513 __ pop_d(v1); 1514 __ fmuld(v0, v1, v0); 1515 break; 1516 case div: 1517 __ pop_d(v1); 1518 __ fdivd(v0, v1, v0); 1519 break; 1520 case rem: 1521 __ fmovd(v1, v0); 1522 __ pop_d(v0); 1523 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::drem), 1524 0, 2, MacroAssembler::ret_type_double); 1525 break; 1526 default: 1527 ShouldNotReachHere(); 1528 break; 1529 } 1530 } 1531 1532 void TemplateTable::ineg() 1533 { 1534 transition(itos, itos); 1535 __ negw(r0, r0); 1536 1537 } 1538 1539 void TemplateTable::lneg() 1540 { 1541 transition(ltos, ltos); 1542 __ neg(r0, r0); 1543 } 1544 1545 void TemplateTable::fneg() 1546 { 1547 transition(ftos, ftos); 1548 __ fnegs(v0, v0); 1549 } 1550 1551 void TemplateTable::dneg() 1552 { 1553 transition(dtos, dtos); 1554 __ fnegd(v0, v0); 1555 } 1556 1557 void TemplateTable::iinc() 1558 { 1559 transition(vtos, vtos); 1560 __ load_signed_byte(r1, at_bcp(2)); // get constant 1561 locals_index(r2); 1562 __ ldr(r0, iaddress(r2)); 1563 __ addw(r0, r0, r1); 1564 __ str(r0, iaddress(r2)); 1565 } 1566 1567 void TemplateTable::wide_iinc() 1568 { 1569 transition(vtos, vtos); 1570 // __ mov(r1, zr); 1571 __ ldrw(r1, at_bcp(2)); // get constant and index 1572 __ rev16(r1, r1); 1573 __ ubfx(r2, r1, 0, 16); 1574 __ neg(r2, r2); 1575 __ sbfx(r1, r1, 16, 16); 1576 __ ldr(r0, iaddress(r2)); 1577 __ addw(r0, r0, r1); 1578 __ str(r0, iaddress(r2)); 1579 } 1580 1581 void TemplateTable::convert() 1582 { 1583 // Checking 1584 #ifdef ASSERT 1585 { 1586 TosState tos_in = ilgl; 1587 TosState tos_out = ilgl; 1588 switch (bytecode()) { 1589 case Bytecodes::_i2l: // fall through 1590 case Bytecodes::_i2f: // fall through 1591 case Bytecodes::_i2d: // fall through 1592 case Bytecodes::_i2b: // fall through 1593 case Bytecodes::_i2c: // fall through 1594 case Bytecodes::_i2s: tos_in = itos; break; 1595 case Bytecodes::_l2i: // fall through 1596 case Bytecodes::_l2f: // fall through 1597 case Bytecodes::_l2d: tos_in = ltos; break; 1598 case Bytecodes::_f2i: // fall through 1599 case Bytecodes::_f2l: // fall through 1600 case Bytecodes::_f2d: tos_in = ftos; break; 1601 case Bytecodes::_d2i: // fall through 1602 case Bytecodes::_d2l: // fall through 1603 case Bytecodes::_d2f: tos_in = dtos; break; 1604 default : ShouldNotReachHere(); 1605 } 1606 switch (bytecode()) { 1607 case Bytecodes::_l2i: // fall through 1608 case Bytecodes::_f2i: // fall through 1609 case Bytecodes::_d2i: // fall through 1610 case Bytecodes::_i2b: // fall through 1611 case Bytecodes::_i2c: // fall through 1612 case Bytecodes::_i2s: tos_out = itos; break; 1613 case Bytecodes::_i2l: // fall through 1614 case Bytecodes::_f2l: // fall through 1615 case Bytecodes::_d2l: tos_out = ltos; break; 1616 case Bytecodes::_i2f: // fall through 1617 case Bytecodes::_l2f: // fall through 1618 case Bytecodes::_d2f: tos_out = ftos; break; 1619 case Bytecodes::_i2d: // fall through 1620 case Bytecodes::_l2d: // fall through 1621 case Bytecodes::_f2d: tos_out = dtos; break; 1622 default : ShouldNotReachHere(); 1623 } 1624 transition(tos_in, tos_out); 1625 } 1626 #endif // ASSERT 1627 // static const int64_t is_nan = 0x8000000000000000L; 1628 1629 // Conversion 1630 switch (bytecode()) { 1631 case Bytecodes::_i2l: 1632 __ sxtw(r0, r0); 1633 break; 1634 case Bytecodes::_i2f: 1635 __ scvtfws(v0, r0); 1636 break; 1637 case Bytecodes::_i2d: 1638 __ scvtfwd(v0, r0); 1639 break; 1640 case Bytecodes::_i2b: 1641 __ sxtbw(r0, r0); 1642 break; 1643 case Bytecodes::_i2c: 1644 __ uxthw(r0, r0); 1645 break; 1646 case Bytecodes::_i2s: 1647 __ sxthw(r0, r0); 1648 break; 1649 case Bytecodes::_l2i: 1650 __ uxtw(r0, r0); 1651 break; 1652 case Bytecodes::_l2f: 1653 __ scvtfs(v0, r0); 1654 break; 1655 case Bytecodes::_l2d: 1656 __ scvtfd(v0, r0); 1657 break; 1658 case Bytecodes::_f2i: 1659 { 1660 Label L_Okay; 1661 __ clear_fpsr(); 1662 __ fcvtzsw(r0, v0); 1663 __ get_fpsr(r1); 1664 __ cbzw(r1, L_Okay); 1665 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::f2i), 1666 0, 1, MacroAssembler::ret_type_integral); 1667 __ bind(L_Okay); 1668 } 1669 break; 1670 case Bytecodes::_f2l: 1671 { 1672 Label L_Okay; 1673 __ clear_fpsr(); 1674 __ fcvtzs(r0, v0); 1675 __ get_fpsr(r1); 1676 __ cbzw(r1, L_Okay); 1677 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::f2l), 1678 0, 1, MacroAssembler::ret_type_integral); 1679 __ bind(L_Okay); 1680 } 1681 break; 1682 case Bytecodes::_f2d: 1683 __ fcvts(v0, v0); 1684 break; 1685 case Bytecodes::_d2i: 1686 { 1687 Label L_Okay; 1688 __ clear_fpsr(); 1689 __ fcvtzdw(r0, v0); 1690 __ get_fpsr(r1); 1691 __ cbzw(r1, L_Okay); 1692 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::d2i), 1693 0, 1, MacroAssembler::ret_type_integral); 1694 __ bind(L_Okay); 1695 } 1696 break; 1697 case Bytecodes::_d2l: 1698 { 1699 Label L_Okay; 1700 __ clear_fpsr(); 1701 __ fcvtzd(r0, v0); 1702 __ get_fpsr(r1); 1703 __ cbzw(r1, L_Okay); 1704 __ call_VM_leaf_base1(CAST_FROM_FN_PTR(address, SharedRuntime::d2l), 1705 0, 1, MacroAssembler::ret_type_integral); 1706 __ bind(L_Okay); 1707 } 1708 break; 1709 case Bytecodes::_d2f: 1710 __ fcvtd(v0, v0); 1711 break; 1712 default: 1713 ShouldNotReachHere(); 1714 } 1715 } 1716 1717 void TemplateTable::lcmp() 1718 { 1719 transition(ltos, itos); 1720 Label done; 1721 __ pop_l(r1); 1722 __ cmp(r1, r0); 1723 __ mov(r0, (u_int64_t)-1L); 1724 __ br(Assembler::LT, done); 1725 // __ mov(r0, 1UL); 1726 // __ csel(r0, r0, zr, Assembler::NE); 1727 // and here is a faster way 1728 __ csinc(r0, zr, zr, Assembler::EQ); 1729 __ bind(done); 1730 } 1731 1732 void TemplateTable::float_cmp(bool is_float, int unordered_result) 1733 { 1734 Label done; 1735 if (is_float) { 1736 // XXX get rid of pop here, use ... reg, mem32 1737 __ pop_f(v1); 1738 __ fcmps(v1, v0); 1739 } else { 1740 // XXX get rid of pop here, use ... reg, mem64 1741 __ pop_d(v1); 1742 __ fcmpd(v1, v0); 1743 } 1744 if (unordered_result < 0) { 1745 // we want -1 for unordered or less than, 0 for equal and 1 for 1746 // greater than. 1747 __ mov(r0, (u_int64_t)-1L); 1748 // for FP LT tests less than or unordered 1749 __ br(Assembler::LT, done); 1750 // install 0 for EQ otherwise 1 1751 __ csinc(r0, zr, zr, Assembler::EQ); 1752 } else { 1753 // we want -1 for less than, 0 for equal and 1 for unordered or 1754 // greater than. 1755 __ mov(r0, 1L); 1756 // for FP HI tests greater than or unordered 1757 __ br(Assembler::HI, done); 1758 // install 0 for EQ otherwise ~0 1759 __ csinv(r0, zr, zr, Assembler::EQ); 1760 1761 } 1762 __ bind(done); 1763 } 1764 1765 void TemplateTable::branch(bool is_jsr, bool is_wide) 1766 { 1767 // We might be moving to a safepoint. The thread which calls 1768 // Interpreter::notice_safepoints() will effectively flush its cache 1769 // when it makes a system call, but we need to do something to 1770 // ensure that we see the changed dispatch table. 1771 __ membar(MacroAssembler::LoadLoad); 1772 1773 __ profile_taken_branch(r0, r1); 1774 const ByteSize be_offset = MethodCounters::backedge_counter_offset() + 1775 InvocationCounter::counter_offset(); 1776 const ByteSize inv_offset = MethodCounters::invocation_counter_offset() + 1777 InvocationCounter::counter_offset(); 1778 1779 // load branch displacement 1780 if (!is_wide) { 1781 __ ldrh(r2, at_bcp(1)); 1782 __ rev16(r2, r2); 1783 // sign extend the 16 bit value in r2 1784 __ sbfm(r2, r2, 0, 15); 1785 } else { 1786 __ ldrw(r2, at_bcp(1)); 1787 __ revw(r2, r2); 1788 // sign extend the 32 bit value in r2 1789 __ sbfm(r2, r2, 0, 31); 1790 } 1791 1792 // Handle all the JSR stuff here, then exit. 1793 // It's much shorter and cleaner than intermingling with the non-JSR 1794 // normal-branch stuff occurring below. 1795 1796 if (is_jsr) { 1797 // Pre-load the next target bytecode into rscratch1 1798 __ load_unsigned_byte(rscratch1, Address(rbcp, r2)); 1799 // compute return address as bci 1800 __ ldr(rscratch2, Address(rmethod, Method::const_offset())); 1801 __ add(rscratch2, rscratch2, 1802 in_bytes(ConstMethod::codes_offset()) - (is_wide ? 5 : 3)); 1803 __ sub(r1, rbcp, rscratch2); 1804 __ push_i(r1); 1805 // Adjust the bcp by the 16-bit displacement in r2 1806 __ add(rbcp, rbcp, r2); 1807 __ dispatch_only(vtos, /*generate_poll*/true); 1808 return; 1809 } 1810 1811 // Normal (non-jsr) branch handling 1812 1813 // Adjust the bcp by the displacement in r2 1814 __ add(rbcp, rbcp, r2); 1815 1816 assert(UseLoopCounter || !UseOnStackReplacement, 1817 "on-stack-replacement requires loop counters"); 1818 Label backedge_counter_overflow; 1819 Label profile_method; 1820 Label dispatch; 1821 if (UseLoopCounter) { 1822 // increment backedge counter for backward branches 1823 // r0: MDO 1824 // w1: MDO bumped taken-count 1825 // r2: target offset 1826 __ cmp(r2, zr); 1827 __ br(Assembler::GT, dispatch); // count only if backward branch 1828 1829 // ECN: FIXME: This code smells 1830 // check if MethodCounters exists 1831 Label has_counters; 1832 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset())); 1833 __ cbnz(rscratch1, has_counters); 1834 __ push(r0); 1835 __ push(r1); 1836 __ push(r2); 1837 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 1838 InterpreterRuntime::build_method_counters), rmethod); 1839 __ pop(r2); 1840 __ pop(r1); 1841 __ pop(r0); 1842 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset())); 1843 __ cbz(rscratch1, dispatch); // No MethodCounters allocated, OutOfMemory 1844 __ bind(has_counters); 1845 1846 if (TieredCompilation) { 1847 Label no_mdo; 1848 int increment = InvocationCounter::count_increment; 1849 if (ProfileInterpreter) { 1850 // Are we profiling? 1851 __ ldr(r1, Address(rmethod, in_bytes(Method::method_data_offset()))); 1852 __ cbz(r1, no_mdo); 1853 // Increment the MDO backedge counter 1854 const Address mdo_backedge_counter(r1, in_bytes(MethodData::backedge_counter_offset()) + 1855 in_bytes(InvocationCounter::counter_offset())); 1856 const Address mask(r1, in_bytes(MethodData::backedge_mask_offset())); 1857 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, 1858 r0, rscratch1, false, Assembler::EQ, 1859 UseOnStackReplacement ? &backedge_counter_overflow : &dispatch); 1860 __ b(dispatch); 1861 } 1862 __ bind(no_mdo); 1863 // Increment backedge counter in MethodCounters* 1864 __ ldr(rscratch1, Address(rmethod, Method::method_counters_offset())); 1865 const Address mask(rscratch1, in_bytes(MethodCounters::backedge_mask_offset())); 1866 __ increment_mask_and_jump(Address(rscratch1, be_offset), increment, mask, 1867 r0, rscratch2, false, Assembler::EQ, 1868 UseOnStackReplacement ? &backedge_counter_overflow : &dispatch); 1869 } else { // not TieredCompilation 1870 // increment counter 1871 __ ldr(rscratch2, Address(rmethod, Method::method_counters_offset())); 1872 __ ldrw(r0, Address(rscratch2, be_offset)); // load backedge counter 1873 __ addw(rscratch1, r0, InvocationCounter::count_increment); // increment counter 1874 __ strw(rscratch1, Address(rscratch2, be_offset)); // store counter 1875 1876 __ ldrw(r0, Address(rscratch2, inv_offset)); // load invocation counter 1877 __ andw(r0, r0, (unsigned)InvocationCounter::count_mask_value); // and the status bits 1878 __ addw(r0, r0, rscratch1); // add both counters 1879 1880 if (ProfileInterpreter) { 1881 // Test to see if we should create a method data oop 1882 __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_profile_limit_offset()))); 1883 __ cmpw(r0, rscratch1); 1884 __ br(Assembler::LT, dispatch); 1885 1886 // if no method data exists, go to profile method 1887 __ test_method_data_pointer(r0, profile_method); 1888 1889 if (UseOnStackReplacement) { 1890 // check for overflow against w1 which is the MDO taken count 1891 __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset()))); 1892 __ cmpw(r1, rscratch1); 1893 __ br(Assembler::LO, dispatch); // Intel == Assembler::below 1894 1895 // When ProfileInterpreter is on, the backedge_count comes 1896 // from the MethodData*, which value does not get reset on 1897 // the call to frequency_counter_overflow(). To avoid 1898 // excessive calls to the overflow routine while the method is 1899 // being compiled, add a second test to make sure the overflow 1900 // function is called only once every overflow_frequency. 1901 const int overflow_frequency = 1024; 1902 __ andsw(r1, r1, overflow_frequency - 1); 1903 __ br(Assembler::EQ, backedge_counter_overflow); 1904 1905 } 1906 } else { 1907 if (UseOnStackReplacement) { 1908 // check for overflow against w0, which is the sum of the 1909 // counters 1910 __ ldrw(rscratch1, Address(rscratch2, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset()))); 1911 __ cmpw(r0, rscratch1); 1912 __ br(Assembler::HS, backedge_counter_overflow); // Intel == Assembler::aboveEqual 1913 } 1914 } 1915 } 1916 __ bind(dispatch); 1917 } 1918 1919 // Pre-load the next target bytecode into rscratch1 1920 __ load_unsigned_byte(rscratch1, Address(rbcp, 0)); 1921 1922 // continue with the bytecode @ target 1923 // rscratch1: target bytecode 1924 // rbcp: target bcp 1925 __ dispatch_only(vtos, /*generate_poll*/true); 1926 1927 if (UseLoopCounter) { 1928 if (ProfileInterpreter) { 1929 // Out-of-line code to allocate method data oop. 1930 __ bind(profile_method); 1931 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1932 __ load_unsigned_byte(r1, Address(rbcp, 0)); // restore target bytecode 1933 __ set_method_data_pointer_for_bcp(); 1934 __ b(dispatch); 1935 } 1936 1937 if (UseOnStackReplacement) { 1938 // invocation counter overflow 1939 __ bind(backedge_counter_overflow); 1940 __ neg(r2, r2); 1941 __ add(r2, r2, rbcp); // branch bcp 1942 // IcoResult frequency_counter_overflow([JavaThread*], address branch_bcp) 1943 __ call_VM(noreg, 1944 CAST_FROM_FN_PTR(address, 1945 InterpreterRuntime::frequency_counter_overflow), 1946 r2); 1947 __ load_unsigned_byte(r1, Address(rbcp, 0)); // restore target bytecode 1948 1949 // r0: osr nmethod (osr ok) or NULL (osr not possible) 1950 // w1: target bytecode 1951 // r2: scratch 1952 __ cbz(r0, dispatch); // test result -- no osr if null 1953 // nmethod may have been invalidated (VM may block upon call_VM return) 1954 __ ldrb(r2, Address(r0, nmethod::state_offset())); 1955 if (nmethod::in_use != 0) 1956 __ sub(r2, r2, nmethod::in_use); 1957 __ cbnz(r2, dispatch); 1958 1959 // We have the address of an on stack replacement routine in r0 1960 // We need to prepare to execute the OSR method. First we must 1961 // migrate the locals and monitors off of the stack. 1962 1963 __ mov(r19, r0); // save the nmethod 1964 1965 call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin)); 1966 1967 // r0 is OSR buffer, move it to expected parameter location 1968 __ mov(j_rarg0, r0); 1969 1970 // remove activation 1971 // get sender esp 1972 __ ldr(esp, 1973 Address(rfp, frame::interpreter_frame_sender_sp_offset * wordSize)); 1974 // remove frame anchor 1975 __ leave(); 1976 // Ensure compiled code always sees stack at proper alignment 1977 __ andr(sp, esp, -16); 1978 1979 // and begin the OSR nmethod 1980 __ ldr(rscratch1, Address(r19, nmethod::osr_entry_point_offset())); 1981 __ br(rscratch1); 1982 } 1983 } 1984 } 1985 1986 1987 void TemplateTable::if_0cmp(Condition cc) 1988 { 1989 transition(itos, vtos); 1990 // assume branch is more often taken than not (loops use backward branches) 1991 Label not_taken; 1992 if (cc == equal) 1993 __ cbnzw(r0, not_taken); 1994 else if (cc == not_equal) 1995 __ cbzw(r0, not_taken); 1996 else { 1997 __ andsw(zr, r0, r0); 1998 __ br(j_not(cc), not_taken); 1999 } 2000 2001 branch(false, false); 2002 __ bind(not_taken); 2003 __ profile_not_taken_branch(r0); 2004 } 2005 2006 void TemplateTable::if_icmp(Condition cc) 2007 { 2008 transition(itos, vtos); 2009 // assume branch is more often taken than not (loops use backward branches) 2010 Label not_taken; 2011 __ pop_i(r1); 2012 __ cmpw(r1, r0, Assembler::LSL); 2013 __ br(j_not(cc), not_taken); 2014 branch(false, false); 2015 __ bind(not_taken); 2016 __ profile_not_taken_branch(r0); 2017 } 2018 2019 void TemplateTable::if_nullcmp(Condition cc) 2020 { 2021 transition(atos, vtos); 2022 // assume branch is more often taken than not (loops use backward branches) 2023 Label not_taken; 2024 if (cc == equal) 2025 __ cbnz(r0, not_taken); 2026 else 2027 __ cbz(r0, not_taken); 2028 branch(false, false); 2029 __ bind(not_taken); 2030 __ profile_not_taken_branch(r0); 2031 } 2032 2033 void TemplateTable::if_acmp(Condition cc) 2034 { 2035 transition(atos, vtos); 2036 // assume branch is more often taken than not (loops use backward branches) 2037 Label not_taken; 2038 __ pop_ptr(r1); 2039 __ cmp(r1, r0); 2040 __ br(j_not(cc), not_taken); 2041 branch(false, false); 2042 __ bind(not_taken); 2043 __ profile_not_taken_branch(r0); 2044 } 2045 2046 void TemplateTable::ret() { 2047 transition(vtos, vtos); 2048 // We might be moving to a safepoint. The thread which calls 2049 // Interpreter::notice_safepoints() will effectively flush its cache 2050 // when it makes a system call, but we need to do something to 2051 // ensure that we see the changed dispatch table. 2052 __ membar(MacroAssembler::LoadLoad); 2053 2054 locals_index(r1); 2055 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp 2056 __ profile_ret(r1, r2); 2057 __ ldr(rbcp, Address(rmethod, Method::const_offset())); 2058 __ lea(rbcp, Address(rbcp, r1)); 2059 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); 2060 __ dispatch_next(vtos, 0, /*generate_poll*/true); 2061 } 2062 2063 void TemplateTable::wide_ret() { 2064 transition(vtos, vtos); 2065 locals_index_wide(r1); 2066 __ ldr(r1, aaddress(r1)); // get return bci, compute return bcp 2067 __ profile_ret(r1, r2); 2068 __ ldr(rbcp, Address(rmethod, Method::const_offset())); 2069 __ lea(rbcp, Address(rbcp, r1)); 2070 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); 2071 __ dispatch_next(vtos, 0, /*generate_poll*/true); 2072 } 2073 2074 2075 void TemplateTable::tableswitch() { 2076 Label default_case, continue_execution; 2077 transition(itos, vtos); 2078 // align rbcp 2079 __ lea(r1, at_bcp(BytesPerInt)); 2080 __ andr(r1, r1, -BytesPerInt); 2081 // load lo & hi 2082 __ ldrw(r2, Address(r1, BytesPerInt)); 2083 __ ldrw(r3, Address(r1, 2 * BytesPerInt)); 2084 __ rev32(r2, r2); 2085 __ rev32(r3, r3); 2086 // check against lo & hi 2087 __ cmpw(r0, r2); 2088 __ br(Assembler::LT, default_case); 2089 __ cmpw(r0, r3); 2090 __ br(Assembler::GT, default_case); 2091 // lookup dispatch offset 2092 __ subw(r0, r0, r2); 2093 __ lea(r3, Address(r1, r0, Address::uxtw(2))); 2094 __ ldrw(r3, Address(r3, 3 * BytesPerInt)); 2095 __ profile_switch_case(r0, r1, r2); 2096 // continue execution 2097 __ bind(continue_execution); 2098 __ rev32(r3, r3); 2099 __ load_unsigned_byte(rscratch1, Address(rbcp, r3, Address::sxtw(0))); 2100 __ add(rbcp, rbcp, r3, ext::sxtw); 2101 __ dispatch_only(vtos, /*generate_poll*/true); 2102 // handle default 2103 __ bind(default_case); 2104 __ profile_switch_default(r0); 2105 __ ldrw(r3, Address(r1, 0)); 2106 __ b(continue_execution); 2107 } 2108 2109 void TemplateTable::lookupswitch() { 2110 transition(itos, itos); 2111 __ stop("lookupswitch bytecode should have been rewritten"); 2112 } 2113 2114 void TemplateTable::fast_linearswitch() { 2115 transition(itos, vtos); 2116 Label loop_entry, loop, found, continue_execution; 2117 // bswap r0 so we can avoid bswapping the table entries 2118 __ rev32(r0, r0); 2119 // align rbcp 2120 __ lea(r19, at_bcp(BytesPerInt)); // btw: should be able to get rid of 2121 // this instruction (change offsets 2122 // below) 2123 __ andr(r19, r19, -BytesPerInt); 2124 // set counter 2125 __ ldrw(r1, Address(r19, BytesPerInt)); 2126 __ rev32(r1, r1); 2127 __ b(loop_entry); 2128 // table search 2129 __ bind(loop); 2130 __ lea(rscratch1, Address(r19, r1, Address::lsl(3))); 2131 __ ldrw(rscratch1, Address(rscratch1, 2 * BytesPerInt)); 2132 __ cmpw(r0, rscratch1); 2133 __ br(Assembler::EQ, found); 2134 __ bind(loop_entry); 2135 __ subs(r1, r1, 1); 2136 __ br(Assembler::PL, loop); 2137 // default case 2138 __ profile_switch_default(r0); 2139 __ ldrw(r3, Address(r19, 0)); 2140 __ b(continue_execution); 2141 // entry found -> get offset 2142 __ bind(found); 2143 __ lea(rscratch1, Address(r19, r1, Address::lsl(3))); 2144 __ ldrw(r3, Address(rscratch1, 3 * BytesPerInt)); 2145 __ profile_switch_case(r1, r0, r19); 2146 // continue execution 2147 __ bind(continue_execution); 2148 __ rev32(r3, r3); 2149 __ add(rbcp, rbcp, r3, ext::sxtw); 2150 __ ldrb(rscratch1, Address(rbcp, 0)); 2151 __ dispatch_only(vtos, /*generate_poll*/true); 2152 } 2153 2154 void TemplateTable::fast_binaryswitch() { 2155 transition(itos, vtos); 2156 // Implementation using the following core algorithm: 2157 // 2158 // int binary_search(int key, LookupswitchPair* array, int n) { 2159 // // Binary search according to "Methodik des Programmierens" by 2160 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. 2161 // int i = 0; 2162 // int j = n; 2163 // while (i+1 < j) { 2164 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) 2165 // // with Q: for all i: 0 <= i < n: key < a[i] 2166 // // where a stands for the array and assuming that the (inexisting) 2167 // // element a[n] is infinitely big. 2168 // int h = (i + j) >> 1; 2169 // // i < h < j 2170 // if (key < array[h].fast_match()) { 2171 // j = h; 2172 // } else { 2173 // i = h; 2174 // } 2175 // } 2176 // // R: a[i] <= key < a[i+1] or Q 2177 // // (i.e., if key is within array, i is the correct index) 2178 // return i; 2179 // } 2180 2181 // Register allocation 2182 const Register key = r0; // already set (tosca) 2183 const Register array = r1; 2184 const Register i = r2; 2185 const Register j = r3; 2186 const Register h = rscratch1; 2187 const Register temp = rscratch2; 2188 2189 // Find array start 2190 __ lea(array, at_bcp(3 * BytesPerInt)); // btw: should be able to 2191 // get rid of this 2192 // instruction (change 2193 // offsets below) 2194 __ andr(array, array, -BytesPerInt); 2195 2196 // Initialize i & j 2197 __ mov(i, 0); // i = 0; 2198 __ ldrw(j, Address(array, -BytesPerInt)); // j = length(array); 2199 2200 // Convert j into native byteordering 2201 __ rev32(j, j); 2202 2203 // And start 2204 Label entry; 2205 __ b(entry); 2206 2207 // binary search loop 2208 { 2209 Label loop; 2210 __ bind(loop); 2211 // int h = (i + j) >> 1; 2212 __ addw(h, i, j); // h = i + j; 2213 __ lsrw(h, h, 1); // h = (i + j) >> 1; 2214 // if (key < array[h].fast_match()) { 2215 // j = h; 2216 // } else { 2217 // i = h; 2218 // } 2219 // Convert array[h].match to native byte-ordering before compare 2220 __ ldr(temp, Address(array, h, Address::lsl(3))); 2221 __ rev32(temp, temp); 2222 __ cmpw(key, temp); 2223 // j = h if (key < array[h].fast_match()) 2224 __ csel(j, h, j, Assembler::LT); 2225 // i = h if (key >= array[h].fast_match()) 2226 __ csel(i, h, i, Assembler::GE); 2227 // while (i+1 < j) 2228 __ bind(entry); 2229 __ addw(h, i, 1); // i+1 2230 __ cmpw(h, j); // i+1 < j 2231 __ br(Assembler::LT, loop); 2232 } 2233 2234 // end of binary search, result index is i (must check again!) 2235 Label default_case; 2236 // Convert array[i].match to native byte-ordering before compare 2237 __ ldr(temp, Address(array, i, Address::lsl(3))); 2238 __ rev32(temp, temp); 2239 __ cmpw(key, temp); 2240 __ br(Assembler::NE, default_case); 2241 2242 // entry found -> j = offset 2243 __ add(j, array, i, ext::uxtx, 3); 2244 __ ldrw(j, Address(j, BytesPerInt)); 2245 __ profile_switch_case(i, key, array); 2246 __ rev32(j, j); 2247 __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0))); 2248 __ lea(rbcp, Address(rbcp, j, Address::sxtw(0))); 2249 __ dispatch_only(vtos, /*generate_poll*/true); 2250 2251 // default case -> j = default offset 2252 __ bind(default_case); 2253 __ profile_switch_default(i); 2254 __ ldrw(j, Address(array, -2 * BytesPerInt)); 2255 __ rev32(j, j); 2256 __ load_unsigned_byte(rscratch1, Address(rbcp, j, Address::sxtw(0))); 2257 __ lea(rbcp, Address(rbcp, j, Address::sxtw(0))); 2258 __ dispatch_only(vtos, /*generate_poll*/true); 2259 } 2260 2261 2262 void TemplateTable::_return(TosState state) 2263 { 2264 transition(state, state); 2265 assert(_desc->calls_vm(), 2266 "inconsistent calls_vm information"); // call in remove_activation 2267 2268 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) { 2269 assert(state == vtos, "only valid state"); 2270 2271 __ ldr(c_rarg1, aaddress(0)); 2272 __ load_klass(r3, c_rarg1); 2273 __ ldrw(r3, Address(r3, Klass::access_flags_offset())); 2274 Label skip_register_finalizer; 2275 __ tbz(r3, exact_log2(JVM_ACC_HAS_FINALIZER), skip_register_finalizer); 2276 2277 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), c_rarg1); 2278 2279 __ bind(skip_register_finalizer); 2280 } 2281 2282 // Issue a StoreStore barrier after all stores but before return 2283 // from any constructor for any class with a final field. We don't 2284 // know if this is a finalizer, so we always do so. 2285 if (_desc->bytecode() == Bytecodes::_return) 2286 __ membar(MacroAssembler::StoreStore); 2287 2288 // Narrow result if state is itos but result type is smaller. 2289 // Need to narrow in the return bytecode rather than in generate_return_entry 2290 // since compiled code callers expect the result to already be narrowed. 2291 if (state == itos) { 2292 __ narrow(r0); 2293 } 2294 2295 __ remove_activation(state); 2296 __ ret(lr); 2297 } 2298 2299 // ---------------------------------------------------------------------------- 2300 // Volatile variables demand their effects be made known to all CPU's 2301 // in order. Store buffers on most chips allow reads & writes to 2302 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode 2303 // without some kind of memory barrier (i.e., it's not sufficient that 2304 // the interpreter does not reorder volatile references, the hardware 2305 // also must not reorder them). 2306 // 2307 // According to the new Java Memory Model (JMM): 2308 // (1) All volatiles are serialized wrt to each other. ALSO reads & 2309 // writes act as aquire & release, so: 2310 // (2) A read cannot let unrelated NON-volatile memory refs that 2311 // happen after the read float up to before the read. It's OK for 2312 // non-volatile memory refs that happen before the volatile read to 2313 // float down below it. 2314 // (3) Similar a volatile write cannot let unrelated NON-volatile 2315 // memory refs that happen BEFORE the write float down to after the 2316 // write. It's OK for non-volatile memory refs that happen after the 2317 // volatile write to float up before it. 2318 // 2319 // We only put in barriers around volatile refs (they are expensive), 2320 // not _between_ memory refs (that would require us to track the 2321 // flavor of the previous memory refs). Requirements (2) and (3) 2322 // require some barriers before volatile stores and after volatile 2323 // loads. These nearly cover requirement (1) but miss the 2324 // volatile-store-volatile-load case. This final case is placed after 2325 // volatile-stores although it could just as well go before 2326 // volatile-loads. 2327 2328 void TemplateTable::resolve_cache_and_index(int byte_no, 2329 Register Rcache, 2330 Register index, 2331 size_t index_size) { 2332 const Register temp = r19; 2333 assert_different_registers(Rcache, index, temp); 2334 2335 Label resolved; 2336 2337 Bytecodes::Code code = bytecode(); 2338 switch (code) { 2339 case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break; 2340 case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break; 2341 } 2342 2343 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 2344 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, index, temp, byte_no, 1, index_size); 2345 __ cmp(temp, (int) code); // have we resolved this bytecode? 2346 __ br(Assembler::EQ, resolved); 2347 2348 // resolve first time through 2349 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache); 2350 __ mov(temp, (int) code); 2351 __ call_VM(noreg, entry, temp); 2352 2353 // Update registers with resolved info 2354 __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size); 2355 // n.b. unlike x86 Rcache is now rcpool plus the indexed offset 2356 // so all clients ofthis method must be modified accordingly 2357 __ bind(resolved); 2358 } 2359 2360 // The Rcache and index registers must be set before call 2361 // n.b unlike x86 cache already includes the index offset 2362 void TemplateTable::load_field_cp_cache_entry(Register obj, 2363 Register cache, 2364 Register index, 2365 Register off, 2366 Register flags, 2367 bool is_static = false) { 2368 assert_different_registers(cache, index, flags, off); 2369 2370 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2371 // Field offset 2372 __ ldr(off, Address(cache, in_bytes(cp_base_offset + 2373 ConstantPoolCacheEntry::f2_offset()))); 2374 // Flags 2375 __ ldrw(flags, Address(cache, in_bytes(cp_base_offset + 2376 ConstantPoolCacheEntry::flags_offset()))); 2377 2378 // klass overwrite register 2379 if (is_static) { 2380 __ ldr(obj, Address(cache, in_bytes(cp_base_offset + 2381 ConstantPoolCacheEntry::f1_offset()))); 2382 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 2383 __ ldr(obj, Address(obj, mirror_offset)); 2384 __ resolve_oop_handle(obj); 2385 } 2386 } 2387 2388 void TemplateTable::load_invoke_cp_cache_entry(int byte_no, 2389 Register method, 2390 Register itable_index, 2391 Register flags, 2392 bool is_invokevirtual, 2393 bool is_invokevfinal, /*unused*/ 2394 bool is_invokedynamic) { 2395 // setup registers 2396 const Register cache = rscratch2; 2397 const Register index = r4; 2398 assert_different_registers(method, flags); 2399 assert_different_registers(method, cache, index); 2400 assert_different_registers(itable_index, flags); 2401 assert_different_registers(itable_index, cache, index); 2402 // determine constant pool cache field offsets 2403 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant"); 2404 const int method_offset = in_bytes( 2405 ConstantPoolCache::base_offset() + 2406 (is_invokevirtual 2407 ? ConstantPoolCacheEntry::f2_offset() 2408 : ConstantPoolCacheEntry::f1_offset())); 2409 const int flags_offset = in_bytes(ConstantPoolCache::base_offset() + 2410 ConstantPoolCacheEntry::flags_offset()); 2411 // access constant pool cache fields 2412 const int index_offset = in_bytes(ConstantPoolCache::base_offset() + 2413 ConstantPoolCacheEntry::f2_offset()); 2414 2415 size_t index_size = (is_invokedynamic ? sizeof(u4) : sizeof(u2)); 2416 resolve_cache_and_index(byte_no, cache, index, index_size); 2417 __ ldr(method, Address(cache, method_offset)); 2418 2419 if (itable_index != noreg) { 2420 __ ldr(itable_index, Address(cache, index_offset)); 2421 } 2422 __ ldrw(flags, Address(cache, flags_offset)); 2423 } 2424 2425 2426 // The registers cache and index expected to be set before call. 2427 // Correct values of the cache and index registers are preserved. 2428 void TemplateTable::jvmti_post_field_access(Register cache, Register index, 2429 bool is_static, bool has_tos) { 2430 // do the JVMTI work here to avoid disturbing the register state below 2431 // We use c_rarg registers here because we want to use the register used in 2432 // the call to the VM 2433 if (JvmtiExport::can_post_field_access()) { 2434 // Check to see if a field access watch has been set before we 2435 // take the time to call into the VM. 2436 Label L1; 2437 assert_different_registers(cache, index, r0); 2438 __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); 2439 __ ldrw(r0, Address(rscratch1)); 2440 __ cbzw(r0, L1); 2441 2442 __ get_cache_and_index_at_bcp(c_rarg2, c_rarg3, 1); 2443 __ lea(c_rarg2, Address(c_rarg2, in_bytes(ConstantPoolCache::base_offset()))); 2444 2445 if (is_static) { 2446 __ mov(c_rarg1, zr); // NULL object reference 2447 } else { 2448 __ ldr(c_rarg1, at_tos()); // get object pointer without popping it 2449 __ verify_oop(c_rarg1); 2450 } 2451 // c_rarg1: object pointer or NULL 2452 // c_rarg2: cache entry pointer 2453 // c_rarg3: jvalue object on the stack 2454 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 2455 InterpreterRuntime::post_field_access), 2456 c_rarg1, c_rarg2, c_rarg3); 2457 __ get_cache_and_index_at_bcp(cache, index, 1); 2458 __ bind(L1); 2459 } 2460 } 2461 2462 void TemplateTable::pop_and_check_object(Register r) 2463 { 2464 __ pop_ptr(r); 2465 __ null_check(r); // for field access must check obj. 2466 __ verify_oop(r); 2467 } 2468 2469 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) 2470 { 2471 const Register cache = r2; 2472 const Register index = r3; 2473 const Register obj = r4; 2474 const Register off = r19; 2475 const Register flags = r0; 2476 const Register raw_flags = r6; 2477 const Register bc = r4; // uses same reg as obj, so don't mix them 2478 2479 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2480 jvmti_post_field_access(cache, index, is_static, false); 2481 load_field_cp_cache_entry(obj, cache, index, off, raw_flags, is_static); 2482 2483 if (!is_static) { 2484 // obj is on the stack 2485 pop_and_check_object(obj); 2486 } 2487 2488 // 8179954: We need to make sure that the code generated for 2489 // volatile accesses forms a sequentially-consistent set of 2490 // operations when combined with STLR and LDAR. Without a leading 2491 // membar it's possible for a simple Dekker test to fail if loads 2492 // use LDR;DMB but stores use STLR. This can happen if C2 compiles 2493 // the stores in one method and we interpret the loads in another. 2494 if (! UseBarriersForVolatile) { 2495 Label notVolatile; 2496 __ tbz(raw_flags, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 2497 __ membar(MacroAssembler::AnyAny); 2498 __ bind(notVolatile); 2499 } 2500 2501 const Address field(obj, off); 2502 2503 Label Done, notByte, notBool, notInt, notShort, notChar, 2504 notLong, notFloat, notObj, notDouble; 2505 2506 // x86 uses a shift and mask or wings it with a shift plus assert 2507 // the mask is not needed. aarch64 just uses bitfield extract 2508 __ ubfxw(flags, raw_flags, ConstantPoolCacheEntry::tos_state_shift, 2509 ConstantPoolCacheEntry::tos_state_bits); 2510 2511 assert(btos == 0, "change code, btos != 0"); 2512 __ cbnz(flags, notByte); 2513 2514 // Don't rewrite getstatic, only getfield 2515 if (is_static) rc = may_not_rewrite; 2516 2517 // btos 2518 __ load_signed_byte(r0, field); 2519 __ push(btos); 2520 // Rewrite bytecode to be faster 2521 if (rc == may_rewrite) { 2522 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1); 2523 } 2524 __ b(Done); 2525 2526 __ bind(notByte); 2527 __ cmp(flags, ztos); 2528 __ br(Assembler::NE, notBool); 2529 2530 // ztos (same code as btos) 2531 __ ldrsb(r0, field); 2532 __ push(ztos); 2533 // Rewrite bytecode to be faster 2534 if (rc == may_rewrite) { 2535 // use btos rewriting, no truncating to t/f bit is needed for getfield. 2536 patch_bytecode(Bytecodes::_fast_bgetfield, bc, r1); 2537 } 2538 __ b(Done); 2539 2540 __ bind(notBool); 2541 __ cmp(flags, atos); 2542 __ br(Assembler::NE, notObj); 2543 // atos 2544 do_oop_load(_masm, field, r0, IN_HEAP); 2545 __ push(atos); 2546 if (rc == may_rewrite) { 2547 patch_bytecode(Bytecodes::_fast_agetfield, bc, r1); 2548 } 2549 __ b(Done); 2550 2551 __ bind(notObj); 2552 __ cmp(flags, itos); 2553 __ br(Assembler::NE, notInt); 2554 // itos 2555 __ ldrw(r0, field); 2556 __ push(itos); 2557 // Rewrite bytecode to be faster 2558 if (rc == may_rewrite) { 2559 patch_bytecode(Bytecodes::_fast_igetfield, bc, r1); 2560 } 2561 __ b(Done); 2562 2563 __ bind(notInt); 2564 __ cmp(flags, ctos); 2565 __ br(Assembler::NE, notChar); 2566 // ctos 2567 __ load_unsigned_short(r0, field); 2568 __ push(ctos); 2569 // Rewrite bytecode to be faster 2570 if (rc == may_rewrite) { 2571 patch_bytecode(Bytecodes::_fast_cgetfield, bc, r1); 2572 } 2573 __ b(Done); 2574 2575 __ bind(notChar); 2576 __ cmp(flags, stos); 2577 __ br(Assembler::NE, notShort); 2578 // stos 2579 __ load_signed_short(r0, field); 2580 __ push(stos); 2581 // Rewrite bytecode to be faster 2582 if (rc == may_rewrite) { 2583 patch_bytecode(Bytecodes::_fast_sgetfield, bc, r1); 2584 } 2585 __ b(Done); 2586 2587 __ bind(notShort); 2588 __ cmp(flags, ltos); 2589 __ br(Assembler::NE, notLong); 2590 // ltos 2591 __ ldr(r0, field); 2592 __ push(ltos); 2593 // Rewrite bytecode to be faster 2594 if (rc == may_rewrite) { 2595 patch_bytecode(Bytecodes::_fast_lgetfield, bc, r1); 2596 } 2597 __ b(Done); 2598 2599 __ bind(notLong); 2600 __ cmp(flags, ftos); 2601 __ br(Assembler::NE, notFloat); 2602 // ftos 2603 __ ldrs(v0, field); 2604 __ push(ftos); 2605 // Rewrite bytecode to be faster 2606 if (rc == may_rewrite) { 2607 patch_bytecode(Bytecodes::_fast_fgetfield, bc, r1); 2608 } 2609 __ b(Done); 2610 2611 __ bind(notFloat); 2612 #ifdef ASSERT 2613 __ cmp(flags, dtos); 2614 __ br(Assembler::NE, notDouble); 2615 #endif 2616 // dtos 2617 __ ldrd(v0, field); 2618 __ push(dtos); 2619 // Rewrite bytecode to be faster 2620 if (rc == may_rewrite) { 2621 patch_bytecode(Bytecodes::_fast_dgetfield, bc, r1); 2622 } 2623 #ifdef ASSERT 2624 __ b(Done); 2625 2626 __ bind(notDouble); 2627 __ stop("Bad state"); 2628 #endif 2629 2630 __ bind(Done); 2631 2632 Label notVolatile; 2633 __ tbz(raw_flags, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 2634 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); 2635 __ bind(notVolatile); 2636 } 2637 2638 2639 void TemplateTable::getfield(int byte_no) 2640 { 2641 getfield_or_static(byte_no, false); 2642 } 2643 2644 void TemplateTable::nofast_getfield(int byte_no) { 2645 getfield_or_static(byte_no, false, may_not_rewrite); 2646 } 2647 2648 void TemplateTable::getstatic(int byte_no) 2649 { 2650 getfield_or_static(byte_no, true); 2651 } 2652 2653 // The registers cache and index expected to be set before call. 2654 // The function may destroy various registers, just not the cache and index registers. 2655 void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) { 2656 transition(vtos, vtos); 2657 2658 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2659 2660 if (JvmtiExport::can_post_field_modification()) { 2661 // Check to see if a field modification watch has been set before 2662 // we take the time to call into the VM. 2663 Label L1; 2664 assert_different_registers(cache, index, r0); 2665 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); 2666 __ ldrw(r0, Address(rscratch1)); 2667 __ cbz(r0, L1); 2668 2669 __ get_cache_and_index_at_bcp(c_rarg2, rscratch1, 1); 2670 2671 if (is_static) { 2672 // Life is simple. Null out the object pointer. 2673 __ mov(c_rarg1, zr); 2674 } else { 2675 // Life is harder. The stack holds the value on top, followed by 2676 // the object. We don't know the size of the value, though; it 2677 // could be one or two words depending on its type. As a result, 2678 // we must find the type to determine where the object is. 2679 __ ldrw(c_rarg3, Address(c_rarg2, 2680 in_bytes(cp_base_offset + 2681 ConstantPoolCacheEntry::flags_offset()))); 2682 __ lsr(c_rarg3, c_rarg3, 2683 ConstantPoolCacheEntry::tos_state_shift); 2684 ConstantPoolCacheEntry::verify_tos_state_shift(); 2685 Label nope2, done, ok; 2686 __ ldr(c_rarg1, at_tos_p1()); // initially assume a one word jvalue 2687 __ cmpw(c_rarg3, ltos); 2688 __ br(Assembler::EQ, ok); 2689 __ cmpw(c_rarg3, dtos); 2690 __ br(Assembler::NE, nope2); 2691 __ bind(ok); 2692 __ ldr(c_rarg1, at_tos_p2()); // ltos (two word jvalue) 2693 __ bind(nope2); 2694 } 2695 // cache entry pointer 2696 __ add(c_rarg2, c_rarg2, in_bytes(cp_base_offset)); 2697 // object (tos) 2698 __ mov(c_rarg3, esp); 2699 // c_rarg1: object pointer set up above (NULL if static) 2700 // c_rarg2: cache entry pointer 2701 // c_rarg3: jvalue object on the stack 2702 __ call_VM(noreg, 2703 CAST_FROM_FN_PTR(address, 2704 InterpreterRuntime::post_field_modification), 2705 c_rarg1, c_rarg2, c_rarg3); 2706 __ get_cache_and_index_at_bcp(cache, index, 1); 2707 __ bind(L1); 2708 } 2709 } 2710 2711 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2712 transition(vtos, vtos); 2713 2714 const Register cache = r2; 2715 const Register index = r3; 2716 const Register obj = r2; 2717 const Register off = r19; 2718 const Register flags = r0; 2719 const Register bc = r4; 2720 2721 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2722 jvmti_post_field_mod(cache, index, is_static); 2723 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); 2724 2725 Label Done; 2726 __ mov(r5, flags); 2727 2728 { 2729 Label notVolatile; 2730 __ tbz(r5, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 2731 __ membar(MacroAssembler::StoreStore); 2732 __ bind(notVolatile); 2733 } 2734 2735 // field address 2736 const Address field(obj, off); 2737 2738 Label notByte, notBool, notInt, notShort, notChar, 2739 notLong, notFloat, notObj, notDouble; 2740 2741 // x86 uses a shift and mask or wings it with a shift plus assert 2742 // the mask is not needed. aarch64 just uses bitfield extract 2743 __ ubfxw(flags, flags, ConstantPoolCacheEntry::tos_state_shift, ConstantPoolCacheEntry::tos_state_bits); 2744 2745 assert(btos == 0, "change code, btos != 0"); 2746 __ cbnz(flags, notByte); 2747 2748 // Don't rewrite putstatic, only putfield 2749 if (is_static) rc = may_not_rewrite; 2750 2751 // btos 2752 { 2753 __ pop(btos); 2754 if (!is_static) pop_and_check_object(obj); 2755 __ strb(r0, field); 2756 if (rc == may_rewrite) { 2757 patch_bytecode(Bytecodes::_fast_bputfield, bc, r1, true, byte_no); 2758 } 2759 __ b(Done); 2760 } 2761 2762 __ bind(notByte); 2763 __ cmp(flags, ztos); 2764 __ br(Assembler::NE, notBool); 2765 2766 // ztos 2767 { 2768 __ pop(ztos); 2769 if (!is_static) pop_and_check_object(obj); 2770 __ andw(r0, r0, 0x1); 2771 __ strb(r0, field); 2772 if (rc == may_rewrite) { 2773 patch_bytecode(Bytecodes::_fast_zputfield, bc, r1, true, byte_no); 2774 } 2775 __ b(Done); 2776 } 2777 2778 __ bind(notBool); 2779 __ cmp(flags, atos); 2780 __ br(Assembler::NE, notObj); 2781 2782 // atos 2783 { 2784 __ pop(atos); 2785 if (!is_static) pop_and_check_object(obj); 2786 // Store into the field 2787 do_oop_store(_masm, field, r0, IN_HEAP); 2788 if (rc == may_rewrite) { 2789 patch_bytecode(Bytecodes::_fast_aputfield, bc, r1, true, byte_no); 2790 } 2791 __ b(Done); 2792 } 2793 2794 __ bind(notObj); 2795 __ cmp(flags, itos); 2796 __ br(Assembler::NE, notInt); 2797 2798 // itos 2799 { 2800 __ pop(itos); 2801 if (!is_static) pop_and_check_object(obj); 2802 __ strw(r0, field); 2803 if (rc == may_rewrite) { 2804 patch_bytecode(Bytecodes::_fast_iputfield, bc, r1, true, byte_no); 2805 } 2806 __ b(Done); 2807 } 2808 2809 __ bind(notInt); 2810 __ cmp(flags, ctos); 2811 __ br(Assembler::NE, notChar); 2812 2813 // ctos 2814 { 2815 __ pop(ctos); 2816 if (!is_static) pop_and_check_object(obj); 2817 __ strh(r0, field); 2818 if (rc == may_rewrite) { 2819 patch_bytecode(Bytecodes::_fast_cputfield, bc, r1, true, byte_no); 2820 } 2821 __ b(Done); 2822 } 2823 2824 __ bind(notChar); 2825 __ cmp(flags, stos); 2826 __ br(Assembler::NE, notShort); 2827 2828 // stos 2829 { 2830 __ pop(stos); 2831 if (!is_static) pop_and_check_object(obj); 2832 __ strh(r0, field); 2833 if (rc == may_rewrite) { 2834 patch_bytecode(Bytecodes::_fast_sputfield, bc, r1, true, byte_no); 2835 } 2836 __ b(Done); 2837 } 2838 2839 __ bind(notShort); 2840 __ cmp(flags, ltos); 2841 __ br(Assembler::NE, notLong); 2842 2843 // ltos 2844 { 2845 __ pop(ltos); 2846 if (!is_static) pop_and_check_object(obj); 2847 __ str(r0, field); 2848 if (rc == may_rewrite) { 2849 patch_bytecode(Bytecodes::_fast_lputfield, bc, r1, true, byte_no); 2850 } 2851 __ b(Done); 2852 } 2853 2854 __ bind(notLong); 2855 __ cmp(flags, ftos); 2856 __ br(Assembler::NE, notFloat); 2857 2858 // ftos 2859 { 2860 __ pop(ftos); 2861 if (!is_static) pop_and_check_object(obj); 2862 __ strs(v0, field); 2863 if (rc == may_rewrite) { 2864 patch_bytecode(Bytecodes::_fast_fputfield, bc, r1, true, byte_no); 2865 } 2866 __ b(Done); 2867 } 2868 2869 __ bind(notFloat); 2870 #ifdef ASSERT 2871 __ cmp(flags, dtos); 2872 __ br(Assembler::NE, notDouble); 2873 #endif 2874 2875 // dtos 2876 { 2877 __ pop(dtos); 2878 if (!is_static) pop_and_check_object(obj); 2879 __ strd(v0, field); 2880 if (rc == may_rewrite) { 2881 patch_bytecode(Bytecodes::_fast_dputfield, bc, r1, true, byte_no); 2882 } 2883 } 2884 2885 #ifdef ASSERT 2886 __ b(Done); 2887 2888 __ bind(notDouble); 2889 __ stop("Bad state"); 2890 #endif 2891 2892 __ bind(Done); 2893 2894 { 2895 Label notVolatile; 2896 __ tbz(r5, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 2897 __ membar(MacroAssembler::StoreLoad); 2898 __ bind(notVolatile); 2899 } 2900 } 2901 2902 void TemplateTable::putfield(int byte_no) 2903 { 2904 putfield_or_static(byte_no, false); 2905 } 2906 2907 void TemplateTable::nofast_putfield(int byte_no) { 2908 putfield_or_static(byte_no, false, may_not_rewrite); 2909 } 2910 2911 void TemplateTable::putstatic(int byte_no) { 2912 putfield_or_static(byte_no, true); 2913 } 2914 2915 void TemplateTable::jvmti_post_fast_field_mod() 2916 { 2917 if (JvmtiExport::can_post_field_modification()) { 2918 // Check to see if a field modification watch has been set before 2919 // we take the time to call into the VM. 2920 Label L2; 2921 __ lea(rscratch1, ExternalAddress((address)JvmtiExport::get_field_modification_count_addr())); 2922 __ ldrw(c_rarg3, Address(rscratch1)); 2923 __ cbzw(c_rarg3, L2); 2924 __ pop_ptr(r19); // copy the object pointer from tos 2925 __ verify_oop(r19); 2926 __ push_ptr(r19); // put the object pointer back on tos 2927 // Save tos values before call_VM() clobbers them. Since we have 2928 // to do it for every data type, we use the saved values as the 2929 // jvalue object. 2930 switch (bytecode()) { // load values into the jvalue object 2931 case Bytecodes::_fast_aputfield: __ push_ptr(r0); break; 2932 case Bytecodes::_fast_bputfield: // fall through 2933 case Bytecodes::_fast_zputfield: // fall through 2934 case Bytecodes::_fast_sputfield: // fall through 2935 case Bytecodes::_fast_cputfield: // fall through 2936 case Bytecodes::_fast_iputfield: __ push_i(r0); break; 2937 case Bytecodes::_fast_dputfield: __ push_d(); break; 2938 case Bytecodes::_fast_fputfield: __ push_f(); break; 2939 case Bytecodes::_fast_lputfield: __ push_l(r0); break; 2940 2941 default: 2942 ShouldNotReachHere(); 2943 } 2944 __ mov(c_rarg3, esp); // points to jvalue on the stack 2945 // access constant pool cache entry 2946 __ get_cache_entry_pointer_at_bcp(c_rarg2, r0, 1); 2947 __ verify_oop(r19); 2948 // r19: object pointer copied above 2949 // c_rarg2: cache entry pointer 2950 // c_rarg3: jvalue object on the stack 2951 __ call_VM(noreg, 2952 CAST_FROM_FN_PTR(address, 2953 InterpreterRuntime::post_field_modification), 2954 r19, c_rarg2, c_rarg3); 2955 2956 switch (bytecode()) { // restore tos values 2957 case Bytecodes::_fast_aputfield: __ pop_ptr(r0); break; 2958 case Bytecodes::_fast_bputfield: // fall through 2959 case Bytecodes::_fast_zputfield: // fall through 2960 case Bytecodes::_fast_sputfield: // fall through 2961 case Bytecodes::_fast_cputfield: // fall through 2962 case Bytecodes::_fast_iputfield: __ pop_i(r0); break; 2963 case Bytecodes::_fast_dputfield: __ pop_d(); break; 2964 case Bytecodes::_fast_fputfield: __ pop_f(); break; 2965 case Bytecodes::_fast_lputfield: __ pop_l(r0); break; 2966 } 2967 __ bind(L2); 2968 } 2969 } 2970 2971 void TemplateTable::fast_storefield(TosState state) 2972 { 2973 transition(state, vtos); 2974 2975 ByteSize base = ConstantPoolCache::base_offset(); 2976 2977 jvmti_post_fast_field_mod(); 2978 2979 // access constant pool cache 2980 __ get_cache_and_index_at_bcp(r2, r1, 1); 2981 2982 // test for volatile with r3 2983 __ ldrw(r3, Address(r2, in_bytes(base + 2984 ConstantPoolCacheEntry::flags_offset()))); 2985 2986 // replace index with field offset from cache entry 2987 __ ldr(r1, Address(r2, in_bytes(base + ConstantPoolCacheEntry::f2_offset()))); 2988 2989 { 2990 Label notVolatile; 2991 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 2992 __ membar(MacroAssembler::StoreStore); 2993 __ bind(notVolatile); 2994 } 2995 2996 Label notVolatile; 2997 2998 // Get object from stack 2999 pop_and_check_object(r2); 3000 3001 // field address 3002 const Address field(r2, r1); 3003 3004 // access field 3005 switch (bytecode()) { 3006 case Bytecodes::_fast_aputfield: 3007 do_oop_store(_masm, field, r0, IN_HEAP); 3008 break; 3009 case Bytecodes::_fast_lputfield: 3010 __ str(r0, field); 3011 break; 3012 case Bytecodes::_fast_iputfield: 3013 __ strw(r0, field); 3014 break; 3015 case Bytecodes::_fast_zputfield: 3016 __ andw(r0, r0, 0x1); // boolean is true if LSB is 1 3017 // fall through to bputfield 3018 case Bytecodes::_fast_bputfield: 3019 __ strb(r0, field); 3020 break; 3021 case Bytecodes::_fast_sputfield: 3022 // fall through 3023 case Bytecodes::_fast_cputfield: 3024 __ strh(r0, field); 3025 break; 3026 case Bytecodes::_fast_fputfield: 3027 __ strs(v0, field); 3028 break; 3029 case Bytecodes::_fast_dputfield: 3030 __ strd(v0, field); 3031 break; 3032 default: 3033 ShouldNotReachHere(); 3034 } 3035 3036 { 3037 Label notVolatile; 3038 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 3039 __ membar(MacroAssembler::StoreLoad); 3040 __ bind(notVolatile); 3041 } 3042 } 3043 3044 3045 void TemplateTable::fast_accessfield(TosState state) 3046 { 3047 transition(atos, state); 3048 // Do the JVMTI work here to avoid disturbing the register state below 3049 if (JvmtiExport::can_post_field_access()) { 3050 // Check to see if a field access watch has been set before we 3051 // take the time to call into the VM. 3052 Label L1; 3053 __ lea(rscratch1, ExternalAddress((address) JvmtiExport::get_field_access_count_addr())); 3054 __ ldrw(r2, Address(rscratch1)); 3055 __ cbzw(r2, L1); 3056 // access constant pool cache entry 3057 __ get_cache_entry_pointer_at_bcp(c_rarg2, rscratch2, 1); 3058 __ verify_oop(r0); 3059 __ push_ptr(r0); // save object pointer before call_VM() clobbers it 3060 __ mov(c_rarg1, r0); 3061 // c_rarg1: object pointer copied above 3062 // c_rarg2: cache entry pointer 3063 __ call_VM(noreg, 3064 CAST_FROM_FN_PTR(address, 3065 InterpreterRuntime::post_field_access), 3066 c_rarg1, c_rarg2); 3067 __ pop_ptr(r0); // restore object pointer 3068 __ bind(L1); 3069 } 3070 3071 // access constant pool cache 3072 __ get_cache_and_index_at_bcp(r2, r1, 1); 3073 __ ldr(r1, Address(r2, in_bytes(ConstantPoolCache::base_offset() + 3074 ConstantPoolCacheEntry::f2_offset()))); 3075 __ ldrw(r3, Address(r2, in_bytes(ConstantPoolCache::base_offset() + 3076 ConstantPoolCacheEntry::flags_offset()))); 3077 3078 // r0: object 3079 __ verify_oop(r0); 3080 __ null_check(r0); 3081 const Address field(r0, r1); 3082 3083 // 8179954: We need to make sure that the code generated for 3084 // volatile accesses forms a sequentially-consistent set of 3085 // operations when combined with STLR and LDAR. Without a leading 3086 // membar it's possible for a simple Dekker test to fail if loads 3087 // use LDR;DMB but stores use STLR. This can happen if C2 compiles 3088 // the stores in one method and we interpret the loads in another. 3089 if (! UseBarriersForVolatile) { 3090 Label notVolatile; 3091 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 3092 __ membar(MacroAssembler::AnyAny); 3093 __ bind(notVolatile); 3094 } 3095 3096 // access field 3097 switch (bytecode()) { 3098 case Bytecodes::_fast_agetfield: 3099 do_oop_load(_masm, field, r0, IN_HEAP); 3100 __ verify_oop(r0); 3101 break; 3102 case Bytecodes::_fast_lgetfield: 3103 __ ldr(r0, field); 3104 break; 3105 case Bytecodes::_fast_igetfield: 3106 __ ldrw(r0, field); 3107 break; 3108 case Bytecodes::_fast_bgetfield: 3109 __ load_signed_byte(r0, field); 3110 break; 3111 case Bytecodes::_fast_sgetfield: 3112 __ load_signed_short(r0, field); 3113 break; 3114 case Bytecodes::_fast_cgetfield: 3115 __ load_unsigned_short(r0, field); 3116 break; 3117 case Bytecodes::_fast_fgetfield: 3118 __ ldrs(v0, field); 3119 break; 3120 case Bytecodes::_fast_dgetfield: 3121 __ ldrd(v0, field); 3122 break; 3123 default: 3124 ShouldNotReachHere(); 3125 } 3126 { 3127 Label notVolatile; 3128 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 3129 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); 3130 __ bind(notVolatile); 3131 } 3132 } 3133 3134 void TemplateTable::fast_xaccess(TosState state) 3135 { 3136 transition(vtos, state); 3137 3138 // get receiver 3139 __ ldr(r0, aaddress(0)); 3140 // access constant pool cache 3141 __ get_cache_and_index_at_bcp(r2, r3, 2); 3142 __ ldr(r1, Address(r2, in_bytes(ConstantPoolCache::base_offset() + 3143 ConstantPoolCacheEntry::f2_offset()))); 3144 3145 // 8179954: We need to make sure that the code generated for 3146 // volatile accesses forms a sequentially-consistent set of 3147 // operations when combined with STLR and LDAR. Without a leading 3148 // membar it's possible for a simple Dekker test to fail if loads 3149 // use LDR;DMB but stores use STLR. This can happen if C2 compiles 3150 // the stores in one method and we interpret the loads in another. 3151 if (! UseBarriersForVolatile) { 3152 Label notVolatile; 3153 __ ldrw(r3, Address(r2, in_bytes(ConstantPoolCache::base_offset() + 3154 ConstantPoolCacheEntry::flags_offset()))); 3155 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 3156 __ membar(MacroAssembler::AnyAny); 3157 __ bind(notVolatile); 3158 } 3159 3160 // make sure exception is reported in correct bcp range (getfield is 3161 // next instruction) 3162 __ increment(rbcp); 3163 __ null_check(r0); 3164 switch (state) { 3165 case itos: 3166 __ ldrw(r0, Address(r0, r1, Address::lsl(0))); 3167 break; 3168 case atos: 3169 do_oop_load(_masm, Address(r0, r1, Address::lsl(0)), r0, IN_HEAP); 3170 __ verify_oop(r0); 3171 break; 3172 case ftos: 3173 __ ldrs(v0, Address(r0, r1, Address::lsl(0))); 3174 break; 3175 default: 3176 ShouldNotReachHere(); 3177 } 3178 3179 { 3180 Label notVolatile; 3181 __ ldrw(r3, Address(r2, in_bytes(ConstantPoolCache::base_offset() + 3182 ConstantPoolCacheEntry::flags_offset()))); 3183 __ tbz(r3, ConstantPoolCacheEntry::is_volatile_shift, notVolatile); 3184 __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); 3185 __ bind(notVolatile); 3186 } 3187 3188 __ decrement(rbcp); 3189 } 3190 3191 3192 3193 //----------------------------------------------------------------------------- 3194 // Calls 3195 3196 void TemplateTable::count_calls(Register method, Register temp) 3197 { 3198 __ call_Unimplemented(); 3199 } 3200 3201 void TemplateTable::prepare_invoke(int byte_no, 3202 Register method, // linked method (or i-klass) 3203 Register index, // itable index, MethodType, etc. 3204 Register recv, // if caller wants to see it 3205 Register flags // if caller wants to test it 3206 ) { 3207 // determine flags 3208 Bytecodes::Code code = bytecode(); 3209 const bool is_invokeinterface = code == Bytecodes::_invokeinterface; 3210 const bool is_invokedynamic = code == Bytecodes::_invokedynamic; 3211 const bool is_invokehandle = code == Bytecodes::_invokehandle; 3212 const bool is_invokevirtual = code == Bytecodes::_invokevirtual; 3213 const bool is_invokespecial = code == Bytecodes::_invokespecial; 3214 const bool load_receiver = (recv != noreg); 3215 const bool save_flags = (flags != noreg); 3216 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), ""); 3217 assert(save_flags == (is_invokeinterface || is_invokevirtual), "need flags for vfinal"); 3218 assert(flags == noreg || flags == r3, ""); 3219 assert(recv == noreg || recv == r2, ""); 3220 3221 // setup registers & access constant pool cache 3222 if (recv == noreg) recv = r2; 3223 if (flags == noreg) flags = r3; 3224 assert_different_registers(method, index, recv, flags); 3225 3226 // save 'interpreter return address' 3227 __ save_bcp(); 3228 3229 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic); 3230 3231 // maybe push appendix to arguments (just before return address) 3232 if (is_invokedynamic || is_invokehandle) { 3233 Label L_no_push; 3234 __ tbz(flags, ConstantPoolCacheEntry::has_appendix_shift, L_no_push); 3235 // Push the appendix as a trailing parameter. 3236 // This must be done before we get the receiver, 3237 // since the parameter_size includes it. 3238 __ push(r19); 3239 __ mov(r19, index); 3240 assert(ConstantPoolCacheEntry::_indy_resolved_references_appendix_offset == 0, "appendix expected at index+0"); 3241 __ load_resolved_reference_at_index(index, r19); 3242 __ pop(r19); 3243 __ push(index); // push appendix (MethodType, CallSite, etc.) 3244 __ bind(L_no_push); 3245 } 3246 3247 // load receiver if needed (note: no return address pushed yet) 3248 if (load_receiver) { 3249 __ andw(recv, flags, ConstantPoolCacheEntry::parameter_size_mask); 3250 // FIXME -- is this actually correct? looks like it should be 2 3251 // const int no_return_pc_pushed_yet = -1; // argument slot correction before we push return address 3252 // const int receiver_is_at_end = -1; // back off one slot to get receiver 3253 // Address recv_addr = __ argument_address(recv, no_return_pc_pushed_yet + receiver_is_at_end); 3254 // __ movptr(recv, recv_addr); 3255 __ add(rscratch1, esp, recv, ext::uxtx, 3); // FIXME: uxtb here? 3256 __ ldr(recv, Address(rscratch1, -Interpreter::expr_offset_in_bytes(1))); 3257 __ verify_oop(recv); 3258 } 3259 3260 // compute return type 3261 // x86 uses a shift and mask or wings it with a shift plus assert 3262 // the mask is not needed. aarch64 just uses bitfield extract 3263 __ ubfxw(rscratch2, flags, ConstantPoolCacheEntry::tos_state_shift, ConstantPoolCacheEntry::tos_state_bits); 3264 // load return address 3265 { 3266 const address table_addr = (address) Interpreter::invoke_return_entry_table_for(code); 3267 __ mov(rscratch1, table_addr); 3268 __ ldr(lr, Address(rscratch1, rscratch2, Address::lsl(3))); 3269 } 3270 } 3271 3272 3273 void TemplateTable::invokevirtual_helper(Register index, 3274 Register recv, 3275 Register flags) 3276 { 3277 // Uses temporary registers r0, r3 3278 assert_different_registers(index, recv, r0, r3); 3279 // Test for an invoke of a final method 3280 Label notFinal; 3281 __ tbz(flags, ConstantPoolCacheEntry::is_vfinal_shift, notFinal); 3282 3283 const Register method = index; // method must be rmethod 3284 assert(method == rmethod, 3285 "methodOop must be rmethod for interpreter calling convention"); 3286 3287 // do the call - the index is actually the method to call 3288 // that is, f2 is a vtable index if !is_vfinal, else f2 is a Method* 3289 3290 // It's final, need a null check here! 3291 __ null_check(recv); 3292 3293 // profile this call 3294 __ profile_final_call(r0); 3295 __ profile_arguments_type(r0, method, r4, true); 3296 3297 __ jump_from_interpreted(method, r0); 3298 3299 __ bind(notFinal); 3300 3301 // get receiver klass 3302 __ null_check(recv, oopDesc::klass_offset_in_bytes()); 3303 __ load_klass(r0, recv); 3304 3305 // profile this call 3306 __ profile_virtual_call(r0, rlocals, r3); 3307 3308 // get target methodOop & entry point 3309 __ lookup_virtual_method(r0, index, method); 3310 __ profile_arguments_type(r3, method, r4, true); 3311 // FIXME -- this looks completely redundant. is it? 3312 // __ ldr(r3, Address(method, Method::interpreter_entry_offset())); 3313 __ jump_from_interpreted(method, r3); 3314 } 3315 3316 void TemplateTable::invokevirtual(int byte_no) 3317 { 3318 transition(vtos, vtos); 3319 assert(byte_no == f2_byte, "use this argument"); 3320 3321 prepare_invoke(byte_no, rmethod, noreg, r2, r3); 3322 3323 // rmethod: index (actually a Method*) 3324 // r2: receiver 3325 // r3: flags 3326 3327 invokevirtual_helper(rmethod, r2, r3); 3328 } 3329 3330 void TemplateTable::invokespecial(int byte_no) 3331 { 3332 transition(vtos, vtos); 3333 assert(byte_no == f1_byte, "use this argument"); 3334 3335 prepare_invoke(byte_no, rmethod, noreg, // get f1 Method* 3336 r2); // get receiver also for null check 3337 __ verify_oop(r2); 3338 __ null_check(r2); 3339 // do the call 3340 __ profile_call(r0); 3341 __ profile_arguments_type(r0, rmethod, rbcp, false); 3342 __ jump_from_interpreted(rmethod, r0); 3343 } 3344 3345 void TemplateTable::invokestatic(int byte_no) 3346 { 3347 transition(vtos, vtos); 3348 assert(byte_no == f1_byte, "use this argument"); 3349 3350 prepare_invoke(byte_no, rmethod); // get f1 Method* 3351 // do the call 3352 __ profile_call(r0); 3353 __ profile_arguments_type(r0, rmethod, r4, false); 3354 __ jump_from_interpreted(rmethod, r0); 3355 } 3356 3357 void TemplateTable::fast_invokevfinal(int byte_no) 3358 { 3359 __ call_Unimplemented(); 3360 } 3361 3362 void TemplateTable::invokeinterface(int byte_no) { 3363 transition(vtos, vtos); 3364 assert(byte_no == f1_byte, "use this argument"); 3365 3366 prepare_invoke(byte_no, r0, rmethod, // get f1 Klass*, f2 Method* 3367 r2, r3); // recv, flags 3368 3369 // r0: interface klass (from f1) 3370 // rmethod: method (from f2) 3371 // r2: receiver 3372 // r3: flags 3373 3374 // Special case of invokeinterface called for virtual method of 3375 // java.lang.Object. See cpCacheOop.cpp for details. 3376 // This code isn't produced by javac, but could be produced by 3377 // another compliant java compiler. 3378 Label notMethod; 3379 __ tbz(r3, ConstantPoolCacheEntry::is_forced_virtual_shift, notMethod); 3380 3381 invokevirtual_helper(rmethod, r2, r3); 3382 __ bind(notMethod); 3383 3384 // Get receiver klass into r3 - also a null check 3385 __ restore_locals(); 3386 __ null_check(r2, oopDesc::klass_offset_in_bytes()); 3387 __ load_klass(r3, r2); 3388 3389 Label no_such_interface, no_such_method; 3390 3391 // Preserve method for throw_AbstractMethodErrorVerbose. 3392 __ mov(r16, rmethod); 3393 // Receiver subtype check against REFC. 3394 // Superklass in r0. Subklass in r3. Blows rscratch2, r13 3395 __ lookup_interface_method(// inputs: rec. class, interface, itable index 3396 r3, r0, noreg, 3397 // outputs: scan temp. reg, scan temp. reg 3398 rscratch2, r13, 3399 no_such_interface, 3400 /*return_method=*/false); 3401 3402 // profile this call 3403 __ profile_virtual_call(r3, r13, r19); 3404 3405 // Get declaring interface class from method, and itable index 3406 __ ldr(r0, Address(rmethod, Method::const_offset())); 3407 __ ldr(r0, Address(r0, ConstMethod::constants_offset())); 3408 __ ldr(r0, Address(r0, ConstantPool::pool_holder_offset_in_bytes())); 3409 __ ldrw(rmethod, Address(rmethod, Method::itable_index_offset())); 3410 __ subw(rmethod, rmethod, Method::itable_index_max); 3411 __ negw(rmethod, rmethod); 3412 3413 // Preserve recvKlass for throw_AbstractMethodErrorVerbose. 3414 __ mov(rlocals, r3); 3415 __ lookup_interface_method(// inputs: rec. class, interface, itable index 3416 rlocals, r0, rmethod, 3417 // outputs: method, scan temp. reg 3418 rmethod, r13, 3419 no_such_interface); 3420 3421 // rmethod,: methodOop to call 3422 // r2: receiver 3423 // Check for abstract method error 3424 // Note: This should be done more efficiently via a throw_abstract_method_error 3425 // interpreter entry point and a conditional jump to it in case of a null 3426 // method. 3427 __ cbz(rmethod, no_such_method); 3428 3429 __ profile_arguments_type(r3, rmethod, r13, true); 3430 3431 // do the call 3432 // r2: receiver 3433 // rmethod,: methodOop 3434 __ jump_from_interpreted(rmethod, r3); 3435 __ should_not_reach_here(); 3436 3437 // exception handling code follows... 3438 // note: must restore interpreter registers to canonical 3439 // state for exception handling to work correctly! 3440 3441 __ bind(no_such_method); 3442 // throw exception 3443 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed) 3444 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 3445 // Pass arguments for generating a verbose error message. 3446 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodErrorVerbose), r3, r16); 3447 // the call_VM checks for exception, so we should never return here. 3448 __ should_not_reach_here(); 3449 3450 __ bind(no_such_interface); 3451 // throw exception 3452 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed) 3453 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 3454 // Pass arguments for generating a verbose error message. 3455 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 3456 InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose), r3, r0); 3457 // the call_VM checks for exception, so we should never return here. 3458 __ should_not_reach_here(); 3459 return; 3460 } 3461 3462 void TemplateTable::invokehandle(int byte_no) { 3463 transition(vtos, vtos); 3464 assert(byte_no == f1_byte, "use this argument"); 3465 3466 prepare_invoke(byte_no, rmethod, r0, r2); 3467 __ verify_method_ptr(r2); 3468 __ verify_oop(r2); 3469 __ null_check(r2); 3470 3471 // FIXME: profile the LambdaForm also 3472 3473 // r13 is safe to use here as a scratch reg because it is about to 3474 // be clobbered by jump_from_interpreted(). 3475 __ profile_final_call(r13); 3476 __ profile_arguments_type(r13, rmethod, r4, true); 3477 3478 __ jump_from_interpreted(rmethod, r0); 3479 } 3480 3481 void TemplateTable::invokedynamic(int byte_no) { 3482 transition(vtos, vtos); 3483 assert(byte_no == f1_byte, "use this argument"); 3484 3485 prepare_invoke(byte_no, rmethod, r0); 3486 3487 // r0: CallSite object (from cpool->resolved_references[]) 3488 // rmethod: MH.linkToCallSite method (from f2) 3489 3490 // Note: r0_callsite is already pushed by prepare_invoke 3491 3492 // %%% should make a type profile for any invokedynamic that takes a ref argument 3493 // profile this call 3494 __ profile_call(rbcp); 3495 __ profile_arguments_type(r3, rmethod, r13, false); 3496 3497 __ verify_oop(r0); 3498 3499 __ jump_from_interpreted(rmethod, r0); 3500 } 3501 3502 3503 //----------------------------------------------------------------------------- 3504 // Allocation 3505 3506 void TemplateTable::_new() { 3507 transition(vtos, atos); 3508 3509 __ get_unsigned_2_byte_index_at_bcp(r3, 1); 3510 Label slow_case; 3511 Label done; 3512 Label initialize_header; 3513 Label initialize_object; // including clearing the fields 3514 3515 __ get_cpool_and_tags(r4, r0); 3516 // Make sure the class we're about to instantiate has been resolved. 3517 // This is done before loading InstanceKlass to be consistent with the order 3518 // how Constant Pool is updated (see ConstantPool::klass_at_put) 3519 const int tags_offset = Array<u1>::base_offset_in_bytes(); 3520 __ lea(rscratch1, Address(r0, r3, Address::lsl(0))); 3521 __ lea(rscratch1, Address(rscratch1, tags_offset)); 3522 __ ldarb(rscratch1, rscratch1); 3523 __ cmp(rscratch1, JVM_CONSTANT_Class); 3524 __ br(Assembler::NE, slow_case); 3525 3526 // get InstanceKlass 3527 __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1); 3528 3529 // make sure klass is initialized & doesn't have finalizer 3530 // make sure klass is fully initialized 3531 __ ldrb(rscratch1, Address(r4, InstanceKlass::init_state_offset())); 3532 __ cmp(rscratch1, InstanceKlass::fully_initialized); 3533 __ br(Assembler::NE, slow_case); 3534 3535 // get instance_size in InstanceKlass (scaled to a count of bytes) 3536 __ ldrw(r3, 3537 Address(r4, 3538 Klass::layout_helper_offset())); 3539 // test to see if it has a finalizer or is malformed in some way 3540 __ tbnz(r3, exact_log2(Klass::_lh_instance_slow_path_bit), slow_case); 3541 3542 // Allocate the instance: 3543 // If TLAB is enabled: 3544 // Try to allocate in the TLAB. 3545 // If fails, go to the slow path. 3546 // Else If inline contiguous allocations are enabled: 3547 // Try to allocate in eden. 3548 // If fails due to heap end, go to slow path. 3549 // 3550 // If TLAB is enabled OR inline contiguous is enabled: 3551 // Initialize the allocation. 3552 // Exit. 3553 // 3554 // Go to slow path. 3555 const bool allow_shared_alloc = 3556 Universe::heap()->supports_inline_contig_alloc(); 3557 3558 if (UseTLAB) { 3559 __ tlab_allocate(r0, r3, 0, noreg, r1, slow_case); 3560 3561 if (ZeroTLAB) { 3562 // the fields have been already cleared 3563 __ b(initialize_header); 3564 } else { 3565 // initialize both the header and fields 3566 __ b(initialize_object); 3567 } 3568 } else { 3569 // Allocation in the shared Eden, if allowed. 3570 // 3571 // r3: instance size in bytes 3572 if (allow_shared_alloc) { 3573 __ eden_allocate(r0, r3, 0, r10, slow_case); 3574 __ incr_allocated_bytes(rthread, r3, 0, rscratch1); 3575 } 3576 } 3577 3578 // If UseTLAB or allow_shared_alloc are true, the object is created above and 3579 // there is an initialize need. Otherwise, skip and go to the slow path. 3580 if (UseTLAB || allow_shared_alloc) { 3581 // The object is initialized before the header. If the object size is 3582 // zero, go directly to the header initialization. 3583 __ bind(initialize_object); 3584 __ sub(r3, r3, sizeof(oopDesc)); 3585 __ cbz(r3, initialize_header); 3586 3587 // Initialize object fields 3588 { 3589 __ add(r2, r0, sizeof(oopDesc)); 3590 Label loop; 3591 __ bind(loop); 3592 __ str(zr, Address(__ post(r2, BytesPerLong))); 3593 __ sub(r3, r3, BytesPerLong); 3594 __ cbnz(r3, loop); 3595 } 3596 3597 // initialize object header only. 3598 __ bind(initialize_header); 3599 if (UseBiasedLocking) { 3600 __ ldr(rscratch1, Address(r4, Klass::prototype_header_offset())); 3601 } else { 3602 __ mov(rscratch1, (intptr_t)markOopDesc::prototype()); 3603 } 3604 __ str(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes())); 3605 __ store_klass_gap(r0, zr); // zero klass gap for compressed oops 3606 __ store_klass(r0, r4); // store klass last 3607 3608 { 3609 SkipIfEqual skip(_masm, &DTraceAllocProbes, false); 3610 // Trigger dtrace event for fastpath 3611 __ push(atos); // save the return value 3612 __ call_VM_leaf( 3613 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), r0); 3614 __ pop(atos); // restore the return value 3615 3616 } 3617 __ b(done); 3618 } 3619 3620 // slow case 3621 __ bind(slow_case); 3622 __ get_constant_pool(c_rarg1); 3623 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1); 3624 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), c_rarg1, c_rarg2); 3625 __ verify_oop(r0); 3626 3627 // continue 3628 __ bind(done); 3629 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3630 __ membar(Assembler::StoreStore); 3631 } 3632 3633 void TemplateTable::newarray() { 3634 transition(itos, atos); 3635 __ load_unsigned_byte(c_rarg1, at_bcp(1)); 3636 __ mov(c_rarg2, r0); 3637 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), 3638 c_rarg1, c_rarg2); 3639 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3640 __ membar(Assembler::StoreStore); 3641 } 3642 3643 void TemplateTable::anewarray() { 3644 transition(itos, atos); 3645 __ get_unsigned_2_byte_index_at_bcp(c_rarg2, 1); 3646 __ get_constant_pool(c_rarg1); 3647 __ mov(c_rarg3, r0); 3648 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), 3649 c_rarg1, c_rarg2, c_rarg3); 3650 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3651 __ membar(Assembler::StoreStore); 3652 } 3653 3654 void TemplateTable::arraylength() { 3655 transition(atos, itos); 3656 __ null_check(r0, arrayOopDesc::length_offset_in_bytes()); 3657 __ ldrw(r0, Address(r0, arrayOopDesc::length_offset_in_bytes())); 3658 } 3659 3660 void TemplateTable::checkcast() 3661 { 3662 transition(atos, atos); 3663 Label done, is_null, ok_is_subtype, quicked, resolved; 3664 __ cbz(r0, is_null); 3665 3666 // Get cpool & tags index 3667 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array 3668 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index 3669 // See if bytecode has already been quicked 3670 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes()); 3671 __ lea(r1, Address(rscratch1, r19)); 3672 __ ldarb(r1, r1); 3673 __ cmp(r1, JVM_CONSTANT_Class); 3674 __ br(Assembler::EQ, quicked); 3675 3676 __ push(atos); // save receiver for result, and for GC 3677 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3678 // vm_result_2 has metadata result 3679 __ get_vm_result_2(r0, rthread); 3680 __ pop(r3); // restore receiver 3681 __ b(resolved); 3682 3683 // Get superklass in r0 and subklass in r3 3684 __ bind(quicked); 3685 __ mov(r3, r0); // Save object in r3; r0 needed for subtype check 3686 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); // r0 = klass 3687 3688 __ bind(resolved); 3689 __ load_klass(r19, r3); 3690 3691 // Generate subtype check. Blows r2, r5. Object in r3. 3692 // Superklass in r0. Subklass in r19. 3693 __ gen_subtype_check(r19, ok_is_subtype); 3694 3695 // Come here on failure 3696 __ push(r3); 3697 // object is at TOS 3698 __ b(Interpreter::_throw_ClassCastException_entry); 3699 3700 // Come here on success 3701 __ bind(ok_is_subtype); 3702 __ mov(r0, r3); // Restore object in r3 3703 3704 // Collect counts on whether this test sees NULLs a lot or not. 3705 if (ProfileInterpreter) { 3706 __ b(done); 3707 __ bind(is_null); 3708 __ profile_null_seen(r2); 3709 } else { 3710 __ bind(is_null); // same as 'done' 3711 } 3712 __ bind(done); 3713 } 3714 3715 void TemplateTable::instanceof() { 3716 transition(atos, itos); 3717 Label done, is_null, ok_is_subtype, quicked, resolved; 3718 __ cbz(r0, is_null); 3719 3720 // Get cpool & tags index 3721 __ get_cpool_and_tags(r2, r3); // r2=cpool, r3=tags array 3722 __ get_unsigned_2_byte_index_at_bcp(r19, 1); // r19=index 3723 // See if bytecode has already been quicked 3724 __ add(rscratch1, r3, Array<u1>::base_offset_in_bytes()); 3725 __ lea(r1, Address(rscratch1, r19)); 3726 __ ldarb(r1, r1); 3727 __ cmp(r1, JVM_CONSTANT_Class); 3728 __ br(Assembler::EQ, quicked); 3729 3730 __ push(atos); // save receiver for result, and for GC 3731 call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3732 // vm_result_2 has metadata result 3733 __ get_vm_result_2(r0, rthread); 3734 __ pop(r3); // restore receiver 3735 __ verify_oop(r3); 3736 __ load_klass(r3, r3); 3737 __ b(resolved); 3738 3739 // Get superklass in r0 and subklass in r3 3740 __ bind(quicked); 3741 __ load_klass(r3, r0); 3742 __ load_resolved_klass_at_offset(r2, r19, r0, rscratch1); 3743 3744 __ bind(resolved); 3745 3746 // Generate subtype check. Blows r2, r5 3747 // Superklass in r0. Subklass in r3. 3748 __ gen_subtype_check(r3, ok_is_subtype); 3749 3750 // Come here on failure 3751 __ mov(r0, 0); 3752 __ b(done); 3753 // Come here on success 3754 __ bind(ok_is_subtype); 3755 __ mov(r0, 1); 3756 3757 // Collect counts on whether this test sees NULLs a lot or not. 3758 if (ProfileInterpreter) { 3759 __ b(done); 3760 __ bind(is_null); 3761 __ profile_null_seen(r2); 3762 } else { 3763 __ bind(is_null); // same as 'done' 3764 } 3765 __ bind(done); 3766 // r0 = 0: obj == NULL or obj is not an instanceof the specified klass 3767 // r0 = 1: obj != NULL and obj is an instanceof the specified klass 3768 } 3769 3770 //----------------------------------------------------------------------------- 3771 // Breakpoints 3772 void TemplateTable::_breakpoint() { 3773 // Note: We get here even if we are single stepping.. 3774 // jbug inists on setting breakpoints at every bytecode 3775 // even if we are in single step mode. 3776 3777 transition(vtos, vtos); 3778 3779 // get the unpatched byte code 3780 __ get_method(c_rarg1); 3781 __ call_VM(noreg, 3782 CAST_FROM_FN_PTR(address, 3783 InterpreterRuntime::get_original_bytecode_at), 3784 c_rarg1, rbcp); 3785 __ mov(r19, r0); 3786 3787 // post the breakpoint event 3788 __ call_VM(noreg, 3789 CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), 3790 rmethod, rbcp); 3791 3792 // complete the execution of original bytecode 3793 __ mov(rscratch1, r19); 3794 __ dispatch_only_normal(vtos); 3795 } 3796 3797 //----------------------------------------------------------------------------- 3798 // Exceptions 3799 3800 void TemplateTable::athrow() { 3801 transition(atos, vtos); 3802 __ null_check(r0); 3803 __ b(Interpreter::throw_exception_entry()); 3804 } 3805 3806 //----------------------------------------------------------------------------- 3807 // Synchronization 3808 // 3809 // Note: monitorenter & exit are symmetric routines; which is reflected 3810 // in the assembly code structure as well 3811 // 3812 // Stack layout: 3813 // 3814 // [expressions ] <--- esp = expression stack top 3815 // .. 3816 // [expressions ] 3817 // [monitor entry] <--- monitor block top = expression stack bot 3818 // .. 3819 // [monitor entry] 3820 // [frame data ] <--- monitor block bot 3821 // ... 3822 // [saved rbp ] <--- rbp 3823 void TemplateTable::monitorenter() 3824 { 3825 transition(atos, vtos); 3826 3827 // check for NULL object 3828 __ null_check(r0); 3829 3830 const Address monitor_block_top( 3831 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 3832 const Address monitor_block_bot( 3833 rfp, frame::interpreter_frame_initial_sp_offset * wordSize); 3834 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 3835 3836 Label allocated; 3837 3838 // initialize entry pointer 3839 __ mov(c_rarg1, zr); // points to free slot or NULL 3840 3841 // find a free slot in the monitor block (result in c_rarg1) 3842 { 3843 Label entry, loop, exit; 3844 __ ldr(c_rarg3, monitor_block_top); // points to current entry, 3845 // starting with top-most entry 3846 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom 3847 3848 __ b(entry); 3849 3850 __ bind(loop); 3851 // check if current entry is used 3852 // if not used then remember entry in c_rarg1 3853 __ ldr(rscratch1, Address(c_rarg3, BasicObjectLock::obj_offset_in_bytes())); 3854 __ cmp(zr, rscratch1); 3855 __ csel(c_rarg1, c_rarg3, c_rarg1, Assembler::EQ); 3856 // check if current entry is for same object 3857 __ cmp(r0, rscratch1); 3858 // if same object then stop searching 3859 __ br(Assembler::EQ, exit); 3860 // otherwise advance to next entry 3861 __ add(c_rarg3, c_rarg3, entry_size); 3862 __ bind(entry); 3863 // check if bottom reached 3864 __ cmp(c_rarg3, c_rarg2); 3865 // if not at bottom then check this entry 3866 __ br(Assembler::NE, loop); 3867 __ bind(exit); 3868 } 3869 3870 __ cbnz(c_rarg1, allocated); // check if a slot has been found and 3871 // if found, continue with that on 3872 3873 // allocate one if there's no free slot 3874 { 3875 Label entry, loop; 3876 // 1. compute new pointers // rsp: old expression stack top 3877 __ ldr(c_rarg1, monitor_block_bot); // c_rarg1: old expression stack bottom 3878 __ sub(esp, esp, entry_size); // move expression stack top 3879 __ sub(c_rarg1, c_rarg1, entry_size); // move expression stack bottom 3880 __ mov(c_rarg3, esp); // set start value for copy loop 3881 __ str(c_rarg1, monitor_block_bot); // set new monitor block bottom 3882 3883 __ sub(sp, sp, entry_size); // make room for the monitor 3884 3885 __ b(entry); 3886 // 2. move expression stack contents 3887 __ bind(loop); 3888 __ ldr(c_rarg2, Address(c_rarg3, entry_size)); // load expression stack 3889 // word from old location 3890 __ str(c_rarg2, Address(c_rarg3, 0)); // and store it at new location 3891 __ add(c_rarg3, c_rarg3, wordSize); // advance to next word 3892 __ bind(entry); 3893 __ cmp(c_rarg3, c_rarg1); // check if bottom reached 3894 __ br(Assembler::NE, loop); // if not at bottom then 3895 // copy next word 3896 } 3897 3898 // call run-time routine 3899 // c_rarg1: points to monitor entry 3900 __ bind(allocated); 3901 3902 // Increment bcp to point to the next bytecode, so exception 3903 // handling for async. exceptions work correctly. 3904 // The object has already been poped from the stack, so the 3905 // expression stack looks correct. 3906 __ increment(rbcp); 3907 3908 // store object 3909 __ str(r0, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); 3910 __ lock_object(c_rarg1); 3911 3912 // check to make sure this monitor doesn't cause stack overflow after locking 3913 __ save_bcp(); // in case of exception 3914 __ generate_stack_overflow_check(0); 3915 3916 // The bcp has already been incremented. Just need to dispatch to 3917 // next instruction. 3918 __ dispatch_next(vtos); 3919 } 3920 3921 3922 void TemplateTable::monitorexit() 3923 { 3924 transition(atos, vtos); 3925 3926 // check for NULL object 3927 __ null_check(r0); 3928 3929 const Address monitor_block_top( 3930 rfp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 3931 const Address monitor_block_bot( 3932 rfp, frame::interpreter_frame_initial_sp_offset * wordSize); 3933 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 3934 3935 Label found; 3936 3937 // find matching slot 3938 { 3939 Label entry, loop; 3940 __ ldr(c_rarg1, monitor_block_top); // points to current entry, 3941 // starting with top-most entry 3942 __ lea(c_rarg2, monitor_block_bot); // points to word before bottom 3943 // of monitor block 3944 __ b(entry); 3945 3946 __ bind(loop); 3947 // check if current entry is for same object 3948 __ ldr(rscratch1, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); 3949 __ cmp(r0, rscratch1); 3950 // if same object then stop searching 3951 __ br(Assembler::EQ, found); 3952 // otherwise advance to next entry 3953 __ add(c_rarg1, c_rarg1, entry_size); 3954 __ bind(entry); 3955 // check if bottom reached 3956 __ cmp(c_rarg1, c_rarg2); 3957 // if not at bottom then check this entry 3958 __ br(Assembler::NE, loop); 3959 } 3960 3961 // error handling. Unlocking was not block-structured 3962 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 3963 InterpreterRuntime::throw_illegal_monitor_state_exception)); 3964 __ should_not_reach_here(); 3965 3966 // call run-time routine 3967 __ bind(found); 3968 __ push_ptr(r0); // make sure object is on stack (contract with oopMaps) 3969 __ unlock_object(c_rarg1); 3970 __ pop_ptr(r0); // discard object 3971 } 3972 3973 3974 // Wide instructions 3975 void TemplateTable::wide() 3976 { 3977 __ load_unsigned_byte(r19, at_bcp(1)); 3978 __ mov(rscratch1, (address)Interpreter::_wentry_point); 3979 __ ldr(rscratch1, Address(rscratch1, r19, Address::uxtw(3))); 3980 __ br(rscratch1); 3981 } 3982 3983 3984 // Multi arrays 3985 void TemplateTable::multianewarray() { 3986 transition(vtos, atos); 3987 __ load_unsigned_byte(r0, at_bcp(3)); // get number of dimensions 3988 // last dim is on top of stack; we want address of first one: 3989 // first_addr = last_addr + (ndims - 1) * wordSize 3990 __ lea(c_rarg1, Address(esp, r0, Address::uxtw(3))); 3991 __ sub(c_rarg1, c_rarg1, wordSize); 3992 call_VM(r0, 3993 CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), 3994 c_rarg1); 3995 __ load_unsigned_byte(r1, at_bcp(3)); 3996 __ lea(esp, Address(esp, r1, Address::uxtw(3))); 3997 }