1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2016, 2017 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "interpreter/interpreter.hpp" 29 #include "interpreter/interpreterRuntime.hpp" 30 #include "interpreter/interp_masm.hpp" 31 #include "interpreter/templateTable.hpp" 32 #include "memory/universe.hpp" 33 #include "oops/objArrayKlass.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "prims/methodHandles.hpp" 36 #include "runtime/safepointMechanism.hpp" 37 #include "runtime/sharedRuntime.hpp" 38 #include "runtime/stubRoutines.hpp" 39 #include "runtime/synchronizer.hpp" 40 41 #ifdef PRODUCT 42 #define __ _masm-> 43 #define BLOCK_COMMENT(str) 44 #define BIND(label) __ bind(label); 45 #else 46 #define __ (PRODUCT_ONLY(false&&)Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)-> 47 #define BLOCK_COMMENT(str) __ block_comment(str) 48 #define BIND(label) __ bind(label); BLOCK_COMMENT(#label ":") 49 #endif 50 51 // The assumed minimum size of a BranchTableBlock. 52 // The actual size of each block heavily depends on the CPU capabilities and, 53 // of course, on the logic implemented in each block. 54 #ifdef ASSERT 55 #define BTB_MINSIZE 256 56 #else 57 #define BTB_MINSIZE 64 58 #endif 59 60 #ifdef ASSERT 61 // Macro to open a BranchTableBlock (a piece of code that is branched to by a calculated branch). 62 #define BTB_BEGIN(lbl, alignment, name) \ 63 __ align_address(alignment); \ 64 __ bind(lbl); \ 65 { unsigned int b_off = __ offset(); \ 66 uintptr_t b_addr = (uintptr_t)__ pc(); \ 67 __ z_larl(Z_R0, (int64_t)0); /* Check current address alignment. */ \ 68 __ z_slgr(Z_R0, br_tab); /* Current Address must be equal */ \ 69 __ z_slgr(Z_R0, flags); /* to calculated branch target. */ \ 70 __ z_brc(Assembler::bcondLogZero, 3); /* skip trap if ok. */ \ 71 __ z_illtrap(0x55); \ 72 guarantee(b_addr%alignment == 0, "bad alignment at begin of block" name); 73 74 // Macro to close a BranchTableBlock (a piece of code that is branched to by a calculated branch). 75 #define BTB_END(lbl, alignment, name) \ 76 uintptr_t e_addr = (uintptr_t)__ pc(); \ 77 unsigned int e_off = __ offset(); \ 78 unsigned int len = e_off-b_off; \ 79 if (len > alignment) { \ 80 tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \ 81 len, alignment, e_addr-len, name); \ 82 guarantee(len <= alignment, "block too large"); \ 83 } \ 84 guarantee(len == e_addr-b_addr, "block len mismatch"); \ 85 } 86 #else 87 // Macro to open a BranchTableBlock (a piece of code that is branched to by a calculated branch). 88 #define BTB_BEGIN(lbl, alignment, name) \ 89 __ align_address(alignment); \ 90 __ bind(lbl); \ 91 { unsigned int b_off = __ offset(); \ 92 uintptr_t b_addr = (uintptr_t)__ pc(); \ 93 guarantee(b_addr%alignment == 0, "bad alignment at begin of block" name); 94 95 // Macro to close a BranchTableBlock (a piece of code that is branched to by a calculated branch). 96 #define BTB_END(lbl, alignment, name) \ 97 uintptr_t e_addr = (uintptr_t)__ pc(); \ 98 unsigned int e_off = __ offset(); \ 99 unsigned int len = e_off-b_off; \ 100 if (len > alignment) { \ 101 tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \ 102 len, alignment, e_addr-len, name); \ 103 guarantee(len <= alignment, "block too large"); \ 104 } \ 105 guarantee(len == e_addr-b_addr, "block len mismatch"); \ 106 } 107 #endif // ASSERT 108 109 // Platform-dependent initialization. 110 111 void TemplateTable::pd_initialize() { 112 // No specific initialization. 113 } 114 115 // Address computation: local variables 116 117 static inline Address iaddress(int n) { 118 return Address(Z_locals, Interpreter::local_offset_in_bytes(n)); 119 } 120 121 static inline Address laddress(int n) { 122 return iaddress(n + 1); 123 } 124 125 static inline Address faddress(int n) { 126 return iaddress(n); 127 } 128 129 static inline Address daddress(int n) { 130 return laddress(n); 131 } 132 133 static inline Address aaddress(int n) { 134 return iaddress(n); 135 } 136 137 // Pass NULL, if no shift instruction should be emitted. 138 static inline Address iaddress(InterpreterMacroAssembler *masm, Register r) { 139 if (masm) { 140 masm->z_sllg(r, r, LogBytesPerWord); // index2bytes 141 } 142 return Address(Z_locals, r, Interpreter::local_offset_in_bytes(0)); 143 } 144 145 // Pass NULL, if no shift instruction should be emitted. 146 static inline Address laddress(InterpreterMacroAssembler *masm, Register r) { 147 if (masm) { 148 masm->z_sllg(r, r, LogBytesPerWord); // index2bytes 149 } 150 return Address(Z_locals, r, Interpreter::local_offset_in_bytes(1) ); 151 } 152 153 static inline Address faddress(InterpreterMacroAssembler *masm, Register r) { 154 return iaddress(masm, r); 155 } 156 157 static inline Address daddress(InterpreterMacroAssembler *masm, Register r) { 158 return laddress(masm, r); 159 } 160 161 static inline Address aaddress(InterpreterMacroAssembler *masm, Register r) { 162 return iaddress(masm, r); 163 } 164 165 // At top of Java expression stack which may be different than esp(). It 166 // isn't for category 1 objects. 167 static inline Address at_tos(int slot = 0) { 168 return Address(Z_esp, Interpreter::expr_offset_in_bytes(slot)); 169 } 170 171 // Condition conversion 172 static Assembler::branch_condition j_not(TemplateTable::Condition cc) { 173 switch (cc) { 174 case TemplateTable::equal : 175 return Assembler::bcondNotEqual; 176 case TemplateTable::not_equal : 177 return Assembler::bcondEqual; 178 case TemplateTable::less : 179 return Assembler::bcondNotLow; 180 case TemplateTable::less_equal : 181 return Assembler::bcondHigh; 182 case TemplateTable::greater : 183 return Assembler::bcondNotHigh; 184 case TemplateTable::greater_equal: 185 return Assembler::bcondLow; 186 } 187 ShouldNotReachHere(); 188 return Assembler::bcondZero; 189 } 190 191 // Do an oop store like *(base + offset) = val 192 // offset can be a register or a constant. 193 static void do_oop_store(InterpreterMacroAssembler* _masm, 194 Register base, 195 RegisterOrConstant offset, 196 Register val, 197 bool val_is_null, // == false does not guarantee that val really is not equal NULL. 198 Register tmp1, // If tmp3 is volatile, either tmp1 or tmp2 must be 199 Register tmp2, // non-volatile to hold a copy of pre_val across runtime calls. 200 Register tmp3, // Ideally, this tmp register is non-volatile, as it is used to 201 // hold pre_val (must survive runtime calls). 202 BarrierSet::Name barrier, 203 bool precise) { 204 BLOCK_COMMENT("do_oop_store {"); 205 assert(val != noreg, "val must always be valid, even if it is zero"); 206 assert_different_registers(tmp1, tmp2, tmp3, val, base, offset.register_or_noreg()); 207 __ verify_oop(val); 208 switch (barrier) { 209 #if INCLUDE_ALL_GCS 210 case BarrierSet::G1BarrierSet: 211 { 212 #ifdef ASSERT 213 if (val_is_null) { // Check if the flag setting reflects reality. 214 Label OK; 215 __ z_ltgr(val, val); 216 __ z_bre(OK); 217 __ z_illtrap(0x11); 218 __ bind(OK); 219 } 220 #endif 221 Register pre_val = tmp3; 222 // Load and record the previous value. 223 __ g1_write_barrier_pre(base, offset, pre_val, val, 224 tmp1, tmp2, 225 false); // Needs to hold pre_val in non_volatile register? 226 227 if (val_is_null) { 228 __ store_heap_oop_null(val, offset, base); 229 } else { 230 Label Done; 231 // val_is_null == false does not guarantee that val really is not equal NULL. 232 // Checking for this case dynamically has some cost, but also some benefit (in GC). 233 // It's hard to say if cost or benefit is greater. 234 { Label OK; 235 __ z_ltgr(val, val); 236 __ z_brne(OK); 237 __ store_heap_oop_null(val, offset, base); 238 __ z_bru(Done); 239 __ bind(OK); 240 } 241 // G1 barrier needs uncompressed oop for region cross check. 242 // Store_heap_oop compresses the oop in the argument register. 243 Register val_work = val; 244 if (UseCompressedOops) { 245 val_work = tmp3; 246 __ z_lgr(val_work, val); 247 } 248 __ store_heap_oop_not_null(val_work, offset, base); 249 250 // We need precise card marks for oop array stores. 251 // Otherwise, cardmarking the object which contains the oop is sufficient. 252 if (precise && !(offset.is_constant() && offset.as_constant() == 0)) { 253 __ add2reg_with_index(base, 254 offset.constant_or_zero(), 255 offset.register_or_noreg(), 256 base); 257 } 258 __ g1_write_barrier_post(base /* store_adr */, val, tmp1, tmp2, tmp3); 259 __ bind(Done); 260 } 261 } 262 break; 263 #endif // INCLUDE_ALL_GCS 264 case BarrierSet::CardTableModRef: 265 { 266 if (val_is_null) { 267 __ store_heap_oop_null(val, offset, base); 268 } else { 269 __ store_heap_oop(val, offset, base); 270 // Flatten object address if needed. 271 if (precise && ((offset.register_or_noreg() != noreg) || (offset.constant_or_zero() != 0))) { 272 __ load_address(base, Address(base, offset.register_or_noreg(), offset.constant_or_zero())); 273 } 274 __ card_write_barrier_post(base, tmp1); 275 } 276 } 277 break; 278 case BarrierSet::ModRef: 279 // fall through 280 default: 281 ShouldNotReachHere(); 282 283 } 284 BLOCK_COMMENT("} do_oop_store"); 285 } 286 287 Address TemplateTable::at_bcp(int offset) { 288 assert(_desc->uses_bcp(), "inconsistent uses_bcp information"); 289 return Address(Z_bcp, offset); 290 } 291 292 void TemplateTable::patch_bytecode(Bytecodes::Code bc, 293 Register bc_reg, 294 Register temp_reg, 295 bool load_bc_into_bc_reg, // = true 296 int byte_no) { 297 if (!RewriteBytecodes) { return; } 298 299 NearLabel L_patch_done; 300 BLOCK_COMMENT("patch_bytecode {"); 301 302 switch (bc) { 303 case Bytecodes::_fast_aputfield: 304 case Bytecodes::_fast_bputfield: 305 case Bytecodes::_fast_zputfield: 306 case Bytecodes::_fast_cputfield: 307 case Bytecodes::_fast_dputfield: 308 case Bytecodes::_fast_fputfield: 309 case Bytecodes::_fast_iputfield: 310 case Bytecodes::_fast_lputfield: 311 case Bytecodes::_fast_sputfield: 312 { 313 // We skip bytecode quickening for putfield instructions when 314 // the put_code written to the constant pool cache is zero. 315 // This is required so that every execution of this instruction 316 // calls out to InterpreterRuntime::resolve_get_put to do 317 // additional, required work. 318 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 319 assert(load_bc_into_bc_reg, "we use bc_reg as temp"); 320 __ get_cache_and_index_and_bytecode_at_bcp(Z_R1_scratch, bc_reg, 321 temp_reg, byte_no, 1); 322 __ load_const_optimized(bc_reg, bc); 323 __ compareU32_and_branch(temp_reg, (intptr_t)0, 324 Assembler::bcondZero, L_patch_done); 325 } 326 break; 327 default: 328 assert(byte_no == -1, "sanity"); 329 // The pair bytecodes have already done the load. 330 if (load_bc_into_bc_reg) { 331 __ load_const_optimized(bc_reg, bc); 332 } 333 break; 334 } 335 336 if (JvmtiExport::can_post_breakpoint()) { 337 338 Label L_fast_patch; 339 340 // If a breakpoint is present we can't rewrite the stream directly. 341 __ z_cli(at_bcp(0), Bytecodes::_breakpoint); 342 __ z_brne(L_fast_patch); 343 __ get_method(temp_reg); 344 // Let breakpoint table handling rewrite to quicker bytecode. 345 __ call_VM_static(noreg, 346 CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), 347 temp_reg, Z_R13, bc_reg); 348 __ z_bru(L_patch_done); 349 350 __ bind(L_fast_patch); 351 } 352 353 #ifdef ASSERT 354 NearLabel L_okay; 355 356 // We load into 64 bits, since this works on any CPU. 357 __ z_llgc(temp_reg, at_bcp(0)); 358 __ compareU32_and_branch(temp_reg, Bytecodes::java_code(bc), 359 Assembler::bcondEqual, L_okay ); 360 __ compareU32_and_branch(temp_reg, bc_reg, Assembler::bcondEqual, L_okay); 361 __ stop_static("patching the wrong bytecode"); 362 __ bind(L_okay); 363 #endif 364 365 // Patch bytecode. 366 __ z_stc(bc_reg, at_bcp(0)); 367 368 __ bind(L_patch_done); 369 BLOCK_COMMENT("} patch_bytecode"); 370 } 371 372 // Individual instructions 373 374 void TemplateTable::nop() { 375 transition(vtos, vtos); 376 } 377 378 void TemplateTable::shouldnotreachhere() { 379 transition(vtos, vtos); 380 __ stop("shouldnotreachhere bytecode"); 381 } 382 383 void TemplateTable::aconst_null() { 384 transition(vtos, atos); 385 __ clear_reg(Z_tos, true, false); 386 } 387 388 void TemplateTable::iconst(int value) { 389 transition(vtos, itos); 390 // Zero extension of the iconst makes zero extension at runtime obsolete. 391 __ load_const_optimized(Z_tos, ((unsigned long)(unsigned int)value)); 392 } 393 394 void TemplateTable::lconst(int value) { 395 transition(vtos, ltos); 396 __ load_const_optimized(Z_tos, value); 397 } 398 399 // No pc-relative load/store for floats. 400 void TemplateTable::fconst(int value) { 401 transition(vtos, ftos); 402 static float one = 1.0f, two = 2.0f; 403 404 switch (value) { 405 case 0: 406 __ z_lzer(Z_ftos); 407 return; 408 case 1: 409 __ load_absolute_address(Z_R1_scratch, (address) &one); 410 __ mem2freg_opt(Z_ftos, Address(Z_R1_scratch), false); 411 return; 412 case 2: 413 __ load_absolute_address(Z_R1_scratch, (address) &two); 414 __ mem2freg_opt(Z_ftos, Address(Z_R1_scratch), false); 415 return; 416 default: 417 ShouldNotReachHere(); 418 return; 419 } 420 } 421 422 void TemplateTable::dconst(int value) { 423 transition(vtos, dtos); 424 static double one = 1.0; 425 426 switch (value) { 427 case 0: 428 __ z_lzdr(Z_ftos); 429 return; 430 case 1: 431 __ load_absolute_address(Z_R1_scratch, (address) &one); 432 __ mem2freg_opt(Z_ftos, Address(Z_R1_scratch)); 433 return; 434 default: 435 ShouldNotReachHere(); 436 return; 437 } 438 } 439 440 void TemplateTable::bipush() { 441 transition(vtos, itos); 442 __ z_lb(Z_tos, at_bcp(1)); 443 } 444 445 void TemplateTable::sipush() { 446 transition(vtos, itos); 447 __ get_2_byte_integer_at_bcp(Z_tos, 1, InterpreterMacroAssembler::Signed); 448 } 449 450 451 void TemplateTable::ldc(bool wide) { 452 transition(vtos, vtos); 453 Label call_ldc, notFloat, notClass, notInt, Done; 454 const Register RcpIndex = Z_tmp_1; 455 const Register Rtags = Z_ARG2; 456 457 if (wide) { 458 __ get_2_byte_integer_at_bcp(RcpIndex, 1, InterpreterMacroAssembler::Unsigned); 459 } else { 460 __ z_llgc(RcpIndex, at_bcp(1)); 461 } 462 463 __ get_cpool_and_tags(Z_tmp_2, Rtags); 464 465 const int base_offset = ConstantPool::header_size() * wordSize; 466 const int tags_offset = Array<u1>::base_offset_in_bytes(); 467 const Register Raddr_type = Rtags; 468 469 // Get address of type. 470 __ add2reg_with_index(Raddr_type, tags_offset, RcpIndex, Rtags); 471 472 __ z_cli(0, Raddr_type, JVM_CONSTANT_UnresolvedClass); 473 __ z_bre(call_ldc); // Unresolved class - get the resolved class. 474 475 __ z_cli(0, Raddr_type, JVM_CONSTANT_UnresolvedClassInError); 476 __ z_bre(call_ldc); // Unresolved class in error state - call into runtime 477 // to throw the error from the first resolution attempt. 478 479 __ z_cli(0, Raddr_type, JVM_CONSTANT_Class); 480 __ z_brne(notClass); // Resolved class - need to call vm to get java 481 // mirror of the class. 482 483 // We deal with a class. Call vm to do the appropriate. 484 __ bind(call_ldc); 485 __ load_const_optimized(Z_ARG2, wide); 486 call_VM(Z_RET, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), Z_ARG2); 487 __ push_ptr(Z_RET); 488 __ z_bru(Done); 489 490 // Not a class. 491 __ bind(notClass); 492 Register RcpOffset = RcpIndex; 493 __ z_sllg(RcpOffset, RcpIndex, LogBytesPerWord); // Convert index to offset. 494 __ z_cli(0, Raddr_type, JVM_CONSTANT_Float); 495 __ z_brne(notFloat); 496 497 // ftos 498 __ mem2freg_opt(Z_ftos, Address(Z_tmp_2, RcpOffset, base_offset), false); 499 __ push_f(); 500 __ z_bru(Done); 501 502 __ bind(notFloat); 503 __ z_cli(0, Raddr_type, JVM_CONSTANT_Integer); 504 __ z_brne(notInt); 505 506 // itos 507 __ mem2reg_opt(Z_tos, Address(Z_tmp_2, RcpOffset, base_offset), false); 508 __ push_i(Z_tos); 509 __ z_bru(Done); 510 511 // assume the tag is for condy; if not, the VM runtime will tell us 512 __ bind(notInt); 513 condy_helper(Done); 514 515 __ bind(Done); 516 } 517 518 // Fast path for caching oop constants. 519 // %%% We should use this to handle Class and String constants also. 520 // %%% It will simplify the ldc/primitive path considerably. 521 void TemplateTable::fast_aldc(bool wide) { 522 transition(vtos, atos); 523 524 const Register index = Z_tmp_2; 525 int index_size = wide ? sizeof(u2) : sizeof(u1); 526 Label L_do_resolve, L_resolved; 527 528 // We are resolved if the resolved reference cache entry contains a 529 // non-null object (CallSite, etc.). 530 __ get_cache_index_at_bcp(index, 1, index_size); // Load index. 531 __ load_resolved_reference_at_index(Z_tos, index); 532 __ z_ltgr(Z_tos, Z_tos); 533 __ z_bre(L_do_resolve); 534 535 // Convert null sentinel to NULL. 536 __ load_const_optimized(Z_R1_scratch, (intptr_t)Universe::the_null_sentinel_addr()); 537 __ z_cg(Z_tos, Address(Z_R1_scratch)); 538 __ z_brne(L_resolved); 539 __ clear_reg(Z_tos); 540 __ z_bru(L_resolved); 541 542 __ bind(L_do_resolve); 543 // First time invocation - must resolve first. 544 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc); 545 __ load_const_optimized(Z_ARG1, (int)bytecode()); 546 __ call_VM(Z_tos, entry, Z_ARG1); 547 548 __ bind(L_resolved); 549 __ verify_oop(Z_tos); 550 } 551 552 void TemplateTable::ldc2_w() { 553 transition(vtos, vtos); 554 Label notDouble, notLong, Done; 555 556 // Z_tmp_1 = index of cp entry 557 __ get_2_byte_integer_at_bcp(Z_tmp_1, 1, InterpreterMacroAssembler::Unsigned); 558 559 __ get_cpool_and_tags(Z_tmp_2, Z_tos); 560 561 const int base_offset = ConstantPool::header_size() * wordSize; 562 const int tags_offset = Array<u1>::base_offset_in_bytes(); 563 564 // Get address of type. 565 __ add2reg_with_index(Z_tos, tags_offset, Z_tos, Z_tmp_1); 566 567 // Index needed in both branches, so calculate here. 568 __ z_sllg(Z_tmp_1, Z_tmp_1, LogBytesPerWord); // index2bytes 569 570 // Check type. 571 __ z_cli(0, Z_tos, JVM_CONSTANT_Double); 572 __ z_brne(notDouble); 573 // dtos 574 __ mem2freg_opt(Z_ftos, Address(Z_tmp_2, Z_tmp_1, base_offset)); 575 __ push_d(); 576 __ z_bru(Done); 577 578 __ bind(notDouble); 579 __ z_cli(0, Z_tos, JVM_CONSTANT_Long); 580 __ z_brne(notLong); 581 // ltos 582 __ mem2reg_opt(Z_tos, Address(Z_tmp_2, Z_tmp_1, base_offset)); 583 __ push_l(); 584 __ z_bru(Done); 585 586 __ bind(notLong); 587 condy_helper(Done); 588 589 __ bind(Done); 590 } 591 592 void TemplateTable::condy_helper(Label& Done) { 593 const Register obj = Z_tmp_1; 594 const Register off = Z_tmp_2; 595 const Register flags = Z_ARG1; 596 const Register rarg = Z_ARG2; 597 __ load_const_optimized(rarg, (int)bytecode()); 598 call_VM(obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc), rarg); 599 __ get_vm_result_2(flags); 600 601 // VMr = obj = base address to find primitive value to push 602 // VMr2 = flags = (tos, off) using format of CPCE::_flags 603 assert(ConstantPoolCacheEntry::field_index_mask == 0xffff, "or use other instructions"); 604 __ z_llghr(off, flags); 605 const Address field(obj, off); 606 607 // What sort of thing are we loading? 608 __ z_srl(flags, ConstantPoolCacheEntry::tos_state_shift); 609 // Make sure we don't need to mask flags for tos_state after the above shift. 610 ConstantPoolCacheEntry::verify_tos_state_shift(); 611 612 switch (bytecode()) { 613 case Bytecodes::_ldc: 614 case Bytecodes::_ldc_w: 615 { 616 // tos in (itos, ftos, stos, btos, ctos, ztos) 617 Label notInt, notFloat, notShort, notByte, notChar, notBool; 618 __ z_cghi(flags, itos); 619 __ z_brne(notInt); 620 // itos 621 __ z_l(Z_tos, field); 622 __ push(itos); 623 __ z_bru(Done); 624 625 __ bind(notInt); 626 __ z_cghi(flags, ftos); 627 __ z_brne(notFloat); 628 // ftos 629 __ z_le(Z_ftos, field); 630 __ push(ftos); 631 __ z_bru(Done); 632 633 __ bind(notFloat); 634 __ z_cghi(flags, stos); 635 __ z_brne(notShort); 636 // stos 637 __ z_lh(Z_tos, field); 638 __ push(stos); 639 __ z_bru(Done); 640 641 __ bind(notShort); 642 __ z_cghi(flags, btos); 643 __ z_brne(notByte); 644 // btos 645 __ z_lb(Z_tos, field); 646 __ push(btos); 647 __ z_bru(Done); 648 649 __ bind(notByte); 650 __ z_cghi(flags, ctos); 651 __ z_brne(notChar); 652 // ctos 653 __ z_llh(Z_tos, field); 654 __ push(ctos); 655 __ z_bru(Done); 656 657 __ bind(notChar); 658 __ z_cghi(flags, ztos); 659 __ z_brne(notBool); 660 // ztos 661 __ z_lb(Z_tos, field); 662 __ push(ztos); 663 __ z_bru(Done); 664 665 __ bind(notBool); 666 break; 667 } 668 669 case Bytecodes::_ldc2_w: 670 { 671 Label notLong, notDouble; 672 __ z_cghi(flags, ltos); 673 __ z_brne(notLong); 674 // ltos 675 __ z_lg(Z_tos, field); 676 __ push(ltos); 677 __ z_bru(Done); 678 679 __ bind(notLong); 680 __ z_cghi(flags, dtos); 681 __ z_brne(notDouble); 682 // dtos 683 __ z_ld(Z_ftos, field); 684 __ push(dtos); 685 __ z_bru(Done); 686 687 __ bind(notDouble); 688 break; 689 } 690 691 default: 692 ShouldNotReachHere(); 693 } 694 695 __ stop("bad ldc/condy"); 696 } 697 698 void TemplateTable::locals_index(Register reg, int offset) { 699 __ z_llgc(reg, at_bcp(offset)); 700 __ z_lcgr(reg); 701 } 702 703 void TemplateTable::iload() { 704 iload_internal(); 705 } 706 707 void TemplateTable::nofast_iload() { 708 iload_internal(may_not_rewrite); 709 } 710 711 void TemplateTable::iload_internal(RewriteControl rc) { 712 transition(vtos, itos); 713 714 if (RewriteFrequentPairs && rc == may_rewrite) { 715 NearLabel rewrite, done; 716 const Register bc = Z_ARG4; 717 718 assert(Z_R1_scratch != bc, "register damaged"); 719 720 // Get next byte. 721 __ z_llgc(Z_R1_scratch, at_bcp(Bytecodes::length_for (Bytecodes::_iload))); 722 723 // If _iload, wait to rewrite to iload2. We only want to rewrite the 724 // last two iloads in a pair. Comparing against fast_iload means that 725 // the next bytecode is neither an iload or a caload, and therefore 726 // an iload pair. 727 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_iload, 728 Assembler::bcondEqual, done); 729 730 __ load_const_optimized(bc, Bytecodes::_fast_iload2); 731 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_fast_iload, 732 Assembler::bcondEqual, rewrite); 733 734 // If _caload, rewrite to fast_icaload. 735 __ load_const_optimized(bc, Bytecodes::_fast_icaload); 736 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_caload, 737 Assembler::bcondEqual, rewrite); 738 739 // Rewrite so iload doesn't check again. 740 __ load_const_optimized(bc, Bytecodes::_fast_iload); 741 742 // rewrite 743 // bc: fast bytecode 744 __ bind(rewrite); 745 patch_bytecode(Bytecodes::_iload, bc, Z_R1_scratch, false); 746 747 __ bind(done); 748 749 } 750 751 // Get the local value into tos. 752 locals_index(Z_R1_scratch); 753 __ mem2reg_opt(Z_tos, iaddress(_masm, Z_R1_scratch), false); 754 } 755 756 void TemplateTable::fast_iload2() { 757 transition(vtos, itos); 758 759 locals_index(Z_R1_scratch); 760 __ mem2reg_opt(Z_tos, iaddress(_masm, Z_R1_scratch), false); 761 __ push_i(Z_tos); 762 locals_index(Z_R1_scratch, 3); 763 __ mem2reg_opt(Z_tos, iaddress(_masm, Z_R1_scratch), false); 764 } 765 766 void TemplateTable::fast_iload() { 767 transition(vtos, itos); 768 769 locals_index(Z_R1_scratch); 770 __ mem2reg_opt(Z_tos, iaddress(_masm, Z_R1_scratch), false); 771 } 772 773 void TemplateTable::lload() { 774 transition(vtos, ltos); 775 776 locals_index(Z_R1_scratch); 777 __ mem2reg_opt(Z_tos, laddress(_masm, Z_R1_scratch)); 778 } 779 780 void TemplateTable::fload() { 781 transition(vtos, ftos); 782 783 locals_index(Z_R1_scratch); 784 __ mem2freg_opt(Z_ftos, faddress(_masm, Z_R1_scratch), false); 785 } 786 787 void TemplateTable::dload() { 788 transition(vtos, dtos); 789 790 locals_index(Z_R1_scratch); 791 __ mem2freg_opt(Z_ftos, daddress(_masm, Z_R1_scratch)); 792 } 793 794 void TemplateTable::aload() { 795 transition(vtos, atos); 796 797 locals_index(Z_R1_scratch); 798 __ mem2reg_opt(Z_tos, aaddress(_masm, Z_R1_scratch)); 799 } 800 801 void TemplateTable::locals_index_wide(Register reg) { 802 __ get_2_byte_integer_at_bcp(reg, 2, InterpreterMacroAssembler::Unsigned); 803 __ z_lcgr(reg); 804 } 805 806 void TemplateTable::wide_iload() { 807 transition(vtos, itos); 808 809 locals_index_wide(Z_tmp_1); 810 __ mem2reg_opt(Z_tos, iaddress(_masm, Z_tmp_1), false); 811 } 812 813 void TemplateTable::wide_lload() { 814 transition(vtos, ltos); 815 816 locals_index_wide(Z_tmp_1); 817 __ mem2reg_opt(Z_tos, laddress(_masm, Z_tmp_1)); 818 } 819 820 void TemplateTable::wide_fload() { 821 transition(vtos, ftos); 822 823 locals_index_wide(Z_tmp_1); 824 __ mem2freg_opt(Z_ftos, faddress(_masm, Z_tmp_1), false); 825 } 826 827 void TemplateTable::wide_dload() { 828 transition(vtos, dtos); 829 830 locals_index_wide(Z_tmp_1); 831 __ mem2freg_opt(Z_ftos, daddress(_masm, Z_tmp_1)); 832 } 833 834 void TemplateTable::wide_aload() { 835 transition(vtos, atos); 836 837 locals_index_wide(Z_tmp_1); 838 __ mem2reg_opt(Z_tos, aaddress(_masm, Z_tmp_1)); 839 } 840 841 void TemplateTable::index_check(Register array, Register index, unsigned int shift) { 842 assert_different_registers(Z_R1_scratch, array, index); 843 844 // Check array. 845 __ null_check(array, Z_R0_scratch, arrayOopDesc::length_offset_in_bytes()); 846 847 // Sign extend index for use by indexed load. 848 __ z_lgfr(index, index); 849 850 // Check index. 851 Label index_ok; 852 __ z_cl(index, Address(array, arrayOopDesc::length_offset_in_bytes())); 853 __ z_brl(index_ok); 854 __ lgr_if_needed(Z_ARG3, index); // See generate_ArrayIndexOutOfBounds_handler(). 855 // Give back the array to create more detailed exceptions. 856 __ lgr_if_needed(Z_ARG2, array); // See generate_ArrayIndexOutOfBounds_handler(). 857 __ load_absolute_address(Z_R1_scratch, 858 Interpreter::_throw_ArrayIndexOutOfBoundsException_entry); 859 __ z_bcr(Assembler::bcondAlways, Z_R1_scratch); 860 __ bind(index_ok); 861 862 if (shift > 0) 863 __ z_sllg(index, index, shift); 864 } 865 866 void TemplateTable::iaload() { 867 transition(itos, itos); 868 869 __ pop_ptr(Z_tmp_1); // array 870 // Index is in Z_tos. 871 Register index = Z_tos; 872 index_check(Z_tmp_1, index, LogBytesPerInt); // Kills Z_ARG3. 873 // Load the value. 874 __ mem2reg_opt(Z_tos, 875 Address(Z_tmp_1, index, arrayOopDesc::base_offset_in_bytes(T_INT)), 876 false); 877 } 878 879 void TemplateTable::laload() { 880 transition(itos, ltos); 881 882 __ pop_ptr(Z_tmp_2); 883 // Z_tos : index 884 // Z_tmp_2 : array 885 Register index = Z_tos; 886 index_check(Z_tmp_2, index, LogBytesPerLong); 887 __ mem2reg_opt(Z_tos, 888 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_LONG))); 889 } 890 891 void TemplateTable::faload() { 892 transition(itos, ftos); 893 894 __ pop_ptr(Z_tmp_2); 895 // Z_tos : index 896 // Z_tmp_2 : array 897 Register index = Z_tos; 898 index_check(Z_tmp_2, index, LogBytesPerInt); 899 __ mem2freg_opt(Z_ftos, 900 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_FLOAT)), 901 false); 902 } 903 904 void TemplateTable::daload() { 905 transition(itos, dtos); 906 907 __ pop_ptr(Z_tmp_2); 908 // Z_tos : index 909 // Z_tmp_2 : array 910 Register index = Z_tos; 911 index_check(Z_tmp_2, index, LogBytesPerLong); 912 __ mem2freg_opt(Z_ftos, 913 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); 914 } 915 916 void TemplateTable::aaload() { 917 transition(itos, atos); 918 919 unsigned const int shift = LogBytesPerHeapOop; 920 __ pop_ptr(Z_tmp_1); // array 921 // Index is in Z_tos. 922 Register index = Z_tos; 923 index_check(Z_tmp_1, index, shift); 924 // Now load array element. 925 __ load_heap_oop(Z_tos, 926 Address(Z_tmp_1, index, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); 927 __ verify_oop(Z_tos); 928 } 929 930 void TemplateTable::baload() { 931 transition(itos, itos); 932 933 __ pop_ptr(Z_tmp_1); 934 // Z_tos : index 935 // Z_tmp_1 : array 936 Register index = Z_tos; 937 index_check(Z_tmp_1, index, 0); 938 __ z_lb(Z_tos, 939 Address(Z_tmp_1, index, arrayOopDesc::base_offset_in_bytes(T_BYTE))); 940 } 941 942 void TemplateTable::caload() { 943 transition(itos, itos); 944 945 __ pop_ptr(Z_tmp_2); 946 // Z_tos : index 947 // Z_tmp_2 : array 948 Register index = Z_tos; 949 index_check(Z_tmp_2, index, LogBytesPerShort); 950 // Load into 64 bits, works on all CPUs. 951 __ z_llgh(Z_tos, 952 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 953 } 954 955 // Iload followed by caload frequent pair. 956 void TemplateTable::fast_icaload() { 957 transition(vtos, itos); 958 959 // Load index out of locals. 960 locals_index(Z_R1_scratch); 961 __ mem2reg_opt(Z_ARG3, iaddress(_masm, Z_R1_scratch), false); 962 // Z_ARG3 : index 963 // Z_tmp_2 : array 964 __ pop_ptr(Z_tmp_2); 965 index_check(Z_tmp_2, Z_ARG3, LogBytesPerShort); 966 // Load into 64 bits, works on all CPUs. 967 __ z_llgh(Z_tos, 968 Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 969 } 970 971 void TemplateTable::saload() { 972 transition(itos, itos); 973 974 __ pop_ptr(Z_tmp_2); 975 // Z_tos : index 976 // Z_tmp_2 : array 977 Register index = Z_tos; 978 index_check(Z_tmp_2, index, LogBytesPerShort); 979 __ z_lh(Z_tos, 980 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_SHORT))); 981 } 982 983 void TemplateTable::iload(int n) { 984 transition(vtos, itos); 985 __ z_ly(Z_tos, iaddress(n)); 986 } 987 988 void TemplateTable::lload(int n) { 989 transition(vtos, ltos); 990 __ z_lg(Z_tos, laddress(n)); 991 } 992 993 void TemplateTable::fload(int n) { 994 transition(vtos, ftos); 995 __ mem2freg_opt(Z_ftos, faddress(n), false); 996 } 997 998 void TemplateTable::dload(int n) { 999 transition(vtos, dtos); 1000 __ mem2freg_opt(Z_ftos, daddress(n)); 1001 } 1002 1003 void TemplateTable::aload(int n) { 1004 transition(vtos, atos); 1005 __ mem2reg_opt(Z_tos, aaddress(n)); 1006 } 1007 1008 void TemplateTable::aload_0() { 1009 aload_0_internal(); 1010 } 1011 1012 void TemplateTable::nofast_aload_0() { 1013 aload_0_internal(may_not_rewrite); 1014 } 1015 1016 void TemplateTable::aload_0_internal(RewriteControl rc) { 1017 transition(vtos, atos); 1018 1019 // According to bytecode histograms, the pairs: 1020 // 1021 // _aload_0, _fast_igetfield 1022 // _aload_0, _fast_agetfield 1023 // _aload_0, _fast_fgetfield 1024 // 1025 // occur frequently. If RewriteFrequentPairs is set, the (slow) 1026 // _aload_0 bytecode checks if the next bytecode is either 1027 // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then 1028 // rewrites the current bytecode into a pair bytecode; otherwise it 1029 // rewrites the current bytecode into _fast_aload_0 that doesn't do 1030 // the pair check anymore. 1031 // 1032 // Note: If the next bytecode is _getfield, the rewrite must be 1033 // delayed, otherwise we may miss an opportunity for a pair. 1034 // 1035 // Also rewrite frequent pairs 1036 // aload_0, aload_1 1037 // aload_0, iload_1 1038 // These bytecodes with a small amount of code are most profitable 1039 // to rewrite. 1040 if (!(RewriteFrequentPairs && (rc == may_rewrite))) { 1041 aload(0); 1042 return; 1043 } 1044 1045 NearLabel rewrite, done; 1046 const Register bc = Z_ARG4; 1047 1048 assert(Z_R1_scratch != bc, "register damaged"); 1049 // Get next byte. 1050 __ z_llgc(Z_R1_scratch, at_bcp(Bytecodes::length_for (Bytecodes::_aload_0))); 1051 1052 // Do actual aload_0. 1053 aload(0); 1054 1055 // If _getfield then wait with rewrite. 1056 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_getfield, 1057 Assembler::bcondEqual, done); 1058 1059 // If _igetfield then rewrite to _fast_iaccess_0. 1060 assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) 1061 == Bytecodes::_aload_0, "fix bytecode definition"); 1062 1063 __ load_const_optimized(bc, Bytecodes::_fast_iaccess_0); 1064 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_fast_igetfield, 1065 Assembler::bcondEqual, rewrite); 1066 1067 // If _agetfield then rewrite to _fast_aaccess_0. 1068 assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) 1069 == Bytecodes::_aload_0, "fix bytecode definition"); 1070 1071 __ load_const_optimized(bc, Bytecodes::_fast_aaccess_0); 1072 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_fast_agetfield, 1073 Assembler::bcondEqual, rewrite); 1074 1075 // If _fgetfield then rewrite to _fast_faccess_0. 1076 assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) 1077 == Bytecodes::_aload_0, "fix bytecode definition"); 1078 1079 __ load_const_optimized(bc, Bytecodes::_fast_faccess_0); 1080 __ compareU32_and_branch(Z_R1_scratch, Bytecodes::_fast_fgetfield, 1081 Assembler::bcondEqual, rewrite); 1082 1083 // Else rewrite to _fast_aload0. 1084 assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) 1085 == Bytecodes::_aload_0, "fix bytecode definition"); 1086 __ load_const_optimized(bc, Bytecodes::_fast_aload_0); 1087 1088 // rewrite 1089 // bc: fast bytecode 1090 __ bind(rewrite); 1091 1092 patch_bytecode(Bytecodes::_aload_0, bc, Z_R1_scratch, false); 1093 // Reload local 0 because of VM call inside patch_bytecode(). 1094 // this may trigger GC and thus change the oop. 1095 aload(0); 1096 1097 __ bind(done); 1098 } 1099 1100 void TemplateTable::istore() { 1101 transition(itos, vtos); 1102 locals_index(Z_R1_scratch); 1103 __ reg2mem_opt(Z_tos, iaddress(_masm, Z_R1_scratch), false); 1104 } 1105 1106 void TemplateTable::lstore() { 1107 transition(ltos, vtos); 1108 locals_index(Z_R1_scratch); 1109 __ reg2mem_opt(Z_tos, laddress(_masm, Z_R1_scratch)); 1110 } 1111 1112 void TemplateTable::fstore() { 1113 transition(ftos, vtos); 1114 locals_index(Z_R1_scratch); 1115 __ freg2mem_opt(Z_ftos, faddress(_masm, Z_R1_scratch)); 1116 } 1117 1118 void TemplateTable::dstore() { 1119 transition(dtos, vtos); 1120 locals_index(Z_R1_scratch); 1121 __ freg2mem_opt(Z_ftos, daddress(_masm, Z_R1_scratch)); 1122 } 1123 1124 void TemplateTable::astore() { 1125 transition(vtos, vtos); 1126 __ pop_ptr(Z_tos); 1127 locals_index(Z_R1_scratch); 1128 __ reg2mem_opt(Z_tos, aaddress(_masm, Z_R1_scratch)); 1129 } 1130 1131 void TemplateTable::wide_istore() { 1132 transition(vtos, vtos); 1133 __ pop_i(Z_tos); 1134 locals_index_wide(Z_tmp_1); 1135 __ reg2mem_opt(Z_tos, iaddress(_masm, Z_tmp_1), false); 1136 } 1137 1138 void TemplateTable::wide_lstore() { 1139 transition(vtos, vtos); 1140 __ pop_l(Z_tos); 1141 locals_index_wide(Z_tmp_1); 1142 __ reg2mem_opt(Z_tos, laddress(_masm, Z_tmp_1)); 1143 } 1144 1145 void TemplateTable::wide_fstore() { 1146 transition(vtos, vtos); 1147 __ pop_f(Z_ftos); 1148 locals_index_wide(Z_tmp_1); 1149 __ freg2mem_opt(Z_ftos, faddress(_masm, Z_tmp_1), false); 1150 } 1151 1152 void TemplateTable::wide_dstore() { 1153 transition(vtos, vtos); 1154 __ pop_d(Z_ftos); 1155 locals_index_wide(Z_tmp_1); 1156 __ freg2mem_opt(Z_ftos, daddress(_masm, Z_tmp_1)); 1157 } 1158 1159 void TemplateTable::wide_astore() { 1160 transition(vtos, vtos); 1161 __ pop_ptr(Z_tos); 1162 locals_index_wide(Z_tmp_1); 1163 __ reg2mem_opt(Z_tos, aaddress(_masm, Z_tmp_1)); 1164 } 1165 1166 void TemplateTable::iastore() { 1167 transition(itos, vtos); 1168 1169 Register index = Z_ARG3; // Index_check expects index in Z_ARG3. 1170 // Value is in Z_tos ... 1171 __ pop_i(index); // index 1172 __ pop_ptr(Z_tmp_1); // array 1173 index_check(Z_tmp_1, index, LogBytesPerInt); 1174 // ... and then move the value. 1175 __ reg2mem_opt(Z_tos, 1176 Address(Z_tmp_1, index, arrayOopDesc::base_offset_in_bytes(T_INT)), 1177 false); 1178 } 1179 1180 void TemplateTable::lastore() { 1181 transition(ltos, vtos); 1182 1183 __ pop_i(Z_ARG3); 1184 __ pop_ptr(Z_tmp_2); 1185 // Z_tos : value 1186 // Z_ARG3 : index 1187 // Z_tmp_2 : array 1188 index_check(Z_tmp_2, Z_ARG3, LogBytesPerLong); // Prefer index in Z_ARG3. 1189 __ reg2mem_opt(Z_tos, 1190 Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_LONG))); 1191 } 1192 1193 void TemplateTable::fastore() { 1194 transition(ftos, vtos); 1195 1196 __ pop_i(Z_ARG3); 1197 __ pop_ptr(Z_tmp_2); 1198 // Z_ftos : value 1199 // Z_ARG3 : index 1200 // Z_tmp_2 : array 1201 index_check(Z_tmp_2, Z_ARG3, LogBytesPerInt); // Prefer index in Z_ARG3. 1202 __ freg2mem_opt(Z_ftos, 1203 Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_FLOAT)), 1204 false); 1205 } 1206 1207 void TemplateTable::dastore() { 1208 transition(dtos, vtos); 1209 1210 __ pop_i(Z_ARG3); 1211 __ pop_ptr(Z_tmp_2); 1212 // Z_ftos : value 1213 // Z_ARG3 : index 1214 // Z_tmp_2 : array 1215 index_check(Z_tmp_2, Z_ARG3, LogBytesPerLong); // Prefer index in Z_ARG3. 1216 __ freg2mem_opt(Z_ftos, 1217 Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE))); 1218 } 1219 1220 void TemplateTable::aastore() { 1221 NearLabel is_null, ok_is_subtype, done; 1222 transition(vtos, vtos); 1223 1224 // stack: ..., array, index, value 1225 1226 Register Rvalue = Z_tos; 1227 Register Rarray = Z_ARG2; 1228 Register Rindex = Z_ARG3; // Convention for index_check(). 1229 1230 __ load_ptr(0, Rvalue); 1231 __ z_l(Rindex, Address(Z_esp, Interpreter::expr_offset_in_bytes(1))); 1232 __ load_ptr(2, Rarray); 1233 1234 unsigned const int shift = LogBytesPerHeapOop; 1235 index_check(Rarray, Rindex, shift); // side effect: Rindex = Rindex << shift 1236 Register Rstore_addr = Rindex; 1237 // Address where the store goes to, i.e. &(Rarry[index]) 1238 __ load_address(Rstore_addr, Address(Rarray, Rindex, arrayOopDesc::base_offset_in_bytes(T_OBJECT))); 1239 1240 // do array store check - check for NULL value first. 1241 __ compareU64_and_branch(Rvalue, (intptr_t)0, Assembler::bcondEqual, is_null); 1242 1243 Register Rsub_klass = Z_ARG4; 1244 Register Rsuper_klass = Z_ARG5; 1245 __ load_klass(Rsub_klass, Rvalue); 1246 // Load superklass. 1247 __ load_klass(Rsuper_klass, Rarray); 1248 __ z_lg(Rsuper_klass, Address(Rsuper_klass, ObjArrayKlass::element_klass_offset())); 1249 1250 // Generate a fast subtype check. Branch to ok_is_subtype if no failure. 1251 // Throw if failure. 1252 Register tmp1 = Z_tmp_1; 1253 Register tmp2 = Z_tmp_2; 1254 __ gen_subtype_check(Rsub_klass, Rsuper_klass, tmp1, tmp2, ok_is_subtype); 1255 1256 // Fall through on failure. 1257 // Object is in Rvalue == Z_tos. 1258 assert(Rvalue == Z_tos, "that's the expected location"); 1259 __ load_absolute_address(tmp1, Interpreter::_throw_ArrayStoreException_entry); 1260 __ z_br(tmp1); 1261 1262 // Come here on success. 1263 __ bind(ok_is_subtype); 1264 1265 // Now store using the appropriate barrier. 1266 Register tmp3 = Rsub_klass; 1267 do_oop_store(_masm, Rstore_addr, (intptr_t)0/*offset*/, Rvalue, false/*val==null*/, 1268 tmp3, tmp2, tmp1, _bs->kind(), true); 1269 __ z_bru(done); 1270 1271 // Have a NULL in Rvalue. 1272 __ bind(is_null); 1273 __ profile_null_seen(tmp1); 1274 1275 // Store a NULL. 1276 do_oop_store(_masm, Rstore_addr, (intptr_t)0/*offset*/, Rvalue, true/*val==null*/, 1277 tmp3, tmp2, tmp1, _bs->kind(), true); 1278 1279 // Pop stack arguments. 1280 __ bind(done); 1281 __ add2reg(Z_esp, 3 * Interpreter::stackElementSize); 1282 } 1283 1284 1285 void TemplateTable::bastore() { 1286 transition(itos, vtos); 1287 1288 __ pop_i(Z_ARG3); 1289 __ pop_ptr(Z_tmp_2); 1290 // Z_tos : value 1291 // Z_ARG3 : index 1292 // Z_tmp_2 : array 1293 1294 // Need to check whether array is boolean or byte 1295 // since both types share the bastore bytecode. 1296 __ load_klass(Z_tmp_1, Z_tmp_2); 1297 __ z_llgf(Z_tmp_1, Address(Z_tmp_1, Klass::layout_helper_offset())); 1298 __ z_tmll(Z_tmp_1, Klass::layout_helper_boolean_diffbit()); 1299 Label L_skip; 1300 __ z_bfalse(L_skip); 1301 // if it is a T_BOOLEAN array, mask the stored value to 0/1 1302 __ z_nilf(Z_tos, 0x1); 1303 __ bind(L_skip); 1304 1305 // No index shift necessary - pass 0. 1306 index_check(Z_tmp_2, Z_ARG3, 0); // Prefer index in Z_ARG3. 1307 __ z_stc(Z_tos, 1308 Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_BYTE))); 1309 } 1310 1311 void TemplateTable::castore() { 1312 transition(itos, vtos); 1313 1314 __ pop_i(Z_ARG3); 1315 __ pop_ptr(Z_tmp_2); 1316 // Z_tos : value 1317 // Z_ARG3 : index 1318 // Z_tmp_2 : array 1319 Register index = Z_ARG3; // prefer index in Z_ARG3 1320 index_check(Z_tmp_2, index, LogBytesPerShort); 1321 __ z_sth(Z_tos, 1322 Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_CHAR))); 1323 } 1324 1325 void TemplateTable::sastore() { 1326 castore(); 1327 } 1328 1329 void TemplateTable::istore(int n) { 1330 transition(itos, vtos); 1331 __ reg2mem_opt(Z_tos, iaddress(n), false); 1332 } 1333 1334 void TemplateTable::lstore(int n) { 1335 transition(ltos, vtos); 1336 __ reg2mem_opt(Z_tos, laddress(n)); 1337 } 1338 1339 void TemplateTable::fstore(int n) { 1340 transition(ftos, vtos); 1341 __ freg2mem_opt(Z_ftos, faddress(n), false); 1342 } 1343 1344 void TemplateTable::dstore(int n) { 1345 transition(dtos, vtos); 1346 __ freg2mem_opt(Z_ftos, daddress(n)); 1347 } 1348 1349 void TemplateTable::astore(int n) { 1350 transition(vtos, vtos); 1351 __ pop_ptr(Z_tos); 1352 __ reg2mem_opt(Z_tos, aaddress(n)); 1353 } 1354 1355 void TemplateTable::pop() { 1356 transition(vtos, vtos); 1357 __ add2reg(Z_esp, Interpreter::stackElementSize); 1358 } 1359 1360 void TemplateTable::pop2() { 1361 transition(vtos, vtos); 1362 __ add2reg(Z_esp, 2 * Interpreter::stackElementSize); 1363 } 1364 1365 void TemplateTable::dup() { 1366 transition(vtos, vtos); 1367 __ load_ptr(0, Z_tos); 1368 __ push_ptr(Z_tos); 1369 // stack: ..., a, a 1370 } 1371 1372 void TemplateTable::dup_x1() { 1373 transition(vtos, vtos); 1374 1375 // stack: ..., a, b 1376 __ load_ptr(0, Z_tos); // load b 1377 __ load_ptr(1, Z_R0_scratch); // load a 1378 __ store_ptr(1, Z_tos); // store b 1379 __ store_ptr(0, Z_R0_scratch); // store a 1380 __ push_ptr(Z_tos); // push b 1381 // stack: ..., b, a, b 1382 } 1383 1384 void TemplateTable::dup_x2() { 1385 transition(vtos, vtos); 1386 1387 // stack: ..., a, b, c 1388 __ load_ptr(0, Z_R0_scratch); // load c 1389 __ load_ptr(2, Z_R1_scratch); // load a 1390 __ store_ptr(2, Z_R0_scratch); // store c in a 1391 __ push_ptr(Z_R0_scratch); // push c 1392 // stack: ..., c, b, c, c 1393 __ load_ptr(2, Z_R0_scratch); // load b 1394 __ store_ptr(2, Z_R1_scratch); // store a in b 1395 // stack: ..., c, a, c, c 1396 __ store_ptr(1, Z_R0_scratch); // store b in c 1397 // stack: ..., c, a, b, c 1398 } 1399 1400 void TemplateTable::dup2() { 1401 transition(vtos, vtos); 1402 1403 // stack: ..., a, b 1404 __ load_ptr(1, Z_R0_scratch); // load a 1405 __ push_ptr(Z_R0_scratch); // push a 1406 __ load_ptr(1, Z_R0_scratch); // load b 1407 __ push_ptr(Z_R0_scratch); // push b 1408 // stack: ..., a, b, a, b 1409 } 1410 1411 void TemplateTable::dup2_x1() { 1412 transition(vtos, vtos); 1413 1414 // stack: ..., a, b, c 1415 __ load_ptr(0, Z_R0_scratch); // load c 1416 __ load_ptr(1, Z_R1_scratch); // load b 1417 __ push_ptr(Z_R1_scratch); // push b 1418 __ push_ptr(Z_R0_scratch); // push c 1419 // stack: ..., a, b, c, b, c 1420 __ store_ptr(3, Z_R0_scratch); // store c in b 1421 // stack: ..., a, c, c, b, c 1422 __ load_ptr( 4, Z_R0_scratch); // load a 1423 __ store_ptr(2, Z_R0_scratch); // store a in 2nd c 1424 // stack: ..., a, c, a, b, c 1425 __ store_ptr(4, Z_R1_scratch); // store b in a 1426 // stack: ..., b, c, a, b, c 1427 } 1428 1429 void TemplateTable::dup2_x2() { 1430 transition(vtos, vtos); 1431 1432 // stack: ..., a, b, c, d 1433 __ load_ptr(0, Z_R0_scratch); // load d 1434 __ load_ptr(1, Z_R1_scratch); // load c 1435 __ push_ptr(Z_R1_scratch); // push c 1436 __ push_ptr(Z_R0_scratch); // push d 1437 // stack: ..., a, b, c, d, c, d 1438 __ load_ptr(4, Z_R1_scratch); // load b 1439 __ store_ptr(2, Z_R1_scratch); // store b in d 1440 __ store_ptr(4, Z_R0_scratch); // store d in b 1441 // stack: ..., a, d, c, b, c, d 1442 __ load_ptr(5, Z_R0_scratch); // load a 1443 __ load_ptr(3, Z_R1_scratch); // load c 1444 __ store_ptr(3, Z_R0_scratch); // store a in c 1445 __ store_ptr(5, Z_R1_scratch); // store c in a 1446 // stack: ..., c, d, a, b, c, d 1447 } 1448 1449 void TemplateTable::swap() { 1450 transition(vtos, vtos); 1451 1452 // stack: ..., a, b 1453 __ load_ptr(1, Z_R0_scratch); // load a 1454 __ load_ptr(0, Z_R1_scratch); // load b 1455 __ store_ptr(0, Z_R0_scratch); // store a in b 1456 __ store_ptr(1, Z_R1_scratch); // store b in a 1457 // stack: ..., b, a 1458 } 1459 1460 void TemplateTable::iop2(Operation op) { 1461 transition(itos, itos); 1462 switch (op) { 1463 case add : __ z_ay(Z_tos, __ stackTop()); __ pop_i(); break; 1464 case sub : __ z_sy(Z_tos, __ stackTop()); __ pop_i(); __ z_lcr(Z_tos, Z_tos); break; 1465 case mul : __ z_msy(Z_tos, __ stackTop()); __ pop_i(); break; 1466 case _and : __ z_ny(Z_tos, __ stackTop()); __ pop_i(); break; 1467 case _or : __ z_oy(Z_tos, __ stackTop()); __ pop_i(); break; 1468 case _xor : __ z_xy(Z_tos, __ stackTop()); __ pop_i(); break; 1469 case shl : __ z_lr(Z_tmp_1, Z_tos); 1470 __ z_nill(Z_tmp_1, 31); // Lowest 5 bits are shiftamount. 1471 __ pop_i(Z_tos); __ z_sll(Z_tos, 0, Z_tmp_1); break; 1472 case shr : __ z_lr(Z_tmp_1, Z_tos); 1473 __ z_nill(Z_tmp_1, 31); // Lowest 5 bits are shiftamount. 1474 __ pop_i(Z_tos); __ z_sra(Z_tos, 0, Z_tmp_1); break; 1475 case ushr : __ z_lr(Z_tmp_1, Z_tos); 1476 __ z_nill(Z_tmp_1, 31); // Lowest 5 bits are shiftamount. 1477 __ pop_i(Z_tos); __ z_srl(Z_tos, 0, Z_tmp_1); break; 1478 default : ShouldNotReachHere(); break; 1479 } 1480 return; 1481 } 1482 1483 void TemplateTable::lop2(Operation op) { 1484 transition(ltos, ltos); 1485 1486 switch (op) { 1487 case add : __ z_ag(Z_tos, __ stackTop()); __ pop_l(); break; 1488 case sub : __ z_sg(Z_tos, __ stackTop()); __ pop_l(); __ z_lcgr(Z_tos, Z_tos); break; 1489 case mul : __ z_msg(Z_tos, __ stackTop()); __ pop_l(); break; 1490 case _and : __ z_ng(Z_tos, __ stackTop()); __ pop_l(); break; 1491 case _or : __ z_og(Z_tos, __ stackTop()); __ pop_l(); break; 1492 case _xor : __ z_xg(Z_tos, __ stackTop()); __ pop_l(); break; 1493 default : ShouldNotReachHere(); break; 1494 } 1495 return; 1496 } 1497 1498 // Common part of idiv/irem. 1499 static void idiv_helper(InterpreterMacroAssembler * _masm, address exception) { 1500 NearLabel not_null; 1501 1502 // Use register pair Z_tmp_1, Z_tmp_2 for DIVIDE SINGLE. 1503 assert(Z_tmp_1->successor() == Z_tmp_2, " need even/odd register pair for idiv/irem"); 1504 1505 // Get dividend. 1506 __ pop_i(Z_tmp_2); 1507 1508 // If divisor == 0 throw exception. 1509 __ compare32_and_branch(Z_tos, (intptr_t) 0, 1510 Assembler::bcondNotEqual, not_null ); 1511 __ load_absolute_address(Z_R1_scratch, exception); 1512 __ z_br(Z_R1_scratch); 1513 1514 __ bind(not_null); 1515 1516 __ z_lgfr(Z_tmp_2, Z_tmp_2); // Sign extend dividend. 1517 __ z_dsgfr(Z_tmp_1, Z_tos); // Do it. 1518 } 1519 1520 void TemplateTable::idiv() { 1521 transition(itos, itos); 1522 1523 idiv_helper(_masm, Interpreter::_throw_ArithmeticException_entry); 1524 __ z_llgfr(Z_tos, Z_tmp_2); // Result is in Z_tmp_2. 1525 } 1526 1527 void TemplateTable::irem() { 1528 transition(itos, itos); 1529 1530 idiv_helper(_masm, Interpreter::_throw_ArithmeticException_entry); 1531 __ z_llgfr(Z_tos, Z_tmp_1); // Result is in Z_tmp_1. 1532 } 1533 1534 void TemplateTable::lmul() { 1535 transition(ltos, ltos); 1536 1537 // Multiply with memory operand. 1538 __ z_msg(Z_tos, __ stackTop()); 1539 __ pop_l(); // Pop operand. 1540 } 1541 1542 // Common part of ldiv/lrem. 1543 // 1544 // Input: 1545 // Z_tos := the divisor (dividend still on stack) 1546 // 1547 // Updated registers: 1548 // Z_tmp_1 := pop_l() % Z_tos ; if is_ldiv == false 1549 // Z_tmp_2 := pop_l() / Z_tos ; if is_ldiv == true 1550 // 1551 static void ldiv_helper(InterpreterMacroAssembler * _masm, address exception, bool is_ldiv) { 1552 NearLabel not_null, done; 1553 1554 // Use register pair Z_tmp_1, Z_tmp_2 for DIVIDE SINGLE. 1555 assert(Z_tmp_1->successor() == Z_tmp_2, 1556 " need even/odd register pair for idiv/irem"); 1557 1558 // Get dividend. 1559 __ pop_l(Z_tmp_2); 1560 1561 // If divisor == 0 throw exception. 1562 __ compare64_and_branch(Z_tos, (intptr_t)0, Assembler::bcondNotEqual, not_null); 1563 __ load_absolute_address(Z_R1_scratch, exception); 1564 __ z_br(Z_R1_scratch); 1565 1566 __ bind(not_null); 1567 // Special case for dividend == 0x8000 and divisor == -1. 1568 if (is_ldiv) { 1569 // result := Z_tmp_2 := - dividend 1570 __ z_lcgr(Z_tmp_2, Z_tmp_2); 1571 } else { 1572 // result remainder := Z_tmp_1 := 0 1573 __ clear_reg(Z_tmp_1, true, false); // Don't set CC. 1574 } 1575 1576 // if divisor == -1 goto done 1577 __ compare64_and_branch(Z_tos, -1, Assembler::bcondEqual, done); 1578 if (is_ldiv) 1579 // Restore sign, because divisor != -1. 1580 __ z_lcgr(Z_tmp_2, Z_tmp_2); 1581 __ z_dsgr(Z_tmp_1, Z_tos); // Do it. 1582 __ bind(done); 1583 } 1584 1585 void TemplateTable::ldiv() { 1586 transition(ltos, ltos); 1587 1588 ldiv_helper(_masm, Interpreter::_throw_ArithmeticException_entry, true /*is_ldiv*/); 1589 __ z_lgr(Z_tos, Z_tmp_2); // Result is in Z_tmp_2. 1590 } 1591 1592 void TemplateTable::lrem() { 1593 transition(ltos, ltos); 1594 1595 ldiv_helper(_masm, Interpreter::_throw_ArithmeticException_entry, false /*is_ldiv*/); 1596 __ z_lgr(Z_tos, Z_tmp_1); // Result is in Z_tmp_1. 1597 } 1598 1599 void TemplateTable::lshl() { 1600 transition(itos, ltos); 1601 1602 // Z_tos: shift amount 1603 __ pop_l(Z_tmp_1); // Get shift value. 1604 __ z_sllg(Z_tos, Z_tmp_1, 0, Z_tos); 1605 } 1606 1607 void TemplateTable::lshr() { 1608 transition(itos, ltos); 1609 1610 // Z_tos: shift amount 1611 __ pop_l(Z_tmp_1); // Get shift value. 1612 __ z_srag(Z_tos, Z_tmp_1, 0, Z_tos); 1613 } 1614 1615 void TemplateTable::lushr() { 1616 transition(itos, ltos); 1617 1618 // Z_tos: shift amount 1619 __ pop_l(Z_tmp_1); // Get shift value. 1620 __ z_srlg(Z_tos, Z_tmp_1, 0, Z_tos); 1621 } 1622 1623 void TemplateTable::fop2(Operation op) { 1624 transition(ftos, ftos); 1625 1626 switch (op) { 1627 case add: 1628 // Add memory operand. 1629 __ z_aeb(Z_ftos, __ stackTop()); __ pop_f(); return; 1630 case sub: 1631 // Sub memory operand. 1632 __ z_ler(Z_F1, Z_ftos); // first operand 1633 __ pop_f(Z_ftos); // second operand from stack 1634 __ z_sebr(Z_ftos, Z_F1); 1635 return; 1636 case mul: 1637 // Multiply with memory operand. 1638 __ z_meeb(Z_ftos, __ stackTop()); __ pop_f(); return; 1639 case div: 1640 __ z_ler(Z_F1, Z_ftos); // first operand 1641 __ pop_f(Z_ftos); // second operand from stack 1642 __ z_debr(Z_ftos, Z_F1); 1643 return; 1644 case rem: 1645 // Do runtime call. 1646 __ z_ler(Z_FARG2, Z_ftos); // divisor 1647 __ pop_f(Z_FARG1); // dividend 1648 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::frem)); 1649 // Result should be in the right place (Z_ftos == Z_FRET). 1650 return; 1651 default: 1652 ShouldNotReachHere(); 1653 return; 1654 } 1655 } 1656 1657 void TemplateTable::dop2(Operation op) { 1658 transition(dtos, dtos); 1659 1660 switch (op) { 1661 case add: 1662 // Add memory operand. 1663 __ z_adb(Z_ftos, __ stackTop()); __ pop_d(); return; 1664 case sub: 1665 // Sub memory operand. 1666 __ z_ldr(Z_F1, Z_ftos); // first operand 1667 __ pop_d(Z_ftos); // second operand from stack 1668 __ z_sdbr(Z_ftos, Z_F1); 1669 return; 1670 case mul: 1671 // Multiply with memory operand. 1672 __ z_mdb(Z_ftos, __ stackTop()); __ pop_d(); return; 1673 case div: 1674 __ z_ldr(Z_F1, Z_ftos); // first operand 1675 __ pop_d(Z_ftos); // second operand from stack 1676 __ z_ddbr(Z_ftos, Z_F1); 1677 return; 1678 case rem: 1679 // Do runtime call. 1680 __ z_ldr(Z_FARG2, Z_ftos); // divisor 1681 __ pop_d(Z_FARG1); // dividend 1682 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::drem)); 1683 // Result should be in the right place (Z_ftos == Z_FRET). 1684 return; 1685 default: 1686 ShouldNotReachHere(); 1687 return; 1688 } 1689 } 1690 1691 void TemplateTable::ineg() { 1692 transition(itos, itos); 1693 __ z_lcr(Z_tos); 1694 } 1695 1696 void TemplateTable::lneg() { 1697 transition(ltos, ltos); 1698 __ z_lcgr(Z_tos); 1699 } 1700 1701 void TemplateTable::fneg() { 1702 transition(ftos, ftos); 1703 __ z_lcebr(Z_ftos, Z_ftos); 1704 } 1705 1706 void TemplateTable::dneg() { 1707 transition(dtos, dtos); 1708 __ z_lcdbr(Z_ftos, Z_ftos); 1709 } 1710 1711 void TemplateTable::iinc() { 1712 transition(vtos, vtos); 1713 1714 Address local; 1715 __ z_lb(Z_R0_scratch, at_bcp(2)); // Get constant. 1716 locals_index(Z_R1_scratch); 1717 local = iaddress(_masm, Z_R1_scratch); 1718 __ z_a(Z_R0_scratch, local); 1719 __ reg2mem_opt(Z_R0_scratch, local, false); 1720 } 1721 1722 void TemplateTable::wide_iinc() { 1723 transition(vtos, vtos); 1724 1725 // Z_tmp_1 := increment 1726 __ get_2_byte_integer_at_bcp(Z_tmp_1, 4, InterpreterMacroAssembler::Signed); 1727 // Z_R1_scratch := index of local to increment 1728 locals_index_wide(Z_tmp_2); 1729 // Load, increment, and store. 1730 __ access_local_int(Z_tmp_2, Z_tos); 1731 __ z_agr(Z_tos, Z_tmp_1); 1732 // Shifted index is still in Z_tmp_2. 1733 __ reg2mem_opt(Z_tos, Address(Z_locals, Z_tmp_2), false); 1734 } 1735 1736 1737 void TemplateTable::convert() { 1738 // Checking 1739 #ifdef ASSERT 1740 TosState tos_in = ilgl; 1741 TosState tos_out = ilgl; 1742 1743 switch (bytecode()) { 1744 case Bytecodes::_i2l: 1745 case Bytecodes::_i2f: 1746 case Bytecodes::_i2d: 1747 case Bytecodes::_i2b: 1748 case Bytecodes::_i2c: 1749 case Bytecodes::_i2s: 1750 tos_in = itos; 1751 break; 1752 case Bytecodes::_l2i: 1753 case Bytecodes::_l2f: 1754 case Bytecodes::_l2d: 1755 tos_in = ltos; 1756 break; 1757 case Bytecodes::_f2i: 1758 case Bytecodes::_f2l: 1759 case Bytecodes::_f2d: 1760 tos_in = ftos; 1761 break; 1762 case Bytecodes::_d2i: 1763 case Bytecodes::_d2l: 1764 case Bytecodes::_d2f: 1765 tos_in = dtos; 1766 break; 1767 default : 1768 ShouldNotReachHere(); 1769 } 1770 switch (bytecode()) { 1771 case Bytecodes::_l2i: 1772 case Bytecodes::_f2i: 1773 case Bytecodes::_d2i: 1774 case Bytecodes::_i2b: 1775 case Bytecodes::_i2c: 1776 case Bytecodes::_i2s: 1777 tos_out = itos; 1778 break; 1779 case Bytecodes::_i2l: 1780 case Bytecodes::_f2l: 1781 case Bytecodes::_d2l: 1782 tos_out = ltos; 1783 break; 1784 case Bytecodes::_i2f: 1785 case Bytecodes::_l2f: 1786 case Bytecodes::_d2f: 1787 tos_out = ftos; 1788 break; 1789 case Bytecodes::_i2d: 1790 case Bytecodes::_l2d: 1791 case Bytecodes::_f2d: 1792 tos_out = dtos; 1793 break; 1794 default : 1795 ShouldNotReachHere(); 1796 } 1797 1798 transition(tos_in, tos_out); 1799 #endif // ASSERT 1800 1801 // Conversion 1802 Label done; 1803 switch (bytecode()) { 1804 case Bytecodes::_i2l: 1805 __ z_lgfr(Z_tos, Z_tos); 1806 return; 1807 case Bytecodes::_i2f: 1808 __ z_cefbr(Z_ftos, Z_tos); 1809 return; 1810 case Bytecodes::_i2d: 1811 __ z_cdfbr(Z_ftos, Z_tos); 1812 return; 1813 case Bytecodes::_i2b: 1814 // Sign extend least significant byte. 1815 __ move_reg_if_needed(Z_tos, T_BYTE, Z_tos, T_INT); 1816 return; 1817 case Bytecodes::_i2c: 1818 // Zero extend 2 least significant bytes. 1819 __ move_reg_if_needed(Z_tos, T_CHAR, Z_tos, T_INT); 1820 return; 1821 case Bytecodes::_i2s: 1822 // Sign extend 2 least significant bytes. 1823 __ move_reg_if_needed(Z_tos, T_SHORT, Z_tos, T_INT); 1824 return; 1825 case Bytecodes::_l2i: 1826 // Sign-extend not needed here, upper 4 bytes of int value in register are ignored. 1827 return; 1828 case Bytecodes::_l2f: 1829 __ z_cegbr(Z_ftos, Z_tos); 1830 return; 1831 case Bytecodes::_l2d: 1832 __ z_cdgbr(Z_ftos, Z_tos); 1833 return; 1834 case Bytecodes::_f2i: 1835 case Bytecodes::_f2l: 1836 __ clear_reg(Z_tos, true, false); // Don't set CC. 1837 __ z_cebr(Z_ftos, Z_ftos); 1838 __ z_brno(done); // NaN -> 0 1839 if (bytecode() == Bytecodes::_f2i) 1840 __ z_cfebr(Z_tos, Z_ftos, Assembler::to_zero); 1841 else // bytecode() == Bytecodes::_f2l 1842 __ z_cgebr(Z_tos, Z_ftos, Assembler::to_zero); 1843 break; 1844 case Bytecodes::_f2d: 1845 __ move_freg_if_needed(Z_ftos, T_DOUBLE, Z_ftos, T_FLOAT); 1846 return; 1847 case Bytecodes::_d2i: 1848 case Bytecodes::_d2l: 1849 __ clear_reg(Z_tos, true, false); // Ddon't set CC. 1850 __ z_cdbr(Z_ftos, Z_ftos); 1851 __ z_brno(done); // NaN -> 0 1852 if (bytecode() == Bytecodes::_d2i) 1853 __ z_cfdbr(Z_tos, Z_ftos, Assembler::to_zero); 1854 else // Bytecodes::_d2l 1855 __ z_cgdbr(Z_tos, Z_ftos, Assembler::to_zero); 1856 break; 1857 case Bytecodes::_d2f: 1858 __ move_freg_if_needed(Z_ftos, T_FLOAT, Z_ftos, T_DOUBLE); 1859 return; 1860 default: 1861 ShouldNotReachHere(); 1862 } 1863 __ bind(done); 1864 } 1865 1866 void TemplateTable::lcmp() { 1867 transition(ltos, itos); 1868 1869 Label done; 1870 Register val1 = Z_R0_scratch; 1871 Register val2 = Z_R1_scratch; 1872 1873 if (VM_Version::has_LoadStoreConditional()) { 1874 __ pop_l(val1); // pop value 1. 1875 __ z_lghi(val2, -1); // lt value 1876 __ z_cgr(val1, Z_tos); // Compare with Z_tos (value 2). Protect CC under all circumstances. 1877 __ z_lghi(val1, 1); // gt value 1878 __ z_lghi(Z_tos, 0); // eq value 1879 1880 __ z_locgr(Z_tos, val1, Assembler::bcondHigh); 1881 __ z_locgr(Z_tos, val2, Assembler::bcondLow); 1882 } else { 1883 __ pop_l(val1); // Pop value 1. 1884 __ z_cgr(val1, Z_tos); // Compare with Z_tos (value 2). Protect CC under all circumstances. 1885 1886 __ z_lghi(Z_tos, 0); // eq value 1887 __ z_bre(done); 1888 1889 __ z_lghi(Z_tos, 1); // gt value 1890 __ z_brh(done); 1891 1892 __ z_lghi(Z_tos, -1); // lt value 1893 } 1894 1895 __ bind(done); 1896 } 1897 1898 1899 void TemplateTable::float_cmp(bool is_float, int unordered_result) { 1900 Label done; 1901 1902 if (is_float) { 1903 __ pop_f(Z_FARG2); 1904 __ z_cebr(Z_FARG2, Z_ftos); 1905 } else { 1906 __ pop_d(Z_FARG2); 1907 __ z_cdbr(Z_FARG2, Z_ftos); 1908 } 1909 1910 if (VM_Version::has_LoadStoreConditional()) { 1911 Register one = Z_R0_scratch; 1912 Register minus_one = Z_R1_scratch; 1913 __ z_lghi(minus_one, -1); 1914 __ z_lghi(one, 1); 1915 __ z_lghi(Z_tos, 0); 1916 __ z_locgr(Z_tos, one, unordered_result == 1 ? Assembler::bcondHighOrNotOrdered : Assembler::bcondHigh); 1917 __ z_locgr(Z_tos, minus_one, unordered_result == 1 ? Assembler::bcondLow : Assembler::bcondLowOrNotOrdered); 1918 } else { 1919 // Z_FARG2 == Z_ftos 1920 __ clear_reg(Z_tos, false, false); 1921 __ z_bre(done); 1922 1923 // F_ARG2 > Z_Ftos, or unordered 1924 __ z_lhi(Z_tos, 1); 1925 __ z_brc(unordered_result == 1 ? Assembler::bcondHighOrNotOrdered : Assembler::bcondHigh, done); 1926 1927 // F_ARG2 < Z_FTOS, or unordered 1928 __ z_lhi(Z_tos, -1); 1929 1930 __ bind(done); 1931 } 1932 } 1933 1934 void TemplateTable::branch(bool is_jsr, bool is_wide) { 1935 const Register bumped_count = Z_tmp_1; 1936 const Register method = Z_tmp_2; 1937 const Register m_counters = Z_R1_scratch; 1938 const Register mdo = Z_tos; 1939 1940 BLOCK_COMMENT("TemplateTable::branch {"); 1941 __ get_method(method); 1942 __ profile_taken_branch(mdo, bumped_count); 1943 1944 const ByteSize ctr_offset = InvocationCounter::counter_offset(); 1945 const ByteSize be_offset = MethodCounters::backedge_counter_offset() + ctr_offset; 1946 const ByteSize inv_offset = MethodCounters::invocation_counter_offset() + ctr_offset; 1947 1948 // Get (wide) offset to disp. 1949 const Register disp = Z_ARG5; 1950 if (is_wide) { 1951 __ get_4_byte_integer_at_bcp(disp, 1); 1952 } else { 1953 __ get_2_byte_integer_at_bcp(disp, 1, InterpreterMacroAssembler::Signed); 1954 } 1955 1956 // Handle all the JSR stuff here, then exit. 1957 // It's much shorter and cleaner than intermingling with the 1958 // non-JSR normal-branch stuff occurring below. 1959 if (is_jsr) { 1960 // Compute return address as bci in Z_tos. 1961 __ z_lgr(Z_R1_scratch, Z_bcp); 1962 __ z_sg(Z_R1_scratch, Address(method, Method::const_offset())); 1963 __ add2reg(Z_tos, (is_wide ? 5 : 3) - in_bytes(ConstMethod::codes_offset()), Z_R1_scratch); 1964 1965 // Bump bcp to target of JSR. 1966 __ z_agr(Z_bcp, disp); 1967 // Push return address for "ret" on stack. 1968 __ push_ptr(Z_tos); 1969 // And away we go! 1970 __ dispatch_next(vtos, 0 , true); 1971 return; 1972 } 1973 1974 // Normal (non-jsr) branch handling. 1975 1976 // Bump bytecode pointer by displacement (take the branch). 1977 __ z_agr(Z_bcp, disp); 1978 1979 assert(UseLoopCounter || !UseOnStackReplacement, 1980 "on-stack-replacement requires loop counters"); 1981 1982 NearLabel backedge_counter_overflow; 1983 NearLabel profile_method; 1984 NearLabel dispatch; 1985 int increment = InvocationCounter::count_increment; 1986 1987 if (UseLoopCounter) { 1988 // Increment backedge counter for backward branches. 1989 // disp: target offset 1990 // Z_bcp: target bcp 1991 // Z_locals: locals pointer 1992 // 1993 // Count only if backward branch. 1994 __ compare32_and_branch(disp, (intptr_t)0, Assembler::bcondHigh, dispatch); 1995 1996 if (TieredCompilation) { 1997 Label noCounters; 1998 1999 if (ProfileInterpreter) { 2000 NearLabel no_mdo; 2001 2002 // Are we profiling? 2003 __ load_and_test_long(mdo, Address(method, Method::method_data_offset())); 2004 __ branch_optimized(Assembler::bcondZero, no_mdo); 2005 2006 // Increment the MDO backedge counter. 2007 const Address mdo_backedge_counter(mdo, MethodData::backedge_counter_offset() + InvocationCounter::counter_offset()); 2008 2009 const Address mask(mdo, MethodData::backedge_mask_offset()); 2010 __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, 2011 Z_ARG2, false, Assembler::bcondZero, 2012 UseOnStackReplacement ? &backedge_counter_overflow : NULL); 2013 __ z_bru(dispatch); 2014 __ bind(no_mdo); 2015 } 2016 2017 // Increment backedge counter in MethodCounters*. 2018 __ get_method_counters(method, m_counters, noCounters); 2019 const Address mask(m_counters, MethodCounters::backedge_mask_offset()); 2020 __ increment_mask_and_jump(Address(m_counters, be_offset), 2021 increment, mask, 2022 Z_ARG2, false, Assembler::bcondZero, 2023 UseOnStackReplacement ? &backedge_counter_overflow : NULL); 2024 __ bind(noCounters); 2025 } else { 2026 Register counter = Z_tos; 2027 Label noCounters; 2028 // Get address of MethodCounters object. 2029 __ get_method_counters(method, m_counters, noCounters); 2030 // Increment backedge counter. 2031 __ increment_backedge_counter(m_counters, counter); 2032 2033 if (ProfileInterpreter) { 2034 // Test to see if we should create a method data obj. 2035 __ z_cl(counter, Address(m_counters, MethodCounters::interpreter_profile_limit_offset())); 2036 __ z_brl(dispatch); 2037 2038 // If no method data exists, go to profile method. 2039 __ test_method_data_pointer(Z_ARG4/*result unused*/, profile_method); 2040 2041 if (UseOnStackReplacement) { 2042 // Check for overflow against 'bumped_count' which is the MDO taken count. 2043 __ z_cl(bumped_count, Address(m_counters, MethodCounters::interpreter_backward_branch_limit_offset())); 2044 __ z_brl(dispatch); 2045 2046 // When ProfileInterpreter is on, the backedge_count comes 2047 // from the methodDataOop, which value does not get reset on 2048 // the call to frequency_counter_overflow(). To avoid 2049 // excessive calls to the overflow routine while the method is 2050 // being compiled, add a second test to make sure the overflow 2051 // function is called only once every overflow_frequency. 2052 const int overflow_frequency = 1024; 2053 __ and_imm(bumped_count, overflow_frequency - 1); 2054 __ z_brz(backedge_counter_overflow); 2055 2056 } 2057 } else { 2058 if (UseOnStackReplacement) { 2059 // Check for overflow against 'counter', which is the sum of the 2060 // counters. 2061 __ z_cl(counter, Address(m_counters, MethodCounters::interpreter_backward_branch_limit_offset())); 2062 __ z_brh(backedge_counter_overflow); 2063 } 2064 } 2065 __ bind(noCounters); 2066 } 2067 2068 __ bind(dispatch); 2069 } 2070 2071 // Pre-load the next target bytecode into rbx. 2072 __ z_llgc(Z_bytecode, Address(Z_bcp, (intptr_t) 0)); 2073 2074 // Continue with the bytecode @ target. 2075 // Z_tos: Return bci for jsr's, unused otherwise. 2076 // Z_bytecode: target bytecode 2077 // Z_bcp: target bcp 2078 __ dispatch_only(vtos, true); 2079 2080 // Out-of-line code runtime calls. 2081 if (UseLoopCounter) { 2082 if (ProfileInterpreter) { 2083 // Out-of-line code to allocate method data oop. 2084 __ bind(profile_method); 2085 2086 __ call_VM(noreg, 2087 CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 2088 __ z_llgc(Z_bytecode, Address(Z_bcp, (intptr_t) 0)); // Restore target bytecode. 2089 __ set_method_data_pointer_for_bcp(); 2090 __ z_bru(dispatch); 2091 } 2092 2093 if (UseOnStackReplacement) { 2094 2095 // invocation counter overflow 2096 __ bind(backedge_counter_overflow); 2097 2098 __ z_lcgr(Z_ARG2, disp); // Z_ARG2 := -disp 2099 __ z_agr(Z_ARG2, Z_bcp); // Z_ARG2 := branch target bcp - disp == branch bcp 2100 __ call_VM(noreg, 2101 CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), 2102 Z_ARG2); 2103 2104 // Z_RET: osr nmethod (osr ok) or NULL (osr not possible). 2105 __ compare64_and_branch(Z_RET, (intptr_t) 0, Assembler::bcondEqual, dispatch); 2106 2107 // Nmethod may have been invalidated (VM may block upon call_VM return). 2108 __ z_cliy(nmethod::state_offset(), Z_RET, nmethod::in_use); 2109 __ z_brne(dispatch); 2110 2111 // Migrate the interpreter frame off of the stack. 2112 2113 __ z_lgr(Z_tmp_1, Z_RET); // Save the nmethod. 2114 2115 call_VM(noreg, 2116 CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin)); 2117 2118 // Z_RET is OSR buffer, move it to expected parameter location. 2119 __ lgr_if_needed(Z_ARG1, Z_RET); 2120 2121 // Pop the interpreter frame ... 2122 __ pop_interpreter_frame(Z_R14, Z_ARG2/*tmp1*/, Z_ARG3/*tmp2*/); 2123 2124 // ... and begin the OSR nmethod. 2125 __ z_lg(Z_R1_scratch, Address(Z_tmp_1, nmethod::osr_entry_point_offset())); 2126 __ z_br(Z_R1_scratch); 2127 } 2128 } 2129 BLOCK_COMMENT("} TemplateTable::branch"); 2130 } 2131 2132 void TemplateTable::if_0cmp(Condition cc) { 2133 transition(itos, vtos); 2134 2135 // Assume branch is more often taken than not (loops use backward branches). 2136 NearLabel not_taken; 2137 __ compare32_and_branch(Z_tos, (intptr_t) 0, j_not(cc), not_taken); 2138 branch(false, false); 2139 __ bind(not_taken); 2140 __ profile_not_taken_branch(Z_tos); 2141 } 2142 2143 void TemplateTable::if_icmp(Condition cc) { 2144 transition(itos, vtos); 2145 2146 // Assume branch is more often taken than not (loops use backward branches). 2147 NearLabel not_taken; 2148 __ pop_i(Z_R0_scratch); 2149 __ compare32_and_branch(Z_R0_scratch, Z_tos, j_not(cc), not_taken); 2150 branch(false, false); 2151 __ bind(not_taken); 2152 __ profile_not_taken_branch(Z_tos); 2153 } 2154 2155 void TemplateTable::if_nullcmp(Condition cc) { 2156 transition(atos, vtos); 2157 2158 // Assume branch is more often taken than not (loops use backward branches) . 2159 NearLabel not_taken; 2160 __ compare64_and_branch(Z_tos, (intptr_t) 0, j_not(cc), not_taken); 2161 branch(false, false); 2162 __ bind(not_taken); 2163 __ profile_not_taken_branch(Z_tos); 2164 } 2165 2166 void TemplateTable::if_acmp(Condition cc) { 2167 transition(atos, vtos); 2168 // Assume branch is more often taken than not (loops use backward branches). 2169 NearLabel not_taken; 2170 __ pop_ptr(Z_ARG2); 2171 __ verify_oop(Z_ARG2); 2172 __ verify_oop(Z_tos); 2173 __ compareU64_and_branch(Z_tos, Z_ARG2, j_not(cc), not_taken); 2174 branch(false, false); 2175 __ bind(not_taken); 2176 __ profile_not_taken_branch(Z_ARG3); 2177 } 2178 2179 void TemplateTable::ret() { 2180 transition(vtos, vtos); 2181 2182 locals_index(Z_tmp_1); 2183 // Get return bci, compute return bcp. Must load 64 bits. 2184 __ mem2reg_opt(Z_tmp_1, iaddress(_masm, Z_tmp_1)); 2185 __ profile_ret(Z_tmp_1, Z_tmp_2); 2186 __ get_method(Z_tos); 2187 __ mem2reg_opt(Z_R1_scratch, Address(Z_tos, Method::const_offset())); 2188 __ load_address(Z_bcp, Address(Z_R1_scratch, Z_tmp_1, ConstMethod::codes_offset())); 2189 __ dispatch_next(vtos, 0 , true); 2190 } 2191 2192 void TemplateTable::wide_ret() { 2193 transition(vtos, vtos); 2194 2195 locals_index_wide(Z_tmp_1); 2196 // Get return bci, compute return bcp. 2197 __ mem2reg_opt(Z_tmp_1, aaddress(_masm, Z_tmp_1)); 2198 __ profile_ret(Z_tmp_1, Z_tmp_2); 2199 __ get_method(Z_tos); 2200 __ mem2reg_opt(Z_R1_scratch, Address(Z_tos, Method::const_offset())); 2201 __ load_address(Z_bcp, Address(Z_R1_scratch, Z_tmp_1, ConstMethod::codes_offset())); 2202 __ dispatch_next(vtos, 0, true); 2203 } 2204 2205 void TemplateTable::tableswitch () { 2206 transition(itos, vtos); 2207 2208 NearLabel default_case, continue_execution; 2209 Register bcp = Z_ARG5; 2210 // Align bcp. 2211 __ load_address(bcp, at_bcp(BytesPerInt)); 2212 __ z_nill(bcp, (-BytesPerInt) & 0xffff); 2213 2214 // Load lo & hi. 2215 Register low = Z_tmp_1; 2216 Register high = Z_tmp_2; 2217 2218 // Load low into 64 bits, since used for address calculation. 2219 __ mem2reg_signed_opt(low, Address(bcp, BytesPerInt)); 2220 __ mem2reg_opt(high, Address(bcp, 2 * BytesPerInt), false); 2221 // Sign extend "label" value for address calculation. 2222 __ z_lgfr(Z_tos, Z_tos); 2223 2224 // Check against lo & hi. 2225 __ compare32_and_branch(Z_tos, low, Assembler::bcondLow, default_case); 2226 __ compare32_and_branch(Z_tos, high, Assembler::bcondHigh, default_case); 2227 2228 // Lookup dispatch offset. 2229 __ z_sgr(Z_tos, low); 2230 Register jump_table_offset = Z_ARG3; 2231 // Index2offset; index in Z_tos is killed by profile_switch_case. 2232 __ z_sllg(jump_table_offset, Z_tos, LogBytesPerInt); 2233 __ profile_switch_case(Z_tos, Z_ARG4 /*tmp for mdp*/, low/*tmp*/, Z_bytecode/*tmp*/); 2234 2235 Register index = Z_tmp_2; 2236 2237 // Load index sign extended for addressing. 2238 __ mem2reg_signed_opt(index, Address(bcp, jump_table_offset, 3 * BytesPerInt)); 2239 2240 // Continue execution. 2241 __ bind(continue_execution); 2242 2243 // Load next bytecode. 2244 __ z_llgc(Z_bytecode, Address(Z_bcp, index)); 2245 __ z_agr(Z_bcp, index); // Advance bcp. 2246 __ dispatch_only(vtos, true); 2247 2248 // Handle default. 2249 __ bind(default_case); 2250 2251 __ profile_switch_default(Z_tos); 2252 __ mem2reg_signed_opt(index, Address(bcp)); 2253 __ z_bru(continue_execution); 2254 } 2255 2256 void TemplateTable::lookupswitch () { 2257 transition(itos, itos); 2258 __ stop("lookupswitch bytecode should have been rewritten"); 2259 } 2260 2261 void TemplateTable::fast_linearswitch () { 2262 transition(itos, vtos); 2263 2264 Label loop_entry, loop, found, continue_execution; 2265 Register bcp = Z_ARG5; 2266 2267 // Align bcp. 2268 __ load_address(bcp, at_bcp(BytesPerInt)); 2269 __ z_nill(bcp, (-BytesPerInt) & 0xffff); 2270 2271 // Start search with last case. 2272 Register current_case_offset = Z_tmp_1; 2273 2274 __ mem2reg_signed_opt(current_case_offset, Address(bcp, BytesPerInt)); 2275 __ z_sllg(current_case_offset, current_case_offset, LogBytesPerWord); // index2bytes 2276 __ z_bru(loop_entry); 2277 2278 // table search 2279 __ bind(loop); 2280 2281 __ z_c(Z_tos, Address(bcp, current_case_offset, 2 * BytesPerInt)); 2282 __ z_bre(found); 2283 2284 __ bind(loop_entry); 2285 __ z_aghi(current_case_offset, -2 * BytesPerInt); // Decrement. 2286 __ z_brnl(loop); 2287 2288 // default case 2289 Register offset = Z_tmp_2; 2290 2291 __ profile_switch_default(Z_tos); 2292 // Load offset sign extended for addressing. 2293 __ mem2reg_signed_opt(offset, Address(bcp)); 2294 __ z_bru(continue_execution); 2295 2296 // Entry found -> get offset. 2297 __ bind(found); 2298 __ mem2reg_signed_opt(offset, Address(bcp, current_case_offset, 3 * BytesPerInt)); 2299 // Profile that this case was taken. 2300 Register current_case_idx = Z_ARG4; 2301 __ z_srlg(current_case_idx, current_case_offset, LogBytesPerWord); // bytes2index 2302 __ profile_switch_case(current_case_idx, Z_tos, bcp, Z_bytecode); 2303 2304 // Continue execution. 2305 __ bind(continue_execution); 2306 2307 // Load next bytecode. 2308 __ z_llgc(Z_bytecode, Address(Z_bcp, offset, 0)); 2309 __ z_agr(Z_bcp, offset); // Advance bcp. 2310 __ dispatch_only(vtos, true); 2311 } 2312 2313 2314 void TemplateTable::fast_binaryswitch() { 2315 2316 transition(itos, vtos); 2317 2318 // Implementation using the following core algorithm: 2319 // 2320 // int binary_search(int key, LookupswitchPair* array, int n) { 2321 // // Binary search according to "Methodik des Programmierens" by 2322 // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. 2323 // int i = 0; 2324 // int j = n; 2325 // while (i+1 < j) { 2326 // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) 2327 // // with Q: for all i: 0 <= i < n: key < a[i] 2328 // // where a stands for the array and assuming that the (inexisting) 2329 // // element a[n] is infinitely big. 2330 // int h = (i + j) >> 1; 2331 // // i < h < j 2332 // if (key < array[h].fast_match()) { 2333 // j = h; 2334 // } else { 2335 // i = h; 2336 // } 2337 // } 2338 // // R: a[i] <= key < a[i+1] or Q 2339 // // (i.e., if key is within array, i is the correct index) 2340 // return i; 2341 // } 2342 2343 // Register allocation 2344 // Note: Since we use the indices in address operands, we do all the 2345 // computation in 64 bits. 2346 const Register key = Z_tos; // Already set (tosca). 2347 const Register array = Z_tmp_1; 2348 const Register i = Z_tmp_2; 2349 const Register j = Z_ARG5; 2350 const Register h = Z_ARG4; 2351 const Register temp = Z_R1_scratch; 2352 2353 // Find array start. 2354 __ load_address(array, at_bcp(3 * BytesPerInt)); 2355 __ z_nill(array, (-BytesPerInt) & 0xffff); // align 2356 2357 // Initialize i & j. 2358 __ clear_reg(i, true, false); // i = 0; Don't set CC. 2359 __ mem2reg_signed_opt(j, Address(array, -BytesPerInt)); // j = length(array); 2360 2361 // And start. 2362 Label entry; 2363 __ z_bru(entry); 2364 2365 // binary search loop 2366 { 2367 NearLabel loop; 2368 2369 __ bind(loop); 2370 2371 // int h = (i + j) >> 1; 2372 __ add2reg_with_index(h, 0, i, j); // h = i + j; 2373 __ z_srag(h, h, 1); // h = (i + j) >> 1; 2374 2375 // if (key < array[h].fast_match()) { 2376 // j = h; 2377 // } else { 2378 // i = h; 2379 // } 2380 2381 // Convert array[h].match to native byte-ordering before compare. 2382 __ z_sllg(temp, h, LogBytesPerWord); // index2bytes 2383 __ mem2reg_opt(temp, Address(array, temp), false); 2384 2385 NearLabel else_; 2386 2387 __ compare32_and_branch(key, temp, Assembler::bcondNotLow, else_); 2388 // j = h if (key < array[h].fast_match()) 2389 __ z_lgr(j, h); 2390 __ z_bru(entry); // continue 2391 2392 __ bind(else_); 2393 2394 // i = h if (key >= array[h].fast_match()) 2395 __ z_lgr(i, h); // and fallthrough 2396 2397 // while (i+1 < j) 2398 __ bind(entry); 2399 2400 // if (i + 1 < j) continue search 2401 __ add2reg(h, 1, i); 2402 __ compare64_and_branch(h, j, Assembler::bcondLow, loop); 2403 } 2404 2405 // End of binary search, result index is i (must check again!). 2406 NearLabel default_case; 2407 2408 // h is no longer needed, so use it to hold the byte offset. 2409 __ z_sllg(h, i, LogBytesPerWord); // index2bytes 2410 __ mem2reg_opt(temp, Address(array, h), false); 2411 __ compare32_and_branch(key, temp, Assembler::bcondNotEqual, default_case); 2412 2413 // entry found -> j = offset 2414 __ mem2reg_signed_opt(j, Address(array, h, BytesPerInt)); 2415 __ profile_switch_case(i, key, array, Z_bytecode); 2416 // Load next bytecode. 2417 __ z_llgc(Z_bytecode, Address(Z_bcp, j)); 2418 __ z_agr(Z_bcp, j); // Advance bcp. 2419 __ dispatch_only(vtos, true); 2420 2421 // default case -> j = default offset 2422 __ bind(default_case); 2423 2424 __ profile_switch_default(i); 2425 __ mem2reg_signed_opt(j, Address(array, -2 * BytesPerInt)); 2426 // Load next bytecode. 2427 __ z_llgc(Z_bytecode, Address(Z_bcp, j)); 2428 __ z_agr(Z_bcp, j); // Advance bcp. 2429 __ dispatch_only(vtos, true); 2430 } 2431 2432 void TemplateTable::_return(TosState state) { 2433 transition(state, state); 2434 assert(_desc->calls_vm(), 2435 "inconsistent calls_vm information"); // call in remove_activation 2436 2437 if (_desc->bytecode() == Bytecodes::_return_register_finalizer) { 2438 Register Rthis = Z_ARG2; 2439 Register Rklass = Z_ARG5; 2440 Label skip_register_finalizer; 2441 assert(state == vtos, "only valid state"); 2442 __ z_lg(Rthis, aaddress(0)); 2443 __ load_klass(Rklass, Rthis); 2444 __ testbit(Address(Rklass, Klass::access_flags_offset()), exact_log2(JVM_ACC_HAS_FINALIZER)); 2445 __ z_bfalse(skip_register_finalizer); 2446 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), Rthis); 2447 __ bind(skip_register_finalizer); 2448 } 2449 2450 if (SafepointMechanism::uses_thread_local_poll() && _desc->bytecode() != Bytecodes::_return_register_finalizer) { 2451 Label no_safepoint; 2452 const Address poll_byte_addr(Z_thread, in_bytes(Thread::polling_page_offset()) + 7 /* Big Endian */); 2453 __ z_tm(poll_byte_addr, SafepointMechanism::poll_bit()); 2454 __ z_braz(no_safepoint); 2455 __ push(state); 2456 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)); 2457 __ pop(state); 2458 __ bind(no_safepoint); 2459 } 2460 2461 if (state == itos) { 2462 // Narrow result if state is itos but result type is smaller. 2463 // Need to narrow in the return bytecode rather than in generate_return_entry 2464 // since compiled code callers expect the result to already be narrowed. 2465 __ narrow(Z_tos, Z_tmp_1); /* fall through */ 2466 } 2467 2468 __ remove_activation(state, Z_R14); 2469 __ z_br(Z_R14); 2470 } 2471 2472 // ---------------------------------------------------------------------------- 2473 // NOTE: Cpe_offset is already computed as byte offset, so we must not 2474 // shift it afterwards! 2475 void TemplateTable::resolve_cache_and_index(int byte_no, 2476 Register Rcache, 2477 Register cpe_offset, 2478 size_t index_size) { 2479 BLOCK_COMMENT("resolve_cache_and_index {"); 2480 NearLabel resolved; 2481 const Register bytecode_in_cpcache = Z_R1_scratch; 2482 const int total_f1_offset = in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f1_offset()); 2483 assert_different_registers(Rcache, cpe_offset, bytecode_in_cpcache); 2484 2485 Bytecodes::Code code = bytecode(); 2486 switch (code) { 2487 case Bytecodes::_nofast_getfield: code = Bytecodes::_getfield; break; 2488 case Bytecodes::_nofast_putfield: code = Bytecodes::_putfield; break; 2489 } 2490 2491 { 2492 assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range"); 2493 __ get_cache_and_index_and_bytecode_at_bcp(Rcache, cpe_offset, bytecode_in_cpcache, byte_no, 1, index_size); 2494 // Have we resolved this bytecode? 2495 __ compare32_and_branch(bytecode_in_cpcache, (int)code, Assembler::bcondEqual, resolved); 2496 } 2497 2498 // Resolve first time through. 2499 address entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_from_cache); 2500 __ load_const_optimized(Z_ARG2, (int) code); 2501 __ call_VM(noreg, entry, Z_ARG2); 2502 2503 // Update registers with resolved info. 2504 __ get_cache_and_index_at_bcp(Rcache, cpe_offset, 1, index_size); 2505 __ bind(resolved); 2506 BLOCK_COMMENT("} resolve_cache_and_index"); 2507 } 2508 2509 // The Rcache and index registers must be set before call. 2510 // Index is already a byte offset, don't shift! 2511 void TemplateTable::load_field_cp_cache_entry(Register obj, 2512 Register cache, 2513 Register index, 2514 Register off, 2515 Register flags, 2516 bool is_static = false) { 2517 assert_different_registers(cache, index, flags, off); 2518 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2519 2520 // Field offset 2521 __ mem2reg_opt(off, Address(cache, index, cp_base_offset + ConstantPoolCacheEntry::f2_offset())); 2522 // Flags. Must load 64 bits. 2523 __ mem2reg_opt(flags, Address(cache, index, cp_base_offset + ConstantPoolCacheEntry::flags_offset())); 2524 2525 // klass overwrite register 2526 if (is_static) { 2527 __ mem2reg_opt(obj, Address(cache, index, cp_base_offset + ConstantPoolCacheEntry::f1_offset())); 2528 __ mem2reg_opt(obj, Address(obj, Klass::java_mirror_offset())); 2529 __ resolve_oop_handle(obj); 2530 } 2531 } 2532 2533 void TemplateTable::load_invoke_cp_cache_entry(int byte_no, 2534 Register method, 2535 Register itable_index, 2536 Register flags, 2537 bool is_invokevirtual, 2538 bool is_invokevfinal, // unused 2539 bool is_invokedynamic) { 2540 BLOCK_COMMENT("load_invoke_cp_cache_entry {"); 2541 // Setup registers. 2542 const Register cache = Z_ARG1; 2543 const Register cpe_offset= flags; 2544 const ByteSize base_off = ConstantPoolCache::base_offset(); 2545 const ByteSize f1_off = ConstantPoolCacheEntry::f1_offset(); 2546 const ByteSize f2_off = ConstantPoolCacheEntry::f2_offset(); 2547 const ByteSize flags_off = ConstantPoolCacheEntry::flags_offset(); 2548 const int method_offset = in_bytes(base_off + ((byte_no == f2_byte) ? f2_off : f1_off)); 2549 const int flags_offset = in_bytes(base_off + flags_off); 2550 // Access constant pool cache fields. 2551 const int index_offset = in_bytes(base_off + f2_off); 2552 2553 assert_different_registers(method, itable_index, flags, cache); 2554 assert(is_invokevirtual == (byte_no == f2_byte), "is_invokevirtual flag redundant"); 2555 2556 if (is_invokevfinal) { 2557 // Already resolved. 2558 assert(itable_index == noreg, "register not used"); 2559 __ get_cache_and_index_at_bcp(cache, cpe_offset, 1); 2560 } else { 2561 // Need to resolve. 2562 resolve_cache_and_index(byte_no, cache, cpe_offset, is_invokedynamic ? sizeof(u4) : sizeof(u2)); 2563 } 2564 __ z_lg(method, Address(cache, cpe_offset, method_offset)); 2565 2566 if (itable_index != noreg) { 2567 __ z_lg(itable_index, Address(cache, cpe_offset, index_offset)); 2568 } 2569 2570 // Only load the lower 4 bytes and fill high bytes of flags with zeros. 2571 // Callers depend on this zero-extension!!! 2572 // Attention: overwrites cpe_offset == flags 2573 __ z_llgf(flags, Address(cache, cpe_offset, flags_offset + (BytesPerLong-BytesPerInt))); 2574 2575 BLOCK_COMMENT("} load_invoke_cp_cache_entry"); 2576 } 2577 2578 // The registers cache and index expected to be set before call. 2579 // Correct values of the cache and index registers are preserved. 2580 void TemplateTable::jvmti_post_field_access(Register cache, Register index, 2581 bool is_static, bool has_tos) { 2582 2583 // Do the JVMTI work here to avoid disturbing the register state below. 2584 // We use c_rarg registers here because we want to use the register used in 2585 // the call to the VM 2586 if (!JvmtiExport::can_post_field_access()) { 2587 return; 2588 } 2589 2590 // Check to see if a field access watch has been set before we 2591 // take the time to call into the VM. 2592 Label exit; 2593 assert_different_registers(cache, index, Z_tos); 2594 __ load_absolute_address(Z_tos, (address)JvmtiExport::get_field_access_count_addr()); 2595 __ load_and_test_int(Z_R0, Address(Z_tos)); 2596 __ z_brz(exit); 2597 2598 // Index is returned as byte offset, do not shift! 2599 __ get_cache_and_index_at_bcp(Z_ARG3, Z_R1_scratch, 1); 2600 2601 // cache entry pointer 2602 __ add2reg_with_index(Z_ARG3, 2603 in_bytes(ConstantPoolCache::base_offset()), 2604 Z_ARG3, Z_R1_scratch); 2605 2606 if (is_static) { 2607 __ clear_reg(Z_ARG2, true, false); // NULL object reference. Don't set CC. 2608 } else { 2609 __ mem2reg_opt(Z_ARG2, at_tos()); // Get object pointer without popping it. 2610 __ verify_oop(Z_ARG2); 2611 } 2612 // Z_ARG2: object pointer or NULL 2613 // Z_ARG3: cache entry pointer 2614 __ call_VM(noreg, 2615 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), 2616 Z_ARG2, Z_ARG3); 2617 __ get_cache_and_index_at_bcp(cache, index, 1); 2618 2619 __ bind(exit); 2620 } 2621 2622 void TemplateTable::pop_and_check_object(Register r) { 2623 __ pop_ptr(r); 2624 __ null_check(r); // for field access must check obj. 2625 __ verify_oop(r); 2626 } 2627 2628 void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2629 transition(vtos, vtos); 2630 2631 const Register cache = Z_tmp_1; 2632 const Register index = Z_tmp_2; 2633 const Register obj = Z_tmp_1; 2634 const Register off = Z_ARG2; 2635 const Register flags = Z_ARG1; 2636 const Register bc = Z_tmp_1; // Uses same reg as obj, so don't mix them. 2637 2638 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2639 jvmti_post_field_access(cache, index, is_static, false); 2640 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); 2641 2642 if (!is_static) { 2643 // Obj is on the stack. 2644 pop_and_check_object(obj); 2645 } 2646 2647 // Displacement is 0, so any store instruction will be fine on any CPU. 2648 const Address field(obj, off); 2649 2650 Label is_Byte, is_Bool, is_Int, is_Short, is_Char, 2651 is_Long, is_Float, is_Object, is_Double; 2652 Label is_badState8, is_badState9, is_badStateA, is_badStateB, 2653 is_badStateC, is_badStateD, is_badStateE, is_badStateF, 2654 is_badState; 2655 Label branchTable, atosHandler, Done; 2656 Register br_tab = Z_R1_scratch; 2657 bool do_rewrite = !is_static && (rc == may_rewrite); 2658 bool dont_rewrite = (is_static || (rc == may_not_rewrite)); 2659 2660 assert(do_rewrite == !dont_rewrite, "Oops, code is not fit for that"); 2661 assert(btos == 0, "change code, btos != 0"); 2662 2663 // Calculate branch table size. Generated code size depends on ASSERT and on bytecode rewriting. 2664 #ifdef ASSERT 2665 const unsigned int bsize = dont_rewrite ? BTB_MINSIZE*1 : BTB_MINSIZE*4; 2666 #else 2667 const unsigned int bsize = dont_rewrite ? BTB_MINSIZE*1 : BTB_MINSIZE*4; 2668 #endif 2669 2670 // Calculate address of branch table entry and branch there. 2671 { 2672 const int bit_shift = exact_log2(bsize); // Size of each branch table entry. 2673 const int r_bitpos = 63 - bit_shift; 2674 const int l_bitpos = r_bitpos - ConstantPoolCacheEntry::tos_state_bits + 1; 2675 const int n_rotate = (bit_shift-ConstantPoolCacheEntry::tos_state_shift); 2676 __ z_larl(br_tab, branchTable); 2677 __ rotate_then_insert(flags, flags, l_bitpos, r_bitpos, n_rotate, true); 2678 } 2679 __ z_bc(Assembler::bcondAlways, 0, flags, br_tab); 2680 2681 __ align_address(bsize); 2682 BIND(branchTable); 2683 2684 // btos 2685 BTB_BEGIN(is_Byte, bsize, "getfield_or_static:is_Byte"); 2686 __ z_lb(Z_tos, field); 2687 __ push(btos); 2688 // Rewrite bytecode to be faster. 2689 if (do_rewrite) { 2690 patch_bytecode(Bytecodes::_fast_bgetfield, bc, Z_ARG5); 2691 } 2692 __ z_bru(Done); 2693 BTB_END(is_Byte, bsize, "getfield_or_static:is_Byte"); 2694 2695 // ztos 2696 BTB_BEGIN(is_Bool, bsize, "getfield_or_static:is_Bool"); 2697 __ z_lb(Z_tos, field); 2698 __ push(ztos); 2699 // Rewrite bytecode to be faster. 2700 if (do_rewrite) { 2701 // Use btos rewriting, no truncating to t/f bit is needed for getfield. 2702 patch_bytecode(Bytecodes::_fast_bgetfield, bc, Z_ARG5); 2703 } 2704 __ z_bru(Done); 2705 BTB_END(is_Bool, bsize, "getfield_or_static:is_Bool"); 2706 2707 // ctos 2708 BTB_BEGIN(is_Char, bsize, "getfield_or_static:is_Char"); 2709 // Load into 64 bits, works on all CPUs. 2710 __ z_llgh(Z_tos, field); 2711 __ push(ctos); 2712 // Rewrite bytecode to be faster. 2713 if (do_rewrite) { 2714 patch_bytecode(Bytecodes::_fast_cgetfield, bc, Z_ARG5); 2715 } 2716 __ z_bru(Done); 2717 BTB_END(is_Char, bsize, "getfield_or_static:is_Char"); 2718 2719 // stos 2720 BTB_BEGIN(is_Short, bsize, "getfield_or_static:is_Short"); 2721 __ z_lh(Z_tos, field); 2722 __ push(stos); 2723 // Rewrite bytecode to be faster. 2724 if (do_rewrite) { 2725 patch_bytecode(Bytecodes::_fast_sgetfield, bc, Z_ARG5); 2726 } 2727 __ z_bru(Done); 2728 BTB_END(is_Short, bsize, "getfield_or_static:is_Short"); 2729 2730 // itos 2731 BTB_BEGIN(is_Int, bsize, "getfield_or_static:is_Int"); 2732 __ mem2reg_opt(Z_tos, field, false); 2733 __ push(itos); 2734 // Rewrite bytecode to be faster. 2735 if (do_rewrite) { 2736 patch_bytecode(Bytecodes::_fast_igetfield, bc, Z_ARG5); 2737 } 2738 __ z_bru(Done); 2739 BTB_END(is_Int, bsize, "getfield_or_static:is_Int"); 2740 2741 // ltos 2742 BTB_BEGIN(is_Long, bsize, "getfield_or_static:is_Long"); 2743 __ mem2reg_opt(Z_tos, field); 2744 __ push(ltos); 2745 // Rewrite bytecode to be faster. 2746 if (do_rewrite) { 2747 patch_bytecode(Bytecodes::_fast_lgetfield, bc, Z_ARG5); 2748 } 2749 __ z_bru(Done); 2750 BTB_END(is_Long, bsize, "getfield_or_static:is_Long"); 2751 2752 // ftos 2753 BTB_BEGIN(is_Float, bsize, "getfield_or_static:is_Float"); 2754 __ mem2freg_opt(Z_ftos, field, false); 2755 __ push(ftos); 2756 // Rewrite bytecode to be faster. 2757 if (do_rewrite) { 2758 patch_bytecode(Bytecodes::_fast_fgetfield, bc, Z_ARG5); 2759 } 2760 __ z_bru(Done); 2761 BTB_END(is_Float, bsize, "getfield_or_static:is_Float"); 2762 2763 // dtos 2764 BTB_BEGIN(is_Double, bsize, "getfield_or_static:is_Double"); 2765 __ mem2freg_opt(Z_ftos, field); 2766 __ push(dtos); 2767 // Rewrite bytecode to be faster. 2768 if (do_rewrite) { 2769 patch_bytecode(Bytecodes::_fast_dgetfield, bc, Z_ARG5); 2770 } 2771 __ z_bru(Done); 2772 BTB_END(is_Double, bsize, "getfield_or_static:is_Double"); 2773 2774 // atos 2775 BTB_BEGIN(is_Object, bsize, "getfield_or_static:is_Object"); 2776 __ z_bru(atosHandler); 2777 BTB_END(is_Object, bsize, "getfield_or_static:is_Object"); 2778 2779 // Bad state detection comes at no extra runtime cost. 2780 BTB_BEGIN(is_badState8, bsize, "getfield_or_static:is_badState8"); 2781 __ z_illtrap(); 2782 __ z_bru(is_badState); 2783 BTB_END( is_badState8, bsize, "getfield_or_static:is_badState8"); 2784 BTB_BEGIN(is_badState9, bsize, "getfield_or_static:is_badState9"); 2785 __ z_illtrap(); 2786 __ z_bru(is_badState); 2787 BTB_END( is_badState9, bsize, "getfield_or_static:is_badState9"); 2788 BTB_BEGIN(is_badStateA, bsize, "getfield_or_static:is_badStateA"); 2789 __ z_illtrap(); 2790 __ z_bru(is_badState); 2791 BTB_END( is_badStateA, bsize, "getfield_or_static:is_badStateA"); 2792 BTB_BEGIN(is_badStateB, bsize, "getfield_or_static:is_badStateB"); 2793 __ z_illtrap(); 2794 __ z_bru(is_badState); 2795 BTB_END( is_badStateB, bsize, "getfield_or_static:is_badStateB"); 2796 BTB_BEGIN(is_badStateC, bsize, "getfield_or_static:is_badStateC"); 2797 __ z_illtrap(); 2798 __ z_bru(is_badState); 2799 BTB_END( is_badStateC, bsize, "getfield_or_static:is_badStateC"); 2800 BTB_BEGIN(is_badStateD, bsize, "getfield_or_static:is_badStateD"); 2801 __ z_illtrap(); 2802 __ z_bru(is_badState); 2803 BTB_END( is_badStateD, bsize, "getfield_or_static:is_badStateD"); 2804 BTB_BEGIN(is_badStateE, bsize, "getfield_or_static:is_badStateE"); 2805 __ z_illtrap(); 2806 __ z_bru(is_badState); 2807 BTB_END( is_badStateE, bsize, "getfield_or_static:is_badStateE"); 2808 BTB_BEGIN(is_badStateF, bsize, "getfield_or_static:is_badStateF"); 2809 __ z_illtrap(); 2810 __ z_bru(is_badState); 2811 BTB_END( is_badStateF, bsize, "getfield_or_static:is_badStateF"); 2812 2813 __ align_address(64); 2814 BIND(is_badState); // Do this outside branch table. Needs a lot of space. 2815 { 2816 unsigned int b_off = __ offset(); 2817 if (is_static) { 2818 __ stop_static("Bad state in getstatic"); 2819 } else { 2820 __ stop_static("Bad state in getfield"); 2821 } 2822 unsigned int e_off = __ offset(); 2823 } 2824 2825 __ align_address(64); 2826 BIND(atosHandler); // Oops are really complicated to handle. 2827 // There is a lot of code generated. 2828 // Therefore: generate the handler outside of branch table. 2829 // There is no performance penalty. The additional branch 2830 // to here is compensated for by the fallthru to "Done". 2831 { 2832 unsigned int b_off = __ offset(); 2833 __ load_heap_oop(Z_tos, field); 2834 __ verify_oop(Z_tos); 2835 __ push(atos); 2836 if (do_rewrite) { 2837 patch_bytecode(Bytecodes::_fast_agetfield, bc, Z_ARG5); 2838 } 2839 unsigned int e_off = __ offset(); 2840 } 2841 2842 BIND(Done); 2843 } 2844 2845 void TemplateTable::getfield(int byte_no) { 2846 BLOCK_COMMENT("getfield {"); 2847 getfield_or_static(byte_no, false); 2848 BLOCK_COMMENT("} getfield"); 2849 } 2850 2851 void TemplateTable::nofast_getfield(int byte_no) { 2852 getfield_or_static(byte_no, false, may_not_rewrite); 2853 } 2854 2855 void TemplateTable::getstatic(int byte_no) { 2856 BLOCK_COMMENT("getstatic {"); 2857 getfield_or_static(byte_no, true); 2858 BLOCK_COMMENT("} getstatic"); 2859 } 2860 2861 // The registers cache and index expected to be set before call. The 2862 // function may destroy various registers, just not the cache and 2863 // index registers. 2864 void TemplateTable::jvmti_post_field_mod(Register cache, 2865 Register index, bool is_static) { 2866 transition(vtos, vtos); 2867 2868 if (!JvmtiExport::can_post_field_modification()) { 2869 return; 2870 } 2871 2872 BLOCK_COMMENT("jvmti_post_field_mod {"); 2873 2874 // Check to see if a field modification watch has been set before 2875 // we take the time to call into the VM. 2876 Label L1; 2877 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 2878 assert_different_registers(cache, index, Z_tos); 2879 2880 __ load_absolute_address(Z_tos, (address)JvmtiExport::get_field_modification_count_addr()); 2881 __ load_and_test_int(Z_R0, Address(Z_tos)); 2882 __ z_brz(L1); 2883 2884 // Index is returned as byte offset, do not shift! 2885 __ get_cache_and_index_at_bcp(Z_ARG3, Z_R1_scratch, 1); 2886 2887 if (is_static) { 2888 // Life is simple. Null out the object pointer. 2889 __ clear_reg(Z_ARG2, true, false); // Don't set CC. 2890 } else { 2891 // Life is harder. The stack holds the value on top, followed by 2892 // the object. We don't know the size of the value, though. It 2893 // could be one or two words depending on its type. As a result, 2894 // we must find the type to determine where the object is. 2895 __ mem2reg_opt(Z_ARG4, 2896 Address(Z_ARG3, Z_R1_scratch, 2897 in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()) + 2898 (BytesPerLong - BytesPerInt)), 2899 false); 2900 __ z_srl(Z_ARG4, ConstantPoolCacheEntry::tos_state_shift); 2901 // Make sure we don't need to mask Z_ARG4 for tos_state after the above shift. 2902 ConstantPoolCacheEntry::verify_tos_state_shift(); 2903 __ mem2reg_opt(Z_ARG2, at_tos(1)); // Initially assume a one word jvalue. 2904 2905 NearLabel load_dtos, cont; 2906 2907 __ compareU32_and_branch(Z_ARG4, (intptr_t) ltos, 2908 Assembler::bcondNotEqual, load_dtos); 2909 __ mem2reg_opt(Z_ARG2, at_tos(2)); // ltos (two word jvalue) 2910 __ z_bru(cont); 2911 2912 __ bind(load_dtos); 2913 __ compareU32_and_branch(Z_ARG4, (intptr_t)dtos, Assembler::bcondNotEqual, cont); 2914 __ mem2reg_opt(Z_ARG2, at_tos(2)); // dtos (two word jvalue) 2915 2916 __ bind(cont); 2917 } 2918 // cache entry pointer 2919 2920 __ add2reg_with_index(Z_ARG3, in_bytes(cp_base_offset), Z_ARG3, Z_R1_scratch); 2921 2922 // object(tos) 2923 __ load_address(Z_ARG4, Address(Z_esp, Interpreter::stackElementSize)); 2924 // Z_ARG2: object pointer set up above (NULL if static) 2925 // Z_ARG3: cache entry pointer 2926 // Z_ARG4: jvalue object on the stack 2927 __ call_VM(noreg, 2928 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), 2929 Z_ARG2, Z_ARG3, Z_ARG4); 2930 __ get_cache_and_index_at_bcp(cache, index, 1); 2931 2932 __ bind(L1); 2933 BLOCK_COMMENT("} jvmti_post_field_mod"); 2934 } 2935 2936 2937 void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteControl rc) { 2938 transition(vtos, vtos); 2939 2940 const Register cache = Z_tmp_1; 2941 const Register index = Z_ARG5; 2942 const Register obj = Z_tmp_1; 2943 const Register off = Z_tmp_2; 2944 const Register flags = Z_R1_scratch; 2945 const Register br_tab = Z_ARG5; 2946 const Register bc = Z_tmp_1; 2947 const Register oopStore_tmp1 = Z_R1_scratch; 2948 const Register oopStore_tmp2 = Z_ARG5; 2949 const Register oopStore_tmp3 = Z_R0_scratch; 2950 2951 resolve_cache_and_index(byte_no, cache, index, sizeof(u2)); 2952 jvmti_post_field_mod(cache, index, is_static); 2953 load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); 2954 // begin of life for: 2955 // obj, off long life range 2956 // flags short life range, up to branch into branch table 2957 // end of life for: 2958 // cache, index 2959 2960 const Address field(obj, off); 2961 Label is_Byte, is_Bool, is_Int, is_Short, is_Char, 2962 is_Long, is_Float, is_Object, is_Double; 2963 Label is_badState8, is_badState9, is_badStateA, is_badStateB, 2964 is_badStateC, is_badStateD, is_badStateE, is_badStateF, 2965 is_badState; 2966 Label branchTable, atosHandler, Done; 2967 bool do_rewrite = !is_static && (rc == may_rewrite); 2968 bool dont_rewrite = (is_static || (rc == may_not_rewrite)); 2969 2970 assert(do_rewrite == !dont_rewrite, "Oops, code is not fit for that"); 2971 2972 assert(btos == 0, "change code, btos != 0"); 2973 2974 #ifdef ASSERT 2975 const unsigned int bsize = is_static ? BTB_MINSIZE*1 : BTB_MINSIZE*4; 2976 #else 2977 const unsigned int bsize = is_static ? BTB_MINSIZE*1 : BTB_MINSIZE*8; 2978 #endif 2979 2980 // Calculate address of branch table entry and branch there. 2981 { 2982 const int bit_shift = exact_log2(bsize); // Size of each branch table entry. 2983 const int r_bitpos = 63 - bit_shift; 2984 const int l_bitpos = r_bitpos - ConstantPoolCacheEntry::tos_state_bits + 1; 2985 const int n_rotate = (bit_shift-ConstantPoolCacheEntry::tos_state_shift); 2986 __ z_larl(br_tab, branchTable); 2987 __ rotate_then_insert(flags, flags, l_bitpos, r_bitpos, n_rotate, true); 2988 __ z_bc(Assembler::bcondAlways, 0, flags, br_tab); 2989 } 2990 // end of life for: 2991 // flags, br_tab 2992 2993 __ align_address(bsize); 2994 BIND(branchTable); 2995 2996 // btos 2997 BTB_BEGIN(is_Byte, bsize, "putfield_or_static:is_Byte"); 2998 __ pop(btos); 2999 if (!is_static) { 3000 pop_and_check_object(obj); 3001 } 3002 __ z_stc(Z_tos, field); 3003 if (do_rewrite) { 3004 patch_bytecode(Bytecodes::_fast_bputfield, bc, Z_ARG5, true, byte_no); 3005 } 3006 __ z_bru(Done); 3007 BTB_END( is_Byte, bsize, "putfield_or_static:is_Byte"); 3008 3009 // ztos 3010 BTB_BEGIN(is_Bool, bsize, "putfield_or_static:is_Bool"); 3011 __ pop(ztos); 3012 if (!is_static) { 3013 pop_and_check_object(obj); 3014 } 3015 __ z_nilf(Z_tos, 0x1); 3016 __ z_stc(Z_tos, field); 3017 if (do_rewrite) { 3018 patch_bytecode(Bytecodes::_fast_zputfield, bc, Z_ARG5, true, byte_no); 3019 } 3020 __ z_bru(Done); 3021 BTB_END(is_Bool, bsize, "putfield_or_static:is_Bool"); 3022 3023 // ctos 3024 BTB_BEGIN(is_Char, bsize, "putfield_or_static:is_Char"); 3025 __ pop(ctos); 3026 if (!is_static) { 3027 pop_and_check_object(obj); 3028 } 3029 __ z_sth(Z_tos, field); 3030 if (do_rewrite) { 3031 patch_bytecode(Bytecodes::_fast_cputfield, bc, Z_ARG5, true, byte_no); 3032 } 3033 __ z_bru(Done); 3034 BTB_END( is_Char, bsize, "putfield_or_static:is_Char"); 3035 3036 // stos 3037 BTB_BEGIN(is_Short, bsize, "putfield_or_static:is_Short"); 3038 __ pop(stos); 3039 if (!is_static) { 3040 pop_and_check_object(obj); 3041 } 3042 __ z_sth(Z_tos, field); 3043 if (do_rewrite) { 3044 patch_bytecode(Bytecodes::_fast_sputfield, bc, Z_ARG5, true, byte_no); 3045 } 3046 __ z_bru(Done); 3047 BTB_END( is_Short, bsize, "putfield_or_static:is_Short"); 3048 3049 // itos 3050 BTB_BEGIN(is_Int, bsize, "putfield_or_static:is_Int"); 3051 __ pop(itos); 3052 if (!is_static) { 3053 pop_and_check_object(obj); 3054 } 3055 __ reg2mem_opt(Z_tos, field, false); 3056 if (do_rewrite) { 3057 patch_bytecode(Bytecodes::_fast_iputfield, bc, Z_ARG5, true, byte_no); 3058 } 3059 __ z_bru(Done); 3060 BTB_END( is_Int, bsize, "putfield_or_static:is_Int"); 3061 3062 // ltos 3063 BTB_BEGIN(is_Long, bsize, "putfield_or_static:is_Long"); 3064 __ pop(ltos); 3065 if (!is_static) { 3066 pop_and_check_object(obj); 3067 } 3068 __ reg2mem_opt(Z_tos, field); 3069 if (do_rewrite) { 3070 patch_bytecode(Bytecodes::_fast_lputfield, bc, Z_ARG5, true, byte_no); 3071 } 3072 __ z_bru(Done); 3073 BTB_END( is_Long, bsize, "putfield_or_static:is_Long"); 3074 3075 // ftos 3076 BTB_BEGIN(is_Float, bsize, "putfield_or_static:is_Float"); 3077 __ pop(ftos); 3078 if (!is_static) { 3079 pop_and_check_object(obj); 3080 } 3081 __ freg2mem_opt(Z_ftos, field, false); 3082 if (do_rewrite) { 3083 patch_bytecode(Bytecodes::_fast_fputfield, bc, Z_ARG5, true, byte_no); 3084 } 3085 __ z_bru(Done); 3086 BTB_END( is_Float, bsize, "putfield_or_static:is_Float"); 3087 3088 // dtos 3089 BTB_BEGIN(is_Double, bsize, "putfield_or_static:is_Double"); 3090 __ pop(dtos); 3091 if (!is_static) { 3092 pop_and_check_object(obj); 3093 } 3094 __ freg2mem_opt(Z_ftos, field); 3095 if (do_rewrite) { 3096 patch_bytecode(Bytecodes::_fast_dputfield, bc, Z_ARG5, true, byte_no); 3097 } 3098 __ z_bru(Done); 3099 BTB_END( is_Double, bsize, "putfield_or_static:is_Double"); 3100 3101 // atos 3102 BTB_BEGIN(is_Object, bsize, "putfield_or_static:is_Object"); 3103 __ z_bru(atosHandler); 3104 BTB_END( is_Object, bsize, "putfield_or_static:is_Object"); 3105 3106 // Bad state detection comes at no extra runtime cost. 3107 BTB_BEGIN(is_badState8, bsize, "putfield_or_static:is_badState8"); 3108 __ z_illtrap(); 3109 __ z_bru(is_badState); 3110 BTB_END( is_badState8, bsize, "putfield_or_static:is_badState8"); 3111 BTB_BEGIN(is_badState9, bsize, "putfield_or_static:is_badState9"); 3112 __ z_illtrap(); 3113 __ z_bru(is_badState); 3114 BTB_END( is_badState9, bsize, "putfield_or_static:is_badState9"); 3115 BTB_BEGIN(is_badStateA, bsize, "putfield_or_static:is_badStateA"); 3116 __ z_illtrap(); 3117 __ z_bru(is_badState); 3118 BTB_END( is_badStateA, bsize, "putfield_or_static:is_badStateA"); 3119 BTB_BEGIN(is_badStateB, bsize, "putfield_or_static:is_badStateB"); 3120 __ z_illtrap(); 3121 __ z_bru(is_badState); 3122 BTB_END( is_badStateB, bsize, "putfield_or_static:is_badStateB"); 3123 BTB_BEGIN(is_badStateC, bsize, "putfield_or_static:is_badStateC"); 3124 __ z_illtrap(); 3125 __ z_bru(is_badState); 3126 BTB_END( is_badStateC, bsize, "putfield_or_static:is_badStateC"); 3127 BTB_BEGIN(is_badStateD, bsize, "putfield_or_static:is_badStateD"); 3128 __ z_illtrap(); 3129 __ z_bru(is_badState); 3130 BTB_END( is_badStateD, bsize, "putfield_or_static:is_badStateD"); 3131 BTB_BEGIN(is_badStateE, bsize, "putfield_or_static:is_badStateE"); 3132 __ z_illtrap(); 3133 __ z_bru(is_badState); 3134 BTB_END( is_badStateE, bsize, "putfield_or_static:is_badStateE"); 3135 BTB_BEGIN(is_badStateF, bsize, "putfield_or_static:is_badStateF"); 3136 __ z_illtrap(); 3137 __ z_bru(is_badState); 3138 BTB_END( is_badStateF, bsize, "putfield_or_static:is_badStateF"); 3139 3140 __ align_address(64); 3141 BIND(is_badState); // Do this outside branch table. Needs a lot of space. 3142 { 3143 unsigned int b_off = __ offset(); 3144 if (is_static) __ stop_static("Bad state in putstatic"); 3145 else __ stop_static("Bad state in putfield"); 3146 unsigned int e_off = __ offset(); 3147 } 3148 3149 __ align_address(64); 3150 BIND(atosHandler); // Oops are really complicated to handle. 3151 // There is a lot of code generated. 3152 // Therefore: generate the handler outside of branch table. 3153 // There is no performance penalty. The additional branch 3154 // to here is compensated for by the fallthru to "Done". 3155 { 3156 unsigned int b_off = __ offset(); 3157 __ pop(atos); 3158 if (!is_static) { 3159 pop_and_check_object(obj); 3160 } 3161 // Store into the field 3162 do_oop_store(_masm, obj, off, Z_tos, false, 3163 oopStore_tmp1, oopStore_tmp2, oopStore_tmp3, _bs->kind(), false); 3164 if (do_rewrite) { 3165 patch_bytecode(Bytecodes::_fast_aputfield, bc, Z_ARG5, true, byte_no); 3166 } 3167 // __ z_bru(Done); // fallthru 3168 unsigned int e_off = __ offset(); 3169 } 3170 3171 BIND(Done); 3172 3173 // Check for volatile store. 3174 Label notVolatile; 3175 3176 __ testbit(Z_ARG4, ConstantPoolCacheEntry::is_volatile_shift); 3177 __ z_brz(notVolatile); 3178 __ z_fence(); 3179 3180 BIND(notVolatile); 3181 } 3182 3183 void TemplateTable::putfield(int byte_no) { 3184 BLOCK_COMMENT("putfield {"); 3185 putfield_or_static(byte_no, false); 3186 BLOCK_COMMENT("} putfield"); 3187 } 3188 3189 void TemplateTable::nofast_putfield(int byte_no) { 3190 putfield_or_static(byte_no, false, may_not_rewrite); 3191 } 3192 3193 void TemplateTable::putstatic(int byte_no) { 3194 BLOCK_COMMENT("putstatic {"); 3195 putfield_or_static(byte_no, true); 3196 BLOCK_COMMENT("} putstatic"); 3197 } 3198 3199 // Push the tos value back to the stack. 3200 // gc will find oops there and update. 3201 void TemplateTable::jvmti_post_fast_field_mod() { 3202 3203 if (!JvmtiExport::can_post_field_modification()) { 3204 return; 3205 } 3206 3207 // Check to see if a field modification watch has been set before 3208 // we take the time to call into the VM. 3209 Label exit; 3210 3211 BLOCK_COMMENT("jvmti_post_fast_field_mod {"); 3212 3213 __ load_absolute_address(Z_R1_scratch, 3214 (address) JvmtiExport::get_field_modification_count_addr()); 3215 __ load_and_test_int(Z_R0_scratch, Address(Z_R1_scratch)); 3216 __ z_brz(exit); 3217 3218 Register obj = Z_tmp_1; 3219 3220 __ pop_ptr(obj); // Copy the object pointer from tos. 3221 __ verify_oop(obj); 3222 __ push_ptr(obj); // Put the object pointer back on tos. 3223 3224 // Save tos values before call_VM() clobbers them. Since we have 3225 // to do it for every data type, we use the saved values as the 3226 // jvalue object. 3227 switch (bytecode()) { // Load values into the jvalue object. 3228 case Bytecodes::_fast_aputfield: 3229 __ push_ptr(Z_tos); 3230 break; 3231 case Bytecodes::_fast_bputfield: 3232 case Bytecodes::_fast_zputfield: 3233 case Bytecodes::_fast_sputfield: 3234 case Bytecodes::_fast_cputfield: 3235 case Bytecodes::_fast_iputfield: 3236 __ push_i(Z_tos); 3237 break; 3238 case Bytecodes::_fast_dputfield: 3239 __ push_d(); 3240 break; 3241 case Bytecodes::_fast_fputfield: 3242 __ push_f(); 3243 break; 3244 case Bytecodes::_fast_lputfield: 3245 __ push_l(Z_tos); 3246 break; 3247 3248 default: 3249 ShouldNotReachHere(); 3250 } 3251 3252 // jvalue on the stack 3253 __ load_address(Z_ARG4, Address(Z_esp, Interpreter::stackElementSize)); 3254 // Access constant pool cache entry. 3255 __ get_cache_entry_pointer_at_bcp(Z_ARG3, Z_tos, 1); 3256 __ verify_oop(obj); 3257 3258 // obj : object pointer copied above 3259 // Z_ARG3: cache entry pointer 3260 // Z_ARG4: jvalue object on the stack 3261 __ call_VM(noreg, 3262 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), 3263 obj, Z_ARG3, Z_ARG4); 3264 3265 switch (bytecode()) { // Restore tos values. 3266 case Bytecodes::_fast_aputfield: 3267 __ pop_ptr(Z_tos); 3268 break; 3269 case Bytecodes::_fast_bputfield: 3270 case Bytecodes::_fast_zputfield: 3271 case Bytecodes::_fast_sputfield: 3272 case Bytecodes::_fast_cputfield: 3273 case Bytecodes::_fast_iputfield: 3274 __ pop_i(Z_tos); 3275 break; 3276 case Bytecodes::_fast_dputfield: 3277 __ pop_d(Z_ftos); 3278 break; 3279 case Bytecodes::_fast_fputfield: 3280 __ pop_f(Z_ftos); 3281 break; 3282 case Bytecodes::_fast_lputfield: 3283 __ pop_l(Z_tos); 3284 break; 3285 } 3286 3287 __ bind(exit); 3288 BLOCK_COMMENT("} jvmti_post_fast_field_mod"); 3289 } 3290 3291 void TemplateTable::fast_storefield(TosState state) { 3292 transition(state, vtos); 3293 3294 ByteSize base = ConstantPoolCache::base_offset(); 3295 jvmti_post_fast_field_mod(); 3296 3297 // Access constant pool cache. 3298 Register cache = Z_tmp_1; 3299 Register index = Z_tmp_2; 3300 Register flags = Z_ARG5; 3301 3302 // Index comes in bytes, don't shift afterwards! 3303 __ get_cache_and_index_at_bcp(cache, index, 1); 3304 3305 // Test for volatile. 3306 assert(!flags->is_volatile(), "do_oop_store could perform leaf RT call"); 3307 __ z_lg(flags, Address(cache, index, base + ConstantPoolCacheEntry::flags_offset())); 3308 3309 // Replace index with field offset from cache entry. 3310 Register field_offset = index; 3311 __ z_lg(field_offset, Address(cache, index, base + ConstantPoolCacheEntry::f2_offset())); 3312 3313 // Get object from stack. 3314 Register obj = cache; 3315 3316 pop_and_check_object(obj); 3317 3318 // field address 3319 const Address field(obj, field_offset); 3320 3321 // access field 3322 switch (bytecode()) { 3323 case Bytecodes::_fast_aputfield: 3324 do_oop_store(_masm, obj, field_offset, Z_tos, false, 3325 Z_ARG2, Z_ARG3, Z_ARG4, _bs->kind(), false); 3326 break; 3327 case Bytecodes::_fast_lputfield: 3328 __ reg2mem_opt(Z_tos, field); 3329 break; 3330 case Bytecodes::_fast_iputfield: 3331 __ reg2mem_opt(Z_tos, field, false); 3332 break; 3333 case Bytecodes::_fast_zputfield: 3334 __ z_nilf(Z_tos, 0x1); 3335 // fall through to bputfield 3336 case Bytecodes::_fast_bputfield: 3337 __ z_stc(Z_tos, field); 3338 break; 3339 case Bytecodes::_fast_sputfield: 3340 // fall through 3341 case Bytecodes::_fast_cputfield: 3342 __ z_sth(Z_tos, field); 3343 break; 3344 case Bytecodes::_fast_fputfield: 3345 __ freg2mem_opt(Z_ftos, field, false); 3346 break; 3347 case Bytecodes::_fast_dputfield: 3348 __ freg2mem_opt(Z_ftos, field); 3349 break; 3350 default: 3351 ShouldNotReachHere(); 3352 } 3353 3354 // Check for volatile store. 3355 Label notVolatile; 3356 3357 __ testbit(flags, ConstantPoolCacheEntry::is_volatile_shift); 3358 __ z_brz(notVolatile); 3359 __ z_fence(); 3360 3361 __ bind(notVolatile); 3362 } 3363 3364 void TemplateTable::fast_accessfield(TosState state) { 3365 transition(atos, state); 3366 3367 Register obj = Z_tos; 3368 3369 // Do the JVMTI work here to avoid disturbing the register state below 3370 if (JvmtiExport::can_post_field_access()) { 3371 // Check to see if a field access watch has been set before we 3372 // take the time to call into the VM. 3373 Label cont; 3374 3375 __ load_absolute_address(Z_R1_scratch, 3376 (address)JvmtiExport::get_field_access_count_addr()); 3377 __ load_and_test_int(Z_R0_scratch, Address(Z_R1_scratch)); 3378 __ z_brz(cont); 3379 3380 // Access constant pool cache entry. 3381 3382 __ get_cache_entry_pointer_at_bcp(Z_ARG3, Z_tmp_1, 1); 3383 __ verify_oop(obj); 3384 __ push_ptr(obj); // Save object pointer before call_VM() clobbers it. 3385 __ z_lgr(Z_ARG2, obj); 3386 3387 // Z_ARG2: object pointer copied above 3388 // Z_ARG3: cache entry pointer 3389 __ call_VM(noreg, 3390 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), 3391 Z_ARG2, Z_ARG3); 3392 __ pop_ptr(obj); // Restore object pointer. 3393 3394 __ bind(cont); 3395 } 3396 3397 // Access constant pool cache. 3398 Register cache = Z_tmp_1; 3399 Register index = Z_tmp_2; 3400 3401 // Index comes in bytes, don't shift afterwards! 3402 __ get_cache_and_index_at_bcp(cache, index, 1); 3403 // Replace index with field offset from cache entry. 3404 __ mem2reg_opt(index, 3405 Address(cache, index, 3406 ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset())); 3407 3408 __ verify_oop(obj); 3409 __ null_check(obj); 3410 3411 Address field(obj, index); 3412 3413 // access field 3414 switch (bytecode()) { 3415 case Bytecodes::_fast_agetfield: 3416 __ load_heap_oop(Z_tos, field); 3417 __ verify_oop(Z_tos); 3418 return; 3419 case Bytecodes::_fast_lgetfield: 3420 __ mem2reg_opt(Z_tos, field); 3421 return; 3422 case Bytecodes::_fast_igetfield: 3423 __ mem2reg_opt(Z_tos, field, false); 3424 return; 3425 case Bytecodes::_fast_bgetfield: 3426 __ z_lb(Z_tos, field); 3427 return; 3428 case Bytecodes::_fast_sgetfield: 3429 __ z_lh(Z_tos, field); 3430 return; 3431 case Bytecodes::_fast_cgetfield: 3432 __ z_llgh(Z_tos, field); // Load into 64 bits, works on all CPUs. 3433 return; 3434 case Bytecodes::_fast_fgetfield: 3435 __ mem2freg_opt(Z_ftos, field, false); 3436 return; 3437 case Bytecodes::_fast_dgetfield: 3438 __ mem2freg_opt(Z_ftos, field); 3439 return; 3440 default: 3441 ShouldNotReachHere(); 3442 } 3443 } 3444 3445 void TemplateTable::fast_xaccess(TosState state) { 3446 transition(vtos, state); 3447 3448 Register receiver = Z_tos; 3449 // Get receiver. 3450 __ mem2reg_opt(Z_tos, aaddress(0)); 3451 3452 // Access constant pool cache. 3453 Register cache = Z_tmp_1; 3454 Register index = Z_tmp_2; 3455 3456 // Index comes in bytes, don't shift afterwards! 3457 __ get_cache_and_index_at_bcp(cache, index, 2); 3458 // Replace index with field offset from cache entry. 3459 __ mem2reg_opt(index, 3460 Address(cache, index, 3461 ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset())); 3462 3463 // Make sure exception is reported in correct bcp range (getfield is 3464 // next instruction). 3465 __ add2reg(Z_bcp, 1); 3466 __ null_check(receiver); 3467 switch (state) { 3468 case itos: 3469 __ mem2reg_opt(Z_tos, Address(receiver, index), false); 3470 break; 3471 case atos: 3472 __ load_heap_oop(Z_tos, Address(receiver, index)); 3473 __ verify_oop(Z_tos); 3474 break; 3475 case ftos: 3476 __ mem2freg_opt(Z_ftos, Address(receiver, index)); 3477 break; 3478 default: 3479 ShouldNotReachHere(); 3480 } 3481 3482 // Reset bcp to original position. 3483 __ add2reg(Z_bcp, -1); 3484 } 3485 3486 //----------------------------------------------------------------------------- 3487 // Calls 3488 3489 void TemplateTable::prepare_invoke(int byte_no, 3490 Register method, // linked method (or i-klass) 3491 Register index, // itable index, MethodType, etc. 3492 Register recv, // If caller wants to see it. 3493 Register flags) { // If caller wants to test it. 3494 // Determine flags. 3495 const Bytecodes::Code code = bytecode(); 3496 const bool is_invokeinterface = code == Bytecodes::_invokeinterface; 3497 const bool is_invokedynamic = code == Bytecodes::_invokedynamic; 3498 const bool is_invokehandle = code == Bytecodes::_invokehandle; 3499 const bool is_invokevirtual = code == Bytecodes::_invokevirtual; 3500 const bool is_invokespecial = code == Bytecodes::_invokespecial; 3501 const bool load_receiver = (recv != noreg); 3502 assert(load_receiver == (code != Bytecodes::_invokestatic && code != Bytecodes::_invokedynamic), ""); 3503 3504 // Setup registers & access constant pool cache. 3505 if (recv == noreg) { recv = Z_ARG1; } 3506 if (flags == noreg) { flags = Z_ARG2; } 3507 assert_different_registers(method, Z_R14, index, recv, flags); 3508 3509 BLOCK_COMMENT("prepare_invoke {"); 3510 3511 load_invoke_cp_cache_entry(byte_no, method, index, flags, is_invokevirtual, false, is_invokedynamic); 3512 3513 // Maybe push appendix to arguments. 3514 if (is_invokedynamic || is_invokehandle) { 3515 Label L_no_push; 3516 Register resolved_reference = Z_R1_scratch; 3517 __ testbit(flags, ConstantPoolCacheEntry::has_appendix_shift); 3518 __ z_bfalse(L_no_push); 3519 // Push the appendix as a trailing parameter. 3520 // This must be done before we get the receiver, 3521 // since the parameter_size includes it. 3522 __ load_resolved_reference_at_index(resolved_reference, index); 3523 __ verify_oop(resolved_reference); 3524 __ push_ptr(resolved_reference); // Push appendix (MethodType, CallSite, etc.). 3525 __ bind(L_no_push); 3526 } 3527 3528 // Load receiver if needed (after appendix is pushed so parameter size is correct). 3529 if (load_receiver) { 3530 assert(!is_invokedynamic, ""); 3531 // recv := int2long(flags & ConstantPoolCacheEntry::parameter_size_mask) << 3 3532 // Flags is zero-extended int2long when loaded during load_invoke_cp_cache_entry(). 3533 // Only the least significant byte (psize) of flags is used. 3534 { 3535 const unsigned int logSES = Interpreter::logStackElementSize; 3536 const int bit_shift = logSES; 3537 const int r_bitpos = 63 - bit_shift; 3538 const int l_bitpos = r_bitpos - ConstantPoolCacheEntry::parameter_size_bits + 1; 3539 const int n_rotate = bit_shift; 3540 assert(ConstantPoolCacheEntry::parameter_size_mask == 255, "adapt bitpositions"); 3541 __ rotate_then_insert(recv, flags, l_bitpos, r_bitpos, n_rotate, true); 3542 } 3543 // Recv now contains #arguments * StackElementSize. 3544 3545 Address recv_addr(Z_esp, recv); 3546 __ z_lg(recv, recv_addr); 3547 __ verify_oop(recv); 3548 } 3549 3550 // Compute return type. 3551 // ret_type is used by callers (invokespecial, invokestatic) at least. 3552 Register ret_type = Z_R1_scratch; 3553 assert_different_registers(ret_type, method); 3554 3555 const address table_addr = (address)Interpreter::invoke_return_entry_table_for(code); 3556 __ load_absolute_address(Z_R14, table_addr); 3557 3558 { 3559 const int bit_shift = LogBytesPerWord; // Size of each table entry. 3560 const int r_bitpos = 63 - bit_shift; 3561 const int l_bitpos = r_bitpos - ConstantPoolCacheEntry::tos_state_bits + 1; 3562 const int n_rotate = bit_shift-ConstantPoolCacheEntry::tos_state_shift; 3563 __ rotate_then_insert(ret_type, flags, l_bitpos, r_bitpos, n_rotate, true); 3564 // Make sure we don't need to mask flags for tos_state after the above shift. 3565 ConstantPoolCacheEntry::verify_tos_state_shift(); 3566 } 3567 3568 __ z_lg(Z_R14, Address(Z_R14, ret_type)); // Load return address. 3569 BLOCK_COMMENT("} prepare_invoke"); 3570 } 3571 3572 3573 void TemplateTable::invokevirtual_helper(Register index, 3574 Register recv, 3575 Register flags) { 3576 // Uses temporary registers Z_tmp_2, Z_ARG4. 3577 assert_different_registers(index, recv, Z_tmp_2, Z_ARG4); 3578 3579 // Test for an invoke of a final method. 3580 Label notFinal; 3581 3582 BLOCK_COMMENT("invokevirtual_helper {"); 3583 3584 __ testbit(flags, ConstantPoolCacheEntry::is_vfinal_shift); 3585 __ z_brz(notFinal); 3586 3587 const Register method = index; // Method must be Z_ARG3. 3588 assert(method == Z_ARG3, "method must be second argument for interpreter calling convention"); 3589 3590 // Do the call - the index is actually the method to call. 3591 // That is, f2 is a vtable index if !is_vfinal, else f2 is a method. 3592 3593 // It's final, need a null check here! 3594 __ null_check(recv); 3595 3596 // Profile this call. 3597 __ profile_final_call(Z_tmp_2); 3598 __ profile_arguments_type(Z_tmp_2, method, Z_ARG5, true); // Argument type profiling. 3599 __ jump_from_interpreted(method, Z_tmp_2); 3600 3601 __ bind(notFinal); 3602 3603 // Get receiver klass. 3604 __ null_check(recv, Z_R0_scratch, oopDesc::klass_offset_in_bytes()); 3605 __ load_klass(Z_tmp_2, recv); 3606 3607 // Profile this call. 3608 __ profile_virtual_call(Z_tmp_2, Z_ARG4, Z_ARG5); 3609 3610 // Get target method & entry point. 3611 __ z_sllg(index, index, exact_log2(vtableEntry::size_in_bytes())); 3612 __ mem2reg_opt(method, 3613 Address(Z_tmp_2, index, 3614 Klass::vtable_start_offset() + in_ByteSize(vtableEntry::method_offset_in_bytes()))); 3615 __ profile_arguments_type(Z_ARG4, method, Z_ARG5, true); 3616 __ jump_from_interpreted(method, Z_ARG4); 3617 BLOCK_COMMENT("} invokevirtual_helper"); 3618 } 3619 3620 void TemplateTable::invokevirtual(int byte_no) { 3621 transition(vtos, vtos); 3622 3623 assert(byte_no == f2_byte, "use this argument"); 3624 prepare_invoke(byte_no, 3625 Z_ARG3, // method or vtable index 3626 noreg, // unused itable index 3627 Z_ARG1, // recv 3628 Z_ARG2); // flags 3629 3630 // Z_ARG3 : index 3631 // Z_ARG1 : receiver 3632 // Z_ARG2 : flags 3633 invokevirtual_helper(Z_ARG3, Z_ARG1, Z_ARG2); 3634 } 3635 3636 void TemplateTable::invokespecial(int byte_no) { 3637 transition(vtos, vtos); 3638 3639 assert(byte_no == f1_byte, "use this argument"); 3640 Register Rmethod = Z_tmp_2; 3641 prepare_invoke(byte_no, Rmethod, noreg, // Get f1 method. 3642 Z_ARG3); // Get receiver also for null check. 3643 __ verify_oop(Z_ARG3); 3644 __ null_check(Z_ARG3); 3645 // Do the call. 3646 __ profile_call(Z_ARG2); 3647 __ profile_arguments_type(Z_ARG2, Rmethod, Z_ARG5, false); 3648 __ jump_from_interpreted(Rmethod, Z_R1_scratch); 3649 } 3650 3651 void TemplateTable::invokestatic(int byte_no) { 3652 transition(vtos, vtos); 3653 3654 assert(byte_no == f1_byte, "use this argument"); 3655 Register Rmethod = Z_tmp_2; 3656 prepare_invoke(byte_no, Rmethod); // Get f1 method. 3657 // Do the call. 3658 __ profile_call(Z_ARG2); 3659 __ profile_arguments_type(Z_ARG2, Rmethod, Z_ARG5, false); 3660 __ jump_from_interpreted(Rmethod, Z_R1_scratch); 3661 } 3662 3663 // Outdated feature, and we don't support it. 3664 void TemplateTable::fast_invokevfinal(int byte_no) { 3665 transition(vtos, vtos); 3666 assert(byte_no == f2_byte, "use this argument"); 3667 __ stop("fast_invokevfinal not used on linuxs390x"); 3668 } 3669 3670 void TemplateTable::invokeinterface(int byte_no) { 3671 transition(vtos, vtos); 3672 3673 assert(byte_no == f1_byte, "use this argument"); 3674 Register klass = Z_ARG2, 3675 method = Z_ARG3, 3676 interface = Z_ARG4, 3677 flags = Z_ARG5, 3678 receiver = Z_tmp_1; 3679 3680 BLOCK_COMMENT("invokeinterface {"); 3681 3682 prepare_invoke(byte_no, interface, method, // Get f1 klassOop, f2 itable index. 3683 receiver, flags); 3684 3685 // Z_R14 (== Z_bytecode) : return entry 3686 3687 // Special case of invokeinterface called for virtual method of 3688 // java.lang.Object. See cpCacheOop.cpp for details. 3689 // This code isn't produced by javac, but could be produced by 3690 // another compliant java compiler. 3691 NearLabel notMethod, no_such_interface, no_such_method; 3692 __ testbit(flags, ConstantPoolCacheEntry::is_forced_virtual_shift); 3693 __ z_brz(notMethod); 3694 invokevirtual_helper(method, receiver, flags); 3695 __ bind(notMethod); 3696 3697 // Get receiver klass into klass - also a null check. 3698 __ restore_locals(); 3699 __ load_klass(klass, receiver); 3700 3701 __ lookup_interface_method(klass, interface, noreg, noreg, /*temp*/Z_ARG1, 3702 no_such_interface, /*return_method=*/false); 3703 3704 // Profile this call. 3705 __ profile_virtual_call(klass, Z_ARG1/*mdp*/, flags/*scratch*/); 3706 3707 // Find entry point to call. 3708 3709 // Get declaring interface class from method 3710 __ z_lg(interface, Address(method, Method::const_offset())); 3711 __ z_lg(interface, Address(interface, ConstMethod::constants_offset())); 3712 __ z_lg(interface, Address(interface, ConstantPool::pool_holder_offset_in_bytes())); 3713 3714 // Get itable index from method 3715 Register index = receiver, 3716 method2 = flags; 3717 __ z_lgf(index, Address(method, Method::itable_index_offset())); 3718 __ z_aghi(index, -Method::itable_index_max); 3719 __ z_lcgr(index, index); 3720 3721 __ lookup_interface_method(klass, interface, index, method2, Z_tmp_2, 3722 no_such_interface); 3723 3724 // Check for abstract method error. 3725 // Note: This should be done more efficiently via a throw_abstract_method_error 3726 // interpreter entry point and a conditional jump to it in case of a null 3727 // method. 3728 __ compareU64_and_branch(method2, (intptr_t) 0, 3729 Assembler::bcondZero, no_such_method); 3730 3731 __ profile_arguments_type(Z_tmp_1, method2, Z_tmp_2, true); 3732 3733 // Do the call. 3734 __ jump_from_interpreted(method2, Z_tmp_2); 3735 __ should_not_reach_here(); 3736 3737 // exception handling code follows... 3738 // Note: Must restore interpreter registers to canonical 3739 // state for exception handling to work correctly! 3740 3741 __ bind(no_such_method); 3742 3743 // Throw exception. 3744 __ restore_bcp(); // Bcp must be correct for exception handler (was destroyed). 3745 __ restore_locals(); // Make sure locals pointer is correct as well (was destroyed). 3746 // Pass arguments for generating a verbose error message. 3747 __ z_lgr(Z_tmp_1, method); // Prevent register clash. 3748 __ call_VM(noreg, 3749 CAST_FROM_FN_PTR(address, 3750 InterpreterRuntime::throw_AbstractMethodErrorVerbose), 3751 klass, Z_tmp_1); 3752 // The call_VM checks for exception, so we should never return here. 3753 __ should_not_reach_here(); 3754 3755 __ bind(no_such_interface); 3756 3757 // Throw exception. 3758 __ restore_bcp(); // Bcp must be correct for exception handler (was destroyed). 3759 __ restore_locals(); // Make sure locals pointer is correct as well (was destroyed). 3760 // Pass arguments for generating a verbose error message. 3761 __ call_VM(noreg, 3762 CAST_FROM_FN_PTR(address, 3763 InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose), 3764 klass, interface); 3765 // The call_VM checks for exception, so we should never return here. 3766 __ should_not_reach_here(); 3767 3768 BLOCK_COMMENT("} invokeinterface"); 3769 return; 3770 } 3771 3772 void TemplateTable::invokehandle(int byte_no) { 3773 transition(vtos, vtos); 3774 3775 const Register method = Z_tmp_2; 3776 const Register recv = Z_ARG5; 3777 const Register mtype = Z_tmp_1; 3778 prepare_invoke(byte_no, 3779 method, mtype, // Get f2 method, f1 MethodType. 3780 recv); 3781 __ verify_method_ptr(method); 3782 __ verify_oop(recv); 3783 __ null_check(recv); 3784 3785 // Note: Mtype is already pushed (if necessary) by prepare_invoke. 3786 3787 // FIXME: profile the LambdaForm also. 3788 __ profile_final_call(Z_ARG2); 3789 __ profile_arguments_type(Z_ARG3, method, Z_ARG5, true); 3790 3791 __ jump_from_interpreted(method, Z_ARG3); 3792 } 3793 3794 void TemplateTable::invokedynamic(int byte_no) { 3795 transition(vtos, vtos); 3796 3797 const Register Rmethod = Z_tmp_2; 3798 const Register Rcallsite = Z_tmp_1; 3799 3800 prepare_invoke(byte_no, Rmethod, Rcallsite); 3801 3802 // Rmethod: CallSite object (from f1) 3803 // Rcallsite: MH.linkToCallSite method (from f2) 3804 3805 // Note: Callsite is already pushed by prepare_invoke. 3806 3807 // TODO: should make a type profile for any invokedynamic that takes a ref argument. 3808 // Profile this call. 3809 __ profile_call(Z_ARG2); 3810 __ profile_arguments_type(Z_ARG2, Rmethod, Z_ARG5, false); 3811 __ jump_from_interpreted(Rmethod, Z_ARG2); 3812 } 3813 3814 //----------------------------------------------------------------------------- 3815 // Allocation 3816 3817 // Original comment on "allow_shared_alloc": 3818 // Always go the slow path. 3819 // + Eliminated optimization within the template-based interpreter: 3820 // If an allocation is done within the interpreter without using 3821 // tlabs, the interpreter tries to do the allocation directly 3822 // on the heap. 3823 // + That means the profiling hooks are not considered and allocations 3824 // get lost for the profiling framework. 3825 // + However, we do not think that this optimization is really needed, 3826 // so we always go now the slow path through the VM in this case -- 3827 // spec jbb2005 shows no measurable performance degradation. 3828 void TemplateTable::_new() { 3829 transition(vtos, atos); 3830 address prev_instr_address = NULL; 3831 Register tags = Z_tmp_1; 3832 Register RallocatedObject = Z_tos; 3833 Register cpool = Z_ARG2; 3834 Register tmp = Z_ARG3; // RobjectFields==tmp and Rsize==offset must be a register pair. 3835 Register offset = Z_ARG4; 3836 Label slow_case; 3837 Label done; 3838 Label initialize_header; 3839 Label allocate_shared; 3840 3841 BLOCK_COMMENT("TemplateTable::_new {"); 3842 __ get_2_byte_integer_at_bcp(offset/*dest*/, 1, InterpreterMacroAssembler::Unsigned); 3843 __ get_cpool_and_tags(cpool, tags); 3844 // Make sure the class we're about to instantiate has been resolved. 3845 // This is done before loading InstanceKlass to be consistent with the order 3846 // how Constant Pool is updated (see ConstantPool::klass_at_put). 3847 const int tags_offset = Array<u1>::base_offset_in_bytes(); 3848 __ load_address(tmp, Address(tags, offset, tags_offset)); 3849 __ z_cli(0, tmp, JVM_CONSTANT_Class); 3850 __ z_brne(slow_case); 3851 3852 __ z_sllg(offset, offset, LogBytesPerWord); // Convert to to offset. 3853 // Get InstanceKlass. 3854 Register iklass = cpool; 3855 __ load_resolved_klass_at_offset(cpool, offset, iklass); 3856 3857 // Make sure klass is initialized & doesn't have finalizer. 3858 // Make sure klass is fully initialized. 3859 const int state_offset = in_bytes(InstanceKlass::init_state_offset()); 3860 if (Immediate::is_uimm12(state_offset)) { 3861 __ z_cli(state_offset, iklass, InstanceKlass::fully_initialized); 3862 } else { 3863 __ z_cliy(state_offset, iklass, InstanceKlass::fully_initialized); 3864 } 3865 __ z_brne(slow_case); 3866 3867 // Get instance_size in InstanceKlass (scaled to a count of bytes). 3868 Register Rsize = offset; 3869 const int mask = 1 << Klass::_lh_instance_slow_path_bit; 3870 __ z_llgf(Rsize, Address(iklass, Klass::layout_helper_offset())); 3871 __ z_tmll(Rsize, mask); 3872 __ z_btrue(slow_case); 3873 3874 // Allocate the instance 3875 // 1) Try to allocate in the TLAB. 3876 // 2) If the above fails (or is not applicable), go to a slow case 3877 // (creates a new TLAB, etc.). 3878 // Note: compared to other architectures, s390's implementation always goes 3879 // to the slow path if TLAB is used and fails. 3880 if (UseTLAB) { 3881 Register RoldTopValue = RallocatedObject; 3882 Register RnewTopValue = tmp; 3883 __ z_lg(RoldTopValue, Address(Z_thread, JavaThread::tlab_top_offset())); 3884 __ load_address(RnewTopValue, Address(RoldTopValue, Rsize)); 3885 __ z_cg(RnewTopValue, Address(Z_thread, JavaThread::tlab_end_offset())); 3886 __ z_brh(slow_case); 3887 __ z_stg(RnewTopValue, Address(Z_thread, JavaThread::tlab_top_offset())); 3888 3889 Register RobjectFields = tmp; 3890 Register Rzero = Z_R1_scratch; 3891 __ clear_reg(Rzero, true /*whole reg*/, false); // Load 0L into Rzero. Don't set CC. 3892 3893 if (!ZeroTLAB) { 3894 // The object is initialized before the header. If the object size is 3895 // zero, go directly to the header initialization. 3896 __ z_aghi(Rsize, (int)-sizeof(oopDesc)); // Subtract header size, set CC. 3897 __ z_bre(initialize_header); // Jump if size of fields is zero. 3898 3899 // Initialize object fields. 3900 // See documentation for MVCLE instruction!!! 3901 assert(RobjectFields->encoding() % 2 == 0, "RobjectFields must be an even register"); 3902 assert(Rsize->encoding() == (RobjectFields->encoding()+1), 3903 "RobjectFields and Rsize must be a register pair"); 3904 assert(Rzero->encoding() % 2 == 1, "Rzero must be an odd register"); 3905 3906 // Set Rzero to 0 and use it as src length, then mvcle will copy nothing 3907 // and fill the object with the padding value 0. 3908 __ add2reg(RobjectFields, sizeof(oopDesc), RallocatedObject); 3909 __ move_long_ext(RobjectFields, as_Register(Rzero->encoding() - 1), 0); 3910 } 3911 3912 // Initialize object header only. 3913 __ bind(initialize_header); 3914 if (UseBiasedLocking) { 3915 Register prototype = RobjectFields; 3916 __ z_lg(prototype, Address(iklass, Klass::prototype_header_offset())); 3917 __ z_stg(prototype, Address(RallocatedObject, oopDesc::mark_offset_in_bytes())); 3918 } else { 3919 __ store_const(Address(RallocatedObject, oopDesc::mark_offset_in_bytes()), 3920 (long)markOopDesc::prototype()); 3921 } 3922 3923 __ store_klass_gap(Rzero, RallocatedObject); // Zero klass gap for compressed oops. 3924 __ store_klass(iklass, RallocatedObject); // Store klass last. 3925 3926 { 3927 SkipIfEqual skip(_masm, &DTraceAllocProbes, false, Z_ARG5 /*scratch*/); 3928 // Trigger dtrace event for fastpath. 3929 __ push(atos); // Save the return value. 3930 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), RallocatedObject); 3931 __ pop(atos); // Restore the return value. 3932 } 3933 __ z_bru(done); 3934 } 3935 3936 // slow case 3937 __ bind(slow_case); 3938 __ get_constant_pool(Z_ARG2); 3939 __ get_2_byte_integer_at_bcp(Z_ARG3/*dest*/, 1, InterpreterMacroAssembler::Unsigned); 3940 call_VM(Z_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), Z_ARG2, Z_ARG3); 3941 __ verify_oop(Z_tos); 3942 3943 // continue 3944 __ bind(done); 3945 3946 BLOCK_COMMENT("} TemplateTable::_new"); 3947 } 3948 3949 void TemplateTable::newarray() { 3950 transition(itos, atos); 3951 3952 // Call runtime. 3953 __ z_llgc(Z_ARG2, at_bcp(1)); // type 3954 __ z_lgfr(Z_ARG3, Z_tos); // size 3955 call_VM(Z_RET, 3956 CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), 3957 Z_ARG2, Z_ARG3); 3958 } 3959 3960 void TemplateTable::anewarray() { 3961 transition(itos, atos); 3962 __ get_2_byte_integer_at_bcp(Z_ARG3, 1, InterpreterMacroAssembler::Unsigned); 3963 __ get_constant_pool(Z_ARG2); 3964 __ z_lgfr(Z_ARG4, Z_tos); 3965 call_VM(Z_tos, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), 3966 Z_ARG2, Z_ARG3, Z_ARG4); 3967 } 3968 3969 void TemplateTable::arraylength() { 3970 transition(atos, itos); 3971 3972 int offset = arrayOopDesc::length_offset_in_bytes(); 3973 3974 __ null_check(Z_tos, Z_R0_scratch, offset); 3975 __ mem2reg_opt(Z_tos, Address(Z_tos, offset), false); 3976 } 3977 3978 void TemplateTable::checkcast() { 3979 transition(atos, atos); 3980 3981 NearLabel done, is_null, ok_is_subtype, quicked, resolved; 3982 3983 BLOCK_COMMENT("checkcast {"); 3984 // If object is NULL, we are almost done. 3985 __ compareU64_and_branch(Z_tos, (intptr_t) 0, Assembler::bcondZero, is_null); 3986 3987 // Get cpool & tags index. 3988 Register cpool = Z_tmp_1; 3989 Register tags = Z_tmp_2; 3990 Register index = Z_ARG5; 3991 3992 __ get_cpool_and_tags(cpool, tags); 3993 __ get_2_byte_integer_at_bcp(index, 1, InterpreterMacroAssembler::Unsigned); 3994 // See if bytecode has already been quicked. 3995 // Note: For CLI, we would have to add the index to the tags pointer first, 3996 // thus load and compare in a "classic" manner. 3997 __ z_llgc(Z_R0_scratch, 3998 Address(tags, index, Array<u1>::base_offset_in_bytes())); 3999 __ compareU64_and_branch(Z_R0_scratch, JVM_CONSTANT_Class, 4000 Assembler::bcondEqual, quicked); 4001 4002 __ push(atos); // Save receiver for result, and for GC. 4003 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 4004 __ get_vm_result_2(Z_tos); 4005 4006 Register receiver = Z_ARG4; 4007 Register klass = Z_tos; 4008 Register subklass = Z_ARG5; 4009 4010 __ pop_ptr(receiver); // restore receiver 4011 __ z_bru(resolved); 4012 4013 // Get superklass in klass and subklass in subklass. 4014 __ bind(quicked); 4015 4016 __ z_lgr(Z_ARG4, Z_tos); // Save receiver. 4017 __ z_sllg(index, index, LogBytesPerWord); // index2bytes for addressing 4018 __ load_resolved_klass_at_offset(cpool, index, klass); 4019 4020 __ bind(resolved); 4021 4022 __ load_klass(subklass, receiver); 4023 4024 // Generate subtype check. Object in receiver. 4025 // Superklass in klass. Subklass in subklass. 4026 __ gen_subtype_check(subklass, klass, Z_ARG3, Z_tmp_1, ok_is_subtype); 4027 4028 // Come here on failure. 4029 __ push_ptr(receiver); 4030 // Object is at TOS, target klass oop expected in rax by convention. 4031 __ z_brul((address) Interpreter::_throw_ClassCastException_entry); 4032 4033 // Come here on success. 4034 __ bind(ok_is_subtype); 4035 4036 __ z_lgr(Z_tos, receiver); // Restore object. 4037 4038 // Collect counts on whether this test sees NULLs a lot or not. 4039 if (ProfileInterpreter) { 4040 __ z_bru(done); 4041 __ bind(is_null); 4042 __ profile_null_seen(Z_tmp_1); 4043 } else { 4044 __ bind(is_null); // Same as 'done'. 4045 } 4046 4047 __ bind(done); 4048 BLOCK_COMMENT("} checkcast"); 4049 } 4050 4051 void TemplateTable::instanceof() { 4052 transition(atos, itos); 4053 4054 NearLabel done, is_null, ok_is_subtype, quicked, resolved; 4055 4056 BLOCK_COMMENT("instanceof {"); 4057 // If object is NULL, we are almost done. 4058 __ compareU64_and_branch(Z_tos, (intptr_t) 0, Assembler::bcondZero, is_null); 4059 4060 // Get cpool & tags index. 4061 Register cpool = Z_tmp_1; 4062 Register tags = Z_tmp_2; 4063 Register index = Z_ARG5; 4064 4065 __ get_cpool_and_tags(cpool, tags); 4066 __ get_2_byte_integer_at_bcp(index, 1, InterpreterMacroAssembler::Unsigned); 4067 // See if bytecode has already been quicked. 4068 // Note: For CLI, we would have to add the index to the tags pointer first, 4069 // thus load and compare in a "classic" manner. 4070 __ z_llgc(Z_R0_scratch, 4071 Address(tags, index, Array<u1>::base_offset_in_bytes())); 4072 __ compareU64_and_branch(Z_R0_scratch, JVM_CONSTANT_Class, Assembler::bcondEqual, quicked); 4073 4074 __ push(atos); // Save receiver for result, and for GC. 4075 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc)); 4076 __ get_vm_result_2(Z_tos); 4077 4078 Register receiver = Z_tmp_2; 4079 Register klass = Z_tos; 4080 Register subklass = Z_tmp_2; 4081 4082 __ pop_ptr(receiver); // Restore receiver. 4083 __ verify_oop(receiver); 4084 __ load_klass(subklass, subklass); 4085 __ z_bru(resolved); 4086 4087 // Get superklass in klass and subklass in subklass. 4088 __ bind(quicked); 4089 4090 __ load_klass(subklass, Z_tos); 4091 __ z_sllg(index, index, LogBytesPerWord); // index2bytes for addressing 4092 __ load_resolved_klass_at_offset(cpool, index, klass); 4093 4094 __ bind(resolved); 4095 4096 // Generate subtype check. 4097 // Superklass in klass. Subklass in subklass. 4098 __ gen_subtype_check(subklass, klass, Z_ARG4, Z_ARG5, ok_is_subtype); 4099 4100 // Come here on failure. 4101 __ clear_reg(Z_tos, true, false); 4102 __ z_bru(done); 4103 4104 // Come here on success. 4105 __ bind(ok_is_subtype); 4106 __ load_const_optimized(Z_tos, 1); 4107 4108 // Collect counts on whether this test sees NULLs a lot or not. 4109 if (ProfileInterpreter) { 4110 __ z_bru(done); 4111 __ bind(is_null); 4112 __ profile_null_seen(Z_tmp_1); 4113 } else { 4114 __ bind(is_null); // same as 'done' 4115 } 4116 4117 __ bind(done); 4118 // tos = 0: obj == NULL or obj is not an instanceof the specified klass 4119 // tos = 1: obj != NULL and obj is an instanceof the specified klass 4120 BLOCK_COMMENT("} instanceof"); 4121 } 4122 4123 //----------------------------------------------------------------------------- 4124 // Breakpoints 4125 void TemplateTable::_breakpoint() { 4126 4127 // Note: We get here even if we are single stepping. 4128 // Jbug insists on setting breakpoints at every bytecode 4129 // even if we are in single step mode. 4130 4131 transition(vtos, vtos); 4132 4133 // Get the unpatched byte code. 4134 __ get_method(Z_ARG2); 4135 __ call_VM(noreg, 4136 CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), 4137 Z_ARG2, Z_bcp); 4138 // Save the result to a register that is preserved over C-function calls. 4139 __ z_lgr(Z_tmp_1, Z_RET); 4140 4141 // Post the breakpoint event. 4142 __ get_method(Z_ARG2); 4143 __ call_VM(noreg, 4144 CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), 4145 Z_ARG2, Z_bcp); 4146 4147 // Must restore the bytecode, because call_VM destroys Z_bytecode. 4148 __ z_lgr(Z_bytecode, Z_tmp_1); 4149 4150 // Complete the execution of original bytecode. 4151 __ dispatch_only_normal(vtos); 4152 } 4153 4154 4155 // Exceptions 4156 4157 void TemplateTable::athrow() { 4158 transition(atos, vtos); 4159 __ null_check(Z_tos); 4160 __ load_absolute_address(Z_ARG2, Interpreter::throw_exception_entry()); 4161 __ z_br(Z_ARG2); 4162 } 4163 4164 // Synchronization 4165 // 4166 // Note: monitorenter & exit are symmetric routines; which is reflected 4167 // in the assembly code structure as well 4168 // 4169 // Stack layout: 4170 // 4171 // callers_sp <- Z_SP (callers_sp == Z_fp (own fp)) 4172 // return_pc 4173 // [rest of ABI_160] 4174 // /slot o: free 4175 // / ... free 4176 // oper. | slot n+1: free <- Z_esp points to first free slot 4177 // stack | slot n: val caches IJAVA_STATE.esp 4178 // | ... 4179 // \slot 0: val 4180 // /slot m <- IJAVA_STATE.monitors = monitor block top 4181 // | ... 4182 // monitors| slot 2 4183 // | slot 1 4184 // \slot 0 4185 // /slot l <- monitor block bot 4186 // ijava_state | ... 4187 // | slot 2 4188 // \slot 0 4189 // <- Z_fp 4190 void TemplateTable::monitorenter() { 4191 transition(atos, vtos); 4192 4193 BLOCK_COMMENT("monitorenter {"); 4194 4195 // Check for NULL object. 4196 __ null_check(Z_tos); 4197 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 4198 NearLabel allocated; 4199 // Initialize entry pointer. 4200 const Register Rfree_slot = Z_tmp_1; 4201 __ clear_reg(Rfree_slot, true, false); // Points to free slot or NULL. Don't set CC. 4202 4203 // Find a free slot in the monitor block from top to bot (result in Rfree_slot). 4204 { 4205 const Register Rcurr_monitor = Z_ARG2; 4206 const Register Rbot = Z_ARG3; // Points to word under bottom of monitor block. 4207 const Register Rlocked_obj = Z_ARG4; 4208 NearLabel loop, exit, not_free; 4209 // Starting with top-most entry. 4210 __ get_monitors(Rcurr_monitor); // Rcur_monitor = IJAVA_STATE.monitors 4211 __ add2reg(Rbot, -frame::z_ijava_state_size, Z_fp); 4212 4213 #ifdef ASSERT 4214 address reentry = NULL; 4215 { NearLabel ok; 4216 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotHigh, ok); 4217 reentry = __ stop_chain_static(reentry, "IJAVA_STATE.monitors points below monitor block bottom"); 4218 __ bind(ok); 4219 } 4220 { NearLabel ok; 4221 __ compareU64_and_branch(Rcurr_monitor, Z_esp, Assembler::bcondHigh, ok); 4222 reentry = __ stop_chain_static(reentry, "IJAVA_STATE.monitors above Z_esp"); 4223 __ bind(ok); 4224 } 4225 #endif 4226 4227 // Check if bottom reached, i.e. if there is at least one monitor. 4228 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondEqual, exit); 4229 4230 __ bind(loop); 4231 // Check if current entry is used. 4232 __ load_and_test_long(Rlocked_obj, Address(Rcurr_monitor, BasicObjectLock::obj_offset_in_bytes())); 4233 __ z_brne(not_free); 4234 // If not used then remember entry in Rfree_slot. 4235 __ z_lgr(Rfree_slot, Rcurr_monitor); 4236 __ bind(not_free); 4237 // Exit if current entry is for same object; this guarantees, that new monitor 4238 // used for recursive lock is above the older one. 4239 __ compareU64_and_branch(Rlocked_obj, Z_tos, Assembler::bcondEqual, exit); 4240 // otherwise advance to next entry 4241 __ add2reg(Rcurr_monitor, entry_size); 4242 // Check if bottom reached, if not at bottom then check this entry. 4243 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotEqual, loop); 4244 __ bind(exit); 4245 } 4246 4247 // Rfree_slot != NULL -> found one 4248 __ compareU64_and_branch(Rfree_slot, (intptr_t)0L, Assembler::bcondNotEqual, allocated); 4249 4250 // Allocate one if there's no free slot. 4251 __ add_monitor_to_stack(false, Z_ARG3, Z_ARG4, Z_ARG5); 4252 __ get_monitors(Rfree_slot); 4253 4254 // Rfree_slot: points to monitor entry. 4255 __ bind(allocated); 4256 4257 // Increment bcp to point to the next bytecode, so exception 4258 // handling for async. exceptions work correctly. 4259 // The object has already been poped from the stack, so the 4260 // expression stack looks correct. 4261 __ add2reg(Z_bcp, 1, Z_bcp); 4262 4263 // Store object. 4264 __ z_stg(Z_tos, BasicObjectLock::obj_offset_in_bytes(), Rfree_slot); 4265 __ lock_object(Rfree_slot, Z_tos); 4266 4267 // Check to make sure this monitor doesn't cause stack overflow after locking. 4268 __ save_bcp(); // in case of exception 4269 __ generate_stack_overflow_check(0); 4270 4271 // The bcp has already been incremented. Just need to dispatch to 4272 // next instruction. 4273 __ dispatch_next(vtos); 4274 4275 BLOCK_COMMENT("} monitorenter"); 4276 } 4277 4278 4279 void TemplateTable::monitorexit() { 4280 transition(atos, vtos); 4281 4282 BLOCK_COMMENT("monitorexit {"); 4283 4284 // Check for NULL object. 4285 __ null_check(Z_tos); 4286 4287 NearLabel found, not_found; 4288 const Register Rcurr_monitor = Z_ARG2; 4289 4290 // Find matching slot. 4291 { 4292 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 4293 NearLabel entry, loop; 4294 4295 const Register Rbot = Z_ARG3; // Points to word under bottom of monitor block. 4296 const Register Rlocked_obj = Z_ARG4; 4297 // Starting with top-most entry. 4298 __ get_monitors(Rcurr_monitor); // Rcur_monitor = IJAVA_STATE.monitors 4299 __ add2reg(Rbot, -frame::z_ijava_state_size, Z_fp); 4300 4301 #ifdef ASSERT 4302 address reentry = NULL; 4303 { NearLabel ok; 4304 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotHigh, ok); 4305 reentry = __ stop_chain_static(reentry, "IJAVA_STATE.monitors points below monitor block bottom"); 4306 __ bind(ok); 4307 } 4308 { NearLabel ok; 4309 __ compareU64_and_branch(Rcurr_monitor, Z_esp, Assembler::bcondHigh, ok); 4310 reentry = __ stop_chain_static(reentry, "IJAVA_STATE.monitors above Z_esp"); 4311 __ bind(ok); 4312 } 4313 #endif 4314 4315 // Check if bottom reached, i.e. if there is at least one monitor. 4316 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondEqual, not_found); 4317 4318 __ bind(loop); 4319 // Check if current entry is for same object. 4320 __ z_lg(Rlocked_obj, Address(Rcurr_monitor, BasicObjectLock::obj_offset_in_bytes())); 4321 // If same object then stop searching. 4322 __ compareU64_and_branch(Rlocked_obj, Z_tos, Assembler::bcondEqual, found); 4323 // Otherwise advance to next entry. 4324 __ add2reg(Rcurr_monitor, entry_size); 4325 // Check if bottom reached, if not at bottom then check this entry. 4326 __ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotEqual, loop); 4327 } 4328 4329 __ bind(not_found); 4330 // Error handling. Unlocking was not block-structured. 4331 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 4332 InterpreterRuntime::throw_illegal_monitor_state_exception)); 4333 __ should_not_reach_here(); 4334 4335 __ bind(found); 4336 __ push_ptr(Z_tos); // Make sure object is on stack (contract with oopMaps). 4337 __ unlock_object(Rcurr_monitor, Z_tos); 4338 __ pop_ptr(Z_tos); // Discard object. 4339 BLOCK_COMMENT("} monitorexit"); 4340 } 4341 4342 // Wide instructions 4343 void TemplateTable::wide() { 4344 transition(vtos, vtos); 4345 4346 __ z_llgc(Z_R1_scratch, at_bcp(1)); 4347 __ z_sllg(Z_R1_scratch, Z_R1_scratch, LogBytesPerWord); 4348 __ load_absolute_address(Z_tmp_1, (address) Interpreter::_wentry_point); 4349 __ mem2reg_opt(Z_tmp_1, Address(Z_tmp_1, Z_R1_scratch)); 4350 __ z_br(Z_tmp_1); 4351 // Note: the bcp increment step is part of the individual wide 4352 // bytecode implementations. 4353 } 4354 4355 // Multi arrays 4356 void TemplateTable::multianewarray() { 4357 transition(vtos, atos); 4358 4359 __ z_llgc(Z_tmp_1, at_bcp(3)); // Get number of dimensions. 4360 // Slot count to byte offset. 4361 __ z_sllg(Z_tmp_1, Z_tmp_1, Interpreter::logStackElementSize); 4362 // Z_esp points past last_dim, so set to Z_ARG2 to first_dim address. 4363 __ load_address(Z_ARG2, Address(Z_esp, Z_tmp_1)); 4364 call_VM(Z_RET, 4365 CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), 4366 Z_ARG2); 4367 // Pop dimensions from expression stack. 4368 __ z_agr(Z_esp, Z_tmp_1); 4369 }