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