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