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