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