1 /* 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2012, 2014 SAP AG. 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 27 #include "precompiled.hpp" 28 #include "asm/assembler.hpp" 29 #include "asm/macroAssembler.inline.hpp" 30 #include "interp_masm_ppc_64.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "prims/jvmtiThreadState.hpp" 33 34 #ifdef PRODUCT 35 #define BLOCK_COMMENT(str) // nothing 36 #else 37 #define BLOCK_COMMENT(str) block_comment(str) 38 #endif 39 40 void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) { 41 #ifdef CC_INTERP 42 address exception_entry = StubRoutines::throw_NullPointerException_at_call_entry(); 43 #else 44 address exception_entry = Interpreter::throw_NullPointerException_entry(); 45 #endif 46 MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry); 47 } 48 49 void InterpreterMacroAssembler::branch_to_entry(address entry, Register Rscratch) { 50 assert(entry, "Entry must have been generated by now"); 51 if (is_within_range_of_b(entry, pc())) { 52 b(entry); 53 } else { 54 load_const_optimized(Rscratch, entry, R0); 55 mtctr(Rscratch); 56 bctr(); 57 } 58 } 59 60 #ifndef CC_INTERP 61 62 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr) { 63 Register bytecode = R12_scratch2; 64 if (bcp_incr != 0) { 65 lbzu(bytecode, bcp_incr, R14_bcp); 66 } else { 67 lbz(bytecode, 0, R14_bcp); 68 } 69 70 dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state)); 71 } 72 73 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { 74 // Load current bytecode. 75 Register bytecode = R12_scratch2; 76 lbz(bytecode, 0, R14_bcp); 77 dispatch_Lbyte_code(state, bytecode, table); 78 } 79 80 // Dispatch code executed in the prolog of a bytecode which does not do it's 81 // own dispatch. The dispatch address is computed and placed in R24_dispatch_addr. 82 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) { 83 Register bytecode = R12_scratch2; 84 lbz(bytecode, bcp_incr, R14_bcp); 85 86 load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state)); 87 88 sldi(bytecode, bytecode, LogBytesPerWord); 89 ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode); 90 } 91 92 // Dispatch code executed in the epilog of a bytecode which does not do it's 93 // own dispatch. The dispatch address in R24_dispatch_addr is used for the 94 // dispatch. 95 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) { 96 mtctr(R24_dispatch_addr); 97 addi(R14_bcp, R14_bcp, bcp_incr); 98 bctr(); 99 } 100 101 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) { 102 assert(scratch_reg != R0, "can't use R0 as scratch_reg here"); 103 if (JvmtiExport::can_pop_frame()) { 104 Label L; 105 106 // Check the "pending popframe condition" flag in the current thread. 107 lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread); 108 109 // Initiate popframe handling only if it is not already being 110 // processed. If the flag has the popframe_processing bit set, it 111 // means that this code is called *during* popframe handling - we 112 // don't want to reenter. 113 andi_(R0, scratch_reg, JavaThread::popframe_pending_bit); 114 beq(CCR0, L); 115 116 andi_(R0, scratch_reg, JavaThread::popframe_processing_bit); 117 bne(CCR0, L); 118 119 // Call the Interpreter::remove_activation_preserving_args_entry() 120 // func to get the address of the same-named entrypoint in the 121 // generated interpreter code. 122 #if defined(ABI_ELFv2) 123 call_c(CAST_FROM_FN_PTR(address, 124 Interpreter::remove_activation_preserving_args_entry), 125 relocInfo::none); 126 #else 127 call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, 128 Interpreter::remove_activation_preserving_args_entry), 129 relocInfo::none); 130 #endif 131 132 // Jump to Interpreter::_remove_activation_preserving_args_entry. 133 mtctr(R3_RET); 134 bctr(); 135 136 align(32, 12); 137 bind(L); 138 } 139 } 140 141 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) { 142 const Register Rthr_state_addr = scratch_reg; 143 if (JvmtiExport::can_force_early_return()) { 144 Label Lno_early_ret; 145 ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread); 146 cmpdi(CCR0, Rthr_state_addr, 0); 147 beq(CCR0, Lno_early_ret); 148 149 lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr); 150 cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending); 151 bne(CCR0, Lno_early_ret); 152 153 // Jump to Interpreter::_earlyret_entry. 154 lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr); 155 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry)); 156 mtlr(R3_RET); 157 blr(); 158 159 align(32, 12); 160 bind(Lno_early_ret); 161 } 162 } 163 164 void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) { 165 const Register RjvmtiState = Rscratch1; 166 const Register Rscratch2 = R0; 167 168 ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread); 169 li(Rscratch2, 0); 170 171 switch (state) { 172 case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState); 173 std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState); 174 break; 175 case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 176 break; 177 case btos: // fall through 178 case ctos: // fall through 179 case stos: // fall through 180 case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 181 break; 182 case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 183 break; 184 case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 185 break; 186 case vtos: break; 187 default : ShouldNotReachHere(); 188 } 189 190 // Clean up tos value in the jvmti thread state. 191 std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 192 // Set tos state field to illegal value. 193 li(Rscratch2, ilgl); 194 stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState); 195 } 196 197 // Common code to dispatch and dispatch_only. 198 // Dispatch value in Lbyte_code and increment Lbcp. 199 200 void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) { 201 address table_base = (address)Interpreter::dispatch_table((TosState)0); 202 intptr_t table_offs = (intptr_t)table - (intptr_t)table_base; 203 if (is_simm16(table_offs)) { 204 addi(dst, R25_templateTableBase, (int)table_offs); 205 } else { 206 load_const_optimized(dst, table, R0); 207 } 208 } 209 210 void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode, address* table, bool verify) { 211 if (verify) { 212 unimplemented("dispatch_Lbyte_code: verify"); // See Sparc Implementation to implement this 213 } 214 215 #ifdef FAST_DISPATCH 216 unimplemented("dispatch_Lbyte_code FAST_DISPATCH"); 217 #else 218 assert_different_registers(bytecode, R11_scratch1); 219 220 // Calc dispatch table address. 221 load_dispatch_table(R11_scratch1, table); 222 223 sldi(R12_scratch2, bytecode, LogBytesPerWord); 224 ldx(R11_scratch1, R11_scratch1, R12_scratch2); 225 226 // Jump off! 227 mtctr(R11_scratch1); 228 bctr(); 229 #endif 230 } 231 232 void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) { 233 sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize); 234 ldx(Rrecv_dst, Rrecv_dst, R15_esp); 235 } 236 237 // helpers for expression stack 238 239 void InterpreterMacroAssembler::pop_i(Register r) { 240 lwzu(r, Interpreter::stackElementSize, R15_esp); 241 } 242 243 void InterpreterMacroAssembler::pop_ptr(Register r) { 244 ldu(r, Interpreter::stackElementSize, R15_esp); 245 } 246 247 void InterpreterMacroAssembler::pop_l(Register r) { 248 ld(r, Interpreter::stackElementSize, R15_esp); 249 addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize); 250 } 251 252 void InterpreterMacroAssembler::pop_f(FloatRegister f) { 253 lfsu(f, Interpreter::stackElementSize, R15_esp); 254 } 255 256 void InterpreterMacroAssembler::pop_d(FloatRegister f) { 257 lfd(f, Interpreter::stackElementSize, R15_esp); 258 addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize); 259 } 260 261 void InterpreterMacroAssembler::push_i(Register r) { 262 stw(r, 0, R15_esp); 263 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 264 } 265 266 void InterpreterMacroAssembler::push_ptr(Register r) { 267 std(r, 0, R15_esp); 268 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 269 } 270 271 void InterpreterMacroAssembler::push_l(Register r) { 272 std(r, - Interpreter::stackElementSize, R15_esp); 273 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 274 } 275 276 void InterpreterMacroAssembler::push_f(FloatRegister f) { 277 stfs(f, 0, R15_esp); 278 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 279 } 280 281 void InterpreterMacroAssembler::push_d(FloatRegister f) { 282 stfd(f, - Interpreter::stackElementSize, R15_esp); 283 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 284 } 285 286 void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) { 287 std(first, 0, R15_esp); 288 std(second, -Interpreter::stackElementSize, R15_esp); 289 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 290 } 291 292 void InterpreterMacroAssembler::push_l_pop_d(Register l, FloatRegister d) { 293 std(l, 0, R15_esp); 294 lfd(d, 0, R15_esp); 295 } 296 297 void InterpreterMacroAssembler::push_d_pop_l(FloatRegister d, Register l) { 298 stfd(d, 0, R15_esp); 299 ld(l, 0, R15_esp); 300 } 301 302 void InterpreterMacroAssembler::push(TosState state) { 303 switch (state) { 304 case atos: push_ptr(); break; 305 case btos: 306 case ctos: 307 case stos: 308 case itos: push_i(); break; 309 case ltos: push_l(); break; 310 case ftos: push_f(); break; 311 case dtos: push_d(); break; 312 case vtos: /* nothing to do */ break; 313 default : ShouldNotReachHere(); 314 } 315 } 316 317 void InterpreterMacroAssembler::pop(TosState state) { 318 switch (state) { 319 case atos: pop_ptr(); break; 320 case btos: 321 case ctos: 322 case stos: 323 case itos: pop_i(); break; 324 case ltos: pop_l(); break; 325 case ftos: pop_f(); break; 326 case dtos: pop_d(); break; 327 case vtos: /* nothing to do */ break; 328 default : ShouldNotReachHere(); 329 } 330 verify_oop(R17_tos, state); 331 } 332 333 void InterpreterMacroAssembler::empty_expression_stack() { 334 addi(R15_esp, R26_monitor, - Interpreter::stackElementSize); 335 } 336 337 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int bcp_offset, 338 Register Rdst, 339 signedOrNot is_signed) { 340 #if defined(VM_LITTLE_ENDIAN) 341 if (bcp_offset) { 342 load_const_optimized(Rdst, bcp_offset); 343 lhbrx(Rdst, R14_bcp, Rdst); 344 } else { 345 lhbrx(Rdst, R14_bcp); 346 } 347 if (is_signed == Signed) { 348 extsh(Rdst, Rdst); 349 } 350 #else 351 // Read Java big endian format. 352 if (is_signed == Signed) { 353 lha(Rdst, bcp_offset, R14_bcp); 354 } else { 355 lhz(Rdst, bcp_offset, R14_bcp); 356 } 357 #endif 358 } 359 360 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int bcp_offset, 361 Register Rdst, 362 signedOrNot is_signed) { 363 #if defined(VM_LITTLE_ENDIAN) 364 if (bcp_offset) { 365 load_const_optimized(Rdst, bcp_offset); 366 lwbrx(Rdst, R14_bcp, Rdst); 367 } else { 368 lwbrx(Rdst, R14_bcp); 369 } 370 if (is_signed == Signed) { 371 extsw(Rdst, Rdst); 372 } 373 #else 374 // Read Java big endian format. 375 if (bcp_offset & 3) { // Offset unaligned? 376 load_const_optimized(Rdst, bcp_offset); 377 if (is_signed == Signed) { 378 lwax(Rdst, R14_bcp, Rdst); 379 } else { 380 lwzx(Rdst, R14_bcp, Rdst); 381 } 382 } else { 383 if (is_signed == Signed) { 384 lwa(Rdst, bcp_offset, R14_bcp); 385 } else { 386 lwz(Rdst, bcp_offset, R14_bcp); 387 } 388 } 389 #endif 390 } 391 392 393 // Load the constant pool cache index from the bytecode stream. 394 // 395 // Kills / writes: 396 // - Rdst, Rscratch 397 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size) { 398 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 399 // Cache index is always in the native format, courtesy of Rewriter. 400 if (index_size == sizeof(u2)) { 401 lhz(Rdst, bcp_offset, R14_bcp); 402 } else if (index_size == sizeof(u4)) { 403 if (bcp_offset & 3) { 404 load_const_optimized(Rdst, bcp_offset); 405 lwax(Rdst, R14_bcp, Rdst); 406 } else { 407 lwa(Rdst, bcp_offset, R14_bcp); 408 } 409 assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line"); 410 nand(Rdst, Rdst, Rdst); // convert to plain index 411 } else if (index_size == sizeof(u1)) { 412 lbz(Rdst, bcp_offset, R14_bcp); 413 } else { 414 ShouldNotReachHere(); 415 } 416 // Rdst now contains cp cache index. 417 } 418 419 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset, size_t index_size) { 420 get_cache_index_at_bcp(cache, bcp_offset, index_size); 421 sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord)); 422 add(cache, R27_constPoolCache, cache); 423 } 424 425 // Load 4-byte signed or unsigned integer in Java format (that is, big-endian format) 426 // from (Rsrc)+offset. 427 void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset, 428 signedOrNot is_signed) { 429 #if defined(VM_LITTLE_ENDIAN) 430 if (offset) { 431 load_const_optimized(Rdst, offset); 432 lwbrx(Rdst, Rdst, Rsrc); 433 } else { 434 lwbrx(Rdst, Rsrc); 435 } 436 if (is_signed == Signed) { 437 extsw(Rdst, Rdst); 438 } 439 #else 440 if (is_signed == Signed) { 441 lwa(Rdst, offset, Rsrc); 442 } else { 443 lwz(Rdst, offset, Rsrc); 444 } 445 #endif 446 } 447 448 // Load object from cpool->resolved_references(index). 449 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index) { 450 assert_different_registers(result, index); 451 get_constant_pool(result); 452 453 // Convert from field index to resolved_references() index and from 454 // word index to byte offset. Since this is a java object, it can be compressed. 455 Register tmp = index; // reuse 456 sldi(tmp, index, LogBytesPerHeapOop); 457 // Load pointer for resolved_references[] objArray. 458 ld(result, ConstantPool::resolved_references_offset_in_bytes(), result); 459 // JNIHandles::resolve(result) 460 ld(result, 0, result); 461 #ifdef ASSERT 462 Label index_ok; 463 lwa(R0, arrayOopDesc::length_offset_in_bytes(), result); 464 sldi(R0, R0, LogBytesPerHeapOop); 465 cmpd(CCR0, tmp, R0); 466 blt(CCR0, index_ok); 467 stop("resolved reference index out of bounds", 0x09256); 468 bind(index_ok); 469 #endif 470 // Add in the index. 471 add(result, tmp, result); 472 load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result); 473 } 474 475 // Generate a subtype check: branch to ok_is_subtype if sub_klass is 476 // a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2. 477 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1, 478 Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) { 479 // Profile the not-null value's klass. 480 profile_typecheck(Rsub_klass, Rtmp1, Rtmp2); 481 check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype); 482 profile_typecheck_failed(Rtmp1, Rtmp2); 483 } 484 485 void InterpreterMacroAssembler::generate_stack_overflow_check_with_compare_and_throw(Register Rmem_frame_size, Register Rscratch1) { 486 Label done; 487 sub(Rmem_frame_size, R1_SP, Rmem_frame_size); 488 ld(Rscratch1, thread_(stack_overflow_limit)); 489 cmpld(CCR0/*is_stack_overflow*/, Rmem_frame_size, Rscratch1); 490 bgt(CCR0/*is_stack_overflow*/, done); 491 492 // Load target address of the runtime stub. 493 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order"); 494 load_const_optimized(Rscratch1, (StubRoutines::throw_StackOverflowError_entry()), R0); 495 mtctr(Rscratch1); 496 // Restore caller_sp. 497 #ifdef ASSERT 498 ld(Rscratch1, 0, R1_SP); 499 ld(R0, 0, R21_sender_SP); 500 cmpd(CCR0, R0, Rscratch1); 501 asm_assert_eq("backlink", 0x547); 502 #endif // ASSERT 503 mr(R1_SP, R21_sender_SP); 504 bctr(); 505 506 align(32, 12); 507 bind(done); 508 } 509 510 // Separate these two to allow for delay slot in middle. 511 // These are used to do a test and full jump to exception-throwing code. 512 513 // Check that index is in range for array, then shift index by index_shift, 514 // and put arrayOop + shifted_index into res. 515 // Note: res is still shy of address by array offset into object. 516 517 void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex, int index_shift, Register Rtmp, Register Rres) { 518 // Check that index is in range for array, then shift index by index_shift, 519 // and put arrayOop + shifted_index into res. 520 // Note: res is still shy of address by array offset into object. 521 // Kills: 522 // - Rindex 523 // Writes: 524 // - Rres: Address that corresponds to the array index if check was successful. 525 verify_oop(Rarray); 526 const Register Rlength = R0; 527 const Register RsxtIndex = Rtmp; 528 Label LisNull, LnotOOR; 529 530 // Array nullcheck 531 if (!ImplicitNullChecks) { 532 cmpdi(CCR0, Rarray, 0); 533 beq(CCR0, LisNull); 534 } else { 535 null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex); 536 } 537 538 // Rindex might contain garbage in upper bits (remember that we don't sign extend 539 // during integer arithmetic operations). So kill them and put value into same register 540 // where ArrayIndexOutOfBounds would expect the index in. 541 rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit 542 543 // Index check 544 lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray); 545 cmplw(CCR0, Rindex, Rlength); 546 sldi(RsxtIndex, RsxtIndex, index_shift); 547 blt(CCR0, LnotOOR); 548 load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry); 549 mtctr(Rtmp); 550 bctr(); 551 552 if (!ImplicitNullChecks) { 553 bind(LisNull); 554 load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry); 555 mtctr(Rtmp); 556 bctr(); 557 } 558 559 align(32, 16); 560 bind(LnotOOR); 561 562 // Calc address 563 add(Rres, RsxtIndex, Rarray); 564 } 565 566 void InterpreterMacroAssembler::index_check(Register array, Register index, int index_shift, Register tmp, Register res) { 567 // pop array 568 pop_ptr(array); 569 570 // check array 571 index_check_without_pop(array, index, index_shift, tmp, res); 572 } 573 574 void InterpreterMacroAssembler::get_const(Register Rdst) { 575 ld(Rdst, in_bytes(Method::const_offset()), R19_method); 576 } 577 578 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) { 579 get_const(Rdst); 580 ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst); 581 } 582 583 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) { 584 get_constant_pool(Rdst); 585 ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst); 586 } 587 588 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) { 589 get_constant_pool(Rcpool); 590 ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool); 591 } 592 593 // Unlock if synchronized method. 594 // 595 // Unlock the receiver if this is a synchronized method. 596 // Unlock any Java monitors from synchronized blocks. 597 // 598 // If there are locked Java monitors 599 // If throw_monitor_exception 600 // throws IllegalMonitorStateException 601 // Else if install_monitor_exception 602 // installs IllegalMonitorStateException 603 // Else 604 // no error processing 605 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state, 606 bool throw_monitor_exception, 607 bool install_monitor_exception) { 608 Label Lunlocked, Lno_unlock; 609 { 610 Register Rdo_not_unlock_flag = R11_scratch1; 611 Register Raccess_flags = R12_scratch2; 612 613 // Check if synchronized method or unlocking prevented by 614 // JavaThread::do_not_unlock_if_synchronized flag. 615 lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); 616 lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method); 617 li(R0, 0); 618 stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag 619 620 push(state); 621 622 // Skip if we don't have to unlock. 623 rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0. 624 beq(CCR0, Lunlocked); 625 626 cmpwi(CCR0, Rdo_not_unlock_flag, 0); 627 bne(CCR0, Lno_unlock); 628 } 629 630 // Unlock 631 { 632 Register Rmonitor_base = R11_scratch1; 633 634 Label Lunlock; 635 // If it's still locked, everything is ok, unlock it. 636 ld(Rmonitor_base, 0, R1_SP); 637 addi(Rmonitor_base, Rmonitor_base, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base 638 639 ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base); 640 cmpdi(CCR0, R0, 0); 641 bne(CCR0, Lunlock); 642 643 // If it's already unlocked, throw exception. 644 if (throw_monitor_exception) { 645 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 646 should_not_reach_here(); 647 } else { 648 if (install_monitor_exception) { 649 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 650 b(Lunlocked); 651 } 652 } 653 654 bind(Lunlock); 655 unlock_object(Rmonitor_base); 656 } 657 658 // Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not. 659 bind(Lunlocked); 660 { 661 Label Lexception, Lrestart; 662 Register Rcurrent_obj_addr = R11_scratch1; 663 const int delta = frame::interpreter_frame_monitor_size_in_bytes(); 664 assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords"); 665 666 bind(Lrestart); 667 // Set up search loop: Calc num of iterations. 668 { 669 Register Riterations = R12_scratch2; 670 Register Rmonitor_base = Rcurrent_obj_addr; 671 ld(Rmonitor_base, 0, R1_SP); 672 addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size); // Monitor base 673 674 subf_(Riterations, R26_monitor, Rmonitor_base); 675 ble(CCR0, Lno_unlock); 676 677 addi(Rcurrent_obj_addr, Rmonitor_base, BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes()); 678 // Check if any monitor is on stack, bail out if not 679 srdi(Riterations, Riterations, exact_log2(delta)); 680 mtctr(Riterations); 681 } 682 683 // The search loop: Look for locked monitors. 684 { 685 const Register Rcurrent_obj = R0; 686 Label Lloop; 687 688 ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 689 addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta); 690 bind(Lloop); 691 692 // Check if current entry is used. 693 cmpdi(CCR0, Rcurrent_obj, 0); 694 bne(CCR0, Lexception); 695 // Preload next iteration's compare value. 696 ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 697 addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta); 698 bdnz(Lloop); 699 } 700 // Fell through: Everything's unlocked => finish. 701 b(Lno_unlock); 702 703 // An object is still locked => need to throw exception. 704 bind(Lexception); 705 if (throw_monitor_exception) { 706 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 707 should_not_reach_here(); 708 } else { 709 // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception. 710 // Unlock does not block, so don't have to worry about the frame. 711 Register Rmonitor_addr = R11_scratch1; 712 addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta); 713 unlock_object(Rmonitor_addr); 714 if (install_monitor_exception) { 715 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 716 } 717 b(Lrestart); 718 } 719 } 720 721 align(32, 12); 722 bind(Lno_unlock); 723 pop(state); 724 } 725 726 // Support function for remove_activation & Co. 727 void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc, Register Rscratch1, Register Rscratch2) { 728 // Pop interpreter frame. 729 ld(Rscratch1, 0, R1_SP); // *SP 730 ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp 731 ld(Rscratch2, 0, Rscratch1); // **SP 732 #ifdef ASSERT 733 { 734 Label Lok; 735 ld(R0, _ijava_state_neg(ijava_reserved), Rscratch1); 736 cmpdi(CCR0, R0, 0x5afe); 737 beq(CCR0, Lok); 738 stop("frame corrupted (remove activation)", 0x5afe); 739 bind(Lok); 740 } 741 #endif 742 if (return_pc!=noreg) { 743 ld(return_pc, _abi(lr), Rscratch1); // LR 744 } 745 746 // Merge top frames. 747 subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP 748 stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP 749 } 750 751 // Remove activation. 752 // 753 // Unlock the receiver if this is a synchronized method. 754 // Unlock any Java monitors from synchronized blocks. 755 // Remove the activation from the stack. 756 // 757 // If there are locked Java monitors 758 // If throw_monitor_exception 759 // throws IllegalMonitorStateException 760 // Else if install_monitor_exception 761 // installs IllegalMonitorStateException 762 // Else 763 // no error processing 764 void InterpreterMacroAssembler::remove_activation(TosState state, 765 bool throw_monitor_exception, 766 bool install_monitor_exception) { 767 unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception); 768 769 // Save result (push state before jvmti call and pop it afterwards) and notify jvmti. 770 notify_method_exit(false, state, NotifyJVMTI, true); 771 772 verify_oop(R17_tos, state); 773 verify_thread(); 774 775 merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2); 776 mtlr(R0); 777 } 778 779 #endif // !CC_INTERP 780 781 // Lock object 782 // 783 // Registers alive 784 // monitor - Address of the BasicObjectLock to be used for locking, 785 // which must be initialized with the object to lock. 786 // object - Address of the object to be locked. 787 // 788 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) { 789 if (UseHeavyMonitors) { 790 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 791 monitor, /*check_for_exceptions=*/true CC_INTERP_ONLY(&& false)); 792 } else { 793 // template code: 794 // 795 // markOop displaced_header = obj->mark().set_unlocked(); 796 // monitor->lock()->set_displaced_header(displaced_header); 797 // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) { 798 // // We stored the monitor address into the object's mark word. 799 // } else if (THREAD->is_lock_owned((address)displaced_header)) 800 // // Simple recursive case. 801 // monitor->lock()->set_displaced_header(NULL); 802 // } else { 803 // // Slow path. 804 // InterpreterRuntime::monitorenter(THREAD, monitor); 805 // } 806 807 const Register displaced_header = R7_ARG5; 808 const Register object_mark_addr = R8_ARG6; 809 const Register current_header = R9_ARG7; 810 const Register tmp = R10_ARG8; 811 812 Label done; 813 Label cas_failed, slow_case; 814 815 assert_different_registers(displaced_header, object_mark_addr, current_header, tmp); 816 817 // markOop displaced_header = obj->mark().set_unlocked(); 818 819 // Load markOop from object into displaced_header. 820 ld(displaced_header, oopDesc::mark_offset_in_bytes(), object); 821 822 if (UseBiasedLocking) { 823 biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case); 824 } 825 826 // Set displaced_header to be (markOop of object | UNLOCK_VALUE). 827 ori(displaced_header, displaced_header, markOopDesc::unlocked_value); 828 829 // monitor->lock()->set_displaced_header(displaced_header); 830 831 // Initialize the box (Must happen before we update the object mark!). 832 std(displaced_header, BasicObjectLock::lock_offset_in_bytes() + 833 BasicLock::displaced_header_offset_in_bytes(), monitor); 834 835 // if (Atomic::cmpxchg_ptr(/*ex=*/monitor, /*addr*/obj->mark_addr(), /*cmp*/displaced_header) == displaced_header) { 836 837 // Store stack address of the BasicObjectLock (this is monitor) into object. 838 addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes()); 839 840 // Must fence, otherwise, preceding store(s) may float below cmpxchg. 841 // CmpxchgX sets CCR0 to cmpX(current, displaced). 842 fence(); // TODO: replace by MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq ? 843 cmpxchgd(/*flag=*/CCR0, 844 /*current_value=*/current_header, 845 /*compare_value=*/displaced_header, /*exchange_value=*/monitor, 846 /*where=*/object_mark_addr, 847 MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq, 848 MacroAssembler::cmpxchgx_hint_acquire_lock(), 849 noreg, 850 &cas_failed); 851 852 // If the compare-and-exchange succeeded, then we found an unlocked 853 // object and we have now locked it. 854 b(done); 855 bind(cas_failed); 856 857 // } else if (THREAD->is_lock_owned((address)displaced_header)) 858 // // Simple recursive case. 859 // monitor->lock()->set_displaced_header(NULL); 860 861 // We did not see an unlocked object so try the fast recursive case. 862 863 // Check if owner is self by comparing the value in the markOop of object 864 // (current_header) with the stack pointer. 865 sub(current_header, current_header, R1_SP); 866 867 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); 868 load_const_optimized(tmp, 869 (address) (~(os::vm_page_size()-1) | 870 markOopDesc::lock_mask_in_place)); 871 872 and_(R0/*==0?*/, current_header, tmp); 873 // If condition is true we are done and hence we can store 0 in the displaced 874 // header indicating it is a recursive lock. 875 bne(CCR0, slow_case); 876 release(); 877 std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() + 878 BasicLock::displaced_header_offset_in_bytes(), monitor); 879 b(done); 880 881 // } else { 882 // // Slow path. 883 // InterpreterRuntime::monitorenter(THREAD, monitor); 884 885 // None of the above fast optimizations worked so we have to get into the 886 // slow case of monitor enter. 887 bind(slow_case); 888 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 889 monitor, /*check_for_exceptions=*/true CC_INTERP_ONLY(&& false)); 890 // } 891 align(32, 12); 892 bind(done); 893 } 894 } 895 896 // Unlocks an object. Used in monitorexit bytecode and remove_activation. 897 // 898 // Registers alive 899 // monitor - Address of the BasicObjectLock to be used for locking, 900 // which must be initialized with the object to lock. 901 // 902 // Throw IllegalMonitorException if object is not locked by current thread. 903 void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_exceptions) { 904 if (UseHeavyMonitors) { 905 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), 906 monitor, check_for_exceptions CC_INTERP_ONLY(&& false)); 907 } else { 908 909 // template code: 910 // 911 // if ((displaced_header = monitor->displaced_header()) == NULL) { 912 // // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL. 913 // monitor->set_obj(NULL); 914 // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) { 915 // // We swapped the unlocked mark in displaced_header into the object's mark word. 916 // monitor->set_obj(NULL); 917 // } else { 918 // // Slow path. 919 // InterpreterRuntime::monitorexit(THREAD, monitor); 920 // } 921 922 const Register object = R7_ARG5; 923 const Register displaced_header = R8_ARG6; 924 const Register object_mark_addr = R9_ARG7; 925 const Register current_header = R10_ARG8; 926 927 Label free_slot; 928 Label slow_case; 929 930 assert_different_registers(object, displaced_header, object_mark_addr, current_header); 931 932 if (UseBiasedLocking) { 933 // The object address from the monitor is in object. 934 ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor); 935 assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0"); 936 biased_locking_exit(CCR0, object, displaced_header, free_slot); 937 } 938 939 // Test first if we are in the fast recursive case. 940 ld(displaced_header, BasicObjectLock::lock_offset_in_bytes() + 941 BasicLock::displaced_header_offset_in_bytes(), monitor); 942 943 // If the displaced header is zero, we have a recursive unlock. 944 cmpdi(CCR0, displaced_header, 0); 945 beq(CCR0, free_slot); // recursive unlock 946 947 // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) { 948 // // We swapped the unlocked mark in displaced_header into the object's mark word. 949 // monitor->set_obj(NULL); 950 951 // If we still have a lightweight lock, unlock the object and be done. 952 953 // The object address from the monitor is in object. 954 if (!UseBiasedLocking) { ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor); } 955 addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes()); 956 957 // We have the displaced header in displaced_header. If the lock is still 958 // lightweight, it will contain the monitor address and we'll store the 959 // displaced header back into the object's mark word. 960 // CmpxchgX sets CCR0 to cmpX(current, monitor). 961 cmpxchgd(/*flag=*/CCR0, 962 /*current_value=*/current_header, 963 /*compare_value=*/monitor, /*exchange_value=*/displaced_header, 964 /*where=*/object_mark_addr, 965 MacroAssembler::MemBarRel, 966 MacroAssembler::cmpxchgx_hint_release_lock(), 967 noreg, 968 &slow_case); 969 b(free_slot); 970 971 // } else { 972 // // Slow path. 973 // InterpreterRuntime::monitorexit(THREAD, monitor); 974 975 // The lock has been converted into a heavy lock and hence 976 // we need to get into the slow case. 977 bind(slow_case); 978 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), 979 monitor, check_for_exceptions CC_INTERP_ONLY(&& false)); 980 // } 981 982 Label done; 983 b(done); // Monitor register may be overwritten! Runtime has already freed the slot. 984 985 // Exchange worked, do monitor->set_obj(NULL); 986 align(32, 12); 987 bind(free_slot); 988 li(R0, 0); 989 std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor); 990 bind(done); 991 } 992 } 993 994 #ifndef CC_INTERP 995 996 // Load compiled (i2c) or interpreter entry when calling from interpreted and 997 // do the call. Centralized so that all interpreter calls will do the same actions. 998 // If jvmti single stepping is on for a thread we must not call compiled code. 999 // 1000 // Input: 1001 // - Rtarget_method: method to call 1002 // - Rret_addr: return address 1003 // - 2 scratch regs 1004 // 1005 void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr, Register Rscratch1, Register Rscratch2) { 1006 assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr); 1007 // Assume we want to go compiled if available. 1008 const Register Rtarget_addr = Rscratch1; 1009 const Register Rinterp_only = Rscratch2; 1010 1011 ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method); 1012 1013 if (JvmtiExport::can_post_interpreter_events()) { 1014 lwz(Rinterp_only, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread); 1015 1016 // JVMTI events, such as single-stepping, are implemented partly by avoiding running 1017 // compiled code in threads for which the event is enabled. Check here for 1018 // interp_only_mode if these events CAN be enabled. 1019 Label done; 1020 verify_thread(); 1021 cmpwi(CCR0, Rinterp_only, 0); 1022 beq(CCR0, done); 1023 ld(Rtarget_addr, in_bytes(Method::interpreter_entry_offset()), Rtarget_method); 1024 align(32, 12); 1025 bind(done); 1026 } 1027 1028 #ifdef ASSERT 1029 { 1030 Label Lok; 1031 cmpdi(CCR0, Rtarget_addr, 0); 1032 bne(CCR0, Lok); 1033 stop("null entry point"); 1034 bind(Lok); 1035 } 1036 #endif // ASSERT 1037 1038 mr(R21_sender_SP, R1_SP); 1039 1040 // Calc a precise SP for the call. The SP value we calculated in 1041 // generate_fixed_frame() is based on the max_stack() value, so we would waste stack space 1042 // if esp is not max. Also, the i2c adapter extends the stack space without restoring 1043 // our pre-calced value, so repeating calls via i2c would result in stack overflow. 1044 // Since esp already points to an empty slot, we just have to sub 1 additional slot 1045 // to meet the abi scratch requirements. 1046 // The max_stack pointer will get restored by means of the GR_Lmax_stack local in 1047 // the return entry of the interpreter. 1048 addi(Rscratch2, R15_esp, Interpreter::stackElementSize - frame::abi_reg_args_size); 1049 clrrdi(Rscratch2, Rscratch2, exact_log2(frame::alignment_in_bytes)); // round towards smaller address 1050 resize_frame_absolute(Rscratch2, Rscratch2, R0); 1051 1052 mr_if_needed(R19_method, Rtarget_method); 1053 mtctr(Rtarget_addr); 1054 mtlr(Rret_addr); 1055 1056 save_interpreter_state(Rscratch2); 1057 #ifdef ASSERT 1058 ld(Rscratch1, _ijava_state_neg(top_frame_sp), Rscratch2); // Rscratch2 contains fp 1059 cmpd(CCR0, R21_sender_SP, Rscratch1); 1060 asm_assert_eq("top_frame_sp incorrect", 0x951); 1061 #endif 1062 1063 bctr(); 1064 } 1065 1066 // Set the method data pointer for the current bcp. 1067 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { 1068 assert(ProfileInterpreter, "must be profiling interpreter"); 1069 Label get_continue; 1070 ld(R28_mdx, in_bytes(Method::method_data_offset()), R19_method); 1071 test_method_data_pointer(get_continue); 1072 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), R19_method, R14_bcp); 1073 1074 addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset())); 1075 add(R28_mdx, R28_mdx, R3_RET); 1076 bind(get_continue); 1077 } 1078 1079 // Test ImethodDataPtr. If it is null, continue at the specified label. 1080 void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) { 1081 assert(ProfileInterpreter, "must be profiling interpreter"); 1082 cmpdi(CCR0, R28_mdx, 0); 1083 beq(CCR0, zero_continue); 1084 } 1085 1086 void InterpreterMacroAssembler::verify_method_data_pointer() { 1087 assert(ProfileInterpreter, "must be profiling interpreter"); 1088 #ifdef ASSERT 1089 Label verify_continue; 1090 test_method_data_pointer(verify_continue); 1091 1092 // If the mdp is valid, it will point to a DataLayout header which is 1093 // consistent with the bcp. The converse is highly probable also. 1094 lhz(R11_scratch1, in_bytes(DataLayout::bci_offset()), R28_mdx); 1095 ld(R12_scratch2, in_bytes(Method::const_offset()), R19_method); 1096 addi(R11_scratch1, R11_scratch1, in_bytes(ConstMethod::codes_offset())); 1097 add(R11_scratch1, R12_scratch2, R12_scratch2); 1098 cmpd(CCR0, R11_scratch1, R14_bcp); 1099 beq(CCR0, verify_continue); 1100 1101 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp ), R19_method, R14_bcp, R28_mdx); 1102 1103 bind(verify_continue); 1104 #endif 1105 } 1106 1107 void InterpreterMacroAssembler::test_invocation_counter_for_mdp(Register invocation_count, 1108 Register Rscratch, 1109 Label &profile_continue) { 1110 assert(ProfileInterpreter, "must be profiling interpreter"); 1111 // Control will flow to "profile_continue" if the counter is less than the 1112 // limit or if we call profile_method(). 1113 Label done; 1114 1115 // If no method data exists, and the counter is high enough, make one. 1116 int ipl_offs = load_const_optimized(Rscratch, &InvocationCounter::InterpreterProfileLimit, R0, true); 1117 lwz(Rscratch, ipl_offs, Rscratch); 1118 1119 cmpdi(CCR0, R28_mdx, 0); 1120 // Test to see if we should create a method data oop. 1121 cmpd(CCR1, Rscratch /* InterpreterProfileLimit */, invocation_count); 1122 bne(CCR0, done); 1123 bge(CCR1, profile_continue); 1124 1125 // Build it now. 1126 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1127 set_method_data_pointer_for_bcp(); 1128 b(profile_continue); 1129 1130 align(32, 12); 1131 bind(done); 1132 } 1133 1134 void InterpreterMacroAssembler::test_backedge_count_for_osr(Register backedge_count, Register branch_bcp, Register Rtmp) { 1135 assert_different_registers(backedge_count, Rtmp, branch_bcp); 1136 assert(UseOnStackReplacement,"Must UseOnStackReplacement to test_backedge_count_for_osr"); 1137 1138 Label did_not_overflow; 1139 Label overflow_with_error; 1140 1141 int ibbl_offs = load_const_optimized(Rtmp, &InvocationCounter::InterpreterBackwardBranchLimit, R0, true); 1142 lwz(Rtmp, ibbl_offs, Rtmp); 1143 cmpw(CCR0, backedge_count, Rtmp); 1144 1145 blt(CCR0, did_not_overflow); 1146 1147 // When ProfileInterpreter is on, the backedge_count comes from the 1148 // methodDataOop, which value does not get reset on the call to 1149 // frequency_counter_overflow(). To avoid excessive calls to the overflow 1150 // routine while the method is being compiled, add a second test to make sure 1151 // the overflow function is called only once every overflow_frequency. 1152 if (ProfileInterpreter) { 1153 const int overflow_frequency = 1024; 1154 li(Rtmp, overflow_frequency-1); 1155 andr(Rtmp, Rtmp, backedge_count); 1156 cmpwi(CCR0, Rtmp, 0); 1157 bne(CCR0, did_not_overflow); 1158 } 1159 1160 // Overflow in loop, pass branch bytecode. 1161 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), branch_bcp, true); 1162 1163 // Was an OSR adapter generated? 1164 // O0 = osr nmethod 1165 cmpdi(CCR0, R3_RET, 0); 1166 beq(CCR0, overflow_with_error); 1167 1168 // Has the nmethod been invalidated already? 1169 lwz(Rtmp, nmethod::entry_bci_offset(), R3_RET); 1170 cmpwi(CCR0, Rtmp, InvalidOSREntryBci); 1171 beq(CCR0, overflow_with_error); 1172 1173 // Migrate the interpreter frame off of the stack. 1174 // We can use all registers because we will not return to interpreter from this point. 1175 1176 // Save nmethod. 1177 const Register osr_nmethod = R31; 1178 mr(osr_nmethod, R3_RET); 1179 set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R11_scratch1); 1180 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), R16_thread); 1181 reset_last_Java_frame(); 1182 // OSR buffer is in ARG1 1183 1184 // Remove the interpreter frame. 1185 merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2); 1186 1187 // Jump to the osr code. 1188 ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod); 1189 mtlr(R0); 1190 mtctr(R11_scratch1); 1191 bctr(); 1192 1193 align(32, 12); 1194 bind(overflow_with_error); 1195 bind(did_not_overflow); 1196 } 1197 1198 // Store a value at some constant offset from the method data pointer. 1199 void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) { 1200 assert(ProfileInterpreter, "must be profiling interpreter"); 1201 1202 std(value, constant, R28_mdx); 1203 } 1204 1205 // Increment the value at some constant offset from the method data pointer. 1206 void InterpreterMacroAssembler::increment_mdp_data_at(int constant, 1207 Register counter_addr, 1208 Register Rbumped_count, 1209 bool decrement) { 1210 // Locate the counter at a fixed offset from the mdp: 1211 addi(counter_addr, R28_mdx, constant); 1212 increment_mdp_data_at(counter_addr, Rbumped_count, decrement); 1213 } 1214 1215 // Increment the value at some non-fixed (reg + constant) offset from 1216 // the method data pointer. 1217 void InterpreterMacroAssembler::increment_mdp_data_at(Register reg, 1218 int constant, 1219 Register scratch, 1220 Register Rbumped_count, 1221 bool decrement) { 1222 // Add the constant to reg to get the offset. 1223 add(scratch, R28_mdx, reg); 1224 // Then calculate the counter address. 1225 addi(scratch, scratch, constant); 1226 increment_mdp_data_at(scratch, Rbumped_count, decrement); 1227 } 1228 1229 void InterpreterMacroAssembler::increment_mdp_data_at(Register counter_addr, 1230 Register Rbumped_count, 1231 bool decrement) { 1232 assert(ProfileInterpreter, "must be profiling interpreter"); 1233 1234 // Load the counter. 1235 ld(Rbumped_count, 0, counter_addr); 1236 1237 if (decrement) { 1238 // Decrement the register. Set condition codes. 1239 addi(Rbumped_count, Rbumped_count, - DataLayout::counter_increment); 1240 // Store the decremented counter, if it is still negative. 1241 std(Rbumped_count, 0, counter_addr); 1242 // Note: add/sub overflow check are not ported, since 64 bit 1243 // calculation should never overflow. 1244 } else { 1245 // Increment the register. Set carry flag. 1246 addi(Rbumped_count, Rbumped_count, DataLayout::counter_increment); 1247 // Store the incremented counter. 1248 std(Rbumped_count, 0, counter_addr); 1249 } 1250 } 1251 1252 // Set a flag value at the current method data pointer position. 1253 void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant, 1254 Register scratch) { 1255 assert(ProfileInterpreter, "must be profiling interpreter"); 1256 // Load the data header. 1257 lbz(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx); 1258 // Set the flag. 1259 ori(scratch, scratch, flag_constant); 1260 // Store the modified header. 1261 stb(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx); 1262 } 1263 1264 // Test the location at some offset from the method data pointer. 1265 // If it is not equal to value, branch to the not_equal_continue Label. 1266 void InterpreterMacroAssembler::test_mdp_data_at(int offset, 1267 Register value, 1268 Label& not_equal_continue, 1269 Register test_out) { 1270 assert(ProfileInterpreter, "must be profiling interpreter"); 1271 1272 ld(test_out, offset, R28_mdx); 1273 cmpd(CCR0, value, test_out); 1274 bne(CCR0, not_equal_continue); 1275 } 1276 1277 // Update the method data pointer by the displacement located at some fixed 1278 // offset from the method data pointer. 1279 void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp, 1280 Register scratch) { 1281 assert(ProfileInterpreter, "must be profiling interpreter"); 1282 1283 ld(scratch, offset_of_disp, R28_mdx); 1284 add(R28_mdx, scratch, R28_mdx); 1285 } 1286 1287 // Update the method data pointer by the displacement located at the 1288 // offset (reg + offset_of_disp). 1289 void InterpreterMacroAssembler::update_mdp_by_offset(Register reg, 1290 int offset_of_disp, 1291 Register scratch) { 1292 assert(ProfileInterpreter, "must be profiling interpreter"); 1293 1294 add(scratch, reg, R28_mdx); 1295 ld(scratch, offset_of_disp, scratch); 1296 add(R28_mdx, scratch, R28_mdx); 1297 } 1298 1299 // Update the method data pointer by a simple constant displacement. 1300 void InterpreterMacroAssembler::update_mdp_by_constant(int constant) { 1301 assert(ProfileInterpreter, "must be profiling interpreter"); 1302 addi(R28_mdx, R28_mdx, constant); 1303 } 1304 1305 // Update the method data pointer for a _ret bytecode whose target 1306 // was not among our cached targets. 1307 void InterpreterMacroAssembler::update_mdp_for_ret(TosState state, 1308 Register return_bci) { 1309 assert(ProfileInterpreter, "must be profiling interpreter"); 1310 1311 push(state); 1312 assert(return_bci->is_nonvolatile(), "need to protect return_bci"); 1313 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci); 1314 pop(state); 1315 } 1316 1317 // Increments the backedge counter. 1318 // Returns backedge counter + invocation counter in Rdst. 1319 void InterpreterMacroAssembler::increment_backedge_counter(const Register Rcounters, const Register Rdst, 1320 const Register Rtmp1, Register Rscratch) { 1321 assert(UseCompiler, "incrementing must be useful"); 1322 assert_different_registers(Rdst, Rtmp1); 1323 const Register invocation_counter = Rtmp1; 1324 const Register counter = Rdst; 1325 // TODO ppc port assert(4 == InvocationCounter::sz_counter(), "unexpected field size."); 1326 1327 // Load backedge counter. 1328 lwz(counter, in_bytes(MethodCounters::backedge_counter_offset()) + 1329 in_bytes(InvocationCounter::counter_offset()), Rcounters); 1330 // Load invocation counter. 1331 lwz(invocation_counter, in_bytes(MethodCounters::invocation_counter_offset()) + 1332 in_bytes(InvocationCounter::counter_offset()), Rcounters); 1333 1334 // Add the delta to the backedge counter. 1335 addi(counter, counter, InvocationCounter::count_increment); 1336 1337 // Mask the invocation counter. 1338 li(Rscratch, InvocationCounter::count_mask_value); 1339 andr(invocation_counter, invocation_counter, Rscratch); 1340 1341 // Store new counter value. 1342 stw(counter, in_bytes(MethodCounters::backedge_counter_offset()) + 1343 in_bytes(InvocationCounter::counter_offset()), Rcounters); 1344 // Return invocation counter + backedge counter. 1345 add(counter, counter, invocation_counter); 1346 } 1347 1348 // Count a taken branch in the bytecodes. 1349 void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) { 1350 if (ProfileInterpreter) { 1351 Label profile_continue; 1352 1353 // If no method data exists, go to profile_continue. 1354 test_method_data_pointer(profile_continue); 1355 1356 // We are taking a branch. Increment the taken count. 1357 increment_mdp_data_at(in_bytes(JumpData::taken_offset()), scratch, bumped_count); 1358 1359 // The method data pointer needs to be updated to reflect the new target. 1360 update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch); 1361 bind (profile_continue); 1362 } 1363 } 1364 1365 // Count a not-taken branch in the bytecodes. 1366 void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch1, Register scratch2) { 1367 if (ProfileInterpreter) { 1368 Label profile_continue; 1369 1370 // If no method data exists, go to profile_continue. 1371 test_method_data_pointer(profile_continue); 1372 1373 // We are taking a branch. Increment the not taken count. 1374 increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch1, scratch2); 1375 1376 // The method data pointer needs to be updated to correspond to the 1377 // next bytecode. 1378 update_mdp_by_constant(in_bytes(BranchData::branch_data_size())); 1379 bind (profile_continue); 1380 } 1381 } 1382 1383 // Count a non-virtual call in the bytecodes. 1384 void InterpreterMacroAssembler::profile_call(Register scratch1, Register scratch2) { 1385 if (ProfileInterpreter) { 1386 Label profile_continue; 1387 1388 // If no method data exists, go to profile_continue. 1389 test_method_data_pointer(profile_continue); 1390 1391 // We are making a call. Increment the count. 1392 increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2); 1393 1394 // The method data pointer needs to be updated to reflect the new target. 1395 update_mdp_by_constant(in_bytes(CounterData::counter_data_size())); 1396 bind (profile_continue); 1397 } 1398 } 1399 1400 // Count a final call in the bytecodes. 1401 void InterpreterMacroAssembler::profile_final_call(Register scratch1, Register scratch2) { 1402 if (ProfileInterpreter) { 1403 Label profile_continue; 1404 1405 // If no method data exists, go to profile_continue. 1406 test_method_data_pointer(profile_continue); 1407 1408 // We are making a call. Increment the count. 1409 increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2); 1410 1411 // The method data pointer needs to be updated to reflect the new target. 1412 update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size())); 1413 bind (profile_continue); 1414 } 1415 } 1416 1417 // Count a virtual call in the bytecodes. 1418 void InterpreterMacroAssembler::profile_virtual_call(Register Rreceiver, 1419 Register Rscratch1, 1420 Register Rscratch2, 1421 bool receiver_can_be_null) { 1422 if (!ProfileInterpreter) { return; } 1423 Label profile_continue; 1424 1425 // If no method data exists, go to profile_continue. 1426 test_method_data_pointer(profile_continue); 1427 1428 Label skip_receiver_profile; 1429 if (receiver_can_be_null) { 1430 Label not_null; 1431 cmpdi(CCR0, Rreceiver, 0); 1432 bne(CCR0, not_null); 1433 // We are making a call. Increment the count for null receiver. 1434 increment_mdp_data_at(in_bytes(CounterData::count_offset()), Rscratch1, Rscratch2); 1435 b(skip_receiver_profile); 1436 bind(not_null); 1437 } 1438 1439 // Record the receiver type. 1440 record_klass_in_profile(Rreceiver, Rscratch1, Rscratch2, true); 1441 bind(skip_receiver_profile); 1442 1443 // The method data pointer needs to be updated to reflect the new target. 1444 update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size())); 1445 bind (profile_continue); 1446 } 1447 1448 void InterpreterMacroAssembler::profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2) { 1449 if (ProfileInterpreter) { 1450 Label profile_continue; 1451 1452 // If no method data exists, go to profile_continue. 1453 test_method_data_pointer(profile_continue); 1454 1455 int mdp_delta = in_bytes(BitData::bit_data_size()); 1456 if (TypeProfileCasts) { 1457 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1458 1459 // Record the object type. 1460 record_klass_in_profile(Rklass, Rscratch1, Rscratch2, false); 1461 } 1462 1463 // The method data pointer needs to be updated. 1464 update_mdp_by_constant(mdp_delta); 1465 1466 bind (profile_continue); 1467 } 1468 } 1469 1470 void InterpreterMacroAssembler::profile_typecheck_failed(Register Rscratch1, Register Rscratch2) { 1471 if (ProfileInterpreter && TypeProfileCasts) { 1472 Label profile_continue; 1473 1474 // If no method data exists, go to profile_continue. 1475 test_method_data_pointer(profile_continue); 1476 1477 int count_offset = in_bytes(CounterData::count_offset()); 1478 // Back up the address, since we have already bumped the mdp. 1479 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); 1480 1481 // *Decrement* the counter. We expect to see zero or small negatives. 1482 increment_mdp_data_at(count_offset, Rscratch1, Rscratch2, true); 1483 1484 bind (profile_continue); 1485 } 1486 } 1487 1488 // Count a ret in the bytecodes. 1489 void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci, Register scratch1, Register scratch2) { 1490 if (ProfileInterpreter) { 1491 Label profile_continue; 1492 uint row; 1493 1494 // If no method data exists, go to profile_continue. 1495 test_method_data_pointer(profile_continue); 1496 1497 // Update the total ret count. 1498 increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 ); 1499 1500 for (row = 0; row < RetData::row_limit(); row++) { 1501 Label next_test; 1502 1503 // See if return_bci is equal to bci[n]: 1504 test_mdp_data_at(in_bytes(RetData::bci_offset(row)), return_bci, next_test, scratch1); 1505 1506 // return_bci is equal to bci[n]. Increment the count. 1507 increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch1, scratch2); 1508 1509 // The method data pointer needs to be updated to reflect the new target. 1510 update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch1); 1511 b(profile_continue); 1512 bind(next_test); 1513 } 1514 1515 update_mdp_for_ret(state, return_bci); 1516 1517 bind (profile_continue); 1518 } 1519 } 1520 1521 // Count the default case of a switch construct. 1522 void InterpreterMacroAssembler::profile_switch_default(Register scratch1, Register scratch2) { 1523 if (ProfileInterpreter) { 1524 Label profile_continue; 1525 1526 // If no method data exists, go to profile_continue. 1527 test_method_data_pointer(profile_continue); 1528 1529 // Update the default case count 1530 increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()), 1531 scratch1, scratch2); 1532 1533 // The method data pointer needs to be updated. 1534 update_mdp_by_offset(in_bytes(MultiBranchData::default_displacement_offset()), 1535 scratch1); 1536 1537 bind (profile_continue); 1538 } 1539 } 1540 1541 // Count the index'th case of a switch construct. 1542 void InterpreterMacroAssembler::profile_switch_case(Register index, 1543 Register scratch1, 1544 Register scratch2, 1545 Register scratch3) { 1546 if (ProfileInterpreter) { 1547 assert_different_registers(index, scratch1, scratch2, scratch3); 1548 Label profile_continue; 1549 1550 // If no method data exists, go to profile_continue. 1551 test_method_data_pointer(profile_continue); 1552 1553 // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes(). 1554 li(scratch3, in_bytes(MultiBranchData::case_array_offset())); 1555 1556 assert (in_bytes(MultiBranchData::per_case_size()) == 16, "so that shladd works"); 1557 sldi(scratch1, index, exact_log2(in_bytes(MultiBranchData::per_case_size()))); 1558 add(scratch1, scratch1, scratch3); 1559 1560 // Update the case count. 1561 increment_mdp_data_at(scratch1, in_bytes(MultiBranchData::relative_count_offset()), scratch2, scratch3); 1562 1563 // The method data pointer needs to be updated. 1564 update_mdp_by_offset(scratch1, in_bytes(MultiBranchData::relative_displacement_offset()), scratch2); 1565 1566 bind (profile_continue); 1567 } 1568 } 1569 1570 void InterpreterMacroAssembler::profile_null_seen(Register Rscratch1, Register Rscratch2) { 1571 if (ProfileInterpreter) { 1572 assert_different_registers(Rscratch1, Rscratch2); 1573 Label profile_continue; 1574 1575 // If no method data exists, go to profile_continue. 1576 test_method_data_pointer(profile_continue); 1577 1578 set_mdp_flag_at(BitData::null_seen_byte_constant(), Rscratch1); 1579 1580 // The method data pointer needs to be updated. 1581 int mdp_delta = in_bytes(BitData::bit_data_size()); 1582 if (TypeProfileCasts) { 1583 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1584 } 1585 update_mdp_by_constant(mdp_delta); 1586 1587 bind (profile_continue); 1588 } 1589 } 1590 1591 void InterpreterMacroAssembler::record_klass_in_profile(Register Rreceiver, 1592 Register Rscratch1, Register Rscratch2, 1593 bool is_virtual_call) { 1594 assert(ProfileInterpreter, "must be profiling"); 1595 assert_different_registers(Rreceiver, Rscratch1, Rscratch2); 1596 1597 Label done; 1598 record_klass_in_profile_helper(Rreceiver, Rscratch1, Rscratch2, 0, done, is_virtual_call); 1599 bind (done); 1600 } 1601 1602 void InterpreterMacroAssembler::record_klass_in_profile_helper( 1603 Register receiver, Register scratch1, Register scratch2, 1604 int start_row, Label& done, bool is_virtual_call) { 1605 if (TypeProfileWidth == 0) { 1606 if (is_virtual_call) { 1607 increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2); 1608 } 1609 return; 1610 } 1611 1612 int last_row = VirtualCallData::row_limit() - 1; 1613 assert(start_row <= last_row, "must be work left to do"); 1614 // Test this row for both the receiver and for null. 1615 // Take any of three different outcomes: 1616 // 1. found receiver => increment count and goto done 1617 // 2. found null => keep looking for case 1, maybe allocate this cell 1618 // 3. found something else => keep looking for cases 1 and 2 1619 // Case 3 is handled by a recursive call. 1620 for (int row = start_row; row <= last_row; row++) { 1621 Label next_test; 1622 bool test_for_null_also = (row == start_row); 1623 1624 // See if the receiver is receiver[n]. 1625 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); 1626 test_mdp_data_at(recvr_offset, receiver, next_test, scratch1); 1627 // delayed()->tst(scratch); 1628 1629 // The receiver is receiver[n]. Increment count[n]. 1630 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); 1631 increment_mdp_data_at(count_offset, scratch1, scratch2); 1632 b(done); 1633 bind(next_test); 1634 1635 if (test_for_null_also) { 1636 Label found_null; 1637 // Failed the equality check on receiver[n]... Test for null. 1638 if (start_row == last_row) { 1639 // The only thing left to do is handle the null case. 1640 if (is_virtual_call) { 1641 // Scratch1 contains test_out from test_mdp_data_at. 1642 cmpdi(CCR0, scratch1, 0); 1643 beq(CCR0, found_null); 1644 // Receiver did not match any saved receiver and there is no empty row for it. 1645 // Increment total counter to indicate polymorphic case. 1646 increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2); 1647 b(done); 1648 bind(found_null); 1649 } else { 1650 cmpdi(CCR0, scratch1, 0); 1651 bne(CCR0, done); 1652 } 1653 break; 1654 } 1655 // Since null is rare, make it be the branch-taken case. 1656 cmpdi(CCR0, scratch1, 0); 1657 beq(CCR0, found_null); 1658 1659 // Put all the "Case 3" tests here. 1660 record_klass_in_profile_helper(receiver, scratch1, scratch2, start_row + 1, done, is_virtual_call); 1661 1662 // Found a null. Keep searching for a matching receiver, 1663 // but remember that this is an empty (unused) slot. 1664 bind(found_null); 1665 } 1666 } 1667 1668 // In the fall-through case, we found no matching receiver, but we 1669 // observed the receiver[start_row] is NULL. 1670 1671 // Fill in the receiver field and increment the count. 1672 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); 1673 set_mdp_data_at(recvr_offset, receiver); 1674 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); 1675 li(scratch1, DataLayout::counter_increment); 1676 set_mdp_data_at(count_offset, scratch1); 1677 if (start_row > 0) { 1678 b(done); 1679 } 1680 } 1681 1682 // Add a InterpMonitorElem to stack (see frame_sparc.hpp). 1683 void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2) { 1684 1685 // Very-local scratch registers. 1686 const Register esp = Rtemp1; 1687 const Register slot = Rtemp2; 1688 1689 // Extracted monitor_size. 1690 int monitor_size = frame::interpreter_frame_monitor_size_in_bytes(); 1691 assert(Assembler::is_aligned((unsigned int)monitor_size, 1692 (unsigned int)frame::alignment_in_bytes), 1693 "size of a monitor must respect alignment of SP"); 1694 1695 resize_frame(-monitor_size, /*temp*/esp); // Allocate space for new monitor 1696 std(R1_SP, _ijava_state_neg(top_frame_sp), esp); // esp contains fp 1697 1698 // Shuffle expression stack down. Recall that stack_base points 1699 // just above the new expression stack bottom. Old_tos and new_tos 1700 // are used to scan thru the old and new expression stacks. 1701 if (!stack_is_empty) { 1702 Label copy_slot, copy_slot_finished; 1703 const Register n_slots = slot; 1704 1705 addi(esp, R15_esp, Interpreter::stackElementSize); // Point to first element (pre-pushed stack). 1706 subf(n_slots, esp, R26_monitor); 1707 srdi_(n_slots, n_slots, LogBytesPerWord); // Compute number of slots to copy. 1708 assert(LogBytesPerWord == 3, "conflicts assembler instructions"); 1709 beq(CCR0, copy_slot_finished); // Nothing to copy. 1710 1711 mtctr(n_slots); 1712 1713 // loop 1714 bind(copy_slot); 1715 ld(slot, 0, esp); // Move expression stack down. 1716 std(slot, -monitor_size, esp); // distance = monitor_size 1717 addi(esp, esp, BytesPerWord); 1718 bdnz(copy_slot); 1719 1720 bind(copy_slot_finished); 1721 } 1722 1723 addi(R15_esp, R15_esp, -monitor_size); 1724 addi(R26_monitor, R26_monitor, -monitor_size); 1725 1726 // Restart interpreter 1727 } 1728 1729 // ============================================================================ 1730 // Java locals access 1731 1732 // Load a local variable at index in Rindex into register Rdst_value. 1733 // Also puts address of local into Rdst_address as a service. 1734 // Kills: 1735 // - Rdst_value 1736 // - Rdst_address 1737 void InterpreterMacroAssembler::load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex) { 1738 sldi(Rdst_address, Rindex, Interpreter::logStackElementSize); 1739 subf(Rdst_address, Rdst_address, R18_locals); 1740 lwz(Rdst_value, 0, Rdst_address); 1741 } 1742 1743 // Load a local variable at index in Rindex into register Rdst_value. 1744 // Also puts address of local into Rdst_address as a service. 1745 // Kills: 1746 // - Rdst_value 1747 // - Rdst_address 1748 void InterpreterMacroAssembler::load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex) { 1749 sldi(Rdst_address, Rindex, Interpreter::logStackElementSize); 1750 subf(Rdst_address, Rdst_address, R18_locals); 1751 ld(Rdst_value, -8, Rdst_address); 1752 } 1753 1754 // Load a local variable at index in Rindex into register Rdst_value. 1755 // Also puts address of local into Rdst_address as a service. 1756 // Input: 1757 // - Rindex: slot nr of local variable 1758 // Kills: 1759 // - Rdst_value 1760 // - Rdst_address 1761 void InterpreterMacroAssembler::load_local_ptr(Register Rdst_value, Register Rdst_address, Register Rindex) { 1762 sldi(Rdst_address, Rindex, Interpreter::logStackElementSize); 1763 subf(Rdst_address, Rdst_address, R18_locals); 1764 ld(Rdst_value, 0, Rdst_address); 1765 } 1766 1767 // Load a local variable at index in Rindex into register Rdst_value. 1768 // Also puts address of local into Rdst_address as a service. 1769 // Kills: 1770 // - Rdst_value 1771 // - Rdst_address 1772 void InterpreterMacroAssembler::load_local_float(FloatRegister Rdst_value, Register Rdst_address, Register Rindex) { 1773 sldi(Rdst_address, Rindex, Interpreter::logStackElementSize); 1774 subf(Rdst_address, Rdst_address, R18_locals); 1775 lfs(Rdst_value, 0, Rdst_address); 1776 } 1777 1778 // Load a local variable at index in Rindex into register Rdst_value. 1779 // Also puts address of local into Rdst_address as a service. 1780 // Kills: 1781 // - Rdst_value 1782 // - Rdst_address 1783 void InterpreterMacroAssembler::load_local_double(FloatRegister Rdst_value, Register Rdst_address, Register Rindex) { 1784 sldi(Rdst_address, Rindex, Interpreter::logStackElementSize); 1785 subf(Rdst_address, Rdst_address, R18_locals); 1786 lfd(Rdst_value, -8, Rdst_address); 1787 } 1788 1789 // Store an int value at local variable slot Rindex. 1790 // Kills: 1791 // - Rindex 1792 void InterpreterMacroAssembler::store_local_int(Register Rvalue, Register Rindex) { 1793 sldi(Rindex, Rindex, Interpreter::logStackElementSize); 1794 subf(Rindex, Rindex, R18_locals); 1795 stw(Rvalue, 0, Rindex); 1796 } 1797 1798 // Store a long value at local variable slot Rindex. 1799 // Kills: 1800 // - Rindex 1801 void InterpreterMacroAssembler::store_local_long(Register Rvalue, Register Rindex) { 1802 sldi(Rindex, Rindex, Interpreter::logStackElementSize); 1803 subf(Rindex, Rindex, R18_locals); 1804 std(Rvalue, -8, Rindex); 1805 } 1806 1807 // Store an oop value at local variable slot Rindex. 1808 // Kills: 1809 // - Rindex 1810 void InterpreterMacroAssembler::store_local_ptr(Register Rvalue, Register Rindex) { 1811 sldi(Rindex, Rindex, Interpreter::logStackElementSize); 1812 subf(Rindex, Rindex, R18_locals); 1813 std(Rvalue, 0, Rindex); 1814 } 1815 1816 // Store an int value at local variable slot Rindex. 1817 // Kills: 1818 // - Rindex 1819 void InterpreterMacroAssembler::store_local_float(FloatRegister Rvalue, Register Rindex) { 1820 sldi(Rindex, Rindex, Interpreter::logStackElementSize); 1821 subf(Rindex, Rindex, R18_locals); 1822 stfs(Rvalue, 0, Rindex); 1823 } 1824 1825 // Store an int value at local variable slot Rindex. 1826 // Kills: 1827 // - Rindex 1828 void InterpreterMacroAssembler::store_local_double(FloatRegister Rvalue, Register Rindex) { 1829 sldi(Rindex, Rindex, Interpreter::logStackElementSize); 1830 subf(Rindex, Rindex, R18_locals); 1831 stfd(Rvalue, -8, Rindex); 1832 } 1833 1834 // Read pending exception from thread and jump to interpreter. 1835 // Throw exception entry if one if pending. Fall through otherwise. 1836 void InterpreterMacroAssembler::check_and_forward_exception(Register Rscratch1, Register Rscratch2) { 1837 assert_different_registers(Rscratch1, Rscratch2, R3); 1838 Register Rexception = Rscratch1; 1839 Register Rtmp = Rscratch2; 1840 Label Ldone; 1841 // Get pending exception oop. 1842 ld(Rexception, thread_(pending_exception)); 1843 cmpdi(CCR0, Rexception, 0); 1844 beq(CCR0, Ldone); 1845 li(Rtmp, 0); 1846 mr_if_needed(R3, Rexception); 1847 std(Rtmp, thread_(pending_exception)); // Clear exception in thread 1848 if (Interpreter::rethrow_exception_entry() != NULL) { 1849 // Already got entry address. 1850 load_dispatch_table(Rtmp, (address*)Interpreter::rethrow_exception_entry()); 1851 } else { 1852 // Dynamically load entry address. 1853 int simm16_rest = load_const_optimized(Rtmp, &Interpreter::_rethrow_exception_entry, R0, true); 1854 ld(Rtmp, simm16_rest, Rtmp); 1855 } 1856 mtctr(Rtmp); 1857 save_interpreter_state(Rtmp); 1858 bctr(); 1859 1860 align(32, 12); 1861 bind(Ldone); 1862 } 1863 1864 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) { 1865 save_interpreter_state(R11_scratch1); 1866 1867 MacroAssembler::call_VM(oop_result, entry_point, false); 1868 1869 restore_interpreter_state(R11_scratch1, /*bcp_and_mdx_only*/ true); 1870 1871 check_and_handle_popframe(R11_scratch1); 1872 check_and_handle_earlyret(R11_scratch1); 1873 // Now check exceptions manually. 1874 if (check_exceptions) { 1875 check_and_forward_exception(R11_scratch1, R12_scratch2); 1876 } 1877 } 1878 1879 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions) { 1880 // ARG1 is reserved for the thread. 1881 mr_if_needed(R4_ARG2, arg_1); 1882 call_VM(oop_result, entry_point, check_exceptions); 1883 } 1884 1885 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) { 1886 // ARG1 is reserved for the thread. 1887 mr_if_needed(R4_ARG2, arg_1); 1888 assert(arg_2 != R4_ARG2, "smashed argument"); 1889 mr_if_needed(R5_ARG3, arg_2); 1890 call_VM(oop_result, entry_point, check_exceptions); 1891 } 1892 1893 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) { 1894 // ARG1 is reserved for the thread. 1895 mr_if_needed(R4_ARG2, arg_1); 1896 assert(arg_2 != R4_ARG2, "smashed argument"); 1897 mr_if_needed(R5_ARG3, arg_2); 1898 assert(arg_3 != R4_ARG2 && arg_3 != R5_ARG3, "smashed argument"); 1899 mr_if_needed(R6_ARG4, arg_3); 1900 call_VM(oop_result, entry_point, check_exceptions); 1901 } 1902 1903 void InterpreterMacroAssembler::save_interpreter_state(Register scratch) { 1904 ld(scratch, 0, R1_SP); 1905 std(R15_esp, _ijava_state_neg(esp), scratch); 1906 std(R14_bcp, _ijava_state_neg(bcp), scratch); 1907 std(R26_monitor, _ijava_state_neg(monitors), scratch); 1908 if (ProfileInterpreter) { std(R28_mdx, _ijava_state_neg(mdx), scratch); } 1909 // Other entries should be unchanged. 1910 } 1911 1912 void InterpreterMacroAssembler::restore_interpreter_state(Register scratch, bool bcp_and_mdx_only) { 1913 ld(scratch, 0, R1_SP); 1914 ld(R14_bcp, _ijava_state_neg(bcp), scratch); // Changed by VM code (exception). 1915 if (ProfileInterpreter) { ld(R28_mdx, _ijava_state_neg(mdx), scratch); } // Changed by VM code. 1916 if (!bcp_and_mdx_only) { 1917 // Following ones are Metadata. 1918 ld(R19_method, _ijava_state_neg(method), scratch); 1919 ld(R27_constPoolCache, _ijava_state_neg(cpoolCache), scratch); 1920 // Following ones are stack addresses and don't require reload. 1921 ld(R15_esp, _ijava_state_neg(esp), scratch); 1922 ld(R18_locals, _ijava_state_neg(locals), scratch); 1923 ld(R26_monitor, _ijava_state_neg(monitors), scratch); 1924 } 1925 #ifdef ASSERT 1926 { 1927 Label Lok; 1928 subf(R0, R1_SP, scratch); 1929 cmpdi(CCR0, R0, frame::abi_reg_args_size + frame::ijava_state_size); 1930 bge(CCR0, Lok); 1931 stop("frame too small (restore istate)", 0x5432); 1932 bind(Lok); 1933 } 1934 { 1935 Label Lok; 1936 ld(R0, _ijava_state_neg(ijava_reserved), scratch); 1937 cmpdi(CCR0, R0, 0x5afe); 1938 beq(CCR0, Lok); 1939 stop("frame corrupted (restore istate)", 0x5afe); 1940 bind(Lok); 1941 } 1942 #endif 1943 } 1944 1945 #endif // !CC_INTERP 1946 1947 void InterpreterMacroAssembler::get_method_counters(Register method, 1948 Register Rcounters, 1949 Label& skip) { 1950 BLOCK_COMMENT("Load and ev. allocate counter object {"); 1951 Label has_counters; 1952 ld(Rcounters, in_bytes(Method::method_counters_offset()), method); 1953 cmpdi(CCR0, Rcounters, 0); 1954 bne(CCR0, has_counters); 1955 call_VM(noreg, CAST_FROM_FN_PTR(address, 1956 InterpreterRuntime::build_method_counters), method, false); 1957 ld(Rcounters, in_bytes(Method::method_counters_offset()), method); 1958 cmpdi(CCR0, Rcounters, 0); 1959 beq(CCR0, skip); // No MethodCounters, OutOfMemory. 1960 BLOCK_COMMENT("} Load and ev. allocate counter object"); 1961 1962 bind(has_counters); 1963 } 1964 1965 void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters, Register iv_be_count, Register Rtmp_r0) { 1966 assert(UseCompiler, "incrementing must be useful"); 1967 Register invocation_count = iv_be_count; 1968 Register backedge_count = Rtmp_r0; 1969 int delta = InvocationCounter::count_increment; 1970 1971 // Load each counter in a register. 1972 // ld(inv_counter, Rtmp); 1973 // ld(be_counter, Rtmp2); 1974 int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() + 1975 InvocationCounter::counter_offset()); 1976 int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() + 1977 InvocationCounter::counter_offset()); 1978 1979 BLOCK_COMMENT("Increment profiling counters {"); 1980 1981 // Load the backedge counter. 1982 lwz(backedge_count, be_counter_offset, Rcounters); // is unsigned int 1983 // Mask the backedge counter. 1984 Register tmp = invocation_count; 1985 li(tmp, InvocationCounter::count_mask_value); 1986 andr(backedge_count, tmp, backedge_count); // Cannot use andi, need sign extension of count_mask_value. 1987 1988 // Load the invocation counter. 1989 lwz(invocation_count, inv_counter_offset, Rcounters); // is unsigned int 1990 // Add the delta to the invocation counter and store the result. 1991 addi(invocation_count, invocation_count, delta); 1992 // Store value. 1993 stw(invocation_count, inv_counter_offset, Rcounters); 1994 1995 // Add invocation counter + backedge counter. 1996 add(iv_be_count, backedge_count, invocation_count); 1997 1998 // Note that this macro must leave the backedge_count + invocation_count in 1999 // register iv_be_count! 2000 BLOCK_COMMENT("} Increment profiling counters"); 2001 } 2002 2003 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { 2004 if (state == atos) { MacroAssembler::verify_oop(reg); } 2005 } 2006 2007 #ifndef CC_INTERP 2008 // Local helper function for the verify_oop_or_return_address macro. 2009 static bool verify_return_address(Method* m, int bci) { 2010 #ifndef PRODUCT 2011 address pc = (address)(m->constMethod()) + in_bytes(ConstMethod::codes_offset()) + bci; 2012 // Assume it is a valid return address if it is inside m and is preceded by a jsr. 2013 if (!m->contains(pc)) return false; 2014 address jsr_pc; 2015 jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr); 2016 if (*jsr_pc == Bytecodes::_jsr && jsr_pc >= m->code_base()) return true; 2017 jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w); 2018 if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base()) return true; 2019 #endif // PRODUCT 2020 return false; 2021 } 2022 2023 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { 2024 if (VerifyFPU) { 2025 unimplemented("verfiyFPU"); 2026 } 2027 } 2028 2029 void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) { 2030 if (!VerifyOops) return; 2031 2032 // The VM documentation for the astore[_wide] bytecode allows 2033 // the TOS to be not only an oop but also a return address. 2034 Label test; 2035 Label skip; 2036 // See if it is an address (in the current method): 2037 2038 const int log2_bytecode_size_limit = 16; 2039 srdi_(Rtmp, reg, log2_bytecode_size_limit); 2040 bne(CCR0, test); 2041 2042 address fd = CAST_FROM_FN_PTR(address, verify_return_address); 2043 unsigned int nbytes_save = 10*8; // 10 volatile gprs 2044 2045 save_LR_CR(Rtmp); 2046 push_frame_reg_args(nbytes_save, Rtmp); 2047 save_volatile_gprs(R1_SP, 112); // except R0 2048 2049 load_const_optimized(Rtmp, fd, R0); 2050 mr_if_needed(R4_ARG2, reg); 2051 mr(R3_ARG1, R19_method); 2052 call_c(Rtmp); // call C 2053 2054 restore_volatile_gprs(R1_SP, 112); // except R0 2055 pop_frame(); 2056 restore_LR_CR(Rtmp); 2057 b(skip); 2058 2059 // Perform a more elaborate out-of-line call. 2060 // Not an address; verify it: 2061 bind(test); 2062 verify_oop(reg); 2063 bind(skip); 2064 } 2065 #endif // !CC_INTERP 2066 2067 // Inline assembly for: 2068 // 2069 // if (thread is in interp_only_mode) { 2070 // InterpreterRuntime::post_method_entry(); 2071 // } 2072 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY ) || 2073 // *jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY2) ) { 2074 // SharedRuntime::jvmpi_method_entry(method, receiver); 2075 // } 2076 void InterpreterMacroAssembler::notify_method_entry() { 2077 // JVMTI 2078 // Whenever JVMTI puts a thread in interp_only_mode, method 2079 // entry/exit events are sent for that thread to track stack 2080 // depth. If it is possible to enter interp_only_mode we add 2081 // the code to check if the event should be sent. 2082 if (JvmtiExport::can_post_interpreter_events()) { 2083 Label jvmti_post_done; 2084 2085 lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread); 2086 cmpwi(CCR0, R0, 0); 2087 beq(CCR0, jvmti_post_done); 2088 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry), 2089 /*check_exceptions=*/true CC_INTERP_ONLY(&& false)); 2090 2091 bind(jvmti_post_done); 2092 } 2093 } 2094 2095 // Inline assembly for: 2096 // 2097 // if (thread is in interp_only_mode) { 2098 // // save result 2099 // InterpreterRuntime::post_method_exit(); 2100 // // restore result 2101 // } 2102 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_EXIT)) { 2103 // // save result 2104 // SharedRuntime::jvmpi_method_exit(); 2105 // // restore result 2106 // } 2107 // 2108 // Native methods have their result stored in d_tmp and l_tmp. 2109 // Java methods have their result stored in the expression stack. 2110 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state, 2111 NotifyMethodExitMode mode, bool check_exceptions) { 2112 // JVMTI 2113 // Whenever JVMTI puts a thread in interp_only_mode, method 2114 // entry/exit events are sent for that thread to track stack 2115 // depth. If it is possible to enter interp_only_mode we add 2116 // the code to check if the event should be sent. 2117 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 2118 Label jvmti_post_done; 2119 2120 lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread); 2121 cmpwi(CCR0, R0, 0); 2122 beq(CCR0, jvmti_post_done); 2123 CC_INTERP_ONLY(assert(is_native_method && !check_exceptions, "must not push state")); 2124 if (!is_native_method) push(state); // Expose tos to GC. 2125 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit), 2126 /*check_exceptions=*/check_exceptions); 2127 if (!is_native_method) pop(state); 2128 2129 align(32, 12); 2130 bind(jvmti_post_done); 2131 } 2132 2133 // Dtrace support not implemented. 2134 } 2135 2136 #ifdef CC_INTERP 2137 // Convert the current TOP_IJAVA_FRAME into a PARENT_IJAVA_FRAME 2138 // (using parent_frame_resize) and push a new interpreter 2139 // TOP_IJAVA_FRAME (using frame_size). 2140 void InterpreterMacroAssembler::push_interpreter_frame(Register top_frame_size, Register parent_frame_resize, 2141 Register tmp1, Register tmp2, Register tmp3, 2142 Register tmp4, Register pc) { 2143 assert_different_registers(top_frame_size, parent_frame_resize, tmp1, tmp2, tmp3, tmp4); 2144 ld(tmp1, _top_ijava_frame_abi(frame_manager_lr), R1_SP); 2145 mr(tmp2/*top_frame_sp*/, R1_SP); 2146 // Move initial_caller_sp. 2147 ld(tmp4, _top_ijava_frame_abi(initial_caller_sp), R1_SP); 2148 neg(parent_frame_resize, parent_frame_resize); 2149 resize_frame(parent_frame_resize/*-parent_frame_resize*/, tmp3); 2150 2151 // Set LR in new parent frame. 2152 std(tmp1, _abi(lr), R1_SP); 2153 // Set top_frame_sp info for new parent frame. 2154 std(tmp2, _parent_ijava_frame_abi(top_frame_sp), R1_SP); 2155 std(tmp4, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); 2156 2157 // Push new TOP_IJAVA_FRAME. 2158 push_frame(top_frame_size, tmp2); 2159 2160 get_PC_trash_LR(tmp3); 2161 std(tmp3, _top_ijava_frame_abi(frame_manager_lr), R1_SP); 2162 // Used for non-initial callers by unextended_sp(). 2163 std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP); 2164 } 2165 2166 // Pop the topmost TOP_IJAVA_FRAME and convert the previous 2167 // PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME. 2168 void InterpreterMacroAssembler::pop_interpreter_frame(Register tmp1, Register tmp2, Register tmp3, Register tmp4) { 2169 assert_different_registers(tmp1, tmp2, tmp3, tmp4); 2170 2171 ld(tmp1/*caller's sp*/, _abi(callers_sp), R1_SP); 2172 ld(tmp3, _abi(lr), tmp1); 2173 2174 ld(tmp4, _parent_ijava_frame_abi(initial_caller_sp), tmp1); 2175 2176 ld(tmp2/*caller's caller's sp*/, _abi(callers_sp), tmp1); 2177 // Merge top frame. 2178 std(tmp2, _abi(callers_sp), R1_SP); 2179 2180 ld(tmp2, _parent_ijava_frame_abi(top_frame_sp), tmp1); 2181 2182 // Update C stack pointer to caller's top_abi. 2183 resize_frame_absolute(tmp2/*addr*/, tmp1/*tmp*/, tmp2/*tmp*/); 2184 2185 // Update LR in top_frame. 2186 std(tmp3, _top_ijava_frame_abi(frame_manager_lr), R1_SP); 2187 2188 std(tmp4, _top_ijava_frame_abi(initial_caller_sp), R1_SP); 2189 2190 // Store the top-frame stack-pointer for c2i adapters. 2191 std(R1_SP, _top_ijava_frame_abi(top_frame_sp), R1_SP); 2192 } 2193 2194 // Turn state's interpreter frame into the current TOP_IJAVA_FRAME. 2195 void InterpreterMacroAssembler::pop_interpreter_frame_to_state(Register state, Register tmp1, Register tmp2, Register tmp3) { 2196 assert_different_registers(R14_state, R15_prev_state, tmp1, tmp2, tmp3); 2197 2198 if (state == R14_state) { 2199 ld(tmp1/*state's fp*/, state_(_last_Java_fp)); 2200 ld(tmp2/*state's sp*/, state_(_last_Java_sp)); 2201 } else if (state == R15_prev_state) { 2202 ld(tmp1/*state's fp*/, prev_state_(_last_Java_fp)); 2203 ld(tmp2/*state's sp*/, prev_state_(_last_Java_sp)); 2204 } else { 2205 ShouldNotReachHere(); 2206 } 2207 2208 // Merge top frames. 2209 std(tmp1, _abi(callers_sp), R1_SP); 2210 2211 // Tmp2 is new SP. 2212 // Tmp1 is parent's SP. 2213 resize_frame_absolute(tmp2/*addr*/, tmp1/*tmp*/, tmp2/*tmp*/); 2214 2215 // Update LR in top_frame. 2216 // Must be interpreter frame. 2217 get_PC_trash_LR(tmp3); 2218 std(tmp3, _top_ijava_frame_abi(frame_manager_lr), R1_SP); 2219 // Used for non-initial callers by unextended_sp(). 2220 std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP); 2221 } 2222 2223 // Set SP to initial caller's sp, but before fix the back chain. 2224 void InterpreterMacroAssembler::resize_frame_to_initial_caller(Register tmp1, Register tmp2) { 2225 ld(tmp1, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); 2226 ld(tmp2, _parent_ijava_frame_abi(callers_sp), R1_SP); 2227 std(tmp2, _parent_ijava_frame_abi(callers_sp), tmp1); // Fix back chain ... 2228 mr(R1_SP, tmp1); // ... and resize to initial caller. 2229 } 2230 2231 // Pop the current interpreter state (without popping the correspoding 2232 // frame) and restore R14_state and R15_prev_state accordingly. 2233 // Use prev_state_may_be_0 to indicate whether prev_state may be 0 2234 // in order to generate an extra check before retrieving prev_state_(_prev_link). 2235 void InterpreterMacroAssembler::pop_interpreter_state(bool prev_state_may_be_0) 2236 { 2237 // Move prev_state to state and restore prev_state from state_(_prev_link). 2238 Label prev_state_is_0; 2239 mr(R14_state, R15_prev_state); 2240 2241 // Don't retrieve /*state==*/prev_state_(_prev_link) 2242 // if /*state==*/prev_state is 0. 2243 if (prev_state_may_be_0) { 2244 cmpdi(CCR0, R15_prev_state, 0); 2245 beq(CCR0, prev_state_is_0); 2246 } 2247 2248 ld(R15_prev_state, /*state==*/prev_state_(_prev_link)); 2249 bind(prev_state_is_0); 2250 } 2251 2252 void InterpreterMacroAssembler::restore_prev_state() { 2253 // _prev_link is private, but cInterpreter is a friend. 2254 ld(R15_prev_state, state_(_prev_link)); 2255 } 2256 #endif // CC_INTERP