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