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