1 /* 2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "compiler/compiler_globals.hpp" 26 #include "interp_masm_x86.hpp" 27 #include "interpreter/interpreter.hpp" 28 #include "interpreter/interpreterRuntime.hpp" 29 #include "logging/log.hpp" 30 #include "oops/arrayOop.hpp" 31 #include "oops/markWord.hpp" 32 #include "oops/methodData.hpp" 33 #include "oops/method.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/basicLock.hpp" 40 #include "runtime/frame.inline.hpp" 41 #include "runtime/javaThread.hpp" 42 #include "runtime/safepointMechanism.hpp" 43 #include "runtime/sharedRuntime.hpp" 44 #include "utilities/powerOfTwo.hpp" 45 46 // Implementation of InterpreterMacroAssembler 47 48 void InterpreterMacroAssembler::jump_to_entry(address entry) { 49 assert(entry, "Entry must have been generated by now"); 50 jump(RuntimeAddress(entry)); 51 } 52 53 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) { 54 Label update, next, none; 55 56 assert_different_registers(obj, rscratch1, mdo_addr.base(), mdo_addr.index()); 57 58 interp_verify_oop(obj, atos); 59 60 testptr(obj, obj); 61 jccb(Assembler::notZero, update); 62 testptr(mdo_addr, TypeEntries::null_seen); 63 jccb(Assembler::notZero, next); // null already seen. Nothing to do anymore. 64 // atomic update to prevent overwriting Klass* with 0 65 lock(); 66 orptr(mdo_addr, TypeEntries::null_seen); 67 jmpb(next); 68 69 bind(update); 70 load_klass(obj, obj, rscratch1); 71 mov(rscratch1, obj); 72 73 xorptr(obj, mdo_addr); 74 testptr(obj, TypeEntries::type_klass_mask); 75 jccb(Assembler::zero, next); // klass seen before, nothing to 76 // do. The unknown bit may have been 77 // set already but no need to check. 78 79 testptr(obj, TypeEntries::type_unknown); 80 jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore. 81 82 cmpptr(mdo_addr, 0); 83 jccb(Assembler::equal, none); 84 cmpptr(mdo_addr, TypeEntries::null_seen); 85 jccb(Assembler::equal, none); 86 87 // There is a chance that the checks above (re-reading profiling 88 // data from memory) fail if another thread has just set the 89 // profiling to this obj's klass 90 mov(obj, rscratch1); 91 xorptr(obj, mdo_addr); 92 testptr(obj, TypeEntries::type_klass_mask); 93 jccb(Assembler::zero, next); 94 95 // different than before. Cannot keep accurate profile. 96 orptr(mdo_addr, TypeEntries::type_unknown); 97 jmpb(next); 98 99 bind(none); 100 // first time here. Set profile type. 101 movptr(mdo_addr, obj); 102 #ifdef ASSERT 103 andptr(obj, TypeEntries::type_klass_mask); 104 verify_klass_ptr(obj); 105 #endif 106 107 bind(next); 108 } 109 110 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) { 111 if (!ProfileInterpreter) { 112 return; 113 } 114 115 if (MethodData::profile_arguments() || MethodData::profile_return()) { 116 Label profile_continue; 117 118 test_method_data_pointer(mdp, profile_continue); 119 120 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size()); 121 122 cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag); 123 jcc(Assembler::notEqual, profile_continue); 124 125 if (MethodData::profile_arguments()) { 126 Label done; 127 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset()); 128 addptr(mdp, off_to_args); 129 130 for (int i = 0; i < TypeProfileArgsLimit; i++) { 131 if (i > 0 || MethodData::profile_return()) { 132 // If return value type is profiled we may have no argument to profile 133 movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args)); 134 subl(tmp, i*TypeStackSlotEntries::per_arg_count()); 135 cmpl(tmp, TypeStackSlotEntries::per_arg_count()); 136 jcc(Assembler::less, done); 137 } 138 movptr(tmp, Address(callee, Method::const_offset())); 139 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset())); 140 // stack offset o (zero based) from the start of the argument 141 // list, for n arguments translates into offset n - o - 1 from 142 // the end of the argument list 143 subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args)); 144 subl(tmp, 1); 145 Address arg_addr = argument_address(tmp); 146 movptr(tmp, arg_addr); 147 148 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args); 149 profile_obj_type(tmp, mdo_arg_addr); 150 151 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size()); 152 addptr(mdp, to_add); 153 off_to_args += to_add; 154 } 155 156 if (MethodData::profile_return()) { 157 movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args)); 158 subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count()); 159 } 160 161 bind(done); 162 163 if (MethodData::profile_return()) { 164 // We're right after the type profile for the last 165 // argument. tmp is the number of cells left in the 166 // CallTypeData/VirtualCallTypeData to reach its end. Non null 167 // if there's a return to profile. 168 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type"); 169 shll(tmp, log2i_exact((int)DataLayout::cell_size)); 170 addptr(mdp, tmp); 171 } 172 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp); 173 } else { 174 assert(MethodData::profile_return(), "either profile call args or call ret"); 175 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size())); 176 } 177 178 // mdp points right after the end of the 179 // CallTypeData/VirtualCallTypeData, right after the cells for the 180 // return value type if there's one 181 182 bind(profile_continue); 183 } 184 } 185 186 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) { 187 assert_different_registers(mdp, ret, tmp, _bcp_register); 188 if (ProfileInterpreter && MethodData::profile_return()) { 189 Label profile_continue; 190 191 test_method_data_pointer(mdp, profile_continue); 192 193 if (MethodData::profile_return_jsr292_only()) { 194 assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2"); 195 196 // If we don't profile all invoke bytecodes we must make sure 197 // it's a bytecode we indeed profile. We can't go back to the 198 // beginning of the ProfileData we intend to update to check its 199 // type because we're right after it and we don't known its 200 // length 201 Label do_profile; 202 cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic); 203 jcc(Assembler::equal, do_profile); 204 cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle); 205 jcc(Assembler::equal, do_profile); 206 get_method(tmp); 207 cmpw(Address(tmp, Method::intrinsic_id_offset()), static_cast<int>(vmIntrinsics::_compiledLambdaForm)); 208 jcc(Assembler::notEqual, profile_continue); 209 210 bind(do_profile); 211 } 212 213 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size())); 214 mov(tmp, ret); 215 profile_obj_type(tmp, mdo_ret_addr); 216 217 bind(profile_continue); 218 } 219 } 220 221 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) { 222 if (ProfileInterpreter && MethodData::profile_parameters()) { 223 Label profile_continue; 224 225 test_method_data_pointer(mdp, profile_continue); 226 227 // Load the offset of the area within the MDO used for 228 // parameters. If it's negative we're not profiling any parameters 229 movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()))); 230 testl(tmp1, tmp1); 231 jcc(Assembler::negative, profile_continue); 232 233 // Compute a pointer to the area for parameters from the offset 234 // and move the pointer to the slot for the last 235 // parameters. Collect profiling from last parameter down. 236 // mdo start + parameters offset + array length - 1 237 addptr(mdp, tmp1); 238 movptr(tmp1, Address(mdp, ArrayData::array_len_offset())); 239 decrement(tmp1, TypeStackSlotEntries::per_arg_count()); 240 241 Label loop; 242 bind(loop); 243 244 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0)); 245 int type_base = in_bytes(ParametersTypeData::type_offset(0)); 246 Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size); 247 Address arg_off(mdp, tmp1, per_arg_scale, off_base); 248 Address arg_type(mdp, tmp1, per_arg_scale, type_base); 249 250 // load offset on the stack from the slot for this parameter 251 movptr(tmp2, arg_off); 252 negptr(tmp2); 253 // read the parameter from the local area 254 movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale())); 255 256 // profile the parameter 257 profile_obj_type(tmp2, arg_type); 258 259 // go to next parameter 260 decrement(tmp1, TypeStackSlotEntries::per_arg_count()); 261 jcc(Assembler::positive, loop); 262 263 bind(profile_continue); 264 } 265 } 266 267 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, 268 int number_of_arguments) { 269 // interpreter specific 270 // 271 // Note: No need to save/restore bcp & locals registers 272 // since these are callee saved registers and no blocking/ 273 // GC can happen in leaf calls. 274 // Further Note: DO NOT save/restore bcp/locals. If a caller has 275 // already saved them so that it can use rsi/rdi as temporaries 276 // then a save/restore here will DESTROY the copy the caller 277 // saved! There used to be a save_bcp() that only happened in 278 // the ASSERT path (no restore_bcp). Which caused bizarre failures 279 // when jvm built with ASSERTs. 280 #ifdef ASSERT 281 { 282 Label L; 283 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); 284 jcc(Assembler::equal, L); 285 stop("InterpreterMacroAssembler::call_VM_leaf_base:" 286 " last_sp != null"); 287 bind(L); 288 } 289 #endif 290 // super call 291 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); 292 // interpreter specific 293 // LP64: Used to ASSERT that r13/r14 were equal to frame's bcp/locals 294 // but since they may not have been saved (and we don't want to 295 // save them here (see note above) the assert is invalid. 296 } 297 298 void InterpreterMacroAssembler::call_VM_base(Register oop_result, 299 Register last_java_sp, 300 address entry_point, 301 int number_of_arguments, 302 bool check_exceptions) { 303 // interpreter specific 304 // 305 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't 306 // really make a difference for these runtime calls, since they are 307 // slow anyway. Btw., bcp must be saved/restored since it may change 308 // due to GC. 309 save_bcp(); 310 #ifdef ASSERT 311 { 312 Label L; 313 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); 314 jcc(Assembler::equal, L); 315 stop("InterpreterMacroAssembler::call_VM_base:" 316 " last_sp isn't null"); 317 bind(L); 318 } 319 #endif /* ASSERT */ 320 // super call 321 MacroAssembler::call_VM_base(oop_result, last_java_sp, 322 entry_point, number_of_arguments, 323 check_exceptions); 324 // interpreter specific 325 restore_bcp(); 326 restore_locals(); 327 } 328 329 void InterpreterMacroAssembler::call_VM_preemptable_helper(Register oop_result, 330 address entry_point, 331 int number_of_arguments, 332 bool check_exceptions) { 333 Label resume_pc, not_preempted; 334 335 #ifdef ASSERT 336 { 337 Label L; 338 cmpptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD); 339 jcc(Assembler::equal, L); 340 stop("Should not have alternate return address set"); 341 bind(L); 342 } 343 #endif /* ASSERT */ 344 345 // Force freeze slow path. 346 push_cont_fastpath(); 347 348 // Make VM call. In case of preemption set last_pc to the one we want to resume to. 349 // Note: call_VM_helper requires last_Java_pc for anchor to be at the top of the stack. 350 lea(rscratch1, resume_pc); 351 push(rscratch1); 352 MacroAssembler::call_VM_helper(oop_result, entry_point, number_of_arguments, check_exceptions); 353 pop(rscratch1); 354 355 pop_cont_fastpath(); 356 357 // Check if preempted. 358 movptr(rscratch1, Address(r15_thread, JavaThread::preempt_alternate_return_offset())); 359 cmpptr(rscratch1, NULL_WORD); 360 jccb(Assembler::zero, not_preempted); 361 movptr(Address(r15_thread, JavaThread::preempt_alternate_return_offset()), NULL_WORD); 362 jmp(rscratch1); 363 364 // In case of preemption, this is where we will resume once we finally acquire the monitor. 365 bind(resume_pc); 366 restore_after_resume(false /* is_native */); 367 368 if (check_exceptions) { 369 // check for pending exceptions (java_thread is set upon return) 370 cmpptr(Address(r15_thread, Thread::pending_exception_offset()), NULL_WORD); 371 Label ok; 372 jcc(Assembler::equal, ok); 373 jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 374 bind(ok); 375 } 376 377 // get oop result if there is one and reset the value in the thread 378 if (oop_result->is_valid()) { 379 get_vm_result_oop(oop_result); 380 } 381 382 bind(not_preempted); 383 } 384 385 static void pass_arg1(MacroAssembler* masm, Register arg) { 386 if (c_rarg1 != arg ) { 387 masm->mov(c_rarg1, arg); 388 } 389 } 390 391 static void pass_arg2(MacroAssembler* masm, Register arg) { 392 if (c_rarg2 != arg ) { 393 masm->mov(c_rarg2, arg); 394 } 395 } 396 397 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result, 398 address entry_point, 399 Register arg_1, 400 bool check_exceptions) { 401 pass_arg1(this, arg_1); 402 call_VM_preemptable_helper(oop_result, entry_point, 1, check_exceptions); 403 } 404 405 void InterpreterMacroAssembler::call_VM_preemptable(Register oop_result, 406 address entry_point, 407 Register arg_1, 408 Register arg_2, 409 bool check_exceptions) { 410 LP64_ONLY(assert_different_registers(arg_1, c_rarg2)); 411 pass_arg2(this, arg_2); 412 pass_arg1(this, arg_1); 413 call_VM_preemptable_helper(oop_result, entry_point, 2, check_exceptions); 414 } 415 416 void InterpreterMacroAssembler::restore_after_resume(bool is_native) { 417 lea(rscratch1, ExternalAddress(Interpreter::cont_resume_interpreter_adapter())); 418 call(rscratch1); 419 if (is_native) { 420 // On resume we need to set up stack as expected. 421 push(dtos); 422 push(ltos); 423 } 424 } 425 426 void InterpreterMacroAssembler::check_and_handle_popframe() { 427 if (JvmtiExport::can_pop_frame()) { 428 Label L; 429 // Initiate popframe handling only if it is not already being 430 // processed. If the flag has the popframe_processing bit set, it 431 // means that this code is called *during* popframe handling - we 432 // don't want to reenter. 433 // This method is only called just after the call into the vm in 434 // call_VM_base, so the arg registers are available. 435 Register pop_cond = c_rarg0; 436 movl(pop_cond, Address(r15_thread, JavaThread::popframe_condition_offset())); 437 testl(pop_cond, JavaThread::popframe_pending_bit); 438 jcc(Assembler::zero, L); 439 testl(pop_cond, JavaThread::popframe_processing_bit); 440 jcc(Assembler::notZero, L); 441 // Call Interpreter::remove_activation_preserving_args_entry() to get the 442 // address of the same-named entrypoint in the generated interpreter code. 443 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); 444 jmp(rax); 445 bind(L); 446 } 447 } 448 449 void InterpreterMacroAssembler::load_earlyret_value(TosState state) { 450 movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); 451 const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset()); 452 const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset()); 453 const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset()); 454 455 switch (state) { 456 case atos: movptr(rax, oop_addr); 457 movptr(oop_addr, NULL_WORD); 458 interp_verify_oop(rax, state); break; 459 case ltos: movptr(rax, val_addr); break; 460 case btos: // fall through 461 case ztos: // fall through 462 case ctos: // fall through 463 case stos: // fall through 464 case itos: movl(rax, val_addr); break; 465 case ftos: movflt(xmm0, val_addr); break; 466 case dtos: movdbl(xmm0, val_addr); break; 467 case vtos: /* nothing to do */ break; 468 default : ShouldNotReachHere(); 469 } 470 471 // Clean up tos value in the thread object 472 movl(tos_addr, ilgl); 473 movptr(val_addr, NULL_WORD); 474 } 475 476 477 void InterpreterMacroAssembler::check_and_handle_earlyret() { 478 if (JvmtiExport::can_force_early_return()) { 479 Label L; 480 Register tmp = c_rarg0; 481 Register rthread = r15_thread; 482 483 movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset())); 484 testptr(tmp, tmp); 485 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == nullptr) exit; 486 487 // Initiate earlyret handling only if it is not already being processed. 488 // If the flag has the earlyret_processing bit set, it means that this code 489 // is called *during* earlyret handling - we don't want to reenter. 490 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset())); 491 cmpl(tmp, JvmtiThreadState::earlyret_pending); 492 jcc(Assembler::notEqual, L); 493 494 // Call Interpreter::remove_activation_early_entry() to get the address of the 495 // same-named entrypoint in the generated interpreter code. 496 movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset())); 497 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_tos_offset())); 498 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), tmp); 499 jmp(rax); 500 bind(L); 501 } 502 } 503 504 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) { 505 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); 506 load_unsigned_short(reg, Address(_bcp_register, bcp_offset)); 507 bswapl(reg); 508 shrl(reg, 16); 509 } 510 511 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, 512 int bcp_offset, 513 size_t index_size) { 514 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 515 if (index_size == sizeof(u2)) { 516 load_unsigned_short(index, Address(_bcp_register, bcp_offset)); 517 } else if (index_size == sizeof(u4)) { 518 movl(index, Address(_bcp_register, bcp_offset)); 519 } else if (index_size == sizeof(u1)) { 520 load_unsigned_byte(index, Address(_bcp_register, bcp_offset)); 521 } else { 522 ShouldNotReachHere(); 523 } 524 } 525 526 // Load object from cpool->resolved_references(index) 527 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, 528 Register index, 529 Register tmp) { 530 assert_different_registers(result, index); 531 532 get_constant_pool(result); 533 // load pointer for resolved_references[] objArray 534 movptr(result, Address(result, ConstantPool::cache_offset())); 535 movptr(result, Address(result, ConstantPoolCache::resolved_references_offset())); 536 resolve_oop_handle(result, tmp); 537 load_heap_oop(result, Address(result, index, 538 UseCompressedOops ? Address::times_4 : Address::times_ptr, 539 arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp); 540 } 541 542 // load cpool->resolved_klass_at(index) 543 void InterpreterMacroAssembler::load_resolved_klass_at_index(Register klass, 544 Register cpool, 545 Register index) { 546 assert_different_registers(cpool, index); 547 548 movw(index, Address(cpool, index, Address::times_ptr, sizeof(ConstantPool))); 549 Register resolved_klasses = cpool; 550 movptr(resolved_klasses, Address(cpool, ConstantPool::resolved_klasses_offset())); 551 movptr(klass, Address(resolved_klasses, index, Address::times_ptr, Array<Klass*>::base_offset_in_bytes())); 552 } 553 554 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a 555 // subtype of super_klass. 556 // 557 // Args: 558 // rax: superklass 559 // Rsub_klass: subklass 560 // 561 // Kills: 562 // rcx, rdi 563 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, 564 Label& ok_is_subtype) { 565 assert(Rsub_klass != rax, "rax holds superklass"); 566 LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");) 567 LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");) 568 assert(Rsub_klass != rcx, "rcx holds 2ndary super array length"); 569 assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr"); 570 571 // Profile the not-null value's klass. 572 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi 573 574 // Do the check. 575 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx 576 } 577 578 579 // Java Expression Stack 580 581 void InterpreterMacroAssembler::pop_ptr(Register r) { 582 pop(r); 583 } 584 585 void InterpreterMacroAssembler::push_ptr(Register r) { 586 push(r); 587 } 588 589 void InterpreterMacroAssembler::push_i(Register r) { 590 push(r); 591 } 592 593 void InterpreterMacroAssembler::push_i_or_ptr(Register r) { 594 push(r); 595 } 596 597 void InterpreterMacroAssembler::push_f(XMMRegister r) { 598 subptr(rsp, wordSize); 599 movflt(Address(rsp, 0), r); 600 } 601 602 void InterpreterMacroAssembler::pop_f(XMMRegister r) { 603 movflt(r, Address(rsp, 0)); 604 addptr(rsp, wordSize); 605 } 606 607 void InterpreterMacroAssembler::push_d(XMMRegister r) { 608 subptr(rsp, 2 * wordSize); 609 movdbl(Address(rsp, 0), r); 610 } 611 612 void InterpreterMacroAssembler::pop_d(XMMRegister r) { 613 movdbl(r, Address(rsp, 0)); 614 addptr(rsp, 2 * Interpreter::stackElementSize); 615 } 616 617 void InterpreterMacroAssembler::pop_i(Register r) { 618 // XXX can't use pop currently, upper half non clean 619 movl(r, Address(rsp, 0)); 620 addptr(rsp, wordSize); 621 } 622 623 void InterpreterMacroAssembler::pop_l(Register r) { 624 movq(r, Address(rsp, 0)); 625 addptr(rsp, 2 * Interpreter::stackElementSize); 626 } 627 628 void InterpreterMacroAssembler::push_l(Register r) { 629 subptr(rsp, 2 * wordSize); 630 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(0)), r ); 631 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(1)), NULL_WORD ); 632 } 633 634 void InterpreterMacroAssembler::pop(TosState state) { 635 switch (state) { 636 case atos: pop_ptr(); break; 637 case btos: 638 case ztos: 639 case ctos: 640 case stos: 641 case itos: pop_i(); break; 642 case ltos: pop_l(); break; 643 case ftos: pop_f(xmm0); break; 644 case dtos: pop_d(xmm0); break; 645 case vtos: /* nothing to do */ break; 646 default: ShouldNotReachHere(); 647 } 648 interp_verify_oop(rax, state); 649 } 650 651 void InterpreterMacroAssembler::push(TosState state) { 652 interp_verify_oop(rax, state); 653 switch (state) { 654 case atos: push_ptr(); break; 655 case btos: 656 case ztos: 657 case ctos: 658 case stos: 659 case itos: push_i(); break; 660 case ltos: push_l(); break; 661 case ftos: push_f(xmm0); break; 662 case dtos: push_d(xmm0); break; 663 case vtos: /* nothing to do */ break; 664 default : ShouldNotReachHere(); 665 } 666 } 667 668 // Helpers for swap and dup 669 void InterpreterMacroAssembler::load_ptr(int n, Register val) { 670 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); 671 } 672 673 void InterpreterMacroAssembler::store_ptr(int n, Register val) { 674 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); 675 } 676 677 678 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { 679 // set sender sp 680 lea(_bcp_register, Address(rsp, wordSize)); 681 // record last_sp 682 mov(rcx, _bcp_register); 683 subptr(rcx, rbp); 684 sarptr(rcx, LogBytesPerWord); 685 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rcx); 686 } 687 688 689 // Jump to from_interpreted entry of a call unless single stepping is possible 690 // in this thread in which case we must call the i2i entry 691 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { 692 prepare_to_jump_from_interpreted(); 693 694 if (JvmtiExport::can_post_interpreter_events()) { 695 Label run_compiled_code; 696 // JVMTI events, such as single-stepping, are implemented partly by avoiding running 697 // compiled code in threads for which the event is enabled. Check here for 698 // interp_only_mode if these events CAN be enabled. 699 // interp_only is an int, on little endian it is sufficient to test the byte only 700 // Is a cmpl faster? 701 cmpb(Address(r15_thread, JavaThread::interp_only_mode_offset()), 0); 702 jccb(Assembler::zero, run_compiled_code); 703 jmp(Address(method, Method::interpreter_entry_offset())); 704 bind(run_compiled_code); 705 } 706 707 jmp(Address(method, Method::from_interpreted_offset())); 708 } 709 710 // The following two routines provide a hook so that an implementation 711 // can schedule the dispatch in two parts. x86 does not do this. 712 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { 713 // Nothing x86 specific to be done here 714 } 715 716 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { 717 dispatch_next(state, step); 718 } 719 720 void InterpreterMacroAssembler::dispatch_base(TosState state, 721 address* table, 722 bool verifyoop, 723 bool generate_poll) { 724 if (VerifyActivationFrameSize) { 725 Label L; 726 mov(rcx, rbp); 727 subptr(rcx, rsp); 728 int32_t min_frame_size = 729 (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * 730 wordSize; 731 cmpptr(rcx, min_frame_size); 732 jcc(Assembler::greaterEqual, L); 733 stop("broken stack frame"); 734 bind(L); 735 } 736 if (verifyoop) { 737 interp_verify_oop(rax, state); 738 } 739 740 address* const safepoint_table = Interpreter::safept_table(state); 741 Label no_safepoint, dispatch; 742 if (table != safepoint_table && generate_poll) { 743 NOT_PRODUCT(block_comment("Thread-local Safepoint poll")); 744 testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit()); 745 746 jccb(Assembler::zero, no_safepoint); 747 lea(rscratch1, ExternalAddress((address)safepoint_table)); 748 jmpb(dispatch); 749 } 750 751 bind(no_safepoint); 752 lea(rscratch1, ExternalAddress((address)table)); 753 bind(dispatch); 754 jmp(Address(rscratch1, rbx, Address::times_8)); 755 } 756 757 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) { 758 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll); 759 } 760 761 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { 762 dispatch_base(state, Interpreter::normal_table(state)); 763 } 764 765 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { 766 dispatch_base(state, Interpreter::normal_table(state), false); 767 } 768 769 770 void InterpreterMacroAssembler::dispatch_next(TosState state, int step, bool generate_poll) { 771 // load next bytecode (load before advancing _bcp_register to prevent AGI) 772 load_unsigned_byte(rbx, Address(_bcp_register, step)); 773 // advance _bcp_register 774 increment(_bcp_register, step); 775 dispatch_base(state, Interpreter::dispatch_table(state), true, generate_poll); 776 } 777 778 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { 779 // load current bytecode 780 load_unsigned_byte(rbx, Address(_bcp_register, 0)); 781 dispatch_base(state, table); 782 } 783 784 void InterpreterMacroAssembler::narrow(Register result) { 785 786 // Get method->_constMethod->_result_type 787 movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); 788 movptr(rcx, Address(rcx, Method::const_offset())); 789 load_unsigned_byte(rcx, Address(rcx, ConstMethod::result_type_offset())); 790 791 Label done, notBool, notByte, notChar; 792 793 // common case first 794 cmpl(rcx, T_INT); 795 jcc(Assembler::equal, done); 796 797 // mask integer result to narrower return type. 798 cmpl(rcx, T_BOOLEAN); 799 jcc(Assembler::notEqual, notBool); 800 andl(result, 0x1); 801 jmp(done); 802 803 bind(notBool); 804 cmpl(rcx, T_BYTE); 805 jcc(Assembler::notEqual, notByte); 806 movsbl(result, result); 807 jmp(done); 808 809 bind(notByte); 810 cmpl(rcx, T_CHAR); 811 jcc(Assembler::notEqual, notChar); 812 movzwl(result, result); 813 jmp(done); 814 815 bind(notChar); 816 // cmpl(rcx, T_SHORT); // all that's left 817 // jcc(Assembler::notEqual, done); 818 movswl(result, result); 819 820 // Nothing to do for T_INT 821 bind(done); 822 } 823 824 // remove activation 825 // 826 // Unlock the receiver if this is a synchronized method. 827 // Unlock any Java monitors from synchronized blocks. 828 // Apply stack watermark barrier. 829 // Notify JVMTI. 830 // Remove the activation from the stack. 831 // 832 // If there are locked Java monitors 833 // If throw_monitor_exception 834 // throws IllegalMonitorStateException 835 // Else if install_monitor_exception 836 // installs IllegalMonitorStateException 837 // Else 838 // no error processing 839 void InterpreterMacroAssembler::remove_activation(TosState state, 840 Register ret_addr, 841 bool throw_monitor_exception, 842 bool install_monitor_exception, 843 bool notify_jvmdi) { 844 // Note: Registers rdx xmm0 may be in use for the 845 // result check if synchronized method 846 Label unlocked, unlock, no_unlock; 847 848 const Register rthread = r15_thread; 849 const Register robj = c_rarg1; 850 const Register rmon = c_rarg1; 851 852 // get the value of _do_not_unlock_if_synchronized into rdx 853 const Address do_not_unlock_if_synchronized(rthread, 854 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 855 movbool(rbx, do_not_unlock_if_synchronized); 856 movbool(do_not_unlock_if_synchronized, false); // reset the flag 857 858 // get method access flags 859 movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); 860 load_unsigned_short(rcx, Address(rcx, Method::access_flags_offset())); 861 testl(rcx, JVM_ACC_SYNCHRONIZED); 862 jcc(Assembler::zero, unlocked); 863 864 // Don't unlock anything if the _do_not_unlock_if_synchronized flag 865 // is set. 866 testbool(rbx); 867 jcc(Assembler::notZero, no_unlock); 868 869 // unlock monitor 870 push(state); // save result 871 872 // BasicObjectLock will be first in list, since this is a 873 // synchronized method. However, need to check that the object has 874 // not been unlocked by an explicit monitorexit bytecode. 875 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * 876 wordSize - (int) sizeof(BasicObjectLock)); 877 // We use c_rarg1/rdx so that if we go slow path it will be the correct 878 // register for unlock_object to pass to VM directly 879 lea(robj, monitor); // address of first monitor 880 881 movptr(rax, Address(robj, BasicObjectLock::obj_offset())); 882 testptr(rax, rax); 883 jcc(Assembler::notZero, unlock); 884 885 pop(state); 886 if (throw_monitor_exception) { 887 // Entry already unlocked, need to throw exception 888 call_VM(noreg, CAST_FROM_FN_PTR(address, 889 InterpreterRuntime::throw_illegal_monitor_state_exception)); 890 should_not_reach_here(); 891 } else { 892 // Monitor already unlocked during a stack unroll. If requested, 893 // install an illegal_monitor_state_exception. Continue with 894 // stack unrolling. 895 if (install_monitor_exception) { 896 call_VM(noreg, CAST_FROM_FN_PTR(address, 897 InterpreterRuntime::new_illegal_monitor_state_exception)); 898 } 899 jmp(unlocked); 900 } 901 902 bind(unlock); 903 unlock_object(robj); 904 pop(state); 905 906 // Check that for block-structured locking (i.e., that all locked 907 // objects has been unlocked) 908 bind(unlocked); 909 910 // rax, rdx: Might contain return value 911 912 // Check that all monitors are unlocked 913 { 914 Label loop, exception, entry, restart; 915 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes(); 916 const Address monitor_block_top( 917 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 918 const Address monitor_block_bot( 919 rbp, frame::interpreter_frame_initial_sp_offset * wordSize); 920 921 bind(restart); 922 // We use c_rarg1 so that if we go slow path it will be the correct 923 // register for unlock_object to pass to VM directly 924 movptr(rmon, monitor_block_top); // derelativize pointer 925 lea(rmon, Address(rbp, rmon, Address::times_ptr)); 926 // c_rarg1 points to current entry, starting with top-most entry 927 928 lea(rbx, monitor_block_bot); // points to word before bottom of 929 // monitor block 930 jmp(entry); 931 932 // Entry already locked, need to throw exception 933 bind(exception); 934 935 if (throw_monitor_exception) { 936 // Throw exception 937 MacroAssembler::call_VM(noreg, 938 CAST_FROM_FN_PTR(address, InterpreterRuntime:: 939 throw_illegal_monitor_state_exception)); 940 should_not_reach_here(); 941 } else { 942 // Stack unrolling. Unlock object and install illegal_monitor_exception. 943 // Unlock does not block, so don't have to worry about the frame. 944 // We don't have to preserve c_rarg1 since we are going to throw an exception. 945 946 push(state); 947 mov(robj, rmon); // nop if robj and rmon are the same 948 unlock_object(robj); 949 pop(state); 950 951 if (install_monitor_exception) { 952 call_VM(noreg, CAST_FROM_FN_PTR(address, 953 InterpreterRuntime:: 954 new_illegal_monitor_state_exception)); 955 } 956 957 jmp(restart); 958 } 959 960 bind(loop); 961 // check if current entry is used 962 cmpptr(Address(rmon, BasicObjectLock::obj_offset()), NULL_WORD); 963 jcc(Assembler::notEqual, exception); 964 965 addptr(rmon, entry_size); // otherwise advance to next entry 966 bind(entry); 967 cmpptr(rmon, rbx); // check if bottom reached 968 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry 969 } 970 971 bind(no_unlock); 972 973 JFR_ONLY(enter_jfr_critical_section();) 974 975 // The below poll is for the stack watermark barrier. It allows fixing up frames lazily, 976 // that would normally not be safe to use. Such bad returns into unsafe territory of 977 // the stack, will call InterpreterRuntime::at_unwind. 978 Label slow_path; 979 Label fast_path; 980 safepoint_poll(slow_path, true /* at_return */, false /* in_nmethod */); 981 jmp(fast_path); 982 bind(slow_path); 983 push(state); 984 set_last_Java_frame(noreg, rbp, (address)pc(), rscratch1); 985 super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), r15_thread); 986 reset_last_Java_frame(true); 987 pop(state); 988 bind(fast_path); 989 990 // JVMTI support. Make sure the safepoint poll test is issued prior. 991 if (notify_jvmdi) { 992 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA 993 } else { 994 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA 995 } 996 997 // remove activation 998 // get sender sp 999 movptr(rbx, 1000 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); 1001 if (StackReservedPages > 0) { 1002 // testing if reserved zone needs to be re-enabled 1003 Register rthread = r15_thread; 1004 Label no_reserved_zone_enabling; 1005 1006 // check if already enabled - if so no re-enabling needed 1007 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size"); 1008 cmpl(Address(rthread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_enabled); 1009 jcc(Assembler::equal, no_reserved_zone_enabling); 1010 1011 cmpptr(rbx, Address(rthread, JavaThread::reserved_stack_activation_offset())); 1012 jcc(Assembler::lessEqual, no_reserved_zone_enabling); 1013 1014 JFR_ONLY(leave_jfr_critical_section();) 1015 1016 call_VM_leaf( 1017 CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread); 1018 call_VM(noreg, CAST_FROM_FN_PTR(address, 1019 InterpreterRuntime::throw_delayed_StackOverflowError)); 1020 should_not_reach_here(); 1021 1022 bind(no_reserved_zone_enabling); 1023 } 1024 1025 leave(); // remove frame anchor 1026 1027 JFR_ONLY(leave_jfr_critical_section();) 1028 1029 pop(ret_addr); // get return address 1030 mov(rsp, rbx); // set sp to sender sp 1031 pop_cont_fastpath(); 1032 1033 } 1034 1035 #if INCLUDE_JFR 1036 void InterpreterMacroAssembler::enter_jfr_critical_section() { 1037 const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR)); 1038 movbool(sampling_critical_section, true); 1039 } 1040 1041 void InterpreterMacroAssembler::leave_jfr_critical_section() { 1042 const Address sampling_critical_section(r15_thread, in_bytes(SAMPLING_CRITICAL_SECTION_OFFSET_JFR)); 1043 movbool(sampling_critical_section, false); 1044 } 1045 #endif // INCLUDE_JFR 1046 1047 void InterpreterMacroAssembler::get_method_counters(Register method, 1048 Register mcs, Label& skip) { 1049 Label has_counters; 1050 movptr(mcs, Address(method, Method::method_counters_offset())); 1051 testptr(mcs, mcs); 1052 jcc(Assembler::notZero, has_counters); 1053 call_VM(noreg, CAST_FROM_FN_PTR(address, 1054 InterpreterRuntime::build_method_counters), method); 1055 movptr(mcs, Address(method,Method::method_counters_offset())); 1056 testptr(mcs, mcs); 1057 jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory 1058 bind(has_counters); 1059 } 1060 1061 1062 // Lock object 1063 // 1064 // Args: 1065 // rdx, c_rarg1: BasicObjectLock to be used for locking 1066 // 1067 // Kills: 1068 // rax, rbx 1069 void InterpreterMacroAssembler::lock_object(Register lock_reg) { 1070 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1"); 1071 1072 if (LockingMode == LM_MONITOR) { 1073 call_VM_preemptable(noreg, 1074 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 1075 lock_reg); 1076 } else { 1077 Label count_locking, done, slow_case; 1078 1079 const Register swap_reg = rax; // Must use rax for cmpxchg instruction 1080 const Register tmp_reg = rbx; 1081 const Register obj_reg = c_rarg3; // Will contain the oop 1082 const Register rklass_decode_tmp = rscratch1; 1083 1084 const int obj_offset = in_bytes(BasicObjectLock::obj_offset()); 1085 const int lock_offset = in_bytes(BasicObjectLock::lock_offset()); 1086 const int mark_offset = lock_offset + 1087 BasicLock::displaced_header_offset_in_bytes(); 1088 1089 // Load object pointer into obj_reg 1090 movptr(obj_reg, Address(lock_reg, obj_offset)); 1091 1092 if (LockingMode == LM_LIGHTWEIGHT) { 1093 lightweight_lock(lock_reg, obj_reg, swap_reg, tmp_reg, slow_case); 1094 } else if (LockingMode == LM_LEGACY) { 1095 if (DiagnoseSyncOnValueBasedClasses != 0) { 1096 load_klass(tmp_reg, obj_reg, rklass_decode_tmp); 1097 testb(Address(tmp_reg, Klass::misc_flags_offset()), KlassFlags::_misc_is_value_based_class); 1098 jcc(Assembler::notZero, slow_case); 1099 } 1100 1101 // Load immediate 1 into swap_reg %rax 1102 movl(swap_reg, 1); 1103 1104 // Load (object->mark() | 1) into swap_reg %rax 1105 orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes())); 1106 1107 // Save (object->mark() | 1) into BasicLock's displaced header 1108 movptr(Address(lock_reg, mark_offset), swap_reg); 1109 1110 assert(lock_offset == 0, 1111 "displaced header must be first word in BasicObjectLock"); 1112 1113 lock(); 1114 cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes())); 1115 jcc(Assembler::zero, count_locking); 1116 1117 const int zero_bits = 7; 1118 1119 // Fast check for recursive lock. 1120 // 1121 // Can apply the optimization only if this is a stack lock 1122 // allocated in this thread. For efficiency, we can focus on 1123 // recently allocated stack locks (instead of reading the stack 1124 // base and checking whether 'mark' points inside the current 1125 // thread stack): 1126 // 1) (mark & zero_bits) == 0, and 1127 // 2) rsp <= mark < mark + os::pagesize() 1128 // 1129 // Warning: rsp + os::pagesize can overflow the stack base. We must 1130 // neither apply the optimization for an inflated lock allocated 1131 // just above the thread stack (this is why condition 1 matters) 1132 // nor apply the optimization if the stack lock is inside the stack 1133 // of another thread. The latter is avoided even in case of overflow 1134 // because we have guard pages at the end of all stacks. Hence, if 1135 // we go over the stack base and hit the stack of another thread, 1136 // this should not be in a writeable area that could contain a 1137 // stack lock allocated by that thread. As a consequence, a stack 1138 // lock less than page size away from rsp is guaranteed to be 1139 // owned by the current thread. 1140 // 1141 // These 3 tests can be done by evaluating the following 1142 // expression: ((mark - rsp) & (zero_bits - os::vm_page_size())), 1143 // assuming both stack pointer and pagesize have their 1144 // least significant bits clear. 1145 // NOTE: the mark is in swap_reg %rax as the result of cmpxchg 1146 subptr(swap_reg, rsp); 1147 andptr(swap_reg, zero_bits - (int)os::vm_page_size()); 1148 1149 // Save the test result, for recursive case, the result is zero 1150 movptr(Address(lock_reg, mark_offset), swap_reg); 1151 jcc(Assembler::notZero, slow_case); 1152 1153 bind(count_locking); 1154 inc_held_monitor_count(); 1155 } 1156 jmp(done); 1157 1158 bind(slow_case); 1159 1160 // Call the runtime routine for slow case 1161 call_VM_preemptable(noreg, 1162 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 1163 lock_reg); 1164 bind(done); 1165 } 1166 } 1167 1168 1169 // Unlocks an object. Used in monitorexit bytecode and 1170 // remove_activation. Throws an IllegalMonitorException if object is 1171 // not locked by current thread. 1172 // 1173 // Args: 1174 // rdx, c_rarg1: BasicObjectLock for lock 1175 // 1176 // Kills: 1177 // rax 1178 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs) 1179 // rscratch1 (scratch reg) 1180 // rax, rbx, rcx, rdx 1181 void InterpreterMacroAssembler::unlock_object(Register lock_reg) { 1182 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1"); 1183 1184 if (LockingMode == LM_MONITOR) { 1185 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 1186 } else { 1187 Label count_locking, done, slow_case; 1188 1189 const Register swap_reg = rax; // Must use rax for cmpxchg instruction 1190 const Register header_reg = c_rarg2; // Will contain the old oopMark 1191 const Register obj_reg = c_rarg3; // Will contain the oop 1192 1193 save_bcp(); // Save in case of exception 1194 1195 if (LockingMode != LM_LIGHTWEIGHT) { 1196 // Convert from BasicObjectLock structure to object and BasicLock 1197 // structure Store the BasicLock address into %rax 1198 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset())); 1199 } 1200 1201 // Load oop into obj_reg(%c_rarg3) 1202 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset())); 1203 1204 // Free entry 1205 movptr(Address(lock_reg, BasicObjectLock::obj_offset()), NULL_WORD); 1206 1207 if (LockingMode == LM_LIGHTWEIGHT) { 1208 lightweight_unlock(obj_reg, swap_reg, header_reg, slow_case); 1209 } else if (LockingMode == LM_LEGACY) { 1210 // Load the old header from BasicLock structure 1211 movptr(header_reg, Address(swap_reg, 1212 BasicLock::displaced_header_offset_in_bytes())); 1213 1214 // Test for recursion 1215 testptr(header_reg, header_reg); 1216 1217 // zero for recursive case 1218 jcc(Assembler::zero, count_locking); 1219 1220 // Atomic swap back the old header 1221 lock(); 1222 cmpxchgptr(header_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes())); 1223 1224 // zero for simple unlock of a stack-lock case 1225 jcc(Assembler::notZero, slow_case); 1226 1227 bind(count_locking); 1228 dec_held_monitor_count(); 1229 } 1230 jmp(done); 1231 1232 bind(slow_case); 1233 // Call the runtime routine for slow case. 1234 movptr(Address(lock_reg, BasicObjectLock::obj_offset()), obj_reg); // restore obj 1235 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 1236 1237 bind(done); 1238 1239 restore_bcp(); 1240 } 1241 } 1242 1243 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, 1244 Label& zero_continue) { 1245 assert(ProfileInterpreter, "must be profiling interpreter"); 1246 movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize)); 1247 testptr(mdp, mdp); 1248 jcc(Assembler::zero, zero_continue); 1249 } 1250 1251 1252 // Set the method data pointer for the current bcp. 1253 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { 1254 assert(ProfileInterpreter, "must be profiling interpreter"); 1255 Label set_mdp; 1256 push(rax); 1257 push(rbx); 1258 1259 get_method(rbx); 1260 // Test MDO to avoid the call if it is null. 1261 movptr(rax, Address(rbx, in_bytes(Method::method_data_offset()))); 1262 testptr(rax, rax); 1263 jcc(Assembler::zero, set_mdp); 1264 // rbx: method 1265 // _bcp_register: bcp 1266 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, _bcp_register); 1267 // rax: mdi 1268 // mdo is guaranteed to be non-zero here, we checked for it before the call. 1269 movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset()))); 1270 addptr(rbx, in_bytes(MethodData::data_offset())); 1271 addptr(rax, rbx); 1272 bind(set_mdp); 1273 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax); 1274 pop(rbx); 1275 pop(rax); 1276 } 1277 1278 void InterpreterMacroAssembler::verify_method_data_pointer() { 1279 assert(ProfileInterpreter, "must be profiling interpreter"); 1280 #ifdef ASSERT 1281 Label verify_continue; 1282 push(rax); 1283 push(rbx); 1284 Register arg3_reg = c_rarg3; 1285 Register arg2_reg = c_rarg2; 1286 push(arg3_reg); 1287 push(arg2_reg); 1288 test_method_data_pointer(arg3_reg, verify_continue); // If mdp is zero, continue 1289 get_method(rbx); 1290 1291 // If the mdp is valid, it will point to a DataLayout header which is 1292 // consistent with the bcp. The converse is highly probable also. 1293 load_unsigned_short(arg2_reg, 1294 Address(arg3_reg, in_bytes(DataLayout::bci_offset()))); 1295 addptr(arg2_reg, Address(rbx, Method::const_offset())); 1296 lea(arg2_reg, Address(arg2_reg, ConstMethod::codes_offset())); 1297 cmpptr(arg2_reg, _bcp_register); 1298 jcc(Assembler::equal, verify_continue); 1299 // rbx: method 1300 // _bcp_register: bcp 1301 // c_rarg3: mdp 1302 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), 1303 rbx, _bcp_register, arg3_reg); 1304 bind(verify_continue); 1305 pop(arg2_reg); 1306 pop(arg3_reg); 1307 pop(rbx); 1308 pop(rax); 1309 #endif // ASSERT 1310 } 1311 1312 1313 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, 1314 int constant, 1315 Register value) { 1316 assert(ProfileInterpreter, "must be profiling interpreter"); 1317 Address data(mdp_in, constant); 1318 movptr(data, value); 1319 } 1320 1321 1322 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 1323 int constant) { 1324 assert(ProfileInterpreter, "must be profiling interpreter"); 1325 Address data(mdp_in, constant); 1326 addptr(data, DataLayout::counter_increment); 1327 } 1328 1329 1330 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 1331 Register index, 1332 int constant) { 1333 assert(ProfileInterpreter, "must be profiling interpreter"); 1334 Address data(mdp_in, index, Address::times_1, constant); 1335 addptr(data, DataLayout::counter_increment); 1336 } 1337 1338 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, 1339 int flag_byte_constant) { 1340 assert(ProfileInterpreter, "must be profiling interpreter"); 1341 int header_offset = in_bytes(DataLayout::flags_offset()); 1342 int header_bits = flag_byte_constant; 1343 // Set the flag 1344 orb(Address(mdp_in, header_offset), header_bits); 1345 } 1346 1347 1348 1349 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, 1350 int offset, 1351 Register value, 1352 Register test_value_out, 1353 Label& not_equal_continue) { 1354 assert(ProfileInterpreter, "must be profiling interpreter"); 1355 if (test_value_out == noreg) { 1356 cmpptr(value, Address(mdp_in, offset)); 1357 } else { 1358 // Put the test value into a register, so caller can use it: 1359 movptr(test_value_out, Address(mdp_in, offset)); 1360 cmpptr(test_value_out, value); 1361 } 1362 jcc(Assembler::notEqual, not_equal_continue); 1363 } 1364 1365 1366 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, 1367 int offset_of_disp) { 1368 assert(ProfileInterpreter, "must be profiling interpreter"); 1369 Address disp_address(mdp_in, offset_of_disp); 1370 addptr(mdp_in, disp_address); 1371 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); 1372 } 1373 1374 1375 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, 1376 Register reg, 1377 int offset_of_disp) { 1378 assert(ProfileInterpreter, "must be profiling interpreter"); 1379 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); 1380 addptr(mdp_in, disp_address); 1381 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); 1382 } 1383 1384 1385 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, 1386 int constant) { 1387 assert(ProfileInterpreter, "must be profiling interpreter"); 1388 addptr(mdp_in, constant); 1389 movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in); 1390 } 1391 1392 1393 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { 1394 assert(ProfileInterpreter, "must be profiling interpreter"); 1395 push(return_bci); // save/restore across call_VM 1396 call_VM(noreg, 1397 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), 1398 return_bci); 1399 pop(return_bci); 1400 } 1401 1402 1403 void InterpreterMacroAssembler::profile_taken_branch(Register mdp) { 1404 if (ProfileInterpreter) { 1405 Label profile_continue; 1406 1407 // If no method data exists, go to profile_continue. 1408 test_method_data_pointer(mdp, profile_continue); 1409 1410 // We are taking a branch. Increment the taken count. 1411 increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); 1412 1413 // The method data pointer needs to be updated to reflect the new target. 1414 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); 1415 bind(profile_continue); 1416 } 1417 } 1418 1419 1420 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { 1421 if (ProfileInterpreter) { 1422 Label profile_continue; 1423 1424 // If no method data exists, go to profile_continue. 1425 test_method_data_pointer(mdp, profile_continue); 1426 1427 // We are not taking a branch. Increment the not taken count. 1428 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); 1429 1430 // The method data pointer needs to be updated to correspond to 1431 // the next bytecode 1432 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); 1433 bind(profile_continue); 1434 } 1435 } 1436 1437 void InterpreterMacroAssembler::profile_call(Register mdp) { 1438 if (ProfileInterpreter) { 1439 Label profile_continue; 1440 1441 // If no method data exists, go to profile_continue. 1442 test_method_data_pointer(mdp, profile_continue); 1443 1444 // We are making a call. Increment the count. 1445 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1446 1447 // The method data pointer needs to be updated to reflect the new target. 1448 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); 1449 bind(profile_continue); 1450 } 1451 } 1452 1453 1454 void InterpreterMacroAssembler::profile_final_call(Register mdp) { 1455 if (ProfileInterpreter) { 1456 Label profile_continue; 1457 1458 // If no method data exists, go to profile_continue. 1459 test_method_data_pointer(mdp, profile_continue); 1460 1461 // We are making a call. Increment the count. 1462 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1463 1464 // The method data pointer needs to be updated to reflect the new target. 1465 update_mdp_by_constant(mdp, 1466 in_bytes(VirtualCallData:: 1467 virtual_call_data_size())); 1468 bind(profile_continue); 1469 } 1470 } 1471 1472 1473 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, 1474 Register mdp, 1475 Register reg2, 1476 bool receiver_can_be_null) { 1477 if (ProfileInterpreter) { 1478 Label profile_continue; 1479 1480 // If no method data exists, go to profile_continue. 1481 test_method_data_pointer(mdp, profile_continue); 1482 1483 Label skip_receiver_profile; 1484 if (receiver_can_be_null) { 1485 Label not_null; 1486 testptr(receiver, receiver); 1487 jccb(Assembler::notZero, not_null); 1488 // We are making a call. Increment the count for null receiver. 1489 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1490 jmp(skip_receiver_profile); 1491 bind(not_null); 1492 } 1493 1494 // Record the receiver type. 1495 record_klass_in_profile(receiver, mdp, reg2, true); 1496 bind(skip_receiver_profile); 1497 1498 // The method data pointer needs to be updated to reflect the new target. 1499 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); 1500 bind(profile_continue); 1501 } 1502 } 1503 1504 // This routine creates a state machine for updating the multi-row 1505 // type profile at a virtual call site (or other type-sensitive bytecode). 1506 // The machine visits each row (of receiver/count) until the receiver type 1507 // is found, or until it runs out of rows. At the same time, it remembers 1508 // the location of the first empty row. (An empty row records null for its 1509 // receiver, and can be allocated for a newly-observed receiver type.) 1510 // Because there are two degrees of freedom in the state, a simple linear 1511 // search will not work; it must be a decision tree. Hence this helper 1512 // function is recursive, to generate the required tree structured code. 1513 // It's the interpreter, so we are trading off code space for speed. 1514 // See below for example code. 1515 void InterpreterMacroAssembler::record_klass_in_profile_helper( 1516 Register receiver, Register mdp, 1517 Register reg2, int start_row, 1518 Label& done, bool is_virtual_call) { 1519 if (TypeProfileWidth == 0) { 1520 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1521 } else { 1522 record_item_in_profile_helper(receiver, mdp, reg2, 0, done, TypeProfileWidth, 1523 &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset); 1524 } 1525 } 1526 1527 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item, Register mdp, Register reg2, int start_row, 1528 Label& done, int total_rows, 1529 OffsetFunction item_offset_fn, 1530 OffsetFunction item_count_offset_fn) { 1531 int last_row = total_rows - 1; 1532 assert(start_row <= last_row, "must be work left to do"); 1533 // Test this row for both the item and for null. 1534 // Take any of three different outcomes: 1535 // 1. found item => increment count and goto done 1536 // 2. found null => keep looking for case 1, maybe allocate this cell 1537 // 3. found something else => keep looking for cases 1 and 2 1538 // Case 3 is handled by a recursive call. 1539 for (int row = start_row; row <= last_row; row++) { 1540 Label next_test; 1541 bool test_for_null_also = (row == start_row); 1542 1543 // See if the item is item[n]. 1544 int item_offset = in_bytes(item_offset_fn(row)); 1545 test_mdp_data_at(mdp, item_offset, item, 1546 (test_for_null_also ? reg2 : noreg), 1547 next_test); 1548 // (Reg2 now contains the item from the CallData.) 1549 1550 // The item is item[n]. Increment count[n]. 1551 int count_offset = in_bytes(item_count_offset_fn(row)); 1552 increment_mdp_data_at(mdp, count_offset); 1553 jmp(done); 1554 bind(next_test); 1555 1556 if (test_for_null_also) { 1557 // Failed the equality check on item[n]... Test for null. 1558 testptr(reg2, reg2); 1559 if (start_row == last_row) { 1560 // The only thing left to do is handle the null case. 1561 Label found_null; 1562 jccb(Assembler::zero, found_null); 1563 // Item did not match any saved item and there is no empty row for it. 1564 // Increment total counter to indicate polymorphic case. 1565 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1566 jmp(done); 1567 bind(found_null); 1568 break; 1569 } 1570 Label found_null; 1571 // Since null is rare, make it be the branch-taken case. 1572 jcc(Assembler::zero, found_null); 1573 1574 // Put all the "Case 3" tests here. 1575 record_item_in_profile_helper(item, mdp, reg2, start_row + 1, done, total_rows, 1576 item_offset_fn, item_count_offset_fn); 1577 1578 // Found a null. Keep searching for a matching item, 1579 // but remember that this is an empty (unused) slot. 1580 bind(found_null); 1581 } 1582 } 1583 1584 // In the fall-through case, we found no matching item, but we 1585 // observed the item[start_row] is null. 1586 1587 // Fill in the item field and increment the count. 1588 int item_offset = in_bytes(item_offset_fn(start_row)); 1589 set_mdp_data_at(mdp, item_offset, item); 1590 int count_offset = in_bytes(item_count_offset_fn(start_row)); 1591 movl(reg2, DataLayout::counter_increment); 1592 set_mdp_data_at(mdp, count_offset, reg2); 1593 if (start_row > 0) { 1594 jmp(done); 1595 } 1596 } 1597 1598 // Example state machine code for three profile rows: 1599 // // main copy of decision tree, rooted at row[1] 1600 // if (row[0].rec == rec) { row[0].incr(); goto done; } 1601 // if (row[0].rec != nullptr) { 1602 // // inner copy of decision tree, rooted at row[1] 1603 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1604 // if (row[1].rec != nullptr) { 1605 // // degenerate decision tree, rooted at row[2] 1606 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1607 // if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow 1608 // row[2].init(rec); goto done; 1609 // } else { 1610 // // remember row[1] is empty 1611 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1612 // row[1].init(rec); goto done; 1613 // } 1614 // } else { 1615 // // remember row[0] is empty 1616 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1617 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1618 // row[0].init(rec); goto done; 1619 // } 1620 // done: 1621 1622 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, 1623 Register mdp, Register reg2, 1624 bool is_virtual_call) { 1625 assert(ProfileInterpreter, "must be profiling"); 1626 Label done; 1627 1628 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); 1629 1630 bind (done); 1631 } 1632 1633 void InterpreterMacroAssembler::profile_ret(Register return_bci, 1634 Register mdp) { 1635 if (ProfileInterpreter) { 1636 Label profile_continue; 1637 uint row; 1638 1639 // If no method data exists, go to profile_continue. 1640 test_method_data_pointer(mdp, profile_continue); 1641 1642 // Update the total ret count. 1643 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1644 1645 for (row = 0; row < RetData::row_limit(); row++) { 1646 Label next_test; 1647 1648 // See if return_bci is equal to bci[n]: 1649 test_mdp_data_at(mdp, 1650 in_bytes(RetData::bci_offset(row)), 1651 return_bci, noreg, 1652 next_test); 1653 1654 // return_bci is equal to bci[n]. Increment the count. 1655 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); 1656 1657 // The method data pointer needs to be updated to reflect the new target. 1658 update_mdp_by_offset(mdp, 1659 in_bytes(RetData::bci_displacement_offset(row))); 1660 jmp(profile_continue); 1661 bind(next_test); 1662 } 1663 1664 update_mdp_for_ret(return_bci); 1665 1666 bind(profile_continue); 1667 } 1668 } 1669 1670 1671 void InterpreterMacroAssembler::profile_null_seen(Register mdp) { 1672 if (ProfileInterpreter) { 1673 Label profile_continue; 1674 1675 // If no method data exists, go to profile_continue. 1676 test_method_data_pointer(mdp, profile_continue); 1677 1678 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); 1679 1680 // The method data pointer needs to be updated. 1681 int mdp_delta = in_bytes(BitData::bit_data_size()); 1682 if (TypeProfileCasts) { 1683 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1684 } 1685 update_mdp_by_constant(mdp, mdp_delta); 1686 1687 bind(profile_continue); 1688 } 1689 } 1690 1691 1692 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { 1693 if (ProfileInterpreter) { 1694 Label profile_continue; 1695 1696 // If no method data exists, go to profile_continue. 1697 test_method_data_pointer(mdp, profile_continue); 1698 1699 // The method data pointer needs to be updated. 1700 int mdp_delta = in_bytes(BitData::bit_data_size()); 1701 if (TypeProfileCasts) { 1702 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1703 1704 // Record the object type. 1705 record_klass_in_profile(klass, mdp, reg2, false); 1706 } 1707 update_mdp_by_constant(mdp, mdp_delta); 1708 1709 bind(profile_continue); 1710 } 1711 } 1712 1713 1714 void InterpreterMacroAssembler::profile_switch_default(Register mdp) { 1715 if (ProfileInterpreter) { 1716 Label profile_continue; 1717 1718 // If no method data exists, go to profile_continue. 1719 test_method_data_pointer(mdp, profile_continue); 1720 1721 // Update the default case count 1722 increment_mdp_data_at(mdp, 1723 in_bytes(MultiBranchData::default_count_offset())); 1724 1725 // The method data pointer needs to be updated. 1726 update_mdp_by_offset(mdp, 1727 in_bytes(MultiBranchData:: 1728 default_displacement_offset())); 1729 1730 bind(profile_continue); 1731 } 1732 } 1733 1734 1735 void InterpreterMacroAssembler::profile_switch_case(Register index, 1736 Register mdp, 1737 Register reg2) { 1738 if (ProfileInterpreter) { 1739 Label profile_continue; 1740 1741 // If no method data exists, go to profile_continue. 1742 test_method_data_pointer(mdp, profile_continue); 1743 1744 // Build the base (index * per_case_size_in_bytes()) + 1745 // case_array_offset_in_bytes() 1746 movl(reg2, in_bytes(MultiBranchData::per_case_size())); 1747 imulptr(index, reg2); // XXX l ? 1748 addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ? 1749 1750 // Update the case count 1751 increment_mdp_data_at(mdp, 1752 index, 1753 in_bytes(MultiBranchData::relative_count_offset())); 1754 1755 // The method data pointer needs to be updated. 1756 update_mdp_by_offset(mdp, 1757 index, 1758 in_bytes(MultiBranchData:: 1759 relative_displacement_offset())); 1760 1761 bind(profile_continue); 1762 } 1763 } 1764 1765 1766 1767 void InterpreterMacroAssembler::_interp_verify_oop(Register reg, TosState state, const char* file, int line) { 1768 if (state == atos) { 1769 MacroAssembler::_verify_oop_checked(reg, "broken oop", file, line); 1770 } 1771 } 1772 1773 1774 // Jump if ((*counter_addr += increment) & mask) == 0 1775 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, Address mask, 1776 Register scratch, Label* where) { 1777 // This update is actually not atomic and can lose a number of updates 1778 // under heavy contention, but the alternative of using the (contended) 1779 // atomic update here penalizes profiling paths too much. 1780 movl(scratch, counter_addr); 1781 incrementl(scratch, InvocationCounter::count_increment); 1782 movl(counter_addr, scratch); 1783 andl(scratch, mask); 1784 if (where != nullptr) { 1785 jcc(Assembler::zero, *where); 1786 } 1787 } 1788 1789 void InterpreterMacroAssembler::notify_method_entry() { 1790 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1791 // track stack depth. If it is possible to enter interp_only_mode we add 1792 // the code to check if the event should be sent. 1793 Register rthread = r15_thread; 1794 Register rarg = c_rarg1; 1795 if (JvmtiExport::can_post_interpreter_events()) { 1796 Label L; 1797 movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset())); 1798 testl(rdx, rdx); 1799 jcc(Assembler::zero, L); 1800 call_VM(noreg, CAST_FROM_FN_PTR(address, 1801 InterpreterRuntime::post_method_entry)); 1802 bind(L); 1803 } 1804 1805 if (DTraceMethodProbes) { 1806 get_method(rarg); 1807 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), 1808 rthread, rarg); 1809 } 1810 1811 // RedefineClasses() tracing support for obsolete method entry 1812 if (log_is_enabled(Trace, redefine, class, obsolete)) { 1813 get_method(rarg); 1814 call_VM_leaf( 1815 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), 1816 rthread, rarg); 1817 } 1818 } 1819 1820 1821 void InterpreterMacroAssembler::notify_method_exit( 1822 TosState state, NotifyMethodExitMode mode) { 1823 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1824 // track stack depth. If it is possible to enter interp_only_mode we add 1825 // the code to check if the event should be sent. 1826 Register rthread = r15_thread; 1827 Register rarg = c_rarg1; 1828 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 1829 Label L; 1830 // Note: frame::interpreter_frame_result has a dependency on how the 1831 // method result is saved across the call to post_method_exit. If this 1832 // is changed then the interpreter_frame_result implementation will 1833 // need to be updated too. 1834 1835 // template interpreter will leave the result on the top of the stack. 1836 push(state); 1837 movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset())); 1838 testl(rdx, rdx); 1839 jcc(Assembler::zero, L); 1840 call_VM(noreg, 1841 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); 1842 bind(L); 1843 pop(state); 1844 } 1845 1846 if (DTraceMethodProbes) { 1847 push(state); 1848 get_method(rarg); 1849 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), 1850 rthread, rarg); 1851 pop(state); 1852 } 1853 } 1854 1855 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) { 1856 // Get index out of bytecode pointer 1857 get_cache_index_at_bcp(index, 1, sizeof(u4)); 1858 // Get address of invokedynamic array 1859 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); 1860 movptr(cache, Address(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()))); 1861 if (is_power_of_2(sizeof(ResolvedIndyEntry))) { 1862 shll(index, log2i_exact(sizeof(ResolvedIndyEntry))); // Scale index by power of 2 1863 } else { 1864 imull(index, index, sizeof(ResolvedIndyEntry)); // Scale the index to be the entry index * sizeof(ResolvedIndyEntry) 1865 } 1866 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedIndyEntry>::base_offset_in_bytes())); 1867 } 1868 1869 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) { 1870 // Get index out of bytecode pointer 1871 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); 1872 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 1873 1874 movptr(cache, Address(cache, ConstantPoolCache::field_entries_offset())); 1875 // Take shortcut if the size is a power of 2 1876 if (is_power_of_2(sizeof(ResolvedFieldEntry))) { 1877 shll(index, log2i_exact(sizeof(ResolvedFieldEntry))); // Scale index by power of 2 1878 } else { 1879 imull(index, index, sizeof(ResolvedFieldEntry)); // Scale the index to be the entry index * sizeof(ResolvedFieldEntry) 1880 } 1881 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedFieldEntry>::base_offset_in_bytes())); 1882 } 1883 1884 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) { 1885 // Get index out of bytecode pointer 1886 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); 1887 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 1888 1889 movptr(cache, Address(cache, ConstantPoolCache::method_entries_offset())); 1890 imull(index, index, sizeof(ResolvedMethodEntry)); // Scale the index to be the entry index * sizeof(ResolvedMethodEntry) 1891 lea(cache, Address(cache, index, Address::times_1, Array<ResolvedMethodEntry>::base_offset_in_bytes())); 1892 }