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