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