1 /* 2 * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2012, 2025 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 "asm/macroAssembler.inline.hpp" 28 #include "gc/shared/barrierSet.hpp" 29 #include "gc/shared/barrierSetAssembler.hpp" 30 #include "interp_masm_ppc.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "oops/methodCounters.hpp" 33 #include "oops/methodData.hpp" 34 #include "oops/resolvedFieldEntry.hpp" 35 #include "oops/resolvedIndyEntry.hpp" 36 #include "oops/resolvedMethodEntry.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "prims/jvmtiThreadState.hpp" 39 #include "runtime/frame.inline.hpp" 40 #include "runtime/safepointMechanism.hpp" 41 #include "runtime/sharedRuntime.hpp" 42 #include "runtime/vm_version.hpp" 43 #include "utilities/macros.hpp" 44 #include "utilities/powerOfTwo.hpp" 45 46 // Implementation of InterpreterMacroAssembler. 47 48 // This file specializes the assembler with interpreter-specific macros. 49 50 #ifdef PRODUCT 51 #define BLOCK_COMMENT(str) // nothing 52 #else 53 #define BLOCK_COMMENT(str) block_comment(str) 54 #endif 55 56 void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) { 57 address exception_entry = Interpreter::throw_NullPointerException_entry(); 58 MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry); 59 } 60 61 void InterpreterMacroAssembler::load_klass_check_null_throw(Register dst, Register src, Register temp_reg) { 62 null_check_throw(src, oopDesc::klass_offset_in_bytes(), temp_reg); 63 load_klass(dst, src); 64 } 65 66 void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) { 67 assert(entry, "Entry must have been generated by now"); 68 if (is_within_range_of_b(entry, pc())) { 69 b(entry); 70 } else { 71 load_const_optimized(Rscratch, entry, R0); 72 mtctr(Rscratch); 73 bctr(); 74 } 75 } 76 77 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) { 78 Register bytecode = R12_scratch2; 79 if (bcp_incr != 0) { 80 lbzu(bytecode, bcp_incr, R14_bcp); 81 } else { 82 lbz(bytecode, 0, R14_bcp); 83 } 84 85 dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state), generate_poll); 86 } 87 88 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { 89 // Load current bytecode. 90 Register bytecode = R12_scratch2; 91 lbz(bytecode, 0, R14_bcp); 92 dispatch_Lbyte_code(state, bytecode, table); 93 } 94 95 // Dispatch code executed in the prolog of a bytecode which does not do it's 96 // own dispatch. The dispatch address is computed and placed in R24_dispatch_addr. 97 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) { 98 Register bytecode = R12_scratch2; 99 lbz(bytecode, bcp_incr, R14_bcp); 100 101 load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state)); 102 103 sldi(bytecode, bytecode, LogBytesPerWord); 104 ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode); 105 } 106 107 // Dispatch code executed in the epilog of a bytecode which does not do it's 108 // own dispatch. The dispatch address in R24_dispatch_addr is used for the 109 // dispatch. 110 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) { 111 if (bcp_incr) { addi(R14_bcp, R14_bcp, bcp_incr); } 112 mtctr(R24_dispatch_addr); 113 bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable); 114 } 115 116 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) { 117 assert(scratch_reg != R0, "can't use R0 as scratch_reg here"); 118 if (JvmtiExport::can_pop_frame()) { 119 Label L; 120 121 // Check the "pending popframe condition" flag in the current thread. 122 lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread); 123 124 // Initiate popframe handling only if it is not already being 125 // processed. If the flag has the popframe_processing bit set, it 126 // means that this code is called *during* popframe handling - we 127 // don't want to reenter. 128 andi_(R0, scratch_reg, JavaThread::popframe_pending_bit); 129 beq(CR0, L); 130 131 andi_(R0, scratch_reg, JavaThread::popframe_processing_bit); 132 bne(CR0, L); 133 134 // Call the Interpreter::remove_activation_preserving_args_entry() 135 // func to get the address of the same-named entrypoint in the 136 // generated interpreter code. 137 call_c(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); 138 139 // Jump to Interpreter::_remove_activation_preserving_args_entry. 140 mtctr(R3_RET); 141 bctr(); 142 143 align(32, 12); 144 bind(L); 145 } 146 } 147 148 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) { 149 const Register Rthr_state_addr = scratch_reg; 150 if (JvmtiExport::can_force_early_return()) { 151 Label Lno_early_ret; 152 ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread); 153 cmpdi(CR0, Rthr_state_addr, 0); 154 beq(CR0, Lno_early_ret); 155 156 lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr); 157 cmpwi(CR0, R0, JvmtiThreadState::earlyret_pending); 158 bne(CR0, Lno_early_ret); 159 160 // Jump to Interpreter::_earlyret_entry. 161 lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr); 162 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry)); 163 mtlr(R3_RET); 164 blr(); 165 166 align(32, 12); 167 bind(Lno_early_ret); 168 } 169 } 170 171 void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) { 172 const Register RjvmtiState = Rscratch1; 173 const Register Rscratch2 = R0; 174 175 ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread); 176 li(Rscratch2, 0); 177 178 switch (state) { 179 case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState); 180 std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState); 181 break; 182 case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 183 break; 184 case btos: // fall through 185 case ztos: // fall through 186 case ctos: // fall through 187 case stos: // fall through 188 case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 189 break; 190 case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 191 break; 192 case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 193 break; 194 case vtos: break; 195 default : ShouldNotReachHere(); 196 } 197 198 // Clean up tos value in the jvmti thread state. 199 std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState); 200 // Set tos state field to illegal value. 201 li(Rscratch2, ilgl); 202 stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState); 203 } 204 205 // Common code to dispatch and dispatch_only. 206 // Dispatch value in Lbyte_code and increment Lbcp. 207 208 void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) { 209 address table_base = (address)Interpreter::dispatch_table((TosState)0); 210 intptr_t table_offs = (intptr_t)table - (intptr_t)table_base; 211 if (is_simm16(table_offs)) { 212 addi(dst, R25_templateTableBase, (int)table_offs); 213 } else { 214 load_const_optimized(dst, table, R0); 215 } 216 } 217 218 void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode, 219 address* table, bool generate_poll) { 220 assert_different_registers(bytecode, R11_scratch1); 221 222 // Calc dispatch table address. 223 load_dispatch_table(R11_scratch1, table); 224 225 if (generate_poll) { 226 address *sfpt_tbl = Interpreter::safept_table(state); 227 if (table != sfpt_tbl) { 228 Label dispatch; 229 ld(R0, in_bytes(JavaThread::polling_word_offset()), R16_thread); 230 // Armed page has poll_bit set, if poll bit is cleared just continue. 231 andi_(R0, R0, SafepointMechanism::poll_bit()); 232 beq(CR0, dispatch); 233 load_dispatch_table(R11_scratch1, sfpt_tbl); 234 align(32, 16); 235 bind(dispatch); 236 } 237 } 238 239 sldi(R12_scratch2, bytecode, LogBytesPerWord); 240 ldx(R11_scratch1, R11_scratch1, R12_scratch2); 241 242 // Jump off! 243 mtctr(R11_scratch1); 244 bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable); 245 } 246 247 void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) { 248 sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize); 249 ldx(Rrecv_dst, Rrecv_dst, R15_esp); 250 } 251 252 // helpers for expression stack 253 254 void InterpreterMacroAssembler::pop_i(Register r) { 255 lwzu(r, Interpreter::stackElementSize, R15_esp); 256 } 257 258 void InterpreterMacroAssembler::pop_ptr(Register r) { 259 ldu(r, Interpreter::stackElementSize, R15_esp); 260 } 261 262 void InterpreterMacroAssembler::pop_l(Register r) { 263 ld(r, Interpreter::stackElementSize, R15_esp); 264 addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize); 265 } 266 267 void InterpreterMacroAssembler::pop_f(FloatRegister f) { 268 lfsu(f, Interpreter::stackElementSize, R15_esp); 269 } 270 271 void InterpreterMacroAssembler::pop_d(FloatRegister f) { 272 lfd(f, Interpreter::stackElementSize, R15_esp); 273 addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize); 274 } 275 276 void InterpreterMacroAssembler::push_i(Register r) { 277 stw(r, 0, R15_esp); 278 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 279 } 280 281 void InterpreterMacroAssembler::push_ptr(Register r) { 282 std(r, 0, R15_esp); 283 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 284 } 285 286 void InterpreterMacroAssembler::push_l(Register r) { 287 // Clear unused slot. 288 load_const_optimized(R0, 0L); 289 std(R0, 0, R15_esp); 290 std(r, - Interpreter::stackElementSize, R15_esp); 291 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 292 } 293 294 void InterpreterMacroAssembler::push_f(FloatRegister f) { 295 stfs(f, 0, R15_esp); 296 addi(R15_esp, R15_esp, - Interpreter::stackElementSize ); 297 } 298 299 void InterpreterMacroAssembler::push_d(FloatRegister f) { 300 stfd(f, - Interpreter::stackElementSize, R15_esp); 301 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 302 } 303 304 void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) { 305 std(first, 0, R15_esp); 306 std(second, -Interpreter::stackElementSize, R15_esp); 307 addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize ); 308 } 309 310 void InterpreterMacroAssembler::move_l_to_d(Register l, FloatRegister d) { 311 if (VM_Version::has_mtfprd()) { 312 mtfprd(d, l); 313 } else { 314 std(l, 0, R15_esp); 315 lfd(d, 0, R15_esp); 316 } 317 } 318 319 void InterpreterMacroAssembler::move_d_to_l(FloatRegister d, Register l) { 320 if (VM_Version::has_mtfprd()) { 321 mffprd(l, d); 322 } else { 323 stfd(d, 0, R15_esp); 324 ld(l, 0, R15_esp); 325 } 326 } 327 328 void InterpreterMacroAssembler::push(TosState state) { 329 switch (state) { 330 case atos: push_ptr(); break; 331 case btos: 332 case ztos: 333 case ctos: 334 case stos: 335 case itos: push_i(); break; 336 case ltos: push_l(); break; 337 case ftos: push_f(); break; 338 case dtos: push_d(); break; 339 case vtos: /* nothing to do */ break; 340 default : ShouldNotReachHere(); 341 } 342 } 343 344 void InterpreterMacroAssembler::pop(TosState state) { 345 switch (state) { 346 case atos: pop_ptr(); break; 347 case btos: 348 case ztos: 349 case ctos: 350 case stos: 351 case itos: pop_i(); break; 352 case ltos: pop_l(); break; 353 case ftos: pop_f(); break; 354 case dtos: pop_d(); break; 355 case vtos: /* nothing to do */ break; 356 default : ShouldNotReachHere(); 357 } 358 verify_oop(R17_tos, state); 359 } 360 361 void InterpreterMacroAssembler::empty_expression_stack() { 362 addi(R15_esp, R26_monitor, - Interpreter::stackElementSize); 363 } 364 365 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int bcp_offset, 366 Register Rdst, 367 signedOrNot is_signed) { 368 #if defined(VM_LITTLE_ENDIAN) 369 if (bcp_offset) { 370 load_const_optimized(Rdst, bcp_offset); 371 lhbrx(Rdst, R14_bcp, Rdst); 372 } else { 373 lhbrx(Rdst, R14_bcp); 374 } 375 if (is_signed == Signed) { 376 extsh(Rdst, Rdst); 377 } 378 #else 379 // Read Java big endian format. 380 if (is_signed == Signed) { 381 lha(Rdst, bcp_offset, R14_bcp); 382 } else { 383 lhz(Rdst, bcp_offset, R14_bcp); 384 } 385 #endif 386 } 387 388 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int bcp_offset, 389 Register Rdst, 390 signedOrNot is_signed) { 391 #if defined(VM_LITTLE_ENDIAN) 392 if (bcp_offset) { 393 load_const_optimized(Rdst, bcp_offset); 394 lwbrx(Rdst, R14_bcp, Rdst); 395 } else { 396 lwbrx(Rdst, R14_bcp); 397 } 398 if (is_signed == Signed) { 399 extsw(Rdst, Rdst); 400 } 401 #else 402 // Read Java big endian format. 403 if (bcp_offset & 3) { // Offset unaligned? 404 load_const_optimized(Rdst, bcp_offset); 405 if (is_signed == Signed) { 406 lwax(Rdst, R14_bcp, Rdst); 407 } else { 408 lwzx(Rdst, R14_bcp, Rdst); 409 } 410 } else { 411 if (is_signed == Signed) { 412 lwa(Rdst, bcp_offset, R14_bcp); 413 } else { 414 lwz(Rdst, bcp_offset, R14_bcp); 415 } 416 } 417 #endif 418 } 419 420 421 // Load the constant pool cache index from the bytecode stream. 422 // 423 // Kills / writes: 424 // - Rdst, Rscratch 425 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset, 426 size_t index_size) { 427 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 428 // Cache index is always in the native format, courtesy of Rewriter. 429 if (index_size == sizeof(u2)) { 430 lhz(Rdst, bcp_offset, R14_bcp); 431 } else if (index_size == sizeof(u4)) { 432 if (bcp_offset & 3) { 433 load_const_optimized(Rdst, bcp_offset); 434 lwax(Rdst, R14_bcp, Rdst); 435 } else { 436 lwa(Rdst, bcp_offset, R14_bcp); 437 } 438 } else if (index_size == sizeof(u1)) { 439 lbz(Rdst, bcp_offset, R14_bcp); 440 } else { 441 ShouldNotReachHere(); 442 } 443 // Rdst now contains cp cache index. 444 } 445 446 // Load 4-byte signed or unsigned integer in Java format (that is, big-endian format) 447 // from (Rsrc)+offset. 448 void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset, 449 signedOrNot is_signed) { 450 #if defined(VM_LITTLE_ENDIAN) 451 if (offset) { 452 load_const_optimized(Rdst, offset); 453 lwbrx(Rdst, Rdst, Rsrc); 454 } else { 455 lwbrx(Rdst, Rsrc); 456 } 457 if (is_signed == Signed) { 458 extsw(Rdst, Rdst); 459 } 460 #else 461 if (is_signed == Signed) { 462 lwa(Rdst, offset, Rsrc); 463 } else { 464 lwz(Rdst, offset, Rsrc); 465 } 466 #endif 467 } 468 469 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) { 470 // Get index out of bytecode pointer 471 get_cache_index_at_bcp(index, 1, sizeof(u4)); 472 473 // Get address of invokedynamic array 474 ld_ptr(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()), R27_constPoolCache); 475 // Scale the index to be the entry index * sizeof(ResolvedIndyEntry) 476 sldi(index, index, log2i_exact(sizeof(ResolvedIndyEntry))); 477 addi(cache, cache, Array<ResolvedIndyEntry>::base_offset_in_bytes()); 478 add(cache, cache, index); 479 } 480 481 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) { 482 // Get index out of bytecode pointer 483 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 484 // Take shortcut if the size is a power of 2 485 if (is_power_of_2(sizeof(ResolvedFieldEntry))) { 486 // Scale index by power of 2 487 sldi(index, index, log2i_exact(sizeof(ResolvedFieldEntry))); 488 } else { 489 // Scale the index to be the entry index * sizeof(ResolvedFieldEntry) 490 mulli(index, index, sizeof(ResolvedFieldEntry)); 491 } 492 // Get address of field entries array 493 ld_ptr(cache, in_bytes(ConstantPoolCache::field_entries_offset()), R27_constPoolCache); 494 addi(cache, cache, Array<ResolvedFieldEntry>::base_offset_in_bytes()); 495 add(cache, cache, index); 496 } 497 498 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) { 499 // Get index out of bytecode pointer 500 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 501 // Scale the index to be the entry index * sizeof(ResolvedMethodEntry) 502 mulli(index, index, sizeof(ResolvedMethodEntry)); 503 504 // Get address of field entries array 505 ld_ptr(cache, ConstantPoolCache::method_entries_offset(), R27_constPoolCache); 506 addi(cache, cache, Array<ResolvedMethodEntry>::base_offset_in_bytes()); 507 add(cache, cache, index); // method_entries + base_offset + scaled index 508 } 509 510 // Load object from cpool->resolved_references(index). 511 // Kills: 512 // - index 513 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index, 514 Register tmp1, Register tmp2, 515 Label *L_handle_null) { 516 assert_different_registers(result, index, tmp1, tmp2); 517 assert(index->is_nonvolatile(), "needs to survive C-call in resolve_oop_handle"); 518 get_constant_pool(result); 519 520 // Convert from field index to resolved_references() index and from 521 // word index to byte offset. Since this is a java object, it can be compressed. 522 sldi(index, index, LogBytesPerHeapOop); 523 // Load pointer for resolved_references[] objArray. 524 ld(result, ConstantPool::cache_offset(), result); 525 ld(result, ConstantPoolCache::resolved_references_offset(), result); 526 resolve_oop_handle(result, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE); 527 #ifdef ASSERT 528 Label index_ok; 529 lwa(R0, arrayOopDesc::length_offset_in_bytes(), result); 530 sldi(R0, R0, LogBytesPerHeapOop); 531 cmpd(CR0, index, R0); 532 blt(CR0, index_ok); 533 stop("resolved reference index out of bounds"); 534 bind(index_ok); 535 #endif 536 // Add in the index. 537 add(result, index, result); 538 load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result, 539 tmp1, tmp2, 540 MacroAssembler::PRESERVATION_NONE, 541 0, L_handle_null); 542 } 543 544 // load cpool->resolved_klass_at(index) 545 void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass) { 546 // int value = *(Rcpool->int_at_addr(which)); 547 // int resolved_klass_index = extract_low_short_from_int(value); 548 add(Roffset, Rcpool, Roffset); 549 #if defined(VM_LITTLE_ENDIAN) 550 lhz(Roffset, sizeof(ConstantPool), Roffset); // Roffset = resolved_klass_index 551 #else 552 lhz(Roffset, sizeof(ConstantPool) + 2, Roffset); // Roffset = resolved_klass_index 553 #endif 554 555 ld(Rklass, ConstantPool::resolved_klasses_offset(), Rcpool); // Rklass = Rcpool->_resolved_klasses 556 557 sldi(Roffset, Roffset, LogBytesPerWord); 558 addi(Roffset, Roffset, Array<Klass*>::base_offset_in_bytes()); 559 isync(); // Order load of instance Klass wrt. tags. 560 ldx(Rklass, Rklass, Roffset); 561 } 562 563 // Generate a subtype check: branch to ok_is_subtype if sub_klass is 564 // a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2. 565 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1, 566 Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) { 567 // Profile the not-null value's klass. 568 profile_typecheck(Rsub_klass, Rtmp1, Rtmp2); 569 check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype); 570 } 571 572 // Separate these two to allow for delay slot in middle. 573 // These are used to do a test and full jump to exception-throwing code. 574 575 // Check that index is in range for array, then shift index by index_shift, 576 // and put arrayOop + shifted_index into res. 577 // Note: res is still shy of address by array offset into object. 578 579 void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex, 580 int index_shift, Register Rtmp, Register Rres) { 581 // Check that index is in range for array, then shift index by index_shift, 582 // and put arrayOop + shifted_index into res. 583 // Note: res is still shy of address by array offset into object. 584 // Kills: 585 // - Rindex 586 // Writes: 587 // - Rres: Address that corresponds to the array index if check was successful. 588 verify_oop(Rarray); 589 const Register Rlength = R0; 590 const Register RsxtIndex = Rtmp; 591 Label LisNull, LnotOOR; 592 593 // Array nullcheck 594 if (!ImplicitNullChecks) { 595 cmpdi(CR0, Rarray, 0); 596 beq(CR0, LisNull); 597 } else { 598 null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex); 599 } 600 601 // Rindex might contain garbage in upper bits (remember that we don't sign extend 602 // during integer arithmetic operations). So kill them and put value into same register 603 // where ArrayIndexOutOfBounds would expect the index in. 604 rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit 605 606 // Index check 607 lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray); 608 cmplw(CR0, Rindex, Rlength); 609 sldi(RsxtIndex, RsxtIndex, index_shift); 610 blt(CR0, LnotOOR); 611 // Index should be in R17_tos, array should be in R4_ARG2. 612 mr_if_needed(R17_tos, Rindex); 613 mr_if_needed(R4_ARG2, Rarray); 614 load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry); 615 mtctr(Rtmp); 616 bctr(); 617 618 if (!ImplicitNullChecks) { 619 bind(LisNull); 620 load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry); 621 mtctr(Rtmp); 622 bctr(); 623 } 624 625 align(32, 16); 626 bind(LnotOOR); 627 628 // Calc address 629 add(Rres, RsxtIndex, Rarray); 630 } 631 632 void InterpreterMacroAssembler::index_check(Register array, Register index, 633 int index_shift, Register tmp, Register res) { 634 // pop array 635 pop_ptr(array); 636 637 // check array 638 index_check_without_pop(array, index, index_shift, tmp, res); 639 } 640 641 void InterpreterMacroAssembler::get_const(Register Rdst) { 642 ld(Rdst, in_bytes(Method::const_offset()), R19_method); 643 } 644 645 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) { 646 get_const(Rdst); 647 ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst); 648 } 649 650 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) { 651 get_constant_pool(Rdst); 652 ld(Rdst, ConstantPool::cache_offset(), Rdst); 653 } 654 655 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) { 656 get_constant_pool(Rcpool); 657 ld(Rtags, ConstantPool::tags_offset(), Rcpool); 658 } 659 660 // Unlock if synchronized method. 661 // 662 // Unlock the receiver if this is a synchronized method. 663 // Unlock any Java monitors from synchronized blocks. 664 // 665 // If there are locked Java monitors 666 // If throw_monitor_exception 667 // throws IllegalMonitorStateException 668 // Else if install_monitor_exception 669 // installs IllegalMonitorStateException 670 // Else 671 // no error processing 672 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state, 673 bool throw_monitor_exception, 674 bool install_monitor_exception) { 675 Label Lunlocked, Lno_unlock; 676 { 677 Register Rdo_not_unlock_flag = R11_scratch1; 678 Register Raccess_flags = R12_scratch2; 679 680 // Check if synchronized method or unlocking prevented by 681 // JavaThread::do_not_unlock_if_synchronized flag. 682 lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); 683 lhz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method); 684 li(R0, 0); 685 stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag 686 687 push(state); 688 689 // Skip if we don't have to unlock. 690 testbitdi(CR0, R0, Raccess_flags, JVM_ACC_SYNCHRONIZED_BIT); 691 beq(CR0, Lunlocked); 692 693 cmpwi(CR0, Rdo_not_unlock_flag, 0); 694 bne(CR0, Lno_unlock); 695 } 696 697 // Unlock 698 { 699 Register Rmonitor_base = R11_scratch1; 700 701 Label Lunlock; 702 // If it's still locked, everything is ok, unlock it. 703 ld(Rmonitor_base, 0, R1_SP); 704 addi(Rmonitor_base, Rmonitor_base, 705 -(frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base 706 707 ld(R0, BasicObjectLock::obj_offset(), Rmonitor_base); 708 cmpdi(CR0, R0, 0); 709 bne(CR0, Lunlock); 710 711 // If it's already unlocked, throw exception. 712 if (throw_monitor_exception) { 713 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 714 should_not_reach_here(); 715 } else { 716 if (install_monitor_exception) { 717 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 718 b(Lunlocked); 719 } 720 } 721 722 bind(Lunlock); 723 unlock_object(Rmonitor_base); 724 } 725 726 // Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not. 727 bind(Lunlocked); 728 { 729 Label Lexception, Lrestart; 730 Register Rcurrent_obj_addr = R11_scratch1; 731 const int delta = frame::interpreter_frame_monitor_size_in_bytes(); 732 assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords"); 733 734 bind(Lrestart); 735 // Set up search loop: Calc num of iterations. 736 { 737 Register Riterations = R12_scratch2; 738 Register Rmonitor_base = Rcurrent_obj_addr; 739 ld(Rmonitor_base, 0, R1_SP); 740 addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size); // Monitor base 741 742 subf_(Riterations, R26_monitor, Rmonitor_base); 743 ble(CR0, Lno_unlock); 744 745 addi(Rcurrent_obj_addr, Rmonitor_base, 746 in_bytes(BasicObjectLock::obj_offset()) - frame::interpreter_frame_monitor_size_in_bytes()); 747 // Check if any monitor is on stack, bail out if not 748 srdi(Riterations, Riterations, exact_log2(delta)); 749 mtctr(Riterations); 750 } 751 752 // The search loop: Look for locked monitors. 753 { 754 const Register Rcurrent_obj = R0; 755 Label Lloop; 756 757 ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 758 addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta); 759 bind(Lloop); 760 761 // Check if current entry is used. 762 cmpdi(CR0, Rcurrent_obj, 0); 763 bne(CR0, Lexception); 764 // Preload next iteration's compare value. 765 ld(Rcurrent_obj, 0, Rcurrent_obj_addr); 766 addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta); 767 bdnz(Lloop); 768 } 769 // Fell through: Everything's unlocked => finish. 770 b(Lno_unlock); 771 772 // An object is still locked => need to throw exception. 773 bind(Lexception); 774 if (throw_monitor_exception) { 775 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 776 should_not_reach_here(); 777 } else { 778 // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception. 779 // Unlock does not block, so don't have to worry about the frame. 780 Register Rmonitor_addr = R11_scratch1; 781 addi(Rmonitor_addr, Rcurrent_obj_addr, -in_bytes(BasicObjectLock::obj_offset()) + delta); 782 unlock_object(Rmonitor_addr); 783 if (install_monitor_exception) { 784 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 785 } 786 b(Lrestart); 787 } 788 } 789 790 align(32, 12); 791 bind(Lno_unlock); 792 pop(state); 793 } 794 795 // Support function for remove_activation & Co. 796 void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc, 797 Register Rscratch1, Register Rscratch2) { 798 // Pop interpreter frame. 799 ld(Rscratch1, 0, R1_SP); // *SP 800 ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp 801 ld(Rscratch2, 0, Rscratch1); // **SP 802 if (return_pc!=noreg) { 803 ld(return_pc, _abi0(lr), Rscratch1); // LR 804 } 805 806 // Merge top frames. 807 subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP 808 stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP 809 } 810 811 void InterpreterMacroAssembler::narrow(Register result) { 812 Register ret_type = R11_scratch1; 813 ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method); 814 lbz(ret_type, in_bytes(ConstMethod::result_type_offset()), R11_scratch1); 815 816 Label notBool, notByte, notChar, done; 817 818 // common case first 819 cmpwi(CR0, ret_type, T_INT); 820 beq(CR0, done); 821 822 cmpwi(CR0, ret_type, T_BOOLEAN); 823 bne(CR0, notBool); 824 andi(result, result, 0x1); 825 b(done); 826 827 bind(notBool); 828 cmpwi(CR0, ret_type, T_BYTE); 829 bne(CR0, notByte); 830 extsb(result, result); 831 b(done); 832 833 bind(notByte); 834 cmpwi(CR0, ret_type, T_CHAR); 835 bne(CR0, notChar); 836 andi(result, result, 0xffff); 837 b(done); 838 839 bind(notChar); 840 // cmpwi(CR0, ret_type, T_SHORT); // all that's left 841 // bne(CR0, done); 842 extsh(result, result); 843 844 // Nothing to do for T_INT 845 bind(done); 846 } 847 848 // Remove activation. 849 // 850 // Apply stack watermark barrier. 851 // Unlock the receiver if this is a synchronized method. 852 // Unlock any Java monitors from synchronized blocks. 853 // Remove the activation from the stack. 854 // 855 // If there are locked Java monitors 856 // If throw_monitor_exception 857 // throws IllegalMonitorStateException 858 // Else if install_monitor_exception 859 // installs IllegalMonitorStateException 860 // Else 861 // no error processing 862 void InterpreterMacroAssembler::remove_activation(TosState state, 863 bool throw_monitor_exception, 864 bool install_monitor_exception) { 865 BLOCK_COMMENT("remove_activation {"); 866 867 // The below poll is for the stack watermark barrier. It allows fixing up frames lazily, 868 // that would normally not be safe to use. Such bad returns into unsafe territory of 869 // the stack, will call InterpreterRuntime::at_unwind. 870 Label slow_path; 871 Label fast_path; 872 safepoint_poll(slow_path, R11_scratch1, true /* at_return */, false /* in_nmethod */); 873 b(fast_path); 874 bind(slow_path); 875 push(state); 876 set_last_Java_frame(R1_SP, noreg); 877 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), R16_thread); 878 reset_last_Java_frame(); 879 pop(state); 880 align(32); 881 bind(fast_path); 882 883 unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception); 884 885 // Save result (push state before jvmti call and pop it afterwards) and notify jvmti. 886 notify_method_exit(false, state, NotifyJVMTI, true); 887 888 BLOCK_COMMENT("reserved_stack_check:"); 889 if (StackReservedPages > 0) { 890 // Test if reserved zone needs to be enabled. 891 Label no_reserved_zone_enabling; 892 893 // check if already enabled - if so no re-enabling needed 894 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size"); 895 lwz(R0, in_bytes(JavaThread::stack_guard_state_offset()), R16_thread); 896 cmpwi(CR0, R0, StackOverflow::stack_guard_enabled); 897 beq_predict_taken(CR0, no_reserved_zone_enabling); 898 899 // Compare frame pointers. There is no good stack pointer, as with stack 900 // frame compression we can get different SPs when we do calls. A subsequent 901 // call could have a smaller SP, so that this compare succeeds for an 902 // inner call of the method annotated with ReservedStack. 903 ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread); 904 ld_ptr(R11_scratch1, _abi0(callers_sp), R1_SP); // Load frame pointer. 905 cmpld(CR0, R11_scratch1, R0); 906 blt_predict_taken(CR0, no_reserved_zone_enabling); 907 908 // Enable reserved zone again, throw stack overflow exception. 909 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread); 910 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError)); 911 912 should_not_reach_here(); 913 914 bind(no_reserved_zone_enabling); 915 } 916 917 verify_oop(R17_tos, state); 918 919 merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2); 920 mtlr(R0); 921 pop_cont_fastpath(); 922 BLOCK_COMMENT("} remove_activation"); 923 } 924 925 // Lock object 926 // 927 // Registers alive 928 // monitor - Address of the BasicObjectLock to be used for locking, 929 // which must be initialized with the object to lock. 930 // object - Address of the object to be locked. 931 // 932 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) { 933 if (LockingMode == LM_MONITOR) { 934 call_VM_preemptable(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor); 935 } else { 936 // template code (for LM_LEGACY): 937 // 938 // markWord displaced_header = obj->mark().set_unlocked(); 939 // monitor->lock()->set_displaced_header(displaced_header); 940 // if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) { 941 // // We stored the monitor address into the object's mark word. 942 // } else if (THREAD->is_lock_owned((address)displaced_header)) 943 // // Simple recursive case. 944 // monitor->lock()->set_displaced_header(nullptr); 945 // } else { 946 // // Slow path. 947 // InterpreterRuntime::monitorenter(THREAD, monitor); 948 // } 949 950 const Register header = R7_ARG5; 951 const Register object_mark_addr = R8_ARG6; 952 const Register current_header = R9_ARG7; 953 const Register tmp = R10_ARG8; 954 955 Label count_locking, done, slow_case, cas_failed; 956 957 assert_different_registers(header, object_mark_addr, current_header, tmp); 958 959 // markWord displaced_header = obj->mark().set_unlocked(); 960 961 if (LockingMode == LM_LIGHTWEIGHT) { 962 lightweight_lock(monitor, object, header, tmp, slow_case); 963 b(done); 964 } else if (LockingMode == LM_LEGACY) { 965 966 if (DiagnoseSyncOnValueBasedClasses != 0) { 967 load_klass(tmp, object); 968 lbz(tmp, in_bytes(Klass::misc_flags_offset()), tmp); 969 testbitdi(CR0, R0, tmp, exact_log2(KlassFlags::_misc_is_value_based_class)); 970 bne(CR0, slow_case); 971 } 972 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 CR0 to cmpX(current, displaced). 994 cmpxchgd(/*flag=*/CR0, 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(CR0, 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(CR0, header, 0); 1092 beq(CR0, 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 CR0 to cmpX(current, monitor). 1113 cmpxchgd(/*flag=*/CR0, 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(CR0, Rinterp_only, 0); 1175 beq(CR0, 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(CR0, Rtarget_addr, 0); 1185 bne(CR0, 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(CR0, 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(CR0, R28_mdx, 0); 1239 beq(CR0, 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(CR0, R11_scratch1, R14_bcp); 1255 beq(CR0, 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(CR0, value, test_out); 1339 bne(CR0, 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(CR0, Rreceiver, 0); 1496 bne(CR0, 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(CR0, scratch1, 0); 1686 beq(CR0, 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(CR0, scratch1, 0); 1696 beq(CR0, 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(CR0, obj, 0); 1739 ori(R0, tmp, TypeEntries::null_seen); 1740 beq(CR0, 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(CR1, R0, klass); 1747 // Klass seen before, nothing to do (regardless of unknown bit). 1748 //beq(CR1, do_nothing); 1749 1750 andi_(R0, tmp, TypeEntries::type_unknown); 1751 // Already unknown. Nothing to do anymore. 1752 //bne(CR0, do_nothing); 1753 crorc(CR0, Assembler::equal, CR1, Assembler::equal); // cr0 eq = cr1 eq or cr0 ne 1754 beq(CR0, 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(CR0, 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(CR0, tmp1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag); 1790 bne(CR0, 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(CR0, tmp1, (i+1)*TypeStackSlotEntries::per_arg_count()); 1802 addi(tmp1, tmp1, -i*TypeStackSlotEntries::per_arg_count()); 1803 blt(CR0, 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(CR0, tmp1, Bytecodes::_invokedynamic); 1870 cmpwi(CR1, tmp1, Bytecodes::_invokehandle); 1871 cror(CR0, Assembler::equal, CR1, Assembler::equal); 1872 cmpwi(CR1, tmp2, static_cast<int>(vmIntrinsics::_compiledLambdaForm)); 1873 cror(CR0, Assembler::equal, CR1, Assembler::equal); 1874 bne(CR0, 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(CR0, tmp1, 0); 1895 blt(CR0, 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(CR0, entry_offset, off_base + delta); 1941 addi(entry_offset, entry_offset, -delta); 1942 bge(CR0, 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(CR0, 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(CR0, Rexception, 0); 2120 beq(CR0, 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(CR0, 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(CR0, R0, 0); 2191 beq(CR0, 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(CR0, R12_scratch2, R11_scratch1); 2220 beq(CR0, 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(CR0, R0, frame::top_ijava_frame_abi_size + frame::ijava_state_size); 2303 bge(CR0, 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(CR0, Rcounters, 0); 2317 bne(CR0, 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(CR0, Rcounters, 0); 2322 beq(CR0, 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_oop_or_return_address(Register reg, Register Rtmp) { 2386 if (!VerifyOops) return; 2387 2388 // The VM documentation for the astore[_wide] bytecode allows 2389 // the TOS to be not only an oop but also a return address. 2390 Label test; 2391 Label skip; 2392 // See if it is an address (in the current method): 2393 2394 const int log2_bytecode_size_limit = 16; 2395 srdi_(Rtmp, reg, log2_bytecode_size_limit); 2396 bne(CR0, test); 2397 2398 address fd = CAST_FROM_FN_PTR(address, verify_return_address); 2399 const int nbytes_save = MacroAssembler::num_volatile_regs * 8; 2400 save_volatile_gprs(R1_SP, -nbytes_save); // except R0 2401 save_LR_CR(Rtmp); // Save in old frame. 2402 push_frame_reg_args(nbytes_save, Rtmp); 2403 2404 load_const_optimized(Rtmp, fd, R0); 2405 mr_if_needed(R4_ARG2, reg); 2406 mr(R3_ARG1, R19_method); 2407 call_c(Rtmp); // call C 2408 2409 pop_frame(); 2410 restore_LR_CR(Rtmp); 2411 restore_volatile_gprs(R1_SP, -nbytes_save); // except R0 2412 b(skip); 2413 2414 // Perform a more elaborate out-of-line call. 2415 // Not an address; verify it: 2416 bind(test); 2417 verify_oop(reg); 2418 bind(skip); 2419 } 2420 2421 // Inline assembly for: 2422 // 2423 // if (thread is in interp_only_mode) { 2424 // InterpreterRuntime::post_method_entry(); 2425 // } 2426 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY ) || 2427 // *jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY2) ) { 2428 // SharedRuntime::jvmpi_method_entry(method, receiver); 2429 // } 2430 void InterpreterMacroAssembler::notify_method_entry() { 2431 // JVMTI 2432 // Whenever JVMTI puts a thread in interp_only_mode, method 2433 // entry/exit events are sent for that thread to track stack 2434 // depth. If it is possible to enter interp_only_mode we add 2435 // the code to check if the event should be sent. 2436 if (JvmtiExport::can_post_interpreter_events()) { 2437 Label jvmti_post_done; 2438 2439 lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread); 2440 cmpwi(CR0, R0, 0); 2441 beq(CR0, jvmti_post_done); 2442 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry)); 2443 2444 bind(jvmti_post_done); 2445 } 2446 } 2447 2448 // Inline assembly for: 2449 // 2450 // if (thread is in interp_only_mode) { 2451 // // save result 2452 // InterpreterRuntime::post_method_exit(); 2453 // // restore result 2454 // } 2455 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_EXIT)) { 2456 // // save result 2457 // SharedRuntime::jvmpi_method_exit(); 2458 // // restore result 2459 // } 2460 // 2461 // Native methods have their result stored in d_tmp and l_tmp. 2462 // Java methods have their result stored in the expression stack. 2463 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state, 2464 NotifyMethodExitMode mode, bool check_exceptions) { 2465 // JVMTI 2466 // Whenever JVMTI puts a thread in interp_only_mode, method 2467 // entry/exit events are sent for that thread to track stack 2468 // depth. If it is possible to enter interp_only_mode we add 2469 // the code to check if the event should be sent. 2470 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 2471 Label jvmti_post_done; 2472 2473 lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread); 2474 cmpwi(CR0, R0, 0); 2475 beq(CR0, jvmti_post_done); 2476 if (!is_native_method) { push(state); } // Expose tos to GC. 2477 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit), check_exceptions); 2478 if (!is_native_method) { pop(state); } 2479 2480 align(32, 12); 2481 bind(jvmti_post_done); 2482 } 2483 2484 // Dtrace support not implemented. 2485 }