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