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