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