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