1 /* 2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2013, 2017 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "gc/shared/barrierSetAssembler.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterRuntime.hpp" 31 #include "interpreter/interp_masm.hpp" 32 #include "interpreter/templateInterpreter.hpp" 33 #include "interpreter/templateTable.hpp" 34 #include "memory/universe.hpp" 35 #include "oops/objArrayKlass.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/methodHandles.hpp" 38 #include "runtime/frame.inline.hpp" 39 #include "runtime/safepointMechanism.hpp" 40 #include "runtime/sharedRuntime.hpp" 41 #include "runtime/stubRoutines.hpp" 42 #include "runtime/synchronizer.hpp" 43 #include "utilities/macros.hpp" 44 45 #undef __ 46 #define __ _masm-> 47 48 // ============================================================================ 49 // Misc helpers 50 51 // Do an oop store like *(base + index) = val OR *(base + offset) = val 52 // (only one of both variants is possible at the same time). 53 // Index can be noreg. 54 // Kills: 55 // Rbase, Rtmp 56 static void do_oop_store(InterpreterMacroAssembler* _masm, 57 Register base, 58 RegisterOrConstant offset, 59 Register val, // Noreg means always null. 60 Register tmp1, 61 Register tmp2, 62 Register tmp3, 63 DecoratorSet decorators) { 64 assert_different_registers(tmp1, tmp2, tmp3, val, base); 65 __ store_heap_oop(val, offset, base, tmp1, tmp2, tmp3, false, decorators); 66 } 67 68 static void do_oop_load(InterpreterMacroAssembler* _masm, 69 Register base, 70 RegisterOrConstant offset, 71 Register dst, 72 Register tmp1, 73 Register tmp2, 74 DecoratorSet decorators) { 75 assert_different_registers(base, tmp1, tmp2); 76 assert_different_registers(dst, tmp1, tmp2); 77 __ load_heap_oop(dst, offset, base, tmp1, tmp2, false, decorators); 78 } 79 80 // ============================================================================ 81 // Platform-dependent initialization 82 83 void TemplateTable::pd_initialize() { 84 // No ppc64 specific initialization. 85 } 86 87 Address TemplateTable::at_bcp(int offset) { 88 // Not used on ppc. 89 ShouldNotReachHere(); 90 return Address(); 91 } 92 93 // Patches the current bytecode (ptr to it located in bcp) 94 // in the bytecode stream with a new one. 95 void TemplateTable::patch_bytecode(Bytecodes::Code new_bc, Register Rnew_bc, Register Rtemp, bool load_bc_into_bc_reg /*=true*/, int byte_no) { 96 // With sharing on, may need to test method flag. 97 if (!RewriteBytecodes) return; 98 Label L_patch_done; 99 100 switch (new_bc) { 101 case Bytecodes::_fast_aputfield: 102 case Bytecodes::_fast_bputfield: 103 case Bytecodes::_fast_zputfield: 104 case Bytecodes::_fast_cputfield: 105 case Bytecodes::_fast_dputfield: 106 case Bytecodes::_fast_fputfield: 107 case Bytecodes::_fast_iputfield: 108 case Bytecodes::_fast_lputfield: 109 case Bytecodes::_fast_sputfield: 110 { 111 // We skip bytecode quickening for putfield instructions when 112 // the put_code written to the constant pool cache is zero. 113 // This is required so that every execution of this instruction 114 // calls out to InterpreterRuntime::resolve_get_put to do 115 // additional, required work. 116 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 117 assert(load_bc_into_bc_reg, "we use bc_reg as temp"); 118 __ get_cache_and_index_at_bcp(Rtemp /* dst = cache */, 1); 119 // ((*(cache+indices))>>((1+byte_no)*8))&0xFF: 120 #if defined(VM_LITTLE_ENDIAN) 121 __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 1 + byte_no, Rtemp); 122 #else 123 __ lbz(Rnew_bc, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (1 + byte_no), Rtemp); 124 #endif 125 __ cmpwi(CCR0, Rnew_bc, 0); 126 __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc); 127 __ beq(CCR0, L_patch_done); 128 // __ isync(); // acquire not needed 129 break; 130 } 131 132 default: 133 assert(byte_no == -1, "sanity"); 134 if (load_bc_into_bc_reg) { 135 __ li(Rnew_bc, (unsigned int)(unsigned char)new_bc); 136 } 137 } 138 139 if (JvmtiExport::can_post_breakpoint()) { 140 Label L_fast_patch; 141 __ lbz(Rtemp, 0, R14_bcp); 142 __ cmpwi(CCR0, Rtemp, (unsigned int)(unsigned char)Bytecodes::_breakpoint); 143 __ bne(CCR0, L_fast_patch); 144 // Perform the quickening, slowly, in the bowels of the breakpoint table. 145 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), R19_method, R14_bcp, Rnew_bc); 146 __ b(L_patch_done); 147 __ bind(L_fast_patch); 148 } 149 150 // Patch bytecode. 151 __ stb(Rnew_bc, 0, R14_bcp); 152 153 __ bind(L_patch_done); 154 } 155 156 // ============================================================================ 157 // Individual instructions 158 159 void TemplateTable::nop() { 160 transition(vtos, vtos); 161 // Nothing to do. 162 } 163 164 void TemplateTable::shouldnotreachhere() { 165 transition(vtos, vtos); 166 __ stop("shouldnotreachhere bytecode"); 167 } 168 169 void TemplateTable::aconst_null() { 170 transition(vtos, atos); 171 __ li(R17_tos, 0); 172 } 173 174 void TemplateTable::iconst(int value) { 175 transition(vtos, itos); 176 assert(value >= -1 && value <= 5, ""); 177 __ li(R17_tos, value); 178 } 179 180 void TemplateTable::lconst(int value) { 181 transition(vtos, ltos); 182 assert(value >= -1 && value <= 5, ""); 183 __ li(R17_tos, value); 184 } 185 186 void TemplateTable::fconst(int value) { 187 transition(vtos, ftos); 188 static float zero = 0.0; 189 static float one = 1.0; 190 static float two = 2.0; 191 switch (value) { 192 default: ShouldNotReachHere(); 193 case 0: { 194 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&zero, R0, true); 195 __ lfs(F15_ftos, simm16_offset, R11_scratch1); 196 break; 197 } 198 case 1: { 199 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&one, R0, true); 200 __ lfs(F15_ftos, simm16_offset, R11_scratch1); 201 break; 202 } 203 case 2: { 204 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&two, R0, true); 205 __ lfs(F15_ftos, simm16_offset, R11_scratch1); 206 break; 207 } 208 } 209 } 210 211 void TemplateTable::dconst(int value) { 212 transition(vtos, dtos); 213 static double zero = 0.0; 214 static double one = 1.0; 215 switch (value) { 216 case 0: { 217 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&zero, R0, true); 218 __ lfd(F15_ftos, simm16_offset, R11_scratch1); 219 break; 220 } 221 case 1: { 222 int simm16_offset = __ load_const_optimized(R11_scratch1, (address*)&one, R0, true); 223 __ lfd(F15_ftos, simm16_offset, R11_scratch1); 224 break; 225 } 226 default: ShouldNotReachHere(); 227 } 228 } 229 230 void TemplateTable::bipush() { 231 transition(vtos, itos); 232 __ lbz(R17_tos, 1, R14_bcp); 233 __ extsb(R17_tos, R17_tos); 234 } 235 236 void TemplateTable::sipush() { 237 transition(vtos, itos); 238 __ get_2_byte_integer_at_bcp(1, R17_tos, InterpreterMacroAssembler::Signed); 239 } 240 241 void TemplateTable::ldc(bool wide) { 242 Register Rscratch1 = R11_scratch1, 243 Rscratch2 = R12_scratch2, 244 Rcpool = R3_ARG1; 245 246 transition(vtos, vtos); 247 Label notInt, notFloat, notClass, exit; 248 249 __ get_cpool_and_tags(Rcpool, Rscratch2); // Set Rscratch2 = &tags. 250 if (wide) { // Read index. 251 __ get_2_byte_integer_at_bcp(1, Rscratch1, InterpreterMacroAssembler::Unsigned); 252 } else { 253 __ lbz(Rscratch1, 1, R14_bcp); 254 } 255 256 const int base_offset = ConstantPool::header_size() * wordSize; 257 const int tags_offset = Array<u1>::base_offset_in_bytes(); 258 259 // Get type from tags. 260 __ addi(Rscratch2, Rscratch2, tags_offset); 261 __ lbzx(Rscratch2, Rscratch2, Rscratch1); 262 263 __ cmpwi(CCR0, Rscratch2, JVM_CONSTANT_UnresolvedClass); // Unresolved class? 264 __ cmpwi(CCR1, Rscratch2, JVM_CONSTANT_UnresolvedClassInError); // Unresolved class in error state? 265 __ cror(CCR0, Assembler::equal, CCR1, Assembler::equal); 266 267 // Resolved class - need to call vm to get java mirror of the class. 268 __ cmpwi(CCR1, Rscratch2, JVM_CONSTANT_Class); 269 __ crnor(CCR0, Assembler::equal, CCR1, Assembler::equal); // Neither resolved class nor unresolved case from above? 270 __ beq(CCR0, notClass); 271 272 __ li(R4, wide ? 1 : 0); 273 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), R4); 274 __ push(atos); 275 __ b(exit); 276 277 __ align(32, 12); 278 __ bind(notClass); 279 __ addi(Rcpool, Rcpool, base_offset); 280 __ sldi(Rscratch1, Rscratch1, LogBytesPerWord); 281 __ cmpdi(CCR0, Rscratch2, JVM_CONSTANT_Integer); 282 __ bne(CCR0, notInt); 283 __ lwax(R17_tos, Rcpool, Rscratch1); 284 __ push(itos); 285 __ b(exit); 286 287 __ align(32, 12); 288 __ bind(notInt); 289 __ cmpdi(CCR0, Rscratch2, JVM_CONSTANT_Float); 290 __ bne(CCR0, notFloat); 291 __ lfsx(F15_ftos, Rcpool, Rscratch1); 292 __ push(ftos); 293 __ b(exit); 294 295 __ align(32, 12); 296 // assume the tag is for condy; if not, the VM runtime will tell us 297 __ bind(notFloat); 298 condy_helper(exit); 299 300 __ align(32, 12); 301 __ bind(exit); 302 } 303 304 // Fast path for caching oop constants. 305 void TemplateTable::fast_aldc(bool wide) { 306 transition(vtos, atos); 307 308 int index_size = wide ? sizeof(u2) : sizeof(u1); 309 const Register Rscratch = R11_scratch1; 310 Label is_null; 311 312 // We are resolved if the resolved reference cache entry contains a 313 // non-null object (CallSite, etc.) 314 __ get_cache_index_at_bcp(Rscratch, 1, index_size); // Load index. 315 __ load_resolved_reference_at_index(R17_tos, Rscratch, &is_null); 316 317 // Convert null sentinel to NULL. 318 int simm16_rest = __ load_const_optimized(Rscratch, Universe::the_null_sentinel_addr(), R0, true); 319 __ ld(Rscratch, simm16_rest, Rscratch); 320 __ cmpld(CCR0, R17_tos, Rscratch); 321 if (VM_Version::has_isel()) { 322 __ isel_0(R17_tos, CCR0, Assembler::equal); 323 } else { 324 Label not_sentinel; 325 __ bne(CCR0, not_sentinel); 326 __ li(R17_tos, 0); 327 __ bind(not_sentinel); 328 } 329 __ verify_oop(R17_tos); 330 __ dispatch_epilog(atos, Bytecodes::length_for(bytecode())); 331 332 __ bind(is_null); 333 __ load_const_optimized(R3_ARG1, (int)bytecode()); 334 335 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); 336 337 // First time invocation - must resolve first. 338 __ call_VM(R17_tos, entry, R3_ARG1); 339 __ verify_oop(R17_tos); 340 } 341 342 void TemplateTable::ldc2_w() { 343 transition(vtos, vtos); 344 Label not_double, not_long, exit; 345 346 Register Rindex = R11_scratch1, 347 Rcpool = R12_scratch2, 348 Rtag = R3_ARG1; 349 __ get_cpool_and_tags(Rcpool, Rtag); 350 __ get_2_byte_integer_at_bcp(1, Rindex, InterpreterMacroAssembler::Unsigned); 351 352 const int base_offset = ConstantPool::header_size() * wordSize; 353 const int tags_offset = Array<u1>::base_offset_in_bytes(); 354 // Get type from tags. 355 __ addi(Rcpool, Rcpool, base_offset); 356 __ addi(Rtag, Rtag, tags_offset); 357 358 __ lbzx(Rtag, Rtag, Rindex); 359 __ sldi(Rindex, Rindex, LogBytesPerWord); 360 361 __ cmpdi(CCR0, Rtag, JVM_CONSTANT_Double); 362 __ bne(CCR0, not_double); 363 __ lfdx(F15_ftos, Rcpool, Rindex); 364 __ push(dtos); 365 __ b(exit); 366 367 __ bind(not_double); 368 __ cmpdi(CCR0, Rtag, JVM_CONSTANT_Long); 369 __ bne(CCR0, not_long); 370 __ ldx(R17_tos, Rcpool, Rindex); 371 __ push(ltos); 372 __ b(exit); 373 374 __ bind(not_long); 375 condy_helper(exit); 376 377 __ align(32, 12); 378 __ bind(exit); 379 } 380 381 void TemplateTable::condy_helper(Label& Done) { 382 const Register obj = R31; 383 const Register off = R11_scratch1; 384 const Register flags = R12_scratch2; 385 const Register rarg = R4_ARG2; 386 __ li(rarg, (int)bytecode()); 387 call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc), rarg); 388 __ get_vm_result_2(flags); 389 390 // VMr = obj = base address to find primitive value to push 391 // VMr2 = flags = (tos, off) using format of CPCE::_flags 392 __ andi(off, flags, ConstantPoolCacheEntry::field_index_mask); 393 394 // What sort of thing are we loading? 395 __ rldicl(flags, flags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 396 397 switch (bytecode()) { 398 case Bytecodes::_ldc: 399 case Bytecodes::_ldc_w: 400 { 401 // tos in (itos, ftos, stos, btos, ctos, ztos) 402 Label notInt, notFloat, notShort, notByte, notChar, notBool; 403 __ cmplwi(CCR0, flags, itos); 404 __ bne(CCR0, notInt); 405 // itos 406 __ lwax(R17_tos, obj, off); 407 __ push(itos); 408 __ b(Done); 409 410 __ bind(notInt); 411 __ cmplwi(CCR0, flags, ftos); 412 __ bne(CCR0, notFloat); 413 // ftos 414 __ lfsx(F15_ftos, obj, off); 415 __ push(ftos); 416 __ b(Done); 417 418 __ bind(notFloat); 419 __ cmplwi(CCR0, flags, stos); 420 __ bne(CCR0, notShort); 421 // stos 422 __ lhax(R17_tos, obj, off); 423 __ push(stos); 424 __ b(Done); 425 426 __ bind(notShort); 427 __ cmplwi(CCR0, flags, btos); 428 __ bne(CCR0, notByte); 429 // btos 430 __ lbzx(R17_tos, obj, off); 431 __ extsb(R17_tos, R17_tos); 432 __ push(btos); 433 __ b(Done); 434 435 __ bind(notByte); 436 __ cmplwi(CCR0, flags, ctos); 437 __ bne(CCR0, notChar); 438 // ctos 439 __ lhzx(R17_tos, obj, off); 440 __ push(ctos); 441 __ b(Done); 442 443 __ bind(notChar); 444 __ cmplwi(CCR0, flags, ztos); 445 __ bne(CCR0, notBool); 446 // ztos 447 __ lbzx(R17_tos, obj, off); 448 __ push(ztos); 449 __ b(Done); 450 451 __ bind(notBool); 452 break; 453 } 454 455 case Bytecodes::_ldc2_w: 456 { 457 Label notLong, notDouble; 458 __ cmplwi(CCR0, flags, ltos); 459 __ bne(CCR0, notLong); 460 // ltos 461 __ ldx(R17_tos, obj, off); 462 __ push(ltos); 463 __ b(Done); 464 465 __ bind(notLong); 466 __ cmplwi(CCR0, flags, dtos); 467 __ bne(CCR0, notDouble); 468 // dtos 469 __ lfdx(F15_ftos, obj, off); 470 __ push(dtos); 471 __ b(Done); 472 473 __ bind(notDouble); 474 break; 475 } 476 477 default: 478 ShouldNotReachHere(); 479 } 480 481 __ stop("bad ldc/condy"); 482 } 483 484 // Get the locals index located in the bytecode stream at bcp + offset. 485 void TemplateTable::locals_index(Register Rdst, int offset) { 486 __ lbz(Rdst, offset, R14_bcp); 487 } 488 489 void TemplateTable::iload() { 490 iload_internal(); 491 } 492 493 void TemplateTable::nofast_iload() { 494 iload_internal(may_not_rewrite); 495 } 496 497 void TemplateTable::iload_internal(RewriteControl rc) { 498 transition(vtos, itos); 499 500 // Get the local value into tos 501 const Register Rindex = R22_tmp2; 502 locals_index(Rindex); 503 504 // Rewrite iload,iload pair into fast_iload2 505 // iload,caload pair into fast_icaload 506 if (RewriteFrequentPairs && rc == may_rewrite) { 507 Label Lrewrite, Ldone; 508 Register Rnext_byte = R3_ARG1, 509 Rrewrite_to = R6_ARG4, 510 Rscratch = R11_scratch1; 511 512 // get next byte 513 __ lbz(Rnext_byte, Bytecodes::length_for(Bytecodes::_iload), R14_bcp); 514 515 // if _iload, wait to rewrite to iload2. We only want to rewrite the 516 // last two iloads in a pair. Comparing against fast_iload means that 517 // the next bytecode is neither an iload or a caload, and therefore 518 // an iload pair. 519 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_iload); 520 __ beq(CCR0, Ldone); 521 522 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_iload); 523 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iload2); 524 __ beq(CCR1, Lrewrite); 525 526 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_caload); 527 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_icaload); 528 __ beq(CCR0, Lrewrite); 529 530 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iload); 531 532 __ bind(Lrewrite); 533 patch_bytecode(Bytecodes::_iload, Rrewrite_to, Rscratch, false); 534 __ bind(Ldone); 535 } 536 537 __ load_local_int(R17_tos, Rindex, Rindex); 538 } 539 540 // Load 2 integers in a row without dispatching 541 void TemplateTable::fast_iload2() { 542 transition(vtos, itos); 543 544 __ lbz(R3_ARG1, 1, R14_bcp); 545 __ lbz(R17_tos, Bytecodes::length_for(Bytecodes::_iload) + 1, R14_bcp); 546 547 __ load_local_int(R3_ARG1, R11_scratch1, R3_ARG1); 548 __ load_local_int(R17_tos, R12_scratch2, R17_tos); 549 __ push_i(R3_ARG1); 550 } 551 552 void TemplateTable::fast_iload() { 553 transition(vtos, itos); 554 // Get the local value into tos 555 556 const Register Rindex = R11_scratch1; 557 locals_index(Rindex); 558 __ load_local_int(R17_tos, Rindex, Rindex); 559 } 560 561 // Load a local variable type long from locals area to TOS cache register. 562 // Local index resides in bytecodestream. 563 void TemplateTable::lload() { 564 transition(vtos, ltos); 565 566 const Register Rindex = R11_scratch1; 567 locals_index(Rindex); 568 __ load_local_long(R17_tos, Rindex, Rindex); 569 } 570 571 void TemplateTable::fload() { 572 transition(vtos, ftos); 573 574 const Register Rindex = R11_scratch1; 575 locals_index(Rindex); 576 __ load_local_float(F15_ftos, Rindex, Rindex); 577 } 578 579 void TemplateTable::dload() { 580 transition(vtos, dtos); 581 582 const Register Rindex = R11_scratch1; 583 locals_index(Rindex); 584 __ load_local_double(F15_ftos, Rindex, Rindex); 585 } 586 587 void TemplateTable::aload() { 588 transition(vtos, atos); 589 590 const Register Rindex = R11_scratch1; 591 locals_index(Rindex); 592 __ load_local_ptr(R17_tos, Rindex, Rindex); 593 } 594 595 void TemplateTable::locals_index_wide(Register Rdst) { 596 // Offset is 2, not 1, because Lbcp points to wide prefix code. 597 __ get_2_byte_integer_at_bcp(2, Rdst, InterpreterMacroAssembler::Unsigned); 598 } 599 600 void TemplateTable::wide_iload() { 601 // Get the local value into tos. 602 603 const Register Rindex = R11_scratch1; 604 locals_index_wide(Rindex); 605 __ load_local_int(R17_tos, Rindex, Rindex); 606 } 607 608 void TemplateTable::wide_lload() { 609 transition(vtos, ltos); 610 611 const Register Rindex = R11_scratch1; 612 locals_index_wide(Rindex); 613 __ load_local_long(R17_tos, Rindex, Rindex); 614 } 615 616 void TemplateTable::wide_fload() { 617 transition(vtos, ftos); 618 619 const Register Rindex = R11_scratch1; 620 locals_index_wide(Rindex); 621 __ load_local_float(F15_ftos, Rindex, Rindex); 622 } 623 624 void TemplateTable::wide_dload() { 625 transition(vtos, dtos); 626 627 const Register Rindex = R11_scratch1; 628 locals_index_wide(Rindex); 629 __ load_local_double(F15_ftos, Rindex, Rindex); 630 } 631 632 void TemplateTable::wide_aload() { 633 transition(vtos, atos); 634 635 const Register Rindex = R11_scratch1; 636 locals_index_wide(Rindex); 637 __ load_local_ptr(R17_tos, Rindex, Rindex); 638 } 639 640 void TemplateTable::iaload() { 641 transition(itos, itos); 642 643 const Register Rload_addr = R3_ARG1, 644 Rarray = R4_ARG2, 645 Rtemp = R5_ARG3; 646 __ index_check(Rarray, R17_tos /* index */, LogBytesPerInt, Rtemp, Rload_addr); 647 __ lwa(R17_tos, arrayOopDesc::base_offset_in_bytes(T_INT), Rload_addr); 648 } 649 650 void TemplateTable::laload() { 651 transition(itos, ltos); 652 653 const Register Rload_addr = R3_ARG1, 654 Rarray = R4_ARG2, 655 Rtemp = R5_ARG3; 656 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr); 657 __ ld(R17_tos, arrayOopDesc::base_offset_in_bytes(T_LONG), Rload_addr); 658 } 659 660 void TemplateTable::faload() { 661 transition(itos, ftos); 662 663 const Register Rload_addr = R3_ARG1, 664 Rarray = R4_ARG2, 665 Rtemp = R5_ARG3; 666 __ index_check(Rarray, R17_tos /* index */, LogBytesPerInt, Rtemp, Rload_addr); 667 __ lfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rload_addr); 668 } 669 670 void TemplateTable::daload() { 671 transition(itos, dtos); 672 673 const Register Rload_addr = R3_ARG1, 674 Rarray = R4_ARG2, 675 Rtemp = R5_ARG3; 676 __ index_check(Rarray, R17_tos /* index */, LogBytesPerLong, Rtemp, Rload_addr); 677 __ lfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rload_addr); 678 } 679 680 void TemplateTable::aaload() { 681 transition(itos, atos); 682 683 // tos: index 684 // result tos: array 685 const Register Rload_addr = R3_ARG1, 686 Rarray = R4_ARG2, 687 Rtemp = R5_ARG3, 688 Rtemp2 = R31; 689 __ index_check(Rarray, R17_tos /* index */, UseCompressedOops ? 2 : LogBytesPerWord, Rtemp, Rload_addr); 690 do_oop_load(_masm, Rload_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos, Rtemp, Rtemp2, 691 IN_HEAP_ARRAY); 692 __ verify_oop(R17_tos); 693 //__ dcbt(R17_tos); // prefetch 694 } 695 696 void TemplateTable::baload() { 697 transition(itos, itos); 698 699 const Register Rload_addr = R3_ARG1, 700 Rarray = R4_ARG2, 701 Rtemp = R5_ARG3; 702 __ index_check(Rarray, R17_tos /* index */, 0, Rtemp, Rload_addr); 703 __ lbz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rload_addr); 704 __ extsb(R17_tos, R17_tos); 705 } 706 707 void TemplateTable::caload() { 708 transition(itos, itos); 709 710 const Register Rload_addr = R3_ARG1, 711 Rarray = R4_ARG2, 712 Rtemp = R5_ARG3; 713 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr); 714 __ lhz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rload_addr); 715 } 716 717 // Iload followed by caload frequent pair. 718 void TemplateTable::fast_icaload() { 719 transition(vtos, itos); 720 721 const Register Rload_addr = R3_ARG1, 722 Rarray = R4_ARG2, 723 Rtemp = R11_scratch1; 724 725 locals_index(R17_tos); 726 __ load_local_int(R17_tos, Rtemp, R17_tos); 727 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr); 728 __ lhz(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rload_addr); 729 } 730 731 void TemplateTable::saload() { 732 transition(itos, itos); 733 734 const Register Rload_addr = R11_scratch1, 735 Rarray = R12_scratch2, 736 Rtemp = R3_ARG1; 737 __ index_check(Rarray, R17_tos /* index */, LogBytesPerShort, Rtemp, Rload_addr); 738 __ lha(R17_tos, arrayOopDesc::base_offset_in_bytes(T_SHORT), Rload_addr); 739 } 740 741 void TemplateTable::iload(int n) { 742 transition(vtos, itos); 743 744 __ lwz(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals); 745 } 746 747 void TemplateTable::lload(int n) { 748 transition(vtos, ltos); 749 750 __ ld(R17_tos, Interpreter::local_offset_in_bytes(n + 1), R18_locals); 751 } 752 753 void TemplateTable::fload(int n) { 754 transition(vtos, ftos); 755 756 __ lfs(F15_ftos, Interpreter::local_offset_in_bytes(n), R18_locals); 757 } 758 759 void TemplateTable::dload(int n) { 760 transition(vtos, dtos); 761 762 __ lfd(F15_ftos, Interpreter::local_offset_in_bytes(n + 1), R18_locals); 763 } 764 765 void TemplateTable::aload(int n) { 766 transition(vtos, atos); 767 768 __ ld(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals); 769 } 770 771 void TemplateTable::aload_0() { 772 aload_0_internal(); 773 } 774 775 void TemplateTable::nofast_aload_0() { 776 aload_0_internal(may_not_rewrite); 777 } 778 779 void TemplateTable::aload_0_internal(RewriteControl rc) { 780 transition(vtos, atos); 781 // According to bytecode histograms, the pairs: 782 // 783 // _aload_0, _fast_igetfield 784 // _aload_0, _fast_agetfield 785 // _aload_0, _fast_fgetfield 786 // 787 // occur frequently. If RewriteFrequentPairs is set, the (slow) 788 // _aload_0 bytecode checks if the next bytecode is either 789 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then 790 // rewrites the current bytecode into a pair bytecode; otherwise it 791 // rewrites the current bytecode into _0 that doesn't do 792 // the pair check anymore. 793 // 794 // Note: If the next bytecode is _getfield, the rewrite must be 795 // delayed, otherwise we may miss an opportunity for a pair. 796 // 797 // Also rewrite frequent pairs 798 // aload_0, aload_1 799 // aload_0, iload_1 800 // These bytecodes with a small amount of code are most profitable 801 // to rewrite. 802 803 if (RewriteFrequentPairs && rc == may_rewrite) { 804 805 Label Lrewrite, Ldont_rewrite; 806 Register Rnext_byte = R3_ARG1, 807 Rrewrite_to = R6_ARG4, 808 Rscratch = R11_scratch1; 809 810 // Get next byte. 811 __ lbz(Rnext_byte, Bytecodes::length_for(Bytecodes::_aload_0), R14_bcp); 812 813 // If _getfield, wait to rewrite. We only want to rewrite the last two bytecodes in a pair. 814 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_getfield); 815 __ beq(CCR0, Ldont_rewrite); 816 817 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_igetfield); 818 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_iaccess_0); 819 __ beq(CCR1, Lrewrite); 820 821 __ cmpwi(CCR0, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_agetfield); 822 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_aaccess_0); 823 __ beq(CCR0, Lrewrite); 824 825 __ cmpwi(CCR1, Rnext_byte, (unsigned int)(unsigned char)Bytecodes::_fast_fgetfield); 826 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_faccess_0); 827 __ beq(CCR1, Lrewrite); 828 829 __ li(Rrewrite_to, (unsigned int)(unsigned char)Bytecodes::_fast_aload_0); 830 831 __ bind(Lrewrite); 832 patch_bytecode(Bytecodes::_aload_0, Rrewrite_to, Rscratch, false); 833 __ bind(Ldont_rewrite); 834 } 835 836 // Do actual aload_0 (must do this after patch_bytecode which might call VM and GC might change oop). 837 aload(0); 838 } 839 840 void TemplateTable::istore() { 841 transition(itos, vtos); 842 843 const Register Rindex = R11_scratch1; 844 locals_index(Rindex); 845 __ store_local_int(R17_tos, Rindex); 846 } 847 848 void TemplateTable::lstore() { 849 transition(ltos, vtos); 850 const Register Rindex = R11_scratch1; 851 locals_index(Rindex); 852 __ store_local_long(R17_tos, Rindex); 853 } 854 855 void TemplateTable::fstore() { 856 transition(ftos, vtos); 857 858 const Register Rindex = R11_scratch1; 859 locals_index(Rindex); 860 __ store_local_float(F15_ftos, Rindex); 861 } 862 863 void TemplateTable::dstore() { 864 transition(dtos, vtos); 865 866 const Register Rindex = R11_scratch1; 867 locals_index(Rindex); 868 __ store_local_double(F15_ftos, Rindex); 869 } 870 871 void TemplateTable::astore() { 872 transition(vtos, vtos); 873 874 const Register Rindex = R11_scratch1; 875 __ pop_ptr(); 876 __ verify_oop_or_return_address(R17_tos, Rindex); 877 locals_index(Rindex); 878 __ store_local_ptr(R17_tos, Rindex); 879 } 880 881 void TemplateTable::wide_istore() { 882 transition(vtos, vtos); 883 884 const Register Rindex = R11_scratch1; 885 __ pop_i(); 886 locals_index_wide(Rindex); 887 __ store_local_int(R17_tos, Rindex); 888 } 889 890 void TemplateTable::wide_lstore() { 891 transition(vtos, vtos); 892 893 const Register Rindex = R11_scratch1; 894 __ pop_l(); 895 locals_index_wide(Rindex); 896 __ store_local_long(R17_tos, Rindex); 897 } 898 899 void TemplateTable::wide_fstore() { 900 transition(vtos, vtos); 901 902 const Register Rindex = R11_scratch1; 903 __ pop_f(); 904 locals_index_wide(Rindex); 905 __ store_local_float(F15_ftos, Rindex); 906 } 907 908 void TemplateTable::wide_dstore() { 909 transition(vtos, vtos); 910 911 const Register Rindex = R11_scratch1; 912 __ pop_d(); 913 locals_index_wide(Rindex); 914 __ store_local_double(F15_ftos, Rindex); 915 } 916 917 void TemplateTable::wide_astore() { 918 transition(vtos, vtos); 919 920 const Register Rindex = R11_scratch1; 921 __ pop_ptr(); 922 __ verify_oop_or_return_address(R17_tos, Rindex); 923 locals_index_wide(Rindex); 924 __ store_local_ptr(R17_tos, Rindex); 925 } 926 927 void TemplateTable::iastore() { 928 transition(itos, vtos); 929 930 const Register Rindex = R3_ARG1, 931 Rstore_addr = R4_ARG2, 932 Rarray = R5_ARG3, 933 Rtemp = R6_ARG4; 934 __ pop_i(Rindex); 935 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr); 936 __ stw(R17_tos, arrayOopDesc::base_offset_in_bytes(T_INT), Rstore_addr); 937 } 938 939 void TemplateTable::lastore() { 940 transition(ltos, vtos); 941 942 const Register Rindex = R3_ARG1, 943 Rstore_addr = R4_ARG2, 944 Rarray = R5_ARG3, 945 Rtemp = R6_ARG4; 946 __ pop_i(Rindex); 947 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr); 948 __ std(R17_tos, arrayOopDesc::base_offset_in_bytes(T_LONG), Rstore_addr); 949 } 950 951 void TemplateTable::fastore() { 952 transition(ftos, vtos); 953 954 const Register Rindex = R3_ARG1, 955 Rstore_addr = R4_ARG2, 956 Rarray = R5_ARG3, 957 Rtemp = R6_ARG4; 958 __ pop_i(Rindex); 959 __ index_check(Rarray, Rindex, LogBytesPerInt, Rtemp, Rstore_addr); 960 __ stfs(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Rstore_addr); 961 } 962 963 void TemplateTable::dastore() { 964 transition(dtos, vtos); 965 966 const Register Rindex = R3_ARG1, 967 Rstore_addr = R4_ARG2, 968 Rarray = R5_ARG3, 969 Rtemp = R6_ARG4; 970 __ pop_i(Rindex); 971 __ index_check(Rarray, Rindex, LogBytesPerLong, Rtemp, Rstore_addr); 972 __ stfd(F15_ftos, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Rstore_addr); 973 } 974 975 // Pop 3 values from the stack and... 976 void TemplateTable::aastore() { 977 transition(vtos, vtos); 978 979 Label Lstore_ok, Lis_null, Ldone; 980 const Register Rindex = R3_ARG1, 981 Rarray = R4_ARG2, 982 Rscratch = R11_scratch1, 983 Rscratch2 = R12_scratch2, 984 Rarray_klass = R5_ARG3, 985 Rarray_element_klass = Rarray_klass, 986 Rvalue_klass = R6_ARG4, 987 Rstore_addr = R31; // Use register which survives VM call. 988 989 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp); // Get value to store. 990 __ lwz(Rindex, Interpreter::expr_offset_in_bytes(1), R15_esp); // Get index. 991 __ ld(Rarray, Interpreter::expr_offset_in_bytes(2), R15_esp); // Get array. 992 993 __ verify_oop(R17_tos); 994 __ index_check_without_pop(Rarray, Rindex, UseCompressedOops ? 2 : LogBytesPerWord, Rscratch, Rstore_addr); 995 // Rindex is dead! 996 Register Rscratch3 = Rindex; 997 998 // Do array store check - check for NULL value first. 999 __ cmpdi(CCR0, R17_tos, 0); 1000 __ beq(CCR0, Lis_null); 1001 1002 __ load_klass(Rarray_klass, Rarray); 1003 __ load_klass(Rvalue_klass, R17_tos); 1004 1005 // Do fast instanceof cache test. 1006 __ ld(Rarray_element_klass, in_bytes(ObjArrayKlass::element_klass_offset()), Rarray_klass); 1007 1008 // Generate a fast subtype check. Branch to store_ok if no failure. Throw if failure. 1009 __ gen_subtype_check(Rvalue_klass /*subklass*/, Rarray_element_klass /*superklass*/, Rscratch, Rscratch2, Rscratch3, Lstore_ok); 1010 1011 // Fell through: subtype check failed => throw an exception. 1012 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArrayStoreException_entry); 1013 __ mtctr(R11_scratch1); 1014 __ bctr(); 1015 1016 __ bind(Lis_null); 1017 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), noreg /* 0 */, 1018 Rscratch, Rscratch2, Rscratch3, IN_HEAP_ARRAY); 1019 __ profile_null_seen(Rscratch, Rscratch2); 1020 __ b(Ldone); 1021 1022 // Store is OK. 1023 __ bind(Lstore_ok); 1024 do_oop_store(_masm, Rstore_addr, arrayOopDesc::base_offset_in_bytes(T_OBJECT), R17_tos /* value */, 1025 Rscratch, Rscratch2, Rscratch3, IN_HEAP_ARRAY | OOP_NOT_NULL); 1026 1027 __ bind(Ldone); 1028 // Adjust sp (pops array, index and value). 1029 __ addi(R15_esp, R15_esp, 3 * Interpreter::stackElementSize); 1030 } 1031 1032 void TemplateTable::bastore() { 1033 transition(itos, vtos); 1034 1035 const Register Rindex = R11_scratch1, 1036 Rarray = R12_scratch2, 1037 Rscratch = R3_ARG1; 1038 __ pop_i(Rindex); 1039 __ pop_ptr(Rarray); 1040 // tos: val 1041 1042 // Need to check whether array is boolean or byte 1043 // since both types share the bastore bytecode. 1044 __ load_klass(Rscratch, Rarray); 1045 __ lwz(Rscratch, in_bytes(Klass::layout_helper_offset()), Rscratch); 1046 int diffbit = exact_log2(Klass::layout_helper_boolean_diffbit()); 1047 __ testbitdi(CCR0, R0, Rscratch, diffbit); 1048 Label L_skip; 1049 __ bfalse(CCR0, L_skip); 1050 __ andi(R17_tos, R17_tos, 1); // if it is a T_BOOLEAN array, mask the stored value to 0/1 1051 __ bind(L_skip); 1052 1053 __ index_check_without_pop(Rarray, Rindex, 0, Rscratch, Rarray); 1054 __ stb(R17_tos, arrayOopDesc::base_offset_in_bytes(T_BYTE), Rarray); 1055 } 1056 1057 void TemplateTable::castore() { 1058 transition(itos, vtos); 1059 1060 const Register Rindex = R11_scratch1, 1061 Rarray = R12_scratch2, 1062 Rscratch = R3_ARG1; 1063 __ pop_i(Rindex); 1064 // tos: val 1065 // Rarray: array ptr (popped by index_check) 1066 __ index_check(Rarray, Rindex, LogBytesPerShort, Rscratch, Rarray); 1067 __ sth(R17_tos, arrayOopDesc::base_offset_in_bytes(T_CHAR), Rarray); 1068 } 1069 1070 void TemplateTable::sastore() { 1071 castore(); 1072 } 1073 1074 void TemplateTable::istore(int n) { 1075 transition(itos, vtos); 1076 __ stw(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals); 1077 } 1078 1079 void TemplateTable::lstore(int n) { 1080 transition(ltos, vtos); 1081 __ std(R17_tos, Interpreter::local_offset_in_bytes(n + 1), R18_locals); 1082 } 1083 1084 void TemplateTable::fstore(int n) { 1085 transition(ftos, vtos); 1086 __ stfs(F15_ftos, Interpreter::local_offset_in_bytes(n), R18_locals); 1087 } 1088 1089 void TemplateTable::dstore(int n) { 1090 transition(dtos, vtos); 1091 __ stfd(F15_ftos, Interpreter::local_offset_in_bytes(n + 1), R18_locals); 1092 } 1093 1094 void TemplateTable::astore(int n) { 1095 transition(vtos, vtos); 1096 1097 __ pop_ptr(); 1098 __ verify_oop_or_return_address(R17_tos, R11_scratch1); 1099 __ std(R17_tos, Interpreter::local_offset_in_bytes(n), R18_locals); 1100 } 1101 1102 void TemplateTable::pop() { 1103 transition(vtos, vtos); 1104 1105 __ addi(R15_esp, R15_esp, Interpreter::stackElementSize); 1106 } 1107 1108 void TemplateTable::pop2() { 1109 transition(vtos, vtos); 1110 1111 __ addi(R15_esp, R15_esp, Interpreter::stackElementSize * 2); 1112 } 1113 1114 void TemplateTable::dup() { 1115 transition(vtos, vtos); 1116 1117 __ ld(R11_scratch1, Interpreter::stackElementSize, R15_esp); 1118 __ push_ptr(R11_scratch1); 1119 } 1120 1121 void TemplateTable::dup_x1() { 1122 transition(vtos, vtos); 1123 1124 Register Ra = R11_scratch1, 1125 Rb = R12_scratch2; 1126 // stack: ..., a, b 1127 __ ld(Rb, Interpreter::stackElementSize, R15_esp); 1128 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp); 1129 __ std(Rb, Interpreter::stackElementSize * 2, R15_esp); 1130 __ std(Ra, Interpreter::stackElementSize, R15_esp); 1131 __ push_ptr(Rb); 1132 // stack: ..., b, a, b 1133 } 1134 1135 void TemplateTable::dup_x2() { 1136 transition(vtos, vtos); 1137 1138 Register Ra = R11_scratch1, 1139 Rb = R12_scratch2, 1140 Rc = R3_ARG1; 1141 1142 // stack: ..., a, b, c 1143 __ ld(Rc, Interpreter::stackElementSize, R15_esp); // load c 1144 __ ld(Ra, Interpreter::stackElementSize * 3, R15_esp); // load a 1145 __ std(Rc, Interpreter::stackElementSize * 3, R15_esp); // store c in a 1146 __ ld(Rb, Interpreter::stackElementSize * 2, R15_esp); // load b 1147 // stack: ..., c, b, c 1148 __ std(Ra, Interpreter::stackElementSize * 2, R15_esp); // store a in b 1149 // stack: ..., c, a, c 1150 __ std(Rb, Interpreter::stackElementSize, R15_esp); // store b in c 1151 __ push_ptr(Rc); // push c 1152 // stack: ..., c, a, b, c 1153 } 1154 1155 void TemplateTable::dup2() { 1156 transition(vtos, vtos); 1157 1158 Register Ra = R11_scratch1, 1159 Rb = R12_scratch2; 1160 // stack: ..., a, b 1161 __ ld(Rb, Interpreter::stackElementSize, R15_esp); 1162 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp); 1163 __ push_2ptrs(Ra, Rb); 1164 // stack: ..., a, b, a, b 1165 } 1166 1167 void TemplateTable::dup2_x1() { 1168 transition(vtos, vtos); 1169 1170 Register Ra = R11_scratch1, 1171 Rb = R12_scratch2, 1172 Rc = R3_ARG1; 1173 // stack: ..., a, b, c 1174 __ ld(Rc, Interpreter::stackElementSize, R15_esp); 1175 __ ld(Rb, Interpreter::stackElementSize * 2, R15_esp); 1176 __ std(Rc, Interpreter::stackElementSize * 2, R15_esp); 1177 __ ld(Ra, Interpreter::stackElementSize * 3, R15_esp); 1178 __ std(Ra, Interpreter::stackElementSize, R15_esp); 1179 __ std(Rb, Interpreter::stackElementSize * 3, R15_esp); 1180 // stack: ..., b, c, a 1181 __ push_2ptrs(Rb, Rc); 1182 // stack: ..., b, c, a, b, c 1183 } 1184 1185 void TemplateTable::dup2_x2() { 1186 transition(vtos, vtos); 1187 1188 Register Ra = R11_scratch1, 1189 Rb = R12_scratch2, 1190 Rc = R3_ARG1, 1191 Rd = R4_ARG2; 1192 // stack: ..., a, b, c, d 1193 __ ld(Rb, Interpreter::stackElementSize * 3, R15_esp); 1194 __ ld(Rd, Interpreter::stackElementSize, R15_esp); 1195 __ std(Rb, Interpreter::stackElementSize, R15_esp); // store b in d 1196 __ std(Rd, Interpreter::stackElementSize * 3, R15_esp); // store d in b 1197 __ ld(Ra, Interpreter::stackElementSize * 4, R15_esp); 1198 __ ld(Rc, Interpreter::stackElementSize * 2, R15_esp); 1199 __ std(Ra, Interpreter::stackElementSize * 2, R15_esp); // store a in c 1200 __ std(Rc, Interpreter::stackElementSize * 4, R15_esp); // store c in a 1201 // stack: ..., c, d, a, b 1202 __ push_2ptrs(Rc, Rd); 1203 // stack: ..., c, d, a, b, c, d 1204 } 1205 1206 void TemplateTable::swap() { 1207 transition(vtos, vtos); 1208 // stack: ..., a, b 1209 1210 Register Ra = R11_scratch1, 1211 Rb = R12_scratch2; 1212 // stack: ..., a, b 1213 __ ld(Rb, Interpreter::stackElementSize, R15_esp); 1214 __ ld(Ra, Interpreter::stackElementSize * 2, R15_esp); 1215 __ std(Rb, Interpreter::stackElementSize * 2, R15_esp); 1216 __ std(Ra, Interpreter::stackElementSize, R15_esp); 1217 // stack: ..., b, a 1218 } 1219 1220 void TemplateTable::iop2(Operation op) { 1221 transition(itos, itos); 1222 1223 Register Rscratch = R11_scratch1; 1224 1225 __ pop_i(Rscratch); 1226 // tos = number of bits to shift 1227 // Rscratch = value to shift 1228 switch (op) { 1229 case add: __ add(R17_tos, Rscratch, R17_tos); break; 1230 case sub: __ sub(R17_tos, Rscratch, R17_tos); break; 1231 case mul: __ mullw(R17_tos, Rscratch, R17_tos); break; 1232 case _and: __ andr(R17_tos, Rscratch, R17_tos); break; 1233 case _or: __ orr(R17_tos, Rscratch, R17_tos); break; 1234 case _xor: __ xorr(R17_tos, Rscratch, R17_tos); break; 1235 case shl: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ slw(R17_tos, Rscratch, R17_tos); break; 1236 case shr: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ sraw(R17_tos, Rscratch, R17_tos); break; 1237 case ushr: __ rldicl(R17_tos, R17_tos, 0, 64-5); __ srw(R17_tos, Rscratch, R17_tos); break; 1238 default: ShouldNotReachHere(); 1239 } 1240 } 1241 1242 void TemplateTable::lop2(Operation op) { 1243 transition(ltos, ltos); 1244 1245 Register Rscratch = R11_scratch1; 1246 __ pop_l(Rscratch); 1247 switch (op) { 1248 case add: __ add(R17_tos, Rscratch, R17_tos); break; 1249 case sub: __ sub(R17_tos, Rscratch, R17_tos); break; 1250 case _and: __ andr(R17_tos, Rscratch, R17_tos); break; 1251 case _or: __ orr(R17_tos, Rscratch, R17_tos); break; 1252 case _xor: __ xorr(R17_tos, Rscratch, R17_tos); break; 1253 default: ShouldNotReachHere(); 1254 } 1255 } 1256 1257 void TemplateTable::idiv() { 1258 transition(itos, itos); 1259 1260 Label Lnormal, Lexception, Ldone; 1261 Register Rdividend = R11_scratch1; // Used by irem. 1262 1263 __ addi(R0, R17_tos, 1); 1264 __ cmplwi(CCR0, R0, 2); 1265 __ bgt(CCR0, Lnormal); // divisor <-1 or >1 1266 1267 __ cmpwi(CCR1, R17_tos, 0); 1268 __ beq(CCR1, Lexception); // divisor == 0 1269 1270 __ pop_i(Rdividend); 1271 __ mullw(R17_tos, Rdividend, R17_tos); // div by +/-1 1272 __ b(Ldone); 1273 1274 __ bind(Lexception); 1275 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArithmeticException_entry); 1276 __ mtctr(R11_scratch1); 1277 __ bctr(); 1278 1279 __ align(32, 12); 1280 __ bind(Lnormal); 1281 __ pop_i(Rdividend); 1282 __ divw(R17_tos, Rdividend, R17_tos); // Can't divide minint/-1. 1283 __ bind(Ldone); 1284 } 1285 1286 void TemplateTable::irem() { 1287 transition(itos, itos); 1288 1289 __ mr(R12_scratch2, R17_tos); 1290 idiv(); 1291 __ mullw(R17_tos, R17_tos, R12_scratch2); 1292 __ subf(R17_tos, R17_tos, R11_scratch1); // Dividend set by idiv. 1293 } 1294 1295 void TemplateTable::lmul() { 1296 transition(ltos, ltos); 1297 1298 __ pop_l(R11_scratch1); 1299 __ mulld(R17_tos, R11_scratch1, R17_tos); 1300 } 1301 1302 void TemplateTable::ldiv() { 1303 transition(ltos, ltos); 1304 1305 Label Lnormal, Lexception, Ldone; 1306 Register Rdividend = R11_scratch1; // Used by lrem. 1307 1308 __ addi(R0, R17_tos, 1); 1309 __ cmpldi(CCR0, R0, 2); 1310 __ bgt(CCR0, Lnormal); // divisor <-1 or >1 1311 1312 __ cmpdi(CCR1, R17_tos, 0); 1313 __ beq(CCR1, Lexception); // divisor == 0 1314 1315 __ pop_l(Rdividend); 1316 __ mulld(R17_tos, Rdividend, R17_tos); // div by +/-1 1317 __ b(Ldone); 1318 1319 __ bind(Lexception); 1320 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ArithmeticException_entry); 1321 __ mtctr(R11_scratch1); 1322 __ bctr(); 1323 1324 __ align(32, 12); 1325 __ bind(Lnormal); 1326 __ pop_l(Rdividend); 1327 __ divd(R17_tos, Rdividend, R17_tos); // Can't divide minint/-1. 1328 __ bind(Ldone); 1329 } 1330 1331 void TemplateTable::lrem() { 1332 transition(ltos, ltos); 1333 1334 __ mr(R12_scratch2, R17_tos); 1335 ldiv(); 1336 __ mulld(R17_tos, R17_tos, R12_scratch2); 1337 __ subf(R17_tos, R17_tos, R11_scratch1); // Dividend set by ldiv. 1338 } 1339 1340 void TemplateTable::lshl() { 1341 transition(itos, ltos); 1342 1343 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits. 1344 __ pop_l(R11_scratch1); 1345 __ sld(R17_tos, R11_scratch1, R17_tos); 1346 } 1347 1348 void TemplateTable::lshr() { 1349 transition(itos, ltos); 1350 1351 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits. 1352 __ pop_l(R11_scratch1); 1353 __ srad(R17_tos, R11_scratch1, R17_tos); 1354 } 1355 1356 void TemplateTable::lushr() { 1357 transition(itos, ltos); 1358 1359 __ rldicl(R17_tos, R17_tos, 0, 64-6); // Extract least significant bits. 1360 __ pop_l(R11_scratch1); 1361 __ srd(R17_tos, R11_scratch1, R17_tos); 1362 } 1363 1364 void TemplateTable::fop2(Operation op) { 1365 transition(ftos, ftos); 1366 1367 switch (op) { 1368 case add: __ pop_f(F0_SCRATCH); __ fadds(F15_ftos, F0_SCRATCH, F15_ftos); break; 1369 case sub: __ pop_f(F0_SCRATCH); __ fsubs(F15_ftos, F0_SCRATCH, F15_ftos); break; 1370 case mul: __ pop_f(F0_SCRATCH); __ fmuls(F15_ftos, F0_SCRATCH, F15_ftos); break; 1371 case div: __ pop_f(F0_SCRATCH); __ fdivs(F15_ftos, F0_SCRATCH, F15_ftos); break; 1372 case rem: 1373 __ pop_f(F1_ARG1); 1374 __ fmr(F2_ARG2, F15_ftos); 1375 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem)); 1376 __ fmr(F15_ftos, F1_RET); 1377 break; 1378 1379 default: ShouldNotReachHere(); 1380 } 1381 } 1382 1383 void TemplateTable::dop2(Operation op) { 1384 transition(dtos, dtos); 1385 1386 switch (op) { 1387 case add: __ pop_d(F0_SCRATCH); __ fadd(F15_ftos, F0_SCRATCH, F15_ftos); break; 1388 case sub: __ pop_d(F0_SCRATCH); __ fsub(F15_ftos, F0_SCRATCH, F15_ftos); break; 1389 case mul: __ pop_d(F0_SCRATCH); __ fmul(F15_ftos, F0_SCRATCH, F15_ftos); break; 1390 case div: __ pop_d(F0_SCRATCH); __ fdiv(F15_ftos, F0_SCRATCH, F15_ftos); break; 1391 case rem: 1392 __ pop_d(F1_ARG1); 1393 __ fmr(F2_ARG2, F15_ftos); 1394 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem)); 1395 __ fmr(F15_ftos, F1_RET); 1396 break; 1397 1398 default: ShouldNotReachHere(); 1399 } 1400 } 1401 1402 // Negate the value in the TOS cache. 1403 void TemplateTable::ineg() { 1404 transition(itos, itos); 1405 1406 __ neg(R17_tos, R17_tos); 1407 } 1408 1409 // Negate the value in the TOS cache. 1410 void TemplateTable::lneg() { 1411 transition(ltos, ltos); 1412 1413 __ neg(R17_tos, R17_tos); 1414 } 1415 1416 void TemplateTable::fneg() { 1417 transition(ftos, ftos); 1418 1419 __ fneg(F15_ftos, F15_ftos); 1420 } 1421 1422 void TemplateTable::dneg() { 1423 transition(dtos, dtos); 1424 1425 __ fneg(F15_ftos, F15_ftos); 1426 } 1427 1428 // Increments a local variable in place. 1429 void TemplateTable::iinc() { 1430 transition(vtos, vtos); 1431 1432 const Register Rindex = R11_scratch1, 1433 Rincrement = R0, 1434 Rvalue = R12_scratch2; 1435 1436 locals_index(Rindex); // Load locals index from bytecode stream. 1437 __ lbz(Rincrement, 2, R14_bcp); // Load increment from the bytecode stream. 1438 __ extsb(Rincrement, Rincrement); 1439 1440 __ load_local_int(Rvalue, Rindex, Rindex); // Puts address of local into Rindex. 1441 1442 __ add(Rvalue, Rincrement, Rvalue); 1443 __ stw(Rvalue, 0, Rindex); 1444 } 1445 1446 void TemplateTable::wide_iinc() { 1447 transition(vtos, vtos); 1448 1449 Register Rindex = R11_scratch1, 1450 Rlocals_addr = Rindex, 1451 Rincr = R12_scratch2; 1452 locals_index_wide(Rindex); 1453 __ get_2_byte_integer_at_bcp(4, Rincr, InterpreterMacroAssembler::Signed); 1454 __ load_local_int(R17_tos, Rlocals_addr, Rindex); 1455 __ add(R17_tos, Rincr, R17_tos); 1456 __ stw(R17_tos, 0, Rlocals_addr); 1457 } 1458 1459 void TemplateTable::convert() { 1460 // %%%%% Factor this first part accross platforms 1461 #ifdef ASSERT 1462 TosState tos_in = ilgl; 1463 TosState tos_out = ilgl; 1464 switch (bytecode()) { 1465 case Bytecodes::_i2l: // fall through 1466 case Bytecodes::_i2f: // fall through 1467 case Bytecodes::_i2d: // fall through 1468 case Bytecodes::_i2b: // fall through 1469 case Bytecodes::_i2c: // fall through 1470 case Bytecodes::_i2s: tos_in = itos; break; 1471 case Bytecodes::_l2i: // fall through 1472 case Bytecodes::_l2f: // fall through 1473 case Bytecodes::_l2d: tos_in = ltos; break; 1474 case Bytecodes::_f2i: // fall through 1475 case Bytecodes::_f2l: // fall through 1476 case Bytecodes::_f2d: tos_in = ftos; break; 1477 case Bytecodes::_d2i: // fall through 1478 case Bytecodes::_d2l: // fall through 1479 case Bytecodes::_d2f: tos_in = dtos; break; 1480 default : ShouldNotReachHere(); 1481 } 1482 switch (bytecode()) { 1483 case Bytecodes::_l2i: // fall through 1484 case Bytecodes::_f2i: // fall through 1485 case Bytecodes::_d2i: // fall through 1486 case Bytecodes::_i2b: // fall through 1487 case Bytecodes::_i2c: // fall through 1488 case Bytecodes::_i2s: tos_out = itos; break; 1489 case Bytecodes::_i2l: // fall through 1490 case Bytecodes::_f2l: // fall through 1491 case Bytecodes::_d2l: tos_out = ltos; break; 1492 case Bytecodes::_i2f: // fall through 1493 case Bytecodes::_l2f: // fall through 1494 case Bytecodes::_d2f: tos_out = ftos; break; 1495 case Bytecodes::_i2d: // fall through 1496 case Bytecodes::_l2d: // fall through 1497 case Bytecodes::_f2d: tos_out = dtos; break; 1498 default : ShouldNotReachHere(); 1499 } 1500 transition(tos_in, tos_out); 1501 #endif 1502 1503 // Conversion 1504 Label done; 1505 switch (bytecode()) { 1506 case Bytecodes::_i2l: 1507 __ extsw(R17_tos, R17_tos); 1508 break; 1509 1510 case Bytecodes::_l2i: 1511 // Nothing to do, we'll continue to work with the lower bits. 1512 break; 1513 1514 case Bytecodes::_i2b: 1515 __ extsb(R17_tos, R17_tos); 1516 break; 1517 1518 case Bytecodes::_i2c: 1519 __ rldicl(R17_tos, R17_tos, 0, 64-2*8); 1520 break; 1521 1522 case Bytecodes::_i2s: 1523 __ extsh(R17_tos, R17_tos); 1524 break; 1525 1526 case Bytecodes::_i2d: 1527 __ extsw(R17_tos, R17_tos); 1528 case Bytecodes::_l2d: 1529 __ move_l_to_d(); 1530 __ fcfid(F15_ftos, F15_ftos); 1531 break; 1532 1533 case Bytecodes::_i2f: 1534 __ extsw(R17_tos, R17_tos); 1535 __ move_l_to_d(); 1536 if (VM_Version::has_fcfids()) { // fcfids is >= Power7 only 1537 // Comment: alternatively, load with sign extend could be done by lfiwax. 1538 __ fcfids(F15_ftos, F15_ftos); 1539 } else { 1540 __ fcfid(F15_ftos, F15_ftos); 1541 __ frsp(F15_ftos, F15_ftos); 1542 } 1543 break; 1544 1545 case Bytecodes::_l2f: 1546 if (VM_Version::has_fcfids()) { // fcfids is >= Power7 only 1547 __ move_l_to_d(); 1548 __ fcfids(F15_ftos, F15_ftos); 1549 } else { 1550 // Avoid rounding problem when result should be 0x3f800001: need fixup code before fcfid+frsp. 1551 __ mr(R3_ARG1, R17_tos); 1552 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::l2f)); 1553 __ fmr(F15_ftos, F1_RET); 1554 } 1555 break; 1556 1557 case Bytecodes::_f2d: 1558 // empty 1559 break; 1560 1561 case Bytecodes::_d2f: 1562 __ frsp(F15_ftos, F15_ftos); 1563 break; 1564 1565 case Bytecodes::_d2i: 1566 case Bytecodes::_f2i: 1567 __ fcmpu(CCR0, F15_ftos, F15_ftos); 1568 __ li(R17_tos, 0); // 0 in case of NAN 1569 __ bso(CCR0, done); 1570 __ fctiwz(F15_ftos, F15_ftos); 1571 __ move_d_to_l(); 1572 break; 1573 1574 case Bytecodes::_d2l: 1575 case Bytecodes::_f2l: 1576 __ fcmpu(CCR0, F15_ftos, F15_ftos); 1577 __ li(R17_tos, 0); // 0 in case of NAN 1578 __ bso(CCR0, done); 1579 __ fctidz(F15_ftos, F15_ftos); 1580 __ move_d_to_l(); 1581 break; 1582 1583 default: ShouldNotReachHere(); 1584 } 1585 __ bind(done); 1586 } 1587 1588 // Long compare 1589 void TemplateTable::lcmp() { 1590 transition(ltos, itos); 1591 1592 const Register Rscratch = R11_scratch1; 1593 __ pop_l(Rscratch); // first operand, deeper in stack 1594 1595 __ cmpd(CCR0, Rscratch, R17_tos); // compare 1596 __ mfcr(R17_tos); // set bit 32..33 as follows: <: 0b10, =: 0b00, >: 0b01 1597 __ srwi(Rscratch, R17_tos, 30); 1598 __ srawi(R17_tos, R17_tos, 31); 1599 __ orr(R17_tos, Rscratch, R17_tos); // set result as follows: <: -1, =: 0, >: 1 1600 } 1601 1602 // fcmpl/fcmpg and dcmpl/dcmpg bytecodes 1603 // unordered_result == -1 => fcmpl or dcmpl 1604 // unordered_result == 1 => fcmpg or dcmpg 1605 void TemplateTable::float_cmp(bool is_float, int unordered_result) { 1606 const FloatRegister Rfirst = F0_SCRATCH, 1607 Rsecond = F15_ftos; 1608 const Register Rscratch = R11_scratch1; 1609 1610 if (is_float) { 1611 __ pop_f(Rfirst); 1612 } else { 1613 __ pop_d(Rfirst); 1614 } 1615 1616 Label Lunordered, Ldone; 1617 __ fcmpu(CCR0, Rfirst, Rsecond); // compare 1618 if (unordered_result) { 1619 __ bso(CCR0, Lunordered); 1620 } 1621 __ mfcr(R17_tos); // set bit 32..33 as follows: <: 0b10, =: 0b00, >: 0b01 1622 __ srwi(Rscratch, R17_tos, 30); 1623 __ srawi(R17_tos, R17_tos, 31); 1624 __ orr(R17_tos, Rscratch, R17_tos); // set result as follows: <: -1, =: 0, >: 1 1625 if (unordered_result) { 1626 __ b(Ldone); 1627 __ bind(Lunordered); 1628 __ load_const_optimized(R17_tos, unordered_result); 1629 } 1630 __ bind(Ldone); 1631 } 1632 1633 // Branch_conditional which takes TemplateTable::Condition. 1634 void TemplateTable::branch_conditional(ConditionRegister crx, TemplateTable::Condition cc, Label& L, bool invert) { 1635 bool positive = false; 1636 Assembler::Condition cond = Assembler::equal; 1637 switch (cc) { 1638 case TemplateTable::equal: positive = true ; cond = Assembler::equal ; break; 1639 case TemplateTable::not_equal: positive = false; cond = Assembler::equal ; break; 1640 case TemplateTable::less: positive = true ; cond = Assembler::less ; break; 1641 case TemplateTable::less_equal: positive = false; cond = Assembler::greater; break; 1642 case TemplateTable::greater: positive = true ; cond = Assembler::greater; break; 1643 case TemplateTable::greater_equal: positive = false; cond = Assembler::less ; break; 1644 default: ShouldNotReachHere(); 1645 } 1646 int bo = (positive != invert) ? Assembler::bcondCRbiIs1 : Assembler::bcondCRbiIs0; 1647 int bi = Assembler::bi0(crx, cond); 1648 __ bc(bo, bi, L); 1649 } 1650 1651 void TemplateTable::branch(bool is_jsr, bool is_wide) { 1652 1653 // Note: on SPARC, we use InterpreterMacroAssembler::if_cmp also. 1654 __ verify_thread(); 1655 1656 const Register Rscratch1 = R11_scratch1, 1657 Rscratch2 = R12_scratch2, 1658 Rscratch3 = R3_ARG1, 1659 R4_counters = R4_ARG2, 1660 bumped_count = R31, 1661 Rdisp = R22_tmp2; 1662 1663 __ profile_taken_branch(Rscratch1, bumped_count); 1664 1665 // Get (wide) offset. 1666 if (is_wide) { 1667 __ get_4_byte_integer_at_bcp(1, Rdisp, InterpreterMacroAssembler::Signed); 1668 } else { 1669 __ get_2_byte_integer_at_bcp(1, Rdisp, InterpreterMacroAssembler::Signed); 1670 } 1671 1672 // -------------------------------------------------------------------------- 1673 // Handle all the JSR stuff here, then exit. 1674 // It's much shorter and cleaner than intermingling with the 1675 // non-JSR normal-branch stuff occurring below. 1676 if (is_jsr) { 1677 // Compute return address as bci in Otos_i. 1678 __ ld(Rscratch1, in_bytes(Method::const_offset()), R19_method); 1679 __ addi(Rscratch2, R14_bcp, -in_bytes(ConstMethod::codes_offset()) + (is_wide ? 5 : 3)); 1680 __ subf(R17_tos, Rscratch1, Rscratch2); 1681 1682 // Bump bcp to target of JSR. 1683 __ add(R14_bcp, Rdisp, R14_bcp); 1684 // Push returnAddress for "ret" on stack. 1685 __ push_ptr(R17_tos); 1686 // And away we go! 1687 __ dispatch_next(vtos, 0 ,true); 1688 return; 1689 } 1690 1691 // -------------------------------------------------------------------------- 1692 // Normal (non-jsr) branch handling 1693 1694 // Bump bytecode pointer by displacement (take the branch). 1695 __ add(R14_bcp, Rdisp, R14_bcp); // Add to bc addr. 1696 1697 const bool increment_invocation_counter_for_backward_branches = UseCompiler && UseLoopCounter; 1698 if (increment_invocation_counter_for_backward_branches) { 1699 Label Lforward; 1700 1701 // Check branch direction. 1702 __ cmpdi(CCR0, Rdisp, 0); 1703 __ bgt(CCR0, Lforward); 1704 1705 __ get_method_counters(R19_method, R4_counters, Lforward); 1706 1707 if (TieredCompilation) { 1708 Label Lno_mdo, Loverflow; 1709 const int increment = InvocationCounter::count_increment; 1710 if (ProfileInterpreter) { 1711 Register Rmdo = Rscratch1; 1712 1713 // If no method data exists, go to profile_continue. 1714 __ ld(Rmdo, in_bytes(Method::method_data_offset()), R19_method); 1715 __ cmpdi(CCR0, Rmdo, 0); 1716 __ beq(CCR0, Lno_mdo); 1717 1718 // Increment backedge counter in the MDO. 1719 const int mdo_bc_offs = in_bytes(MethodData::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset()); 1720 __ lwz(Rscratch2, mdo_bc_offs, Rmdo); 1721 __ lwz(Rscratch3, in_bytes(MethodData::backedge_mask_offset()), Rmdo); 1722 __ addi(Rscratch2, Rscratch2, increment); 1723 __ stw(Rscratch2, mdo_bc_offs, Rmdo); 1724 if (UseOnStackReplacement) { 1725 __ and_(Rscratch3, Rscratch2, Rscratch3); 1726 __ bne(CCR0, Lforward); 1727 __ b(Loverflow); 1728 } else { 1729 __ b(Lforward); 1730 } 1731 } 1732 1733 // If there's no MDO, increment counter in method. 1734 const int mo_bc_offs = in_bytes(MethodCounters::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset()); 1735 __ bind(Lno_mdo); 1736 __ lwz(Rscratch2, mo_bc_offs, R4_counters); 1737 __ lwz(Rscratch3, in_bytes(MethodCounters::backedge_mask_offset()), R4_counters); 1738 __ addi(Rscratch2, Rscratch2, increment); 1739 __ stw(Rscratch2, mo_bc_offs, R4_counters); 1740 if (UseOnStackReplacement) { 1741 __ and_(Rscratch3, Rscratch2, Rscratch3); 1742 __ bne(CCR0, Lforward); 1743 } else { 1744 __ b(Lforward); 1745 } 1746 __ bind(Loverflow); 1747 1748 // Notify point for loop, pass branch bytecode. 1749 __ subf(R4_ARG2, Rdisp, R14_bcp); // Compute branch bytecode (previous bcp). 1750 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R4_ARG2, true); 1751 1752 // Was an OSR adapter generated? 1753 __ cmpdi(CCR0, R3_RET, 0); 1754 __ beq(CCR0, Lforward); 1755 1756 // Has the nmethod been invalidated already? 1757 __ lbz(R0, nmethod::state_offset(), R3_RET); 1758 __ cmpwi(CCR0, R0, nmethod::in_use); 1759 __ bne(CCR0, Lforward); 1760 1761 // Migrate the interpreter frame off of the stack. 1762 // We can use all registers because we will not return to interpreter from this point. 1763 1764 // Save nmethod. 1765 const Register osr_nmethod = R31; 1766 __ mr(osr_nmethod, R3_RET); 1767 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R11_scratch1); 1768 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), R16_thread); 1769 __ reset_last_Java_frame(); 1770 // OSR buffer is in ARG1. 1771 1772 // Remove the interpreter frame. 1773 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2); 1774 1775 // Jump to the osr code. 1776 __ ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod); 1777 __ mtlr(R0); 1778 __ mtctr(R11_scratch1); 1779 __ bctr(); 1780 1781 } else { 1782 1783 const Register invoke_ctr = Rscratch1; 1784 // Update Backedge branch separately from invocations. 1785 __ increment_backedge_counter(R4_counters, invoke_ctr, Rscratch2, Rscratch3); 1786 1787 if (ProfileInterpreter) { 1788 __ test_invocation_counter_for_mdp(invoke_ctr, R4_counters, Rscratch2, Lforward); 1789 if (UseOnStackReplacement) { 1790 __ test_backedge_count_for_osr(bumped_count, R4_counters, R14_bcp, Rdisp, Rscratch2); 1791 } 1792 } else { 1793 if (UseOnStackReplacement) { 1794 __ test_backedge_count_for_osr(invoke_ctr, R4_counters, R14_bcp, Rdisp, Rscratch2); 1795 } 1796 } 1797 } 1798 1799 __ bind(Lforward); 1800 } 1801 __ dispatch_next(vtos, 0, true); 1802 } 1803 1804 // Helper function for if_cmp* methods below. 1805 // Factored out common compare and branch code. 1806 void TemplateTable::if_cmp_common(Register Rfirst, Register Rsecond, Register Rscratch1, Register Rscratch2, Condition cc, bool is_jint, bool cmp0) { 1807 Label Lnot_taken; 1808 // Note: The condition code we get is the condition under which we 1809 // *fall through*! So we have to inverse the CC here. 1810 1811 if (is_jint) { 1812 if (cmp0) { 1813 __ cmpwi(CCR0, Rfirst, 0); 1814 } else { 1815 __ cmpw(CCR0, Rfirst, Rsecond); 1816 } 1817 } else { 1818 if (cmp0) { 1819 __ cmpdi(CCR0, Rfirst, 0); 1820 } else { 1821 __ cmpd(CCR0, Rfirst, Rsecond); 1822 } 1823 } 1824 branch_conditional(CCR0, cc, Lnot_taken, /*invert*/ true); 1825 1826 // Conition is false => Jump! 1827 branch(false, false); 1828 1829 // Condition is not true => Continue. 1830 __ align(32, 12); 1831 __ bind(Lnot_taken); 1832 __ profile_not_taken_branch(Rscratch1, Rscratch2); 1833 } 1834 1835 // Compare integer values with zero and fall through if CC holds, branch away otherwise. 1836 void TemplateTable::if_0cmp(Condition cc) { 1837 transition(itos, vtos); 1838 1839 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, true, true); 1840 } 1841 1842 // Compare integer values and fall through if CC holds, branch away otherwise. 1843 // 1844 // Interface: 1845 // - Rfirst: First operand (older stack value) 1846 // - tos: Second operand (younger stack value) 1847 void TemplateTable::if_icmp(Condition cc) { 1848 transition(itos, vtos); 1849 1850 const Register Rfirst = R0, 1851 Rsecond = R17_tos; 1852 1853 __ pop_i(Rfirst); 1854 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, true, false); 1855 } 1856 1857 void TemplateTable::if_nullcmp(Condition cc) { 1858 transition(atos, vtos); 1859 1860 if_cmp_common(R17_tos, noreg, R11_scratch1, R12_scratch2, cc, false, true); 1861 } 1862 1863 void TemplateTable::if_acmp(Condition cc) { 1864 transition(atos, vtos); 1865 1866 const Register Rfirst = R0, 1867 Rsecond = R17_tos; 1868 1869 __ pop_ptr(Rfirst); 1870 if_cmp_common(Rfirst, Rsecond, R11_scratch1, R12_scratch2, cc, false, false); 1871 } 1872 1873 void TemplateTable::ret() { 1874 locals_index(R11_scratch1); 1875 __ load_local_ptr(R17_tos, R11_scratch1, R11_scratch1); 1876 1877 __ profile_ret(vtos, R17_tos, R11_scratch1, R12_scratch2); 1878 1879 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method); 1880 __ add(R11_scratch1, R17_tos, R11_scratch1); 1881 __ addi(R14_bcp, R11_scratch1, in_bytes(ConstMethod::codes_offset())); 1882 __ dispatch_next(vtos, 0, true); 1883 } 1884 1885 void TemplateTable::wide_ret() { 1886 transition(vtos, vtos); 1887 1888 const Register Rindex = R3_ARG1, 1889 Rscratch1 = R11_scratch1, 1890 Rscratch2 = R12_scratch2; 1891 1892 locals_index_wide(Rindex); 1893 __ load_local_ptr(R17_tos, R17_tos, Rindex); 1894 __ profile_ret(vtos, R17_tos, Rscratch1, R12_scratch2); 1895 // Tos now contains the bci, compute the bcp from that. 1896 __ ld(Rscratch1, in_bytes(Method::const_offset()), R19_method); 1897 __ addi(Rscratch2, R17_tos, in_bytes(ConstMethod::codes_offset())); 1898 __ add(R14_bcp, Rscratch1, Rscratch2); 1899 __ dispatch_next(vtos, 0, true); 1900 } 1901 1902 void TemplateTable::tableswitch() { 1903 transition(itos, vtos); 1904 1905 Label Ldispatch, Ldefault_case; 1906 Register Rlow_byte = R3_ARG1, 1907 Rindex = Rlow_byte, 1908 Rhigh_byte = R4_ARG2, 1909 Rdef_offset_addr = R5_ARG3, // is going to contain address of default offset 1910 Rscratch1 = R11_scratch1, 1911 Rscratch2 = R12_scratch2, 1912 Roffset = R6_ARG4; 1913 1914 // Align bcp. 1915 __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt); 1916 __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt)); 1917 1918 // Load lo & hi. 1919 __ get_u4(Rlow_byte, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned); 1920 __ get_u4(Rhigh_byte, Rdef_offset_addr, 2 *BytesPerInt, InterpreterMacroAssembler::Unsigned); 1921 1922 // Check for default case (=index outside [low,high]). 1923 __ cmpw(CCR0, R17_tos, Rlow_byte); 1924 __ cmpw(CCR1, R17_tos, Rhigh_byte); 1925 __ blt(CCR0, Ldefault_case); 1926 __ bgt(CCR1, Ldefault_case); 1927 1928 // Lookup dispatch offset. 1929 __ sub(Rindex, R17_tos, Rlow_byte); 1930 __ extsw(Rindex, Rindex); 1931 __ profile_switch_case(Rindex, Rhigh_byte /* scratch */, Rscratch1, Rscratch2); 1932 __ sldi(Rindex, Rindex, LogBytesPerInt); 1933 __ addi(Rindex, Rindex, 3 * BytesPerInt); 1934 #if defined(VM_LITTLE_ENDIAN) 1935 __ lwbrx(Roffset, Rdef_offset_addr, Rindex); 1936 __ extsw(Roffset, Roffset); 1937 #else 1938 __ lwax(Roffset, Rdef_offset_addr, Rindex); 1939 #endif 1940 __ b(Ldispatch); 1941 1942 __ bind(Ldefault_case); 1943 __ profile_switch_default(Rhigh_byte, Rscratch1); 1944 __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Signed); 1945 1946 __ bind(Ldispatch); 1947 1948 __ add(R14_bcp, Roffset, R14_bcp); 1949 __ dispatch_next(vtos, 0, true); 1950 } 1951 1952 void TemplateTable::lookupswitch() { 1953 transition(itos, itos); 1954 __ stop("lookupswitch bytecode should have been rewritten"); 1955 } 1956 1957 // Table switch using linear search through cases. 1958 // Bytecode stream format: 1959 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ... 1960 // Note: Everything is big-endian format here. 1961 void TemplateTable::fast_linearswitch() { 1962 transition(itos, vtos); 1963 1964 Label Lloop_entry, Lsearch_loop, Lcontinue_execution, Ldefault_case; 1965 Register Rcount = R3_ARG1, 1966 Rcurrent_pair = R4_ARG2, 1967 Rdef_offset_addr = R5_ARG3, // Is going to contain address of default offset. 1968 Roffset = R31, // Might need to survive C call. 1969 Rvalue = R12_scratch2, 1970 Rscratch = R11_scratch1, 1971 Rcmp_value = R17_tos; 1972 1973 // Align bcp. 1974 __ addi(Rdef_offset_addr, R14_bcp, BytesPerInt); 1975 __ clrrdi(Rdef_offset_addr, Rdef_offset_addr, log2_long((jlong)BytesPerInt)); 1976 1977 // Setup loop counter and limit. 1978 __ get_u4(Rcount, Rdef_offset_addr, BytesPerInt, InterpreterMacroAssembler::Unsigned); 1979 __ addi(Rcurrent_pair, Rdef_offset_addr, 2 * BytesPerInt); // Rcurrent_pair now points to first pair. 1980 1981 __ mtctr(Rcount); 1982 __ cmpwi(CCR0, Rcount, 0); 1983 __ bne(CCR0, Lloop_entry); 1984 1985 // Default case 1986 __ bind(Ldefault_case); 1987 __ get_u4(Roffset, Rdef_offset_addr, 0, InterpreterMacroAssembler::Signed); 1988 if (ProfileInterpreter) { 1989 __ profile_switch_default(Rdef_offset_addr, Rcount/* scratch */); 1990 } 1991 __ b(Lcontinue_execution); 1992 1993 // Next iteration 1994 __ bind(Lsearch_loop); 1995 __ bdz(Ldefault_case); 1996 __ addi(Rcurrent_pair, Rcurrent_pair, 2 * BytesPerInt); 1997 __ bind(Lloop_entry); 1998 __ get_u4(Rvalue, Rcurrent_pair, 0, InterpreterMacroAssembler::Unsigned); 1999 __ cmpw(CCR0, Rvalue, Rcmp_value); 2000 __ bne(CCR0, Lsearch_loop); 2001 2002 // Found, load offset. 2003 __ get_u4(Roffset, Rcurrent_pair, BytesPerInt, InterpreterMacroAssembler::Signed); 2004 // Calculate case index and profile 2005 __ mfctr(Rcurrent_pair); 2006 if (ProfileInterpreter) { 2007 __ sub(Rcurrent_pair, Rcount, Rcurrent_pair); 2008 __ profile_switch_case(Rcurrent_pair, Rcount /*scratch*/, Rdef_offset_addr/*scratch*/, Rscratch); 2009 } 2010 2011 __ bind(Lcontinue_execution); 2012 __ add(R14_bcp, Roffset, R14_bcp); 2013 __ dispatch_next(vtos, 0, true); 2014 } 2015 2016 // Table switch using binary search (value/offset pairs are ordered). 2017 // Bytecode stream format: 2018 // Bytecode (1) | 4-byte padding | default offset (4) | count (4) | value/offset pair1 (8) | value/offset pair2 (8) | ... 2019 // Note: Everything is big-endian format here. So on little endian machines, we have to revers offset and count and cmp value. 2020 void TemplateTable::fast_binaryswitch() { 2021 2022 transition(itos, vtos); 2023 // Implementation using the following core algorithm: (copied from Intel) 2024 // 2025 // int binary_search(int key, LookupswitchPair* array, int n) { 2026 // // Binary search according to "Methodik des Programmierens" by 2027 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. 2028 // int i = 0; 2029 // int j = n; 2030 // while (i+1 < j) { 2031 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) 2032 // // with Q: for all i: 0 <= i < n: key < a[i] 2033 // // where a stands for the array and assuming that the (inexisting) 2034 // // element a[n] is infinitely big. 2035 // int h = (i + j) >> 1; 2036 // // i < h < j 2037 // if (key < array[h].fast_match()) { 2038 // j = h; 2039 // } else { 2040 // i = h; 2041 // } 2042 // } 2043 // // R: a[i] <= key < a[i+1] or Q 2044 // // (i.e., if key is within array, i is the correct index) 2045 // return i; 2046 // } 2047 2048 // register allocation 2049 const Register Rkey = R17_tos; // already set (tosca) 2050 const Register Rarray = R3_ARG1; 2051 const Register Ri = R4_ARG2; 2052 const Register Rj = R5_ARG3; 2053 const Register Rh = R6_ARG4; 2054 const Register Rscratch = R11_scratch1; 2055 2056 const int log_entry_size = 3; 2057 const int entry_size = 1 << log_entry_size; 2058 2059 Label found; 2060 2061 // Find Array start, 2062 __ addi(Rarray, R14_bcp, 3 * BytesPerInt); 2063 __ clrrdi(Rarray, Rarray, log2_long((jlong)BytesPerInt)); 2064 2065 // initialize i & j 2066 __ li(Ri,0); 2067 __ get_u4(Rj, Rarray, -BytesPerInt, InterpreterMacroAssembler::Unsigned); 2068 2069 // and start. 2070 Label entry; 2071 __ b(entry); 2072 2073 // binary search loop 2074 { Label loop; 2075 __ bind(loop); 2076 // int h = (i + j) >> 1; 2077 __ srdi(Rh, Rh, 1); 2078 // if (key < array[h].fast_match()) { 2079 // j = h; 2080 // } else { 2081 // i = h; 2082 // } 2083 __ sldi(Rscratch, Rh, log_entry_size); 2084 #if defined(VM_LITTLE_ENDIAN) 2085 __ lwbrx(Rscratch, Rscratch, Rarray); 2086 #else 2087 __ lwzx(Rscratch, Rscratch, Rarray); 2088 #endif 2089 2090 // if (key < current value) 2091 // Rh = Rj 2092 // else 2093 // Rh = Ri 2094 Label Lgreater; 2095 __ cmpw(CCR0, Rkey, Rscratch); 2096 __ bge(CCR0, Lgreater); 2097 __ mr(Rj, Rh); 2098 __ b(entry); 2099 __ bind(Lgreater); 2100 __ mr(Ri, Rh); 2101 2102 // while (i+1 < j) 2103 __ bind(entry); 2104 __ addi(Rscratch, Ri, 1); 2105 __ cmpw(CCR0, Rscratch, Rj); 2106 __ add(Rh, Ri, Rj); // start h = i + j >> 1; 2107 2108 __ blt(CCR0, loop); 2109 } 2110 2111 // End of binary search, result index is i (must check again!). 2112 Label default_case; 2113 Label continue_execution; 2114 if (ProfileInterpreter) { 2115 __ mr(Rh, Ri); // Save index in i for profiling. 2116 } 2117 // Ri = value offset 2118 __ sldi(Ri, Ri, log_entry_size); 2119 __ add(Ri, Ri, Rarray); 2120 __ get_u4(Rscratch, Ri, 0, InterpreterMacroAssembler::Unsigned); 2121 2122 Label not_found; 2123 // Ri = offset offset 2124 __ cmpw(CCR0, Rkey, Rscratch); 2125 __ beq(CCR0, not_found); 2126 // entry not found -> j = default offset 2127 __ get_u4(Rj, Rarray, -2 * BytesPerInt, InterpreterMacroAssembler::Unsigned); 2128 __ b(default_case); 2129 2130 __ bind(not_found); 2131 // entry found -> j = offset 2132 __ profile_switch_case(Rh, Rj, Rscratch, Rkey); 2133 __ get_u4(Rj, Ri, BytesPerInt, InterpreterMacroAssembler::Unsigned); 2134 2135 if (ProfileInterpreter) { 2136 __ b(continue_execution); 2137 } 2138 2139 __ bind(default_case); // fall through (if not profiling) 2140 __ profile_switch_default(Ri, Rscratch); 2141 2142 __ bind(continue_execution); 2143 2144 __ extsw(Rj, Rj); 2145 __ add(R14_bcp, Rj, R14_bcp); 2146 __ dispatch_next(vtos, 0 , true); 2147 } 2148 2149 void TemplateTable::_return(TosState state) { 2150 transition(state, state); 2151 assert(_desc->calls_vm(), 2152 "inconsistent calls_vm information"); // call in remove_activation 2153 2154 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) { 2155 2156 Register Rscratch = R11_scratch1, 2157 Rklass = R12_scratch2, 2158 Rklass_flags = Rklass; 2159 Label Lskip_register_finalizer; 2160 2161 // Check if the method has the FINALIZER flag set and call into the VM to finalize in this case. 2162 assert(state == vtos, "only valid state"); 2163 __ ld(R17_tos, 0, R18_locals); 2164 2165 // Load klass of this obj. 2166 __ load_klass(Rklass, R17_tos); 2167 __ lwz(Rklass_flags, in_bytes(Klass::access_flags_offset()), Rklass); 2168 __ testbitdi(CCR0, R0, Rklass_flags, exact_log2(JVM_ACC_HAS_FINALIZER)); 2169 __ bfalse(CCR0, Lskip_register_finalizer); 2170 2171 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), R17_tos /* obj */); 2172 2173 __ align(32, 12); 2174 __ bind(Lskip_register_finalizer); 2175 } 2176 2177 if (SafepointMechanism::uses_thread_local_poll() && _desc->bytecode() != Bytecodes::_return_register_finalizer) { 2178 Label no_safepoint; 2179 __ ld(R11_scratch1, in_bytes(Thread::polling_page_offset()), R16_thread); 2180 __ andi_(R11_scratch1, R11_scratch1, SafepointMechanism::poll_bit()); 2181 __ beq(CCR0, no_safepoint); 2182 __ push(state); 2183 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)); 2184 __ pop(state); 2185 __ bind(no_safepoint); 2186 } 2187 2188 // Move the result value into the correct register and remove memory stack frame. 2189 __ remove_activation(state, /* throw_monitor_exception */ true); 2190 // Restoration of lr done by remove_activation. 2191 switch (state) { 2192 // Narrow result if state is itos but result type is smaller. 2193 // Need to narrow in the return bytecode rather than in generate_return_entry 2194 // since compiled code callers expect the result to already be narrowed. 2195 case itos: __ narrow(R17_tos); /* fall through */ 2196 case ltos: 2197 case atos: __ mr(R3_RET, R17_tos); break; 2198 case ftos: 2199 case dtos: __ fmr(F1_RET, F15_ftos); break; 2200 case vtos: // This might be a constructor. Final fields (and volatile fields on PPC64) need 2201 // to get visible before the reference to the object gets stored anywhere. 2202 __ membar(Assembler::StoreStore); break; 2203 default : ShouldNotReachHere(); 2204 } 2205 __ blr(); 2206 } 2207 2208 // ============================================================================ 2209 // Constant pool cache access 2210 // 2211 // Memory ordering: 2212 // 2213 // Like done in C++ interpreter, we load the fields 2214 // - _indices 2215 // - _f12_oop 2216 // acquired, because these are asked if the cache is already resolved. We don't 2217 // want to float loads above this check. 2218 // See also comments in ConstantPoolCacheEntry::bytecode_1(), 2219 // ConstantPoolCacheEntry::bytecode_2() and ConstantPoolCacheEntry::f1(); 2220 2221 // Call into the VM if call site is not yet resolved 2222 // 2223 // Input regs: 2224 // - None, all passed regs are outputs. 2225 // 2226 // Returns: 2227 // - Rcache: The const pool cache entry that contains the resolved result. 2228 // - Rresult: Either noreg or output for f1/f2. 2229 // 2230 // Kills: 2231 // - Rscratch 2232 void TemplateTable::resolve_cache_and_index(int byte_no, Register Rcache, Register Rscratch, size_t index_size) { 2233 2234 __ get_cache_and_index_at_bcp(Rcache, 1, index_size); 2235 Label Lresolved, Ldone; 2236 2237 Bytecodes::Code code = bytecode(); 2238 switch (code) { 2239 case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break; 2240 case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break; 2241 } 2242 2243 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 2244 // We are resolved if the indices offset contains the current bytecode. 2245 #if defined(VM_LITTLE_ENDIAN) 2246 __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + byte_no + 1, Rcache); 2247 #else 2248 __ lbz(Rscratch, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()) + 7 - (byte_no + 1), Rcache); 2249 #endif 2250 // Acquire by cmp-br-isync (see below). 2251 __ cmpdi(CCR0, Rscratch, (int)code); 2252 __ beq(CCR0, Lresolved); 2253 2254 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache); 2255 __ li(R4_ARG2, code); 2256 __ call_VM(noreg, entry, R4_ARG2, true); 2257 2258 // Update registers with resolved info. 2259 __ get_cache_and_index_at_bcp(Rcache, 1, index_size); 2260 __ b(Ldone); 2261 2262 __ bind(Lresolved); 2263 __ isync(); // Order load wrt. succeeding loads. 2264 __ bind(Ldone); 2265 } 2266 2267 // Load the constant pool cache entry at field accesses into registers. 2268 // The Rcache and Rindex registers must be set before call. 2269 // Input: 2270 // - Rcache, Rindex 2271 // Output: 2272 // - Robj, Roffset, Rflags 2273 void TemplateTable::load_field_cp_cache_entry(Register Robj, 2274 Register Rcache, 2275 Register Rindex /* unused on PPC64 */, 2276 Register Roffset, 2277 Register Rflags, 2278 bool is_static = false) { 2279 assert_different_registers(Rcache, Rflags, Roffset); 2280 // assert(Rindex == noreg, "parameter not used on PPC64"); 2281 2282 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2283 __ ld(Rflags, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcache); 2284 __ ld(Roffset, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f2_offset()), Rcache); 2285 if (is_static) { 2286 __ ld(Robj, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f1_offset()), Rcache); 2287 __ ld(Robj, in_bytes(Klass::java_mirror_offset()), Robj); 2288 __ resolve_oop_handle(Robj); 2289 // Acquire not needed here. Following access has an address dependency on this value. 2290 } 2291 } 2292 2293 // Load the constant pool cache entry at invokes into registers. 2294 // Resolve if necessary. 2295 2296 // Input Registers: 2297 // - None, bcp is used, though 2298 // 2299 // Return registers: 2300 // - Rmethod (f1 field or f2 if invokevirtual) 2301 // - Ritable_index (f2 field) 2302 // - Rflags (flags field) 2303 // 2304 // Kills: 2305 // - R21 2306 // 2307 void TemplateTable::load_invoke_cp_cache_entry(int byte_no, 2308 Register Rmethod, 2309 Register Ritable_index, 2310 Register Rflags, 2311 bool is_invokevirtual, 2312 bool is_invokevfinal, 2313 bool is_invokedynamic) { 2314 2315 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2316 // Determine constant pool cache field offsets. 2317 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant"); 2318 const int method_offset = in_bytes(cp_base_offset + (is_invokevirtual ? ConstantPoolCacheEntry::f2_offset() : ConstantPoolCacheEntry::f1_offset())); 2319 const int flags_offset = in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()); 2320 // Access constant pool cache fields. 2321 const int index_offset = in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()); 2322 2323 Register Rcache = R21_tmp1; // Note: same register as R21_sender_SP. 2324 2325 if (is_invokevfinal) { 2326 assert(Ritable_index == noreg, "register not used"); 2327 // Already resolved. 2328 __ get_cache_and_index_at_bcp(Rcache, 1); 2329 } else { 2330 resolve_cache_and_index(byte_no, Rcache, R0, is_invokedynamic ? sizeof(u4) : sizeof(u2)); 2331 } 2332 2333 __ ld(Rmethod, method_offset, Rcache); 2334 __ ld(Rflags, flags_offset, Rcache); 2335 2336 if (Ritable_index != noreg) { 2337 __ ld(Ritable_index, index_offset, Rcache); 2338 } 2339 } 2340 2341 // ============================================================================ 2342 // Field access 2343 2344 // Volatile variables demand their effects be made known to all CPU's 2345 // in order. Store buffers on most chips allow reads & writes to 2346 // reorder; the JMM's ReadAfterWrite.java test fails in -Xint mode 2347 // without some kind of memory barrier (i.e., it's not sufficient that 2348 // the interpreter does not reorder volatile references, the hardware 2349 // also must not reorder them). 2350 // 2351 // According to the new Java Memory Model (JMM): 2352 // (1) All volatiles are serialized wrt to each other. ALSO reads & 2353 // writes act as aquire & release, so: 2354 // (2) A read cannot let unrelated NON-volatile memory refs that 2355 // happen after the read float up to before the read. It's OK for 2356 // non-volatile memory refs that happen before the volatile read to 2357 // float down below it. 2358 // (3) Similar a volatile write cannot let unrelated NON-volatile 2359 // memory refs that happen BEFORE the write float down to after the 2360 // write. It's OK for non-volatile memory refs that happen after the 2361 // volatile write to float up before it. 2362 // 2363 // We only put in barriers around volatile refs (they are expensive), 2364 // not _between_ memory refs (that would require us to track the 2365 // flavor of the previous memory refs). Requirements (2) and (3) 2366 // require some barriers before volatile stores and after volatile 2367 // loads. These nearly cover requirement (1) but miss the 2368 // volatile-store-volatile-load case. This final case is placed after 2369 // volatile-stores although it could just as well go before 2370 // volatile-loads. 2371 2372 // The registers cache and index expected to be set before call. 2373 // Correct values of the cache and index registers are preserved. 2374 // Kills: 2375 // Rcache (if has_tos) 2376 // Rscratch 2377 void TemplateTable::jvmti_post_field_access(Register Rcache, Register Rscratch, bool is_static, bool has_tos) { 2378 2379 assert_different_registers(Rcache, Rscratch); 2380 2381 if (JvmtiExport::can_post_field_access()) { 2382 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2383 Label Lno_field_access_post; 2384 2385 // Check if post field access in enabled. 2386 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_access_count_addr(), R0, true); 2387 __ lwz(Rscratch, offs, Rscratch); 2388 2389 __ cmpwi(CCR0, Rscratch, 0); 2390 __ beq(CCR0, Lno_field_access_post); 2391 2392 // Post access enabled - do it! 2393 __ addi(Rcache, Rcache, in_bytes(cp_base_offset)); 2394 if (is_static) { 2395 __ li(R17_tos, 0); 2396 } else { 2397 if (has_tos) { 2398 // The fast bytecode versions have obj ptr in register. 2399 // Thus, save object pointer before call_VM() clobbers it 2400 // put object on tos where GC wants it. 2401 __ push_ptr(R17_tos); 2402 } else { 2403 // Load top of stack (do not pop the value off the stack). 2404 __ ld(R17_tos, Interpreter::expr_offset_in_bytes(0), R15_esp); 2405 } 2406 __ verify_oop(R17_tos); 2407 } 2408 // tos: object pointer or NULL if static 2409 // cache: cache entry pointer 2410 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), R17_tos, Rcache); 2411 if (!is_static && has_tos) { 2412 // Restore object pointer. 2413 __ pop_ptr(R17_tos); 2414 __ verify_oop(R17_tos); 2415 } else { 2416 // Cache is still needed to get class or obj. 2417 __ get_cache_and_index_at_bcp(Rcache, 1); 2418 } 2419 2420 __ align(32, 12); 2421 __ bind(Lno_field_access_post); 2422 } 2423 } 2424 2425 // kills R11_scratch1 2426 void TemplateTable::pop_and_check_object(Register Roop) { 2427 Register Rtmp = R11_scratch1; 2428 2429 assert_different_registers(Rtmp, Roop); 2430 __ pop_ptr(Roop); 2431 // For field access must check obj. 2432 __ null_check_throw(Roop, -1, Rtmp); 2433 __ verify_oop(Roop); 2434 } 2435 2436 // PPC64: implement volatile loads as fence-store-acquire. 2437 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2438 transition(vtos, vtos); 2439 2440 Label Lacquire, Lisync; 2441 2442 const Register Rcache = R3_ARG1, 2443 Rclass_or_obj = R22_tmp2, 2444 Roffset = R23_tmp3, 2445 Rflags = R31, 2446 Rbtable = R5_ARG3, 2447 Rbc = R6_ARG4, 2448 Rscratch = R12_scratch2; 2449 2450 static address field_branch_table[number_of_states], 2451 static_branch_table[number_of_states]; 2452 2453 address* branch_table = (is_static || rc == may_not_rewrite) ? static_branch_table : field_branch_table; 2454 2455 // Get field offset. 2456 resolve_cache_and_index(byte_no, Rcache, Rscratch, sizeof(u2)); 2457 2458 // JVMTI support 2459 jvmti_post_field_access(Rcache, Rscratch, is_static, false); 2460 2461 // Load after possible GC. 2462 load_field_cp_cache_entry(Rclass_or_obj, Rcache, noreg, Roffset, Rflags, is_static); 2463 2464 // Load pointer to branch table. 2465 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch); 2466 2467 // Get volatile flag. 2468 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit. 2469 // Note: sync is needed before volatile load on PPC64. 2470 2471 // Check field type. 2472 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 2473 2474 #ifdef ASSERT 2475 Label LFlagInvalid; 2476 __ cmpldi(CCR0, Rflags, number_of_states); 2477 __ bge(CCR0, LFlagInvalid); 2478 #endif 2479 2480 // Load from branch table and dispatch (volatile case: one instruction ahead). 2481 __ sldi(Rflags, Rflags, LogBytesPerWord); 2482 __ cmpwi(CCR6, Rscratch, 1); // Volatile? 2483 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 2484 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // Volatile ? size of 1 instruction : 0. 2485 } 2486 __ ldx(Rbtable, Rbtable, Rflags); 2487 2488 // Get the obj from stack. 2489 if (!is_static) { 2490 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1. 2491 } else { 2492 __ verify_oop(Rclass_or_obj); 2493 } 2494 2495 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 2496 __ subf(Rbtable, Rscratch, Rbtable); // Point to volatile/non-volatile entry point. 2497 } 2498 __ mtctr(Rbtable); 2499 __ bctr(); 2500 2501 #ifdef ASSERT 2502 __ bind(LFlagInvalid); 2503 __ stop("got invalid flag", 0x654); 2504 #endif 2505 2506 if (!is_static && rc == may_not_rewrite) { 2507 // We reuse the code from is_static. It's jumped to via the table above. 2508 return; 2509 } 2510 2511 #ifdef ASSERT 2512 // __ bind(Lvtos); 2513 address pc_before_fence = __ pc(); 2514 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2515 assert(__ pc() - pc_before_fence == (ptrdiff_t)BytesPerInstWord, "must be single instruction"); 2516 assert(branch_table[vtos] == 0, "can't compute twice"); 2517 branch_table[vtos] = __ pc(); // non-volatile_entry point 2518 __ stop("vtos unexpected", 0x655); 2519 #endif 2520 2521 __ align(32, 28, 28); // Align load. 2522 // __ bind(Ldtos); 2523 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2524 assert(branch_table[dtos] == 0, "can't compute twice"); 2525 branch_table[dtos] = __ pc(); // non-volatile_entry point 2526 __ lfdx(F15_ftos, Rclass_or_obj, Roffset); 2527 __ push(dtos); 2528 if (!is_static && rc == may_rewrite) { 2529 patch_bytecode(Bytecodes::_fast_dgetfield, Rbc, Rscratch); 2530 } 2531 { 2532 Label acquire_double; 2533 __ beq(CCR6, acquire_double); // Volatile? 2534 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2535 2536 __ bind(acquire_double); 2537 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync. 2538 __ beq_predict_taken(CCR0, Lisync); 2539 __ b(Lisync); // In case of NAN. 2540 } 2541 2542 __ align(32, 28, 28); // Align load. 2543 // __ bind(Lftos); 2544 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2545 assert(branch_table[ftos] == 0, "can't compute twice"); 2546 branch_table[ftos] = __ pc(); // non-volatile_entry point 2547 __ lfsx(F15_ftos, Rclass_or_obj, Roffset); 2548 __ push(ftos); 2549 if (!is_static && rc == may_rewrite) { 2550 patch_bytecode(Bytecodes::_fast_fgetfield, Rbc, Rscratch); 2551 } 2552 { 2553 Label acquire_float; 2554 __ beq(CCR6, acquire_float); // Volatile? 2555 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2556 2557 __ bind(acquire_float); 2558 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync. 2559 __ beq_predict_taken(CCR0, Lisync); 2560 __ b(Lisync); // In case of NAN. 2561 } 2562 2563 __ align(32, 28, 28); // Align load. 2564 // __ bind(Litos); 2565 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2566 assert(branch_table[itos] == 0, "can't compute twice"); 2567 branch_table[itos] = __ pc(); // non-volatile_entry point 2568 __ lwax(R17_tos, Rclass_or_obj, Roffset); 2569 __ push(itos); 2570 if (!is_static && rc == may_rewrite) { 2571 patch_bytecode(Bytecodes::_fast_igetfield, Rbc, Rscratch); 2572 } 2573 __ beq(CCR6, Lacquire); // Volatile? 2574 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2575 2576 __ align(32, 28, 28); // Align load. 2577 // __ bind(Lltos); 2578 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2579 assert(branch_table[ltos] == 0, "can't compute twice"); 2580 branch_table[ltos] = __ pc(); // non-volatile_entry point 2581 __ ldx(R17_tos, Rclass_or_obj, Roffset); 2582 __ push(ltos); 2583 if (!is_static && rc == may_rewrite) { 2584 patch_bytecode(Bytecodes::_fast_lgetfield, Rbc, Rscratch); 2585 } 2586 __ beq(CCR6, Lacquire); // Volatile? 2587 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2588 2589 __ align(32, 28, 28); // Align load. 2590 // __ bind(Lbtos); 2591 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2592 assert(branch_table[btos] == 0, "can't compute twice"); 2593 branch_table[btos] = __ pc(); // non-volatile_entry point 2594 __ lbzx(R17_tos, Rclass_or_obj, Roffset); 2595 __ extsb(R17_tos, R17_tos); 2596 __ push(btos); 2597 if (!is_static && rc == may_rewrite) { 2598 patch_bytecode(Bytecodes::_fast_bgetfield, Rbc, Rscratch); 2599 } 2600 __ beq(CCR6, Lacquire); // Volatile? 2601 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2602 2603 __ align(32, 28, 28); // Align load. 2604 // __ bind(Lztos); (same code as btos) 2605 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2606 assert(branch_table[ztos] == 0, "can't compute twice"); 2607 branch_table[ztos] = __ pc(); // non-volatile_entry point 2608 __ lbzx(R17_tos, Rclass_or_obj, Roffset); 2609 __ push(ztos); 2610 if (!is_static && rc == may_rewrite) { 2611 // use btos rewriting, no truncating to t/f bit is needed for getfield. 2612 patch_bytecode(Bytecodes::_fast_bgetfield, Rbc, Rscratch); 2613 } 2614 __ beq(CCR6, Lacquire); // Volatile? 2615 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2616 2617 __ align(32, 28, 28); // Align load. 2618 // __ bind(Lctos); 2619 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2620 assert(branch_table[ctos] == 0, "can't compute twice"); 2621 branch_table[ctos] = __ pc(); // non-volatile_entry point 2622 __ lhzx(R17_tos, Rclass_or_obj, Roffset); 2623 __ push(ctos); 2624 if (!is_static && rc == may_rewrite) { 2625 patch_bytecode(Bytecodes::_fast_cgetfield, Rbc, Rscratch); 2626 } 2627 __ beq(CCR6, Lacquire); // Volatile? 2628 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2629 2630 __ align(32, 28, 28); // Align load. 2631 // __ bind(Lstos); 2632 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2633 assert(branch_table[stos] == 0, "can't compute twice"); 2634 branch_table[stos] = __ pc(); // non-volatile_entry point 2635 __ lhax(R17_tos, Rclass_or_obj, Roffset); 2636 __ push(stos); 2637 if (!is_static && rc == may_rewrite) { 2638 patch_bytecode(Bytecodes::_fast_sgetfield, Rbc, Rscratch); 2639 } 2640 __ beq(CCR6, Lacquire); // Volatile? 2641 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2642 2643 __ align(32, 28, 28); // Align load. 2644 // __ bind(Latos); 2645 __ fence(); // Volatile entry point (one instruction before non-volatile_entry point). 2646 assert(branch_table[atos] == 0, "can't compute twice"); 2647 branch_table[atos] = __ pc(); // non-volatile_entry point 2648 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP); 2649 __ verify_oop(R17_tos); 2650 __ push(atos); 2651 //__ dcbt(R17_tos); // prefetch 2652 if (!is_static && rc == may_rewrite) { 2653 patch_bytecode(Bytecodes::_fast_agetfield, Rbc, Rscratch); 2654 } 2655 __ beq(CCR6, Lacquire); // Volatile? 2656 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2657 2658 __ align(32, 12); 2659 __ bind(Lacquire); 2660 __ twi_0(R17_tos); 2661 __ bind(Lisync); 2662 __ isync(); // acquire 2663 2664 #ifdef ASSERT 2665 for (int i = 0; i<number_of_states; ++i) { 2666 assert(branch_table[i], "get initialization"); 2667 //tty->print_cr("get: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)", 2668 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i])); 2669 } 2670 #endif 2671 } 2672 2673 void TemplateTable::getfield(int byte_no) { 2674 getfield_or_static(byte_no, false); 2675 } 2676 2677 void TemplateTable::nofast_getfield(int byte_no) { 2678 getfield_or_static(byte_no, false, may_not_rewrite); 2679 } 2680 2681 void TemplateTable::getstatic(int byte_no) { 2682 getfield_or_static(byte_no, true); 2683 } 2684 2685 // The registers cache and index expected to be set before call. 2686 // The function may destroy various registers, just not the cache and index registers. 2687 void TemplateTable::jvmti_post_field_mod(Register Rcache, Register Rscratch, bool is_static) { 2688 2689 assert_different_registers(Rcache, Rscratch, R6_ARG4); 2690 2691 if (JvmtiExport::can_post_field_modification()) { 2692 Label Lno_field_mod_post; 2693 2694 // Check if post field access in enabled. 2695 int offs = __ load_const_optimized(Rscratch, JvmtiExport::get_field_modification_count_addr(), R0, true); 2696 __ lwz(Rscratch, offs, Rscratch); 2697 2698 __ cmpwi(CCR0, Rscratch, 0); 2699 __ beq(CCR0, Lno_field_mod_post); 2700 2701 // Do the post 2702 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2703 const Register Robj = Rscratch; 2704 2705 __ addi(Rcache, Rcache, in_bytes(cp_base_offset)); 2706 if (is_static) { 2707 // Life is simple. Null out the object pointer. 2708 __ li(Robj, 0); 2709 } else { 2710 // In case of the fast versions, value lives in registers => put it back on tos. 2711 int offs = Interpreter::expr_offset_in_bytes(0); 2712 Register base = R15_esp; 2713 switch(bytecode()) { 2714 case Bytecodes::_fast_aputfield: __ push_ptr(); offs+= Interpreter::stackElementSize; break; 2715 case Bytecodes::_fast_iputfield: // Fall through 2716 case Bytecodes::_fast_bputfield: // Fall through 2717 case Bytecodes::_fast_zputfield: // Fall through 2718 case Bytecodes::_fast_cputfield: // Fall through 2719 case Bytecodes::_fast_sputfield: __ push_i(); offs+= Interpreter::stackElementSize; break; 2720 case Bytecodes::_fast_lputfield: __ push_l(); offs+=2*Interpreter::stackElementSize; break; 2721 case Bytecodes::_fast_fputfield: __ push_f(); offs+= Interpreter::stackElementSize; break; 2722 case Bytecodes::_fast_dputfield: __ push_d(); offs+=2*Interpreter::stackElementSize; break; 2723 default: { 2724 offs = 0; 2725 base = Robj; 2726 const Register Rflags = Robj; 2727 Label is_one_slot; 2728 // Life is harder. The stack holds the value on top, followed by the 2729 // object. We don't know the size of the value, though; it could be 2730 // one or two words depending on its type. As a result, we must find 2731 // the type to determine where the object is. 2732 __ ld(Rflags, in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcache); // Big Endian 2733 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 2734 2735 __ cmpwi(CCR0, Rflags, ltos); 2736 __ cmpwi(CCR1, Rflags, dtos); 2737 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(1)); 2738 __ crnor(CCR0, Assembler::equal, CCR1, Assembler::equal); 2739 __ beq(CCR0, is_one_slot); 2740 __ addi(base, R15_esp, Interpreter::expr_offset_in_bytes(2)); 2741 __ bind(is_one_slot); 2742 break; 2743 } 2744 } 2745 __ ld(Robj, offs, base); 2746 __ verify_oop(Robj); 2747 } 2748 2749 __ addi(R6_ARG4, R15_esp, Interpreter::expr_offset_in_bytes(0)); 2750 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), Robj, Rcache, R6_ARG4); 2751 __ get_cache_and_index_at_bcp(Rcache, 1); 2752 2753 // In case of the fast versions, value lives in registers => put it back on tos. 2754 switch(bytecode()) { 2755 case Bytecodes::_fast_aputfield: __ pop_ptr(); break; 2756 case Bytecodes::_fast_iputfield: // Fall through 2757 case Bytecodes::_fast_bputfield: // Fall through 2758 case Bytecodes::_fast_zputfield: // Fall through 2759 case Bytecodes::_fast_cputfield: // Fall through 2760 case Bytecodes::_fast_sputfield: __ pop_i(); break; 2761 case Bytecodes::_fast_lputfield: __ pop_l(); break; 2762 case Bytecodes::_fast_fputfield: __ pop_f(); break; 2763 case Bytecodes::_fast_dputfield: __ pop_d(); break; 2764 default: break; // Nothin' to do. 2765 } 2766 2767 __ align(32, 12); 2768 __ bind(Lno_field_mod_post); 2769 } 2770 } 2771 2772 // PPC64: implement volatile stores as release-store (return bytecode contains an additional release). 2773 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2774 Label Lvolatile; 2775 2776 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod). 2777 Rclass_or_obj = R31, // Needs to survive C call. 2778 Roffset = R22_tmp2, // Needs to survive C call. 2779 Rflags = R3_ARG1, 2780 Rbtable = R4_ARG2, 2781 Rscratch = R11_scratch1, 2782 Rscratch2 = R12_scratch2, 2783 Rscratch3 = R6_ARG4, 2784 Rbc = Rscratch3; 2785 const ConditionRegister CR_is_vol = CCR2; // Non-volatile condition register (survives runtime call in do_oop_store). 2786 2787 static address field_rw_branch_table[number_of_states], 2788 field_norw_branch_table[number_of_states], 2789 static_branch_table[number_of_states]; 2790 2791 address* branch_table = is_static ? static_branch_table : 2792 (rc == may_rewrite ? field_rw_branch_table : field_norw_branch_table); 2793 2794 // Stack (grows up): 2795 // value 2796 // obj 2797 2798 // Load the field offset. 2799 resolve_cache_and_index(byte_no, Rcache, Rscratch, sizeof(u2)); 2800 jvmti_post_field_mod(Rcache, Rscratch, is_static); 2801 load_field_cp_cache_entry(Rclass_or_obj, Rcache, noreg, Roffset, Rflags, is_static); 2802 2803 // Load pointer to branch table. 2804 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch); 2805 2806 // Get volatile flag. 2807 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit. 2808 2809 // Check the field type. 2810 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 2811 2812 #ifdef ASSERT 2813 Label LFlagInvalid; 2814 __ cmpldi(CCR0, Rflags, number_of_states); 2815 __ bge(CCR0, LFlagInvalid); 2816 #endif 2817 2818 // Load from branch table and dispatch (volatile case: one instruction ahead). 2819 __ sldi(Rflags, Rflags, LogBytesPerWord); 2820 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2821 __ cmpwi(CR_is_vol, Rscratch, 1); // Volatile? 2822 } 2823 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // Volatile? size of instruction 1 : 0. 2824 __ ldx(Rbtable, Rbtable, Rflags); 2825 2826 __ subf(Rbtable, Rscratch, Rbtable); // Point to volatile/non-volatile entry point. 2827 __ mtctr(Rbtable); 2828 __ bctr(); 2829 2830 #ifdef ASSERT 2831 __ bind(LFlagInvalid); 2832 __ stop("got invalid flag", 0x656); 2833 2834 // __ bind(Lvtos); 2835 address pc_before_release = __ pc(); 2836 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2837 assert(__ pc() - pc_before_release == (ptrdiff_t)BytesPerInstWord, "must be single instruction"); 2838 assert(branch_table[vtos] == 0, "can't compute twice"); 2839 branch_table[vtos] = __ pc(); // non-volatile_entry point 2840 __ stop("vtos unexpected", 0x657); 2841 #endif 2842 2843 __ align(32, 28, 28); // Align pop. 2844 // __ bind(Ldtos); 2845 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2846 assert(branch_table[dtos] == 0, "can't compute twice"); 2847 branch_table[dtos] = __ pc(); // non-volatile_entry point 2848 __ pop(dtos); 2849 if (!is_static) { 2850 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1. 2851 } 2852 __ stfdx(F15_ftos, Rclass_or_obj, Roffset); 2853 if (!is_static && rc == may_rewrite) { 2854 patch_bytecode(Bytecodes::_fast_dputfield, Rbc, Rscratch, true, byte_no); 2855 } 2856 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2857 __ beq(CR_is_vol, Lvolatile); // Volatile? 2858 } 2859 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2860 2861 __ align(32, 28, 28); // Align pop. 2862 // __ bind(Lftos); 2863 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2864 assert(branch_table[ftos] == 0, "can't compute twice"); 2865 branch_table[ftos] = __ pc(); // non-volatile_entry point 2866 __ pop(ftos); 2867 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2868 __ stfsx(F15_ftos, Rclass_or_obj, Roffset); 2869 if (!is_static && rc == may_rewrite) { 2870 patch_bytecode(Bytecodes::_fast_fputfield, Rbc, Rscratch, true, byte_no); 2871 } 2872 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2873 __ beq(CR_is_vol, Lvolatile); // Volatile? 2874 } 2875 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2876 2877 __ align(32, 28, 28); // Align pop. 2878 // __ bind(Litos); 2879 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2880 assert(branch_table[itos] == 0, "can't compute twice"); 2881 branch_table[itos] = __ pc(); // non-volatile_entry point 2882 __ pop(itos); 2883 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2884 __ stwx(R17_tos, Rclass_or_obj, Roffset); 2885 if (!is_static && rc == may_rewrite) { 2886 patch_bytecode(Bytecodes::_fast_iputfield, Rbc, Rscratch, true, byte_no); 2887 } 2888 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2889 __ beq(CR_is_vol, Lvolatile); // Volatile? 2890 } 2891 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2892 2893 __ align(32, 28, 28); // Align pop. 2894 // __ bind(Lltos); 2895 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2896 assert(branch_table[ltos] == 0, "can't compute twice"); 2897 branch_table[ltos] = __ pc(); // non-volatile_entry point 2898 __ pop(ltos); 2899 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2900 __ stdx(R17_tos, Rclass_or_obj, Roffset); 2901 if (!is_static && rc == may_rewrite) { 2902 patch_bytecode(Bytecodes::_fast_lputfield, Rbc, Rscratch, true, byte_no); 2903 } 2904 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2905 __ beq(CR_is_vol, Lvolatile); // Volatile? 2906 } 2907 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2908 2909 __ align(32, 28, 28); // Align pop. 2910 // __ bind(Lbtos); 2911 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2912 assert(branch_table[btos] == 0, "can't compute twice"); 2913 branch_table[btos] = __ pc(); // non-volatile_entry point 2914 __ pop(btos); 2915 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2916 __ stbx(R17_tos, Rclass_or_obj, Roffset); 2917 if (!is_static && rc == may_rewrite) { 2918 patch_bytecode(Bytecodes::_fast_bputfield, Rbc, Rscratch, true, byte_no); 2919 } 2920 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2921 __ beq(CR_is_vol, Lvolatile); // Volatile? 2922 } 2923 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2924 2925 __ align(32, 28, 28); // Align pop. 2926 // __ bind(Lztos); 2927 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2928 assert(branch_table[ztos] == 0, "can't compute twice"); 2929 branch_table[ztos] = __ pc(); // non-volatile_entry point 2930 __ pop(ztos); 2931 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2932 __ andi(R17_tos, R17_tos, 0x1); 2933 __ stbx(R17_tos, Rclass_or_obj, Roffset); 2934 if (!is_static && rc == may_rewrite) { 2935 patch_bytecode(Bytecodes::_fast_zputfield, Rbc, Rscratch, true, byte_no); 2936 } 2937 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2938 __ beq(CR_is_vol, Lvolatile); // Volatile? 2939 } 2940 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2941 2942 __ align(32, 28, 28); // Align pop. 2943 // __ bind(Lctos); 2944 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2945 assert(branch_table[ctos] == 0, "can't compute twice"); 2946 branch_table[ctos] = __ pc(); // non-volatile_entry point 2947 __ pop(ctos); 2948 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1.. 2949 __ sthx(R17_tos, Rclass_or_obj, Roffset); 2950 if (!is_static && rc == may_rewrite) { 2951 patch_bytecode(Bytecodes::_fast_cputfield, Rbc, Rscratch, true, byte_no); 2952 } 2953 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2954 __ beq(CR_is_vol, Lvolatile); // Volatile? 2955 } 2956 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2957 2958 __ align(32, 28, 28); // Align pop. 2959 // __ bind(Lstos); 2960 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2961 assert(branch_table[stos] == 0, "can't compute twice"); 2962 branch_table[stos] = __ pc(); // non-volatile_entry point 2963 __ pop(stos); 2964 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // Kills R11_scratch1. 2965 __ sthx(R17_tos, Rclass_or_obj, Roffset); 2966 if (!is_static && rc == may_rewrite) { 2967 patch_bytecode(Bytecodes::_fast_sputfield, Rbc, Rscratch, true, byte_no); 2968 } 2969 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2970 __ beq(CR_is_vol, Lvolatile); // Volatile? 2971 } 2972 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2973 2974 __ align(32, 28, 28); // Align pop. 2975 // __ bind(Latos); 2976 __ release(); // Volatile entry point (one instruction before non-volatile_entry point). 2977 assert(branch_table[atos] == 0, "can't compute twice"); 2978 branch_table[atos] = __ pc(); // non-volatile_entry point 2979 __ pop(atos); 2980 if (!is_static) { pop_and_check_object(Rclass_or_obj); } // kills R11_scratch1 2981 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP); 2982 if (!is_static && rc == may_rewrite) { 2983 patch_bytecode(Bytecodes::_fast_aputfield, Rbc, Rscratch, true, byte_no); 2984 } 2985 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2986 __ beq(CR_is_vol, Lvolatile); // Volatile? 2987 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 2988 2989 __ align(32, 12); 2990 __ bind(Lvolatile); 2991 __ fence(); 2992 } 2993 // fallthru: __ b(Lexit); 2994 2995 #ifdef ASSERT 2996 for (int i = 0; i<number_of_states; ++i) { 2997 assert(branch_table[i], "put initialization"); 2998 //tty->print_cr("put: %s_branch_table[%d] = 0x%llx (opcode 0x%llx)", 2999 // is_static ? "static" : "field", i, branch_table[i], *((unsigned int*)branch_table[i])); 3000 } 3001 #endif 3002 } 3003 3004 void TemplateTable::putfield(int byte_no) { 3005 putfield_or_static(byte_no, false); 3006 } 3007 3008 void TemplateTable::nofast_putfield(int byte_no) { 3009 putfield_or_static(byte_no, false, may_not_rewrite); 3010 } 3011 3012 void TemplateTable::putstatic(int byte_no) { 3013 putfield_or_static(byte_no, true); 3014 } 3015 3016 // See SPARC. On PPC64, we have a different jvmti_post_field_mod which does the job. 3017 void TemplateTable::jvmti_post_fast_field_mod() { 3018 __ should_not_reach_here(); 3019 } 3020 3021 void TemplateTable::fast_storefield(TosState state) { 3022 transition(state, vtos); 3023 3024 const Register Rcache = R5_ARG3, // Do not use ARG1/2 (causes trouble in jvmti_post_field_mod). 3025 Rclass_or_obj = R31, // Needs to survive C call. 3026 Roffset = R22_tmp2, // Needs to survive C call. 3027 Rflags = R3_ARG1, 3028 Rscratch = R11_scratch1, 3029 Rscratch2 = R12_scratch2, 3030 Rscratch3 = R4_ARG2; 3031 const ConditionRegister CR_is_vol = CCR2; // Non-volatile condition register (survives runtime call in do_oop_store). 3032 3033 // Constant pool already resolved => Load flags and offset of field. 3034 __ get_cache_and_index_at_bcp(Rcache, 1); 3035 jvmti_post_field_mod(Rcache, Rscratch, false /* not static */); 3036 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false); 3037 3038 // Get the obj and the final store addr. 3039 pop_and_check_object(Rclass_or_obj); // Kills R11_scratch1. 3040 3041 // Get volatile flag. 3042 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit. 3043 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { __ cmpdi(CR_is_vol, Rscratch, 1); } 3044 { 3045 Label LnotVolatile; 3046 __ beq(CCR0, LnotVolatile); 3047 __ release(); 3048 __ align(32, 12); 3049 __ bind(LnotVolatile); 3050 } 3051 3052 // Do the store and fencing. 3053 switch(bytecode()) { 3054 case Bytecodes::_fast_aputfield: 3055 // Store into the field. 3056 do_oop_store(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, Rscratch2, Rscratch3, IN_HEAP); 3057 break; 3058 3059 case Bytecodes::_fast_iputfield: 3060 __ stwx(R17_tos, Rclass_or_obj, Roffset); 3061 break; 3062 3063 case Bytecodes::_fast_lputfield: 3064 __ stdx(R17_tos, Rclass_or_obj, Roffset); 3065 break; 3066 3067 case Bytecodes::_fast_zputfield: 3068 __ andi(R17_tos, R17_tos, 0x1); // boolean is true if LSB is 1 3069 // fall through to bputfield 3070 case Bytecodes::_fast_bputfield: 3071 __ stbx(R17_tos, Rclass_or_obj, Roffset); 3072 break; 3073 3074 case Bytecodes::_fast_cputfield: 3075 case Bytecodes::_fast_sputfield: 3076 __ sthx(R17_tos, Rclass_or_obj, Roffset); 3077 break; 3078 3079 case Bytecodes::_fast_fputfield: 3080 __ stfsx(F15_ftos, Rclass_or_obj, Roffset); 3081 break; 3082 3083 case Bytecodes::_fast_dputfield: 3084 __ stfdx(F15_ftos, Rclass_or_obj, Roffset); 3085 break; 3086 3087 default: ShouldNotReachHere(); 3088 } 3089 3090 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 3091 Label LVolatile; 3092 __ beq(CR_is_vol, LVolatile); 3093 __ dispatch_epilog(vtos, Bytecodes::length_for(bytecode())); 3094 3095 __ align(32, 12); 3096 __ bind(LVolatile); 3097 __ fence(); 3098 } 3099 } 3100 3101 void TemplateTable::fast_accessfield(TosState state) { 3102 transition(atos, state); 3103 3104 Label LisVolatile; 3105 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 3106 3107 const Register Rcache = R3_ARG1, 3108 Rclass_or_obj = R17_tos, 3109 Roffset = R22_tmp2, 3110 Rflags = R23_tmp3, 3111 Rscratch = R12_scratch2; 3112 3113 // Constant pool already resolved. Get the field offset. 3114 __ get_cache_and_index_at_bcp(Rcache, 1); 3115 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false); 3116 3117 // JVMTI support 3118 jvmti_post_field_access(Rcache, Rscratch, false, true); 3119 3120 // Get the load address. 3121 __ null_check_throw(Rclass_or_obj, -1, Rscratch); 3122 3123 // Get volatile flag. 3124 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit. 3125 __ bne(CCR0, LisVolatile); 3126 3127 switch(bytecode()) { 3128 case Bytecodes::_fast_agetfield: 3129 { 3130 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP); 3131 __ verify_oop(R17_tos); 3132 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3133 3134 __ bind(LisVolatile); 3135 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3136 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP); 3137 __ verify_oop(R17_tos); 3138 __ twi_0(R17_tos); 3139 __ isync(); 3140 break; 3141 } 3142 case Bytecodes::_fast_igetfield: 3143 { 3144 __ lwax(R17_tos, Rclass_or_obj, Roffset); 3145 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3146 3147 __ bind(LisVolatile); 3148 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3149 __ lwax(R17_tos, Rclass_or_obj, Roffset); 3150 __ twi_0(R17_tos); 3151 __ isync(); 3152 break; 3153 } 3154 case Bytecodes::_fast_lgetfield: 3155 { 3156 __ ldx(R17_tos, Rclass_or_obj, Roffset); 3157 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3158 3159 __ bind(LisVolatile); 3160 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3161 __ ldx(R17_tos, Rclass_or_obj, Roffset); 3162 __ twi_0(R17_tos); 3163 __ isync(); 3164 break; 3165 } 3166 case Bytecodes::_fast_bgetfield: 3167 { 3168 __ lbzx(R17_tos, Rclass_or_obj, Roffset); 3169 __ extsb(R17_tos, R17_tos); 3170 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3171 3172 __ bind(LisVolatile); 3173 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3174 __ lbzx(R17_tos, Rclass_or_obj, Roffset); 3175 __ twi_0(R17_tos); 3176 __ extsb(R17_tos, R17_tos); 3177 __ isync(); 3178 break; 3179 } 3180 case Bytecodes::_fast_cgetfield: 3181 { 3182 __ lhzx(R17_tos, Rclass_or_obj, Roffset); 3183 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3184 3185 __ bind(LisVolatile); 3186 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3187 __ lhzx(R17_tos, Rclass_or_obj, Roffset); 3188 __ twi_0(R17_tos); 3189 __ isync(); 3190 break; 3191 } 3192 case Bytecodes::_fast_sgetfield: 3193 { 3194 __ lhax(R17_tos, Rclass_or_obj, Roffset); 3195 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3196 3197 __ bind(LisVolatile); 3198 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3199 __ lhax(R17_tos, Rclass_or_obj, Roffset); 3200 __ twi_0(R17_tos); 3201 __ isync(); 3202 break; 3203 } 3204 case Bytecodes::_fast_fgetfield: 3205 { 3206 __ lfsx(F15_ftos, Rclass_or_obj, Roffset); 3207 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3208 3209 __ bind(LisVolatile); 3210 Label Ldummy; 3211 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3212 __ lfsx(F15_ftos, Rclass_or_obj, Roffset); 3213 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync. 3214 __ bne_predict_not_taken(CCR0, Ldummy); 3215 __ bind(Ldummy); 3216 __ isync(); 3217 break; 3218 } 3219 case Bytecodes::_fast_dgetfield: 3220 { 3221 __ lfdx(F15_ftos, Rclass_or_obj, Roffset); 3222 __ dispatch_epilog(state, Bytecodes::length_for(bytecode())); 3223 3224 __ bind(LisVolatile); 3225 Label Ldummy; 3226 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3227 __ lfdx(F15_ftos, Rclass_or_obj, Roffset); 3228 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync. 3229 __ bne_predict_not_taken(CCR0, Ldummy); 3230 __ bind(Ldummy); 3231 __ isync(); 3232 break; 3233 } 3234 default: ShouldNotReachHere(); 3235 } 3236 } 3237 3238 void TemplateTable::fast_xaccess(TosState state) { 3239 transition(vtos, state); 3240 3241 Label LisVolatile; 3242 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 3243 const Register Rcache = R3_ARG1, 3244 Rclass_or_obj = R17_tos, 3245 Roffset = R22_tmp2, 3246 Rflags = R23_tmp3, 3247 Rscratch = R12_scratch2; 3248 3249 __ ld(Rclass_or_obj, 0, R18_locals); 3250 3251 // Constant pool already resolved. Get the field offset. 3252 __ get_cache_and_index_at_bcp(Rcache, 2); 3253 load_field_cp_cache_entry(noreg, Rcache, noreg, Roffset, Rflags, false); 3254 3255 // JVMTI support not needed, since we switch back to single bytecode as soon as debugger attaches. 3256 3257 // Needed to report exception at the correct bcp. 3258 __ addi(R14_bcp, R14_bcp, 1); 3259 3260 // Get the load address. 3261 __ null_check_throw(Rclass_or_obj, -1, Rscratch); 3262 3263 // Get volatile flag. 3264 __ rldicl_(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // Extract volatile bit. 3265 __ bne(CCR0, LisVolatile); 3266 3267 switch(state) { 3268 case atos: 3269 { 3270 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP); 3271 __ verify_oop(R17_tos); 3272 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment. 3273 3274 __ bind(LisVolatile); 3275 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3276 do_oop_load(_masm, Rclass_or_obj, Roffset, R17_tos, Rscratch, /* nv temp */ Rflags, IN_HEAP); 3277 __ verify_oop(R17_tos); 3278 __ twi_0(R17_tos); 3279 __ isync(); 3280 break; 3281 } 3282 case itos: 3283 { 3284 __ lwax(R17_tos, Rclass_or_obj, Roffset); 3285 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment. 3286 3287 __ bind(LisVolatile); 3288 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3289 __ lwax(R17_tos, Rclass_or_obj, Roffset); 3290 __ twi_0(R17_tos); 3291 __ isync(); 3292 break; 3293 } 3294 case ftos: 3295 { 3296 __ lfsx(F15_ftos, Rclass_or_obj, Roffset); 3297 __ dispatch_epilog(state, Bytecodes::length_for(bytecode()) - 1); // Undo bcp increment. 3298 3299 __ bind(LisVolatile); 3300 Label Ldummy; 3301 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { __ fence(); } 3302 __ lfsx(F15_ftos, Rclass_or_obj, Roffset); 3303 __ fcmpu(CCR0, F15_ftos, F15_ftos); // Acquire by cmp-br-isync. 3304 __ bne_predict_not_taken(CCR0, Ldummy); 3305 __ bind(Ldummy); 3306 __ isync(); 3307 break; 3308 } 3309 default: ShouldNotReachHere(); 3310 } 3311 __ addi(R14_bcp, R14_bcp, -1); 3312 } 3313 3314 // ============================================================================ 3315 // Calls 3316 3317 // Common code for invoke 3318 // 3319 // Input: 3320 // - byte_no 3321 // 3322 // Output: 3323 // - Rmethod: The method to invoke next. 3324 // - Rret_addr: The return address to return to. 3325 // - Rindex: MethodType (invokehandle) or CallSite obj (invokedynamic) 3326 // - Rrecv: Cache for "this" pointer, might be noreg if static call. 3327 // - Rflags: Method flags from const pool cache. 3328 // 3329 // Kills: 3330 // - Rscratch1 3331 // 3332 void TemplateTable::prepare_invoke(int byte_no, 3333 Register Rmethod, // linked method (or i-klass) 3334 Register Rret_addr,// return address 3335 Register Rindex, // itable index, MethodType, etc. 3336 Register Rrecv, // If caller wants to see it. 3337 Register Rflags, // If caller wants to test it. 3338 Register Rscratch 3339 ) { 3340 // Determine flags. 3341 const Bytecodes::Code code = bytecode(); 3342 const bool is_invokeinterface = code == Bytecodes::_invokeinterface; 3343 const bool is_invokedynamic = code == Bytecodes::_invokedynamic; 3344 const bool is_invokehandle = code == Bytecodes::_invokehandle; 3345 const bool is_invokevirtual = code == Bytecodes::_invokevirtual; 3346 const bool is_invokespecial = code == Bytecodes::_invokespecial; 3347 const bool load_receiver = (Rrecv != noreg); 3348 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), ""); 3349 3350 assert_different_registers(Rmethod, Rindex, Rflags, Rscratch); 3351 assert_different_registers(Rmethod, Rrecv, Rflags, Rscratch); 3352 assert_different_registers(Rret_addr, Rscratch); 3353 3354 load_invoke_cp_cache_entry(byte_no, Rmethod, Rindex, Rflags, is_invokevirtual, false, is_invokedynamic); 3355 3356 // Saving of SP done in call_from_interpreter. 3357 3358 // Maybe push "appendix" to arguments. 3359 if (is_invokedynamic || is_invokehandle) { 3360 Label Ldone; 3361 __ rldicl_(R0, Rflags, 64-ConstantPoolCacheEntry::has_appendix_shift, 63); 3362 __ beq(CCR0, Ldone); 3363 // Push "appendix" (MethodType, CallSite, etc.). 3364 // This must be done before we get the receiver, 3365 // since the parameter_size includes it. 3366 __ load_resolved_reference_at_index(Rscratch, Rindex); 3367 __ verify_oop(Rscratch); 3368 __ push_ptr(Rscratch); 3369 __ bind(Ldone); 3370 } 3371 3372 // Load receiver if needed (after appendix is pushed so parameter size is correct). 3373 if (load_receiver) { 3374 const Register Rparam_count = Rscratch; 3375 __ andi(Rparam_count, Rflags, ConstantPoolCacheEntry::parameter_size_mask); 3376 __ load_receiver(Rparam_count, Rrecv); 3377 __ verify_oop(Rrecv); 3378 } 3379 3380 // Get return address. 3381 { 3382 Register Rtable_addr = Rscratch; 3383 Register Rret_type = Rret_addr; 3384 address table_addr = (address) Interpreter::invoke_return_entry_table_for(code); 3385 3386 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value. 3387 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 3388 __ load_dispatch_table(Rtable_addr, (address*)table_addr); 3389 __ sldi(Rret_type, Rret_type, LogBytesPerWord); 3390 // Get return address. 3391 __ ldx(Rret_addr, Rtable_addr, Rret_type); 3392 } 3393 } 3394 3395 // Helper for virtual calls. Load target out of vtable and jump off! 3396 // Kills all passed registers. 3397 void TemplateTable::generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp) { 3398 3399 assert_different_registers(Rrecv_klass, Rtemp, Rret); 3400 const Register Rtarget_method = Rindex; 3401 3402 // Get target method & entry point. 3403 const int base = in_bytes(Klass::vtable_start_offset()); 3404 // Calc vtable addr scale the vtable index by 8. 3405 __ sldi(Rindex, Rindex, exact_log2(vtableEntry::size_in_bytes())); 3406 // Load target. 3407 __ addi(Rrecv_klass, Rrecv_klass, base + vtableEntry::method_offset_in_bytes()); 3408 __ ldx(Rtarget_method, Rindex, Rrecv_klass); 3409 // Argument and return type profiling. 3410 __ profile_arguments_type(Rtarget_method, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */, true); 3411 __ call_from_interpreter(Rtarget_method, Rret, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */); 3412 } 3413 3414 // Virtual or final call. Final calls are rewritten on the fly to run through "fast_finalcall" next time. 3415 void TemplateTable::invokevirtual(int byte_no) { 3416 transition(vtos, vtos); 3417 3418 Register Rtable_addr = R11_scratch1, 3419 Rret_type = R12_scratch2, 3420 Rret_addr = R5_ARG3, 3421 Rflags = R22_tmp2, // Should survive C call. 3422 Rrecv = R3_ARG1, 3423 Rrecv_klass = Rrecv, 3424 Rvtableindex_or_method = R31, // Should survive C call. 3425 Rnum_params = R4_ARG2, 3426 Rnew_bc = R6_ARG4; 3427 3428 Label LnotFinal; 3429 3430 load_invoke_cp_cache_entry(byte_no, Rvtableindex_or_method, noreg, Rflags, /*virtual*/ true, false, false); 3431 3432 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift); 3433 __ bfalse(CCR0, LnotFinal); 3434 3435 if (RewriteBytecodes && !UseSharedSpaces && !DumpSharedSpaces) { 3436 patch_bytecode(Bytecodes::_fast_invokevfinal, Rnew_bc, R12_scratch2); 3437 } 3438 invokevfinal_helper(Rvtableindex_or_method, Rflags, R11_scratch1, R12_scratch2); 3439 3440 __ align(32, 12); 3441 __ bind(LnotFinal); 3442 // Load "this" pointer (receiver). 3443 __ rldicl(Rnum_params, Rflags, 64, 48); 3444 __ load_receiver(Rnum_params, Rrecv); 3445 __ verify_oop(Rrecv); 3446 3447 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value. 3448 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 3449 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table()); 3450 __ sldi(Rret_type, Rret_type, LogBytesPerWord); 3451 __ ldx(Rret_addr, Rret_type, Rtable_addr); 3452 __ null_check_throw(Rrecv, oopDesc::klass_offset_in_bytes(), R11_scratch1); 3453 __ load_klass(Rrecv_klass, Rrecv); 3454 __ verify_klass_ptr(Rrecv_klass); 3455 __ profile_virtual_call(Rrecv_klass, R11_scratch1, R12_scratch2, false); 3456 3457 generate_vtable_call(Rrecv_klass, Rvtableindex_or_method, Rret_addr, R11_scratch1); 3458 } 3459 3460 void TemplateTable::fast_invokevfinal(int byte_no) { 3461 transition(vtos, vtos); 3462 3463 assert(byte_no == f2_byte, "use this argument"); 3464 Register Rflags = R22_tmp2, 3465 Rmethod = R31; 3466 load_invoke_cp_cache_entry(byte_no, Rmethod, noreg, Rflags, /*virtual*/ true, /*is_invokevfinal*/ true, false); 3467 invokevfinal_helper(Rmethod, Rflags, R11_scratch1, R12_scratch2); 3468 } 3469 3470 void TemplateTable::invokevfinal_helper(Register Rmethod, Register Rflags, Register Rscratch1, Register Rscratch2) { 3471 3472 assert_different_registers(Rmethod, Rflags, Rscratch1, Rscratch2); 3473 3474 // Load receiver from stack slot. 3475 Register Rrecv = Rscratch2; 3476 Register Rnum_params = Rrecv; 3477 3478 __ ld(Rnum_params, in_bytes(Method::const_offset()), Rmethod); 3479 __ lhz(Rnum_params /* number of params */, in_bytes(ConstMethod::size_of_parameters_offset()), Rnum_params); 3480 3481 // Get return address. 3482 Register Rtable_addr = Rscratch1, 3483 Rret_addr = Rflags, 3484 Rret_type = Rret_addr; 3485 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value. 3486 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 3487 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table()); 3488 __ sldi(Rret_type, Rret_type, LogBytesPerWord); 3489 __ ldx(Rret_addr, Rret_type, Rtable_addr); 3490 3491 // Load receiver and receiver NULL check. 3492 __ load_receiver(Rnum_params, Rrecv); 3493 __ null_check_throw(Rrecv, -1, Rscratch1); 3494 3495 __ profile_final_call(Rrecv, Rscratch1); 3496 // Argument and return type profiling. 3497 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true); 3498 3499 // Do the call. 3500 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1, Rscratch2); 3501 } 3502 3503 void TemplateTable::invokespecial(int byte_no) { 3504 assert(byte_no == f1_byte, "use this argument"); 3505 transition(vtos, vtos); 3506 3507 Register Rtable_addr = R3_ARG1, 3508 Rret_addr = R4_ARG2, 3509 Rflags = R5_ARG3, 3510 Rreceiver = R6_ARG4, 3511 Rmethod = R31; 3512 3513 prepare_invoke(byte_no, Rmethod, Rret_addr, noreg, Rreceiver, Rflags, R11_scratch1); 3514 3515 // Receiver NULL check. 3516 __ null_check_throw(Rreceiver, -1, R11_scratch1); 3517 3518 __ profile_call(R11_scratch1, R12_scratch2); 3519 // Argument and return type profiling. 3520 __ profile_arguments_type(Rmethod, R11_scratch1, R12_scratch2, false); 3521 __ call_from_interpreter(Rmethod, Rret_addr, R11_scratch1, R12_scratch2); 3522 } 3523 3524 void TemplateTable::invokestatic(int byte_no) { 3525 assert(byte_no == f1_byte, "use this argument"); 3526 transition(vtos, vtos); 3527 3528 Register Rtable_addr = R3_ARG1, 3529 Rret_addr = R4_ARG2, 3530 Rflags = R5_ARG3; 3531 3532 prepare_invoke(byte_no, R19_method, Rret_addr, noreg, noreg, Rflags, R11_scratch1); 3533 3534 __ profile_call(R11_scratch1, R12_scratch2); 3535 // Argument and return type profiling. 3536 __ profile_arguments_type(R19_method, R11_scratch1, R12_scratch2, false); 3537 __ call_from_interpreter(R19_method, Rret_addr, R11_scratch1, R12_scratch2); 3538 } 3539 3540 void TemplateTable::invokeinterface_object_method(Register Rrecv_klass, 3541 Register Rret, 3542 Register Rflags, 3543 Register Rmethod, 3544 Register Rtemp1, 3545 Register Rtemp2) { 3546 3547 assert_different_registers(Rmethod, Rret, Rrecv_klass, Rflags, Rtemp1, Rtemp2); 3548 Label LnotFinal; 3549 3550 // Check for vfinal. 3551 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift); 3552 __ bfalse(CCR0, LnotFinal); 3553 3554 Register Rscratch = Rflags; // Rflags is dead now. 3555 3556 // Final call case. 3557 __ profile_final_call(Rtemp1, Rscratch); 3558 // Argument and return type profiling. 3559 __ profile_arguments_type(Rmethod, Rscratch, Rrecv_klass /* scratch */, true); 3560 // Do the final call - the index (f2) contains the method. 3561 __ call_from_interpreter(Rmethod, Rret, Rscratch, Rrecv_klass /* scratch */); 3562 3563 // Non-final callc case. 3564 __ bind(LnotFinal); 3565 __ profile_virtual_call(Rrecv_klass, Rtemp1, Rscratch, false); 3566 generate_vtable_call(Rrecv_klass, Rmethod, Rret, Rscratch); 3567 } 3568 3569 void TemplateTable::invokeinterface(int byte_no) { 3570 assert(byte_no == f1_byte, "use this argument"); 3571 transition(vtos, vtos); 3572 3573 const Register Rscratch1 = R11_scratch1, 3574 Rscratch2 = R12_scratch2, 3575 Rmethod = R6_ARG4, 3576 Rmethod2 = R9_ARG7, 3577 Rinterface_klass = R5_ARG3, 3578 Rret_addr = R8_ARG6, 3579 Rindex = R10_ARG8, 3580 Rreceiver = R3_ARG1, 3581 Rrecv_klass = R4_ARG2, 3582 Rflags = R7_ARG5; 3583 3584 prepare_invoke(byte_no, Rinterface_klass, Rret_addr, Rmethod, Rreceiver, Rflags, Rscratch1); 3585 3586 // First check for Object case, then private interface method, 3587 // then regular interface method. 3588 3589 // Get receiver klass - this is also a null check 3590 __ null_check_throw(Rreceiver, oopDesc::klass_offset_in_bytes(), Rscratch2); 3591 __ load_klass(Rrecv_klass, Rreceiver); 3592 3593 // Check corner case object method. 3594 // Special case of invokeinterface called for virtual method of 3595 // java.lang.Object. See ConstantPoolCacheEntry::set_method() for details: 3596 // The invokeinterface was rewritten to a invokevirtual, hence we have 3597 // to handle this corner case. 3598 3599 Label LnotObjectMethod, Lthrow_ame; 3600 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_forced_virtual_shift); 3601 __ bfalse(CCR0, LnotObjectMethod); 3602 invokeinterface_object_method(Rrecv_klass, Rret_addr, Rflags, Rmethod, Rscratch1, Rscratch2); 3603 __ bind(LnotObjectMethod); 3604 3605 // Check for private method invocation - indicated by vfinal 3606 Label LnotVFinal, L_no_such_interface, L_subtype; 3607 3608 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift); 3609 __ bfalse(CCR0, LnotVFinal); 3610 3611 __ check_klass_subtype(Rrecv_klass, Rinterface_klass, Rscratch1, Rscratch2, L_subtype); 3612 // If we get here the typecheck failed 3613 __ b(L_no_such_interface); 3614 __ bind(L_subtype); 3615 3616 // do the call 3617 3618 Register Rscratch = Rflags; // Rflags is dead now. 3619 3620 __ profile_final_call(Rscratch1, Rscratch); 3621 __ profile_arguments_type(Rindex, Rscratch, Rrecv_klass /* scratch */, true); 3622 3623 __ call_from_interpreter(Rindex, Rret_addr, Rscratch, Rrecv_klass /* scratch */); 3624 3625 __ bind(LnotVFinal); 3626 3627 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, noreg, noreg, Rscratch1, Rscratch2, 3628 L_no_such_interface, /*return_method=*/false); 3629 3630 __ profile_virtual_call(Rrecv_klass, Rscratch1, Rscratch2, false); 3631 3632 // Find entry point to call. 3633 3634 // Get declaring interface class from method 3635 __ ld(Rinterface_klass, in_bytes(Method::const_offset()), Rmethod); 3636 __ ld(Rinterface_klass, in_bytes(ConstMethod::constants_offset()), Rinterface_klass); 3637 __ ld(Rinterface_klass, ConstantPool::pool_holder_offset_in_bytes(), Rinterface_klass); 3638 3639 // Get itable index from method 3640 __ lwa(Rindex, in_bytes(Method::itable_index_offset()), Rmethod); 3641 __ subfic(Rindex, Rindex, Method::itable_index_max); 3642 3643 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, Rindex, Rmethod2, Rscratch1, Rscratch2, 3644 L_no_such_interface); 3645 3646 __ cmpdi(CCR0, Rmethod2, 0); 3647 __ beq(CCR0, Lthrow_ame); 3648 // Found entry. Jump off! 3649 // Argument and return type profiling. 3650 __ profile_arguments_type(Rmethod2, Rscratch1, Rscratch2, true); 3651 //__ profile_called_method(Rindex, Rscratch1); 3652 __ call_from_interpreter(Rmethod2, Rret_addr, Rscratch1, Rscratch2); 3653 3654 // Vtable entry was NULL => Throw abstract method error. 3655 __ bind(Lthrow_ame); 3656 // Pass arguments for generating a verbose error message. 3657 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodErrorVerbose), 3658 Rrecv_klass, Rmethod); 3659 3660 // Interface was not found => Throw incompatible class change error. 3661 __ bind(L_no_such_interface); 3662 // Pass arguments for generating a verbose error message. 3663 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose), 3664 Rrecv_klass, Rinterface_klass); 3665 DEBUG_ONLY( __ should_not_reach_here(); ) 3666 } 3667 3668 void TemplateTable::invokedynamic(int byte_no) { 3669 transition(vtos, vtos); 3670 3671 const Register Rret_addr = R3_ARG1, 3672 Rflags = R4_ARG2, 3673 Rmethod = R22_tmp2, 3674 Rscratch1 = R11_scratch1, 3675 Rscratch2 = R12_scratch2; 3676 3677 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, noreg, Rflags, Rscratch2); 3678 3679 // Profile this call. 3680 __ profile_call(Rscratch1, Rscratch2); 3681 3682 // Off we go. With the new method handles, we don't jump to a method handle 3683 // entry any more. Instead, we pushed an "appendix" in prepare invoke, which happens 3684 // to be the callsite object the bootstrap method returned. This is passed to a 3685 // "link" method which does the dispatch (Most likely just grabs the MH stored 3686 // inside the callsite and does an invokehandle). 3687 // Argument and return type profiling. 3688 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, false); 3689 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */); 3690 } 3691 3692 void TemplateTable::invokehandle(int byte_no) { 3693 transition(vtos, vtos); 3694 3695 const Register Rret_addr = R3_ARG1, 3696 Rflags = R4_ARG2, 3697 Rrecv = R5_ARG3, 3698 Rmethod = R22_tmp2, 3699 Rscratch1 = R11_scratch1, 3700 Rscratch2 = R12_scratch2; 3701 3702 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, Rrecv, Rflags, Rscratch2); 3703 __ verify_method_ptr(Rmethod); 3704 __ null_check_throw(Rrecv, -1, Rscratch2); 3705 3706 __ profile_final_call(Rrecv, Rscratch1); 3707 3708 // Still no call from handle => We call the method handle interpreter here. 3709 // Argument and return type profiling. 3710 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true); 3711 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */); 3712 } 3713 3714 // ============================================================================= 3715 // Allocation 3716 3717 // Puts allocated obj ref onto the expression stack. 3718 void TemplateTable::_new() { 3719 transition(vtos, atos); 3720 3721 Label Lslow_case, 3722 Ldone; 3723 3724 const Register RallocatedObject = R17_tos, 3725 RinstanceKlass = R9_ARG7, 3726 Rscratch = R11_scratch1, 3727 Roffset = R8_ARG6, 3728 Rinstance_size = Roffset, 3729 Rcpool = R4_ARG2, 3730 Rtags = R3_ARG1, 3731 Rindex = R5_ARG3; 3732 3733 // -------------------------------------------------------------------------- 3734 // Check if fast case is possible. 3735 3736 // Load pointers to const pool and const pool's tags array. 3737 __ get_cpool_and_tags(Rcpool, Rtags); 3738 // Load index of constant pool entry. 3739 __ get_2_byte_integer_at_bcp(1, Rindex, InterpreterMacroAssembler::Unsigned); 3740 3741 // Note: compared to other architectures, PPC's implementation always goes 3742 // to the slow path if TLAB is used and fails. 3743 if (UseTLAB) { 3744 // Make sure the class we're about to instantiate has been resolved 3745 // This is done before loading instanceKlass to be consistent with the order 3746 // how Constant Pool is updated (see ConstantPoolCache::klass_at_put). 3747 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes()); 3748 __ lbzx(Rtags, Rindex, Rtags); 3749 3750 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class); 3751 __ bne(CCR0, Lslow_case); 3752 3753 // Get instanceKlass 3754 __ sldi(Roffset, Rindex, LogBytesPerWord); 3755 __ load_resolved_klass_at_offset(Rcpool, Roffset, RinstanceKlass); 3756 3757 // Make sure klass is fully initialized and get instance_size. 3758 __ lbz(Rscratch, in_bytes(InstanceKlass::init_state_offset()), RinstanceKlass); 3759 __ lwz(Rinstance_size, in_bytes(Klass::layout_helper_offset()), RinstanceKlass); 3760 3761 __ cmpdi(CCR1, Rscratch, InstanceKlass::fully_initialized); 3762 // Make sure klass does not have has_finalizer, or is abstract, or interface or java/lang/Class. 3763 __ andi_(R0, Rinstance_size, Klass::_lh_instance_slow_path_bit); // slow path bit equals 0? 3764 3765 __ crnand(CCR0, Assembler::equal, CCR1, Assembler::equal); // slow path bit set or not fully initialized? 3766 __ beq(CCR0, Lslow_case); 3767 3768 // -------------------------------------------------------------------------- 3769 // Fast case: 3770 // Allocate the instance. 3771 // 1) Try to allocate in the TLAB. 3772 // 2) If the above fails (or is not applicable), go to a slow case (creates a new TLAB, etc.). 3773 3774 Register RoldTopValue = RallocatedObject; // Object will be allocated here if it fits. 3775 Register RnewTopValue = R6_ARG4; 3776 Register RendValue = R7_ARG5; 3777 3778 // Check if we can allocate in the TLAB. 3779 __ ld(RoldTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread); 3780 __ ld(RendValue, in_bytes(JavaThread::tlab_end_offset()), R16_thread); 3781 3782 __ add(RnewTopValue, Rinstance_size, RoldTopValue); 3783 3784 // If there is enough space, we do not CAS and do not clear. 3785 __ cmpld(CCR0, RnewTopValue, RendValue); 3786 __ bgt(CCR0, Lslow_case); 3787 3788 __ std(RnewTopValue, in_bytes(JavaThread::tlab_top_offset()), R16_thread); 3789 3790 if (!ZeroTLAB) { 3791 // -------------------------------------------------------------------------- 3792 // Init1: Zero out newly allocated memory. 3793 // Initialize remaining object fields. 3794 Register Rbase = Rtags; 3795 __ addi(Rinstance_size, Rinstance_size, 7 - (int)sizeof(oopDesc)); 3796 __ addi(Rbase, RallocatedObject, sizeof(oopDesc)); 3797 __ srdi(Rinstance_size, Rinstance_size, 3); 3798 3799 // Clear out object skipping header. Takes also care of the zero length case. 3800 __ clear_memory_doubleword(Rbase, Rinstance_size); 3801 } 3802 3803 // -------------------------------------------------------------------------- 3804 // Init2: Initialize the header: mark, klass 3805 // Init mark. 3806 if (UseBiasedLocking) { 3807 __ ld(Rscratch, in_bytes(Klass::prototype_header_offset()), RinstanceKlass); 3808 } else { 3809 __ load_const_optimized(Rscratch, markOopDesc::prototype(), R0); 3810 } 3811 __ std(Rscratch, oopDesc::mark_offset_in_bytes(), RallocatedObject); 3812 3813 // Init klass. 3814 __ store_klass_gap(RallocatedObject); 3815 __ store_klass(RallocatedObject, RinstanceKlass, Rscratch); // klass (last for cms) 3816 3817 // Check and trigger dtrace event. 3818 SkipIfEqualZero::skip_to_label_if_equal_zero(_masm, Rscratch, &DTraceAllocProbes, Ldone); 3819 __ push(atos); 3820 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)); 3821 __ pop(atos); 3822 3823 __ b(Ldone); 3824 } 3825 3826 // -------------------------------------------------------------------------- 3827 // slow case 3828 __ bind(Lslow_case); 3829 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), Rcpool, Rindex); 3830 3831 // continue 3832 __ bind(Ldone); 3833 3834 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3835 __ membar(Assembler::StoreStore); 3836 } 3837 3838 void TemplateTable::newarray() { 3839 transition(itos, atos); 3840 3841 __ lbz(R4, 1, R14_bcp); 3842 __ extsw(R5, R17_tos); 3843 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), R4, R5 /* size */); 3844 3845 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3846 __ membar(Assembler::StoreStore); 3847 } 3848 3849 void TemplateTable::anewarray() { 3850 transition(itos, atos); 3851 3852 __ get_constant_pool(R4); 3853 __ get_2_byte_integer_at_bcp(1, R5, InterpreterMacroAssembler::Unsigned); 3854 __ extsw(R6, R17_tos); // size 3855 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), R4 /* pool */, R5 /* index */, R6 /* size */); 3856 3857 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3858 __ membar(Assembler::StoreStore); 3859 } 3860 3861 // Allocate a multi dimensional array 3862 void TemplateTable::multianewarray() { 3863 transition(vtos, atos); 3864 3865 Register Rptr = R31; // Needs to survive C call. 3866 3867 // Put ndims * wordSize into frame temp slot 3868 __ lbz(Rptr, 3, R14_bcp); 3869 __ sldi(Rptr, Rptr, Interpreter::logStackElementSize); 3870 // Esp points past last_dim, so set to R4 to first_dim address. 3871 __ add(R4, Rptr, R15_esp); 3872 call_VM(R17_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), R4 /* first_size_address */); 3873 // Pop all dimensions off the stack. 3874 __ add(R15_esp, Rptr, R15_esp); 3875 3876 // Must prevent reordering of stores for object initialization with stores that publish the new object. 3877 __ membar(Assembler::StoreStore); 3878 } 3879 3880 void TemplateTable::arraylength() { 3881 transition(atos, itos); 3882 3883 Label LnoException; 3884 __ verify_oop(R17_tos); 3885 __ null_check_throw(R17_tos, arrayOopDesc::length_offset_in_bytes(), R11_scratch1); 3886 __ lwa(R17_tos, arrayOopDesc::length_offset_in_bytes(), R17_tos); 3887 } 3888 3889 // ============================================================================ 3890 // Typechecks 3891 3892 void TemplateTable::checkcast() { 3893 transition(atos, atos); 3894 3895 Label Ldone, Lis_null, Lquicked, Lresolved; 3896 Register Roffset = R6_ARG4, 3897 RobjKlass = R4_ARG2, 3898 RspecifiedKlass = R5_ARG3, // Generate_ClassCastException_verbose_handler will read value from this register. 3899 Rcpool = R11_scratch1, 3900 Rtags = R12_scratch2; 3901 3902 // Null does not pass. 3903 __ cmpdi(CCR0, R17_tos, 0); 3904 __ beq(CCR0, Lis_null); 3905 3906 // Get constant pool tag to find out if the bytecode has already been "quickened". 3907 __ get_cpool_and_tags(Rcpool, Rtags); 3908 3909 __ get_2_byte_integer_at_bcp(1, Roffset, InterpreterMacroAssembler::Unsigned); 3910 3911 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes()); 3912 __ lbzx(Rtags, Rtags, Roffset); 3913 3914 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class); 3915 __ beq(CCR0, Lquicked); 3916 3917 // Call into the VM to "quicken" instanceof. 3918 __ push_ptr(); // for GC 3919 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3920 __ get_vm_result_2(RspecifiedKlass); 3921 __ pop_ptr(); // Restore receiver. 3922 __ b(Lresolved); 3923 3924 // Extract target class from constant pool. 3925 __ bind(Lquicked); 3926 __ sldi(Roffset, Roffset, LogBytesPerWord); 3927 __ load_resolved_klass_at_offset(Rcpool, Roffset, RspecifiedKlass); 3928 3929 // Do the checkcast. 3930 __ bind(Lresolved); 3931 // Get value klass in RobjKlass. 3932 __ load_klass(RobjKlass, R17_tos); 3933 // Generate a fast subtype check. Branch to cast_ok if no failure. Return 0 if failure. 3934 __ gen_subtype_check(RobjKlass, RspecifiedKlass, /*3 temp regs*/ Roffset, Rcpool, Rtags, /*target if subtype*/ Ldone); 3935 3936 // Not a subtype; so must throw exception 3937 // Target class oop is in register R6_ARG4 == RspecifiedKlass by convention. 3938 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::_throw_ClassCastException_entry); 3939 __ mtctr(R11_scratch1); 3940 __ bctr(); 3941 3942 // Profile the null case. 3943 __ align(32, 12); 3944 __ bind(Lis_null); 3945 __ profile_null_seen(R11_scratch1, Rtags); // Rtags used as scratch. 3946 3947 __ align(32, 12); 3948 __ bind(Ldone); 3949 } 3950 3951 // Output: 3952 // - tos == 0: Obj was null or not an instance of class. 3953 // - tos == 1: Obj was an instance of class. 3954 void TemplateTable::instanceof() { 3955 transition(atos, itos); 3956 3957 Label Ldone, Lis_null, Lquicked, Lresolved; 3958 Register Roffset = R6_ARG4, 3959 RobjKlass = R4_ARG2, 3960 RspecifiedKlass = R5_ARG3, 3961 Rcpool = R11_scratch1, 3962 Rtags = R12_scratch2; 3963 3964 // Null does not pass. 3965 __ cmpdi(CCR0, R17_tos, 0); 3966 __ beq(CCR0, Lis_null); 3967 3968 // Get constant pool tag to find out if the bytecode has already been "quickened". 3969 __ get_cpool_and_tags(Rcpool, Rtags); 3970 3971 __ get_2_byte_integer_at_bcp(1, Roffset, InterpreterMacroAssembler::Unsigned); 3972 3973 __ addi(Rtags, Rtags, Array<u1>::base_offset_in_bytes()); 3974 __ lbzx(Rtags, Rtags, Roffset); 3975 3976 __ cmpdi(CCR0, Rtags, JVM_CONSTANT_Class); 3977 __ beq(CCR0, Lquicked); 3978 3979 // Call into the VM to "quicken" instanceof. 3980 __ push_ptr(); // for GC 3981 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 3982 __ get_vm_result_2(RspecifiedKlass); 3983 __ pop_ptr(); // Restore receiver. 3984 __ b(Lresolved); 3985 3986 // Extract target class from constant pool. 3987 __ bind(Lquicked); 3988 __ sldi(Roffset, Roffset, LogBytesPerWord); 3989 __ load_resolved_klass_at_offset(Rcpool, Roffset, RspecifiedKlass); 3990 3991 // Do the checkcast. 3992 __ bind(Lresolved); 3993 // Get value klass in RobjKlass. 3994 __ load_klass(RobjKlass, R17_tos); 3995 // Generate a fast subtype check. Branch to cast_ok if no failure. Return 0 if failure. 3996 __ li(R17_tos, 1); 3997 __ gen_subtype_check(RobjKlass, RspecifiedKlass, /*3 temp regs*/ Roffset, Rcpool, Rtags, /*target if subtype*/ Ldone); 3998 __ li(R17_tos, 0); 3999 4000 if (ProfileInterpreter) { 4001 __ b(Ldone); 4002 } 4003 4004 // Profile the null case. 4005 __ align(32, 12); 4006 __ bind(Lis_null); 4007 __ profile_null_seen(Rcpool, Rtags); // Rcpool and Rtags used as scratch. 4008 4009 __ align(32, 12); 4010 __ bind(Ldone); 4011 } 4012 4013 // ============================================================================= 4014 // Breakpoints 4015 4016 void TemplateTable::_breakpoint() { 4017 transition(vtos, vtos); 4018 4019 // Get the unpatched byte code. 4020 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), R19_method, R14_bcp); 4021 __ mr(R31, R3_RET); 4022 4023 // Post the breakpoint event. 4024 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), R19_method, R14_bcp); 4025 4026 // Complete the execution of original bytecode. 4027 __ dispatch_Lbyte_code(vtos, R31, Interpreter::normal_table(vtos)); 4028 } 4029 4030 // ============================================================================= 4031 // Exceptions 4032 4033 void TemplateTable::athrow() { 4034 transition(atos, vtos); 4035 4036 // Exception oop is in tos 4037 __ verify_oop(R17_tos); 4038 4039 __ null_check_throw(R17_tos, -1, R11_scratch1); 4040 4041 // Throw exception interpreter entry expects exception oop to be in R3. 4042 __ mr(R3_RET, R17_tos); 4043 __ load_dispatch_table(R11_scratch1, (address*)Interpreter::throw_exception_entry()); 4044 __ mtctr(R11_scratch1); 4045 __ bctr(); 4046 } 4047 4048 // ============================================================================= 4049 // Synchronization 4050 // Searches the basic object lock list on the stack for a free slot 4051 // and uses it to lock the obect in tos. 4052 // 4053 // Recursive locking is enabled by exiting the search if the same 4054 // object is already found in the list. Thus, a new basic lock obj lock 4055 // is allocated "higher up" in the stack and thus is found first 4056 // at next monitor exit. 4057 void TemplateTable::monitorenter() { 4058 transition(atos, vtos); 4059 4060 __ verify_oop(R17_tos); 4061 4062 Register Rcurrent_monitor = R11_scratch1, 4063 Rcurrent_obj = R12_scratch2, 4064 Robj_to_lock = R17_tos, 4065 Rscratch1 = R3_ARG1, 4066 Rscratch2 = R4_ARG2, 4067 Rscratch3 = R5_ARG3, 4068 Rcurrent_obj_addr = R6_ARG4; 4069 4070 // ------------------------------------------------------------------------------ 4071 // Null pointer exception. 4072 __ null_check_throw(Robj_to_lock, -1, R11_scratch1); 4073 4074 // Try to acquire a lock on the object. 4075 // Repeat until succeeded (i.e., until monitorenter returns true). 4076 4077 // ------------------------------------------------------------------------------ 4078 // Find a free slot in the monitor block. 4079 Label Lfound, Lexit, Lallocate_new; 4080 ConditionRegister found_free_slot = CCR0, 4081 found_same_obj = CCR1, 4082 reached_limit = CCR6; 4083 { 4084 Label Lloop, Lentry; 4085 Register Rlimit = Rcurrent_monitor; 4086 4087 // Set up search loop - start with topmost monitor. 4088 __ add(Rcurrent_obj_addr, BasicObjectLock::obj_offset_in_bytes(), R26_monitor); 4089 4090 __ ld(Rlimit, 0, R1_SP); 4091 __ addi(Rlimit, Rlimit, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes() - BasicObjectLock::obj_offset_in_bytes())); // Monitor base 4092 4093 // Check if any slot is present => short cut to allocation if not. 4094 __ cmpld(reached_limit, Rcurrent_obj_addr, Rlimit); 4095 __ bgt(reached_limit, Lallocate_new); 4096 4097 // Pre-load topmost slot. 4098 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 4099 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize); 4100 // The search loop. 4101 __ bind(Lloop); 4102 // Found free slot? 4103 __ cmpdi(found_free_slot, Rcurrent_obj, 0); 4104 // Is this entry for same obj? If so, stop the search and take the found 4105 // free slot or allocate a new one to enable recursive locking. 4106 __ cmpd(found_same_obj, Rcurrent_obj, Robj_to_lock); 4107 __ cmpld(reached_limit, Rcurrent_obj_addr, Rlimit); 4108 __ beq(found_free_slot, Lexit); 4109 __ beq(found_same_obj, Lallocate_new); 4110 __ bgt(reached_limit, Lallocate_new); 4111 // Check if last allocated BasicLockObj reached. 4112 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 4113 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize); 4114 // Next iteration if unchecked BasicObjectLocks exist on the stack. 4115 __ b(Lloop); 4116 } 4117 4118 // ------------------------------------------------------------------------------ 4119 // Check if we found a free slot. 4120 __ bind(Lexit); 4121 4122 __ addi(Rcurrent_monitor, Rcurrent_obj_addr, -(frame::interpreter_frame_monitor_size() * wordSize) - BasicObjectLock::obj_offset_in_bytes()); 4123 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, - frame::interpreter_frame_monitor_size() * wordSize); 4124 __ b(Lfound); 4125 4126 // We didn't find a free BasicObjLock => allocate one. 4127 __ align(32, 12); 4128 __ bind(Lallocate_new); 4129 __ add_monitor_to_stack(false, Rscratch1, Rscratch2); 4130 __ mr(Rcurrent_monitor, R26_monitor); 4131 __ addi(Rcurrent_obj_addr, R26_monitor, BasicObjectLock::obj_offset_in_bytes()); 4132 4133 // ------------------------------------------------------------------------------ 4134 // We now have a slot to lock. 4135 __ bind(Lfound); 4136 4137 // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly. 4138 // The object has already been poped from the stack, so the expression stack looks correct. 4139 __ addi(R14_bcp, R14_bcp, 1); 4140 4141 __ std(Robj_to_lock, 0, Rcurrent_obj_addr); 4142 __ lock_object(Rcurrent_monitor, Robj_to_lock); 4143 4144 // Check if there's enough space on the stack for the monitors after locking. 4145 // This emits a single store. 4146 __ generate_stack_overflow_check(0); 4147 4148 // The bcp has already been incremented. Just need to dispatch to next instruction. 4149 __ dispatch_next(vtos); 4150 } 4151 4152 void TemplateTable::monitorexit() { 4153 transition(atos, vtos); 4154 __ verify_oop(R17_tos); 4155 4156 Register Rcurrent_monitor = R11_scratch1, 4157 Rcurrent_obj = R12_scratch2, 4158 Robj_to_lock = R17_tos, 4159 Rcurrent_obj_addr = R3_ARG1, 4160 Rlimit = R4_ARG2; 4161 Label Lfound, Lillegal_monitor_state; 4162 4163 // Check corner case: unbalanced monitorEnter / Exit. 4164 __ ld(Rlimit, 0, R1_SP); 4165 __ addi(Rlimit, Rlimit, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base 4166 4167 // Null pointer check. 4168 __ null_check_throw(Robj_to_lock, -1, R11_scratch1); 4169 4170 __ cmpld(CCR0, R26_monitor, Rlimit); 4171 __ bgt(CCR0, Lillegal_monitor_state); 4172 4173 // Find the corresponding slot in the monitors stack section. 4174 { 4175 Label Lloop; 4176 4177 // Start with topmost monitor. 4178 __ addi(Rcurrent_obj_addr, R26_monitor, BasicObjectLock::obj_offset_in_bytes()); 4179 __ addi(Rlimit, Rlimit, BasicObjectLock::obj_offset_in_bytes()); 4180 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 4181 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize); 4182 4183 __ bind(Lloop); 4184 // Is this entry for same obj? 4185 __ cmpd(CCR0, Rcurrent_obj, Robj_to_lock); 4186 __ beq(CCR0, Lfound); 4187 4188 // Check if last allocated BasicLockObj reached. 4189 4190 __ ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 4191 __ cmpld(CCR0, Rcurrent_obj_addr, Rlimit); 4192 __ addi(Rcurrent_obj_addr, Rcurrent_obj_addr, frame::interpreter_frame_monitor_size() * wordSize); 4193 4194 // Next iteration if unchecked BasicObjectLocks exist on the stack. 4195 __ ble(CCR0, Lloop); 4196 } 4197 4198 // Fell through without finding the basic obj lock => throw up! 4199 __ bind(Lillegal_monitor_state); 4200 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 4201 __ should_not_reach_here(); 4202 4203 __ align(32, 12); 4204 __ bind(Lfound); 4205 __ addi(Rcurrent_monitor, Rcurrent_obj_addr, 4206 -(frame::interpreter_frame_monitor_size() * wordSize) - BasicObjectLock::obj_offset_in_bytes()); 4207 __ unlock_object(Rcurrent_monitor); 4208 } 4209 4210 // ============================================================================ 4211 // Wide bytecodes 4212 4213 // Wide instructions. Simply redirects to the wide entry point for that instruction. 4214 void TemplateTable::wide() { 4215 transition(vtos, vtos); 4216 4217 const Register Rtable = R11_scratch1, 4218 Rindex = R12_scratch2, 4219 Rtmp = R0; 4220 4221 __ lbz(Rindex, 1, R14_bcp); 4222 4223 __ load_dispatch_table(Rtable, Interpreter::_wentry_point); 4224 4225 __ slwi(Rindex, Rindex, LogBytesPerWord); 4226 __ ldx(Rtmp, Rtable, Rindex); 4227 __ mtctr(Rtmp); 4228 __ bctr(); 4229 // Note: the bcp increment step is part of the individual wide bytecode implementations. 4230 }