1 /* 2 * Copyright (c) 1997, 2011, 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_32.hpp" 27 #include "interpreter/interpreter.hpp" 28 #include "interpreter/interpreterRuntime.hpp" 29 #include "oops/arrayOop.hpp" 30 #include "oops/markOop.hpp" 31 #include "oops/methodDataOop.hpp" 32 #include "oops/methodOop.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 #ifdef TARGET_OS_FAMILY_linux 40 # include "thread_linux.inline.hpp" 41 #endif 42 #ifdef TARGET_OS_FAMILY_solaris 43 # include "thread_solaris.inline.hpp" 44 #endif 45 #ifdef TARGET_OS_FAMILY_windows 46 # include "thread_windows.inline.hpp" 47 #endif 48 49 50 // Implementation of InterpreterMacroAssembler 51 #ifdef CC_INTERP 52 void InterpreterMacroAssembler::get_method(Register reg) { 53 movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize))); 54 movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method))); 55 } 56 #endif // CC_INTERP 57 58 59 #ifndef CC_INTERP 60 void InterpreterMacroAssembler::call_VM_leaf_base( 61 address entry_point, 62 int number_of_arguments 63 ) { 64 // interpreter specific 65 // 66 // Note: No need to save/restore bcp & locals (rsi & rdi) pointer 67 // since these are callee saved registers and no blocking/ 68 // GC can happen in leaf calls. 69 // Further Note: DO NOT save/restore bcp/locals. If a caller has 70 // already saved them so that it can use rsi/rdi as temporaries 71 // then a save/restore here will DESTROY the copy the caller 72 // saved! There used to be a save_bcp() that only happened in 73 // the ASSERT path (no restore_bcp). Which caused bizarre failures 74 // when jvm built with ASSERTs. 75 #ifdef ASSERT 76 { Label L; 77 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 78 jcc(Assembler::equal, L); 79 stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL"); 80 bind(L); 81 } 82 #endif 83 // super call 84 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); 85 // interpreter specific 86 87 // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals 88 // but since they may not have been saved (and we don't want to 89 // save them here (see note above) the assert is invalid. 90 } 91 92 93 void InterpreterMacroAssembler::call_VM_base( 94 Register oop_result, 95 Register java_thread, 96 Register last_java_sp, 97 address entry_point, 98 int number_of_arguments, 99 bool check_exceptions 100 ) { 101 #ifdef ASSERT 102 { Label L; 103 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 104 jcc(Assembler::equal, L); 105 stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL"); 106 bind(L); 107 } 108 #endif /* ASSERT */ 109 // interpreter specific 110 // 111 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't 112 // really make a difference for these runtime calls, since they are 113 // slow anyway. Btw., bcp must be saved/restored since it may change 114 // due to GC. 115 assert(java_thread == noreg , "not expecting a precomputed java thread"); 116 save_bcp(); 117 // super call 118 MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions); 119 // interpreter specific 120 restore_bcp(); 121 restore_locals(); 122 } 123 124 125 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { 126 if (JvmtiExport::can_pop_frame()) { 127 Label L; 128 // Initiate popframe handling only if it is not already being processed. If the flag 129 // has the popframe_processing bit set, it means that this code is called *during* popframe 130 // handling - we don't want to reenter. 131 Register pop_cond = java_thread; // Not clear if any other register is available... 132 movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset())); 133 testl(pop_cond, JavaThread::popframe_pending_bit); 134 jcc(Assembler::zero, L); 135 testl(pop_cond, JavaThread::popframe_processing_bit); 136 jcc(Assembler::notZero, L); 137 // Call Interpreter::remove_activation_preserving_args_entry() to get the 138 // address of the same-named entrypoint in the generated interpreter code. 139 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); 140 jmp(rax); 141 bind(L); 142 get_thread(java_thread); 143 } 144 } 145 146 147 void InterpreterMacroAssembler::load_earlyret_value(TosState state) { 148 get_thread(rcx); 149 movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset())); 150 const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset()); 151 const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset()); 152 const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset()); 153 const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset() 154 + in_ByteSize(wordSize)); 155 switch (state) { 156 case atos: movptr(rax, oop_addr); 157 movptr(oop_addr, NULL_WORD); 158 verify_oop(rax, state); break; 159 case ltos: 160 movl(rdx, val_addr1); // fall through 161 case btos: // fall through 162 case ctos: // fall through 163 case stos: // fall through 164 case itos: movl(rax, val_addr); break; 165 case ftos: fld_s(val_addr); break; 166 case dtos: fld_d(val_addr); break; 167 case vtos: /* nothing to do */ break; 168 default : ShouldNotReachHere(); 169 } 170 // Clean up tos value in the thread object 171 movl(tos_addr, (int32_t) ilgl); 172 movptr(val_addr, NULL_WORD); 173 NOT_LP64(movptr(val_addr1, NULL_WORD)); 174 } 175 176 177 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { 178 if (JvmtiExport::can_force_early_return()) { 179 Label L; 180 Register tmp = java_thread; 181 movptr(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset())); 182 testptr(tmp, tmp); 183 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit; 184 185 // Initiate earlyret handling only if it is not already being processed. 186 // If the flag has the earlyret_processing bit set, it means that this code 187 // is called *during* earlyret handling - we don't want to reenter. 188 movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset())); 189 cmpl(tmp, JvmtiThreadState::earlyret_pending); 190 jcc(Assembler::notEqual, L); 191 192 // Call Interpreter::remove_activation_early_entry() to get the address of the 193 // same-named entrypoint in the generated interpreter code. 194 get_thread(java_thread); 195 movptr(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset())); 196 pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset())); 197 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1); 198 jmp(rax); 199 bind(L); 200 get_thread(java_thread); 201 } 202 } 203 204 205 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) { 206 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); 207 movl(reg, Address(rsi, bcp_offset)); 208 bswapl(reg); 209 shrl(reg, 16); 210 } 211 212 213 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register reg, int bcp_offset, size_t index_size) { 214 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 215 if (index_size == sizeof(u2)) { 216 load_unsigned_short(reg, Address(rsi, bcp_offset)); 217 } else if (index_size == sizeof(u4)) { 218 assert(EnableInvokeDynamic, "giant index used only for JSR 292"); 219 movl(reg, Address(rsi, bcp_offset)); 220 // Check if the secondary index definition is still ~x, otherwise 221 // we have to change the following assembler code to calculate the 222 // plain index. 223 assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line"); 224 notl(reg); // convert to plain index 225 } else if (index_size == sizeof(u1)) { 226 assert(EnableInvokeDynamic, "tiny index used only for JSR 292"); 227 load_unsigned_byte(reg, Address(rsi, bcp_offset)); 228 } else { 229 ShouldNotReachHere(); 230 } 231 } 232 233 234 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index, 235 int bcp_offset, size_t index_size) { 236 assert(cache != index, "must use different registers"); 237 get_cache_index_at_bcp(index, bcp_offset, index_size); 238 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); 239 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below"); 240 shlptr(index, 2); // convert from field index to ConstantPoolCacheEntry index 241 } 242 243 244 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp, 245 int bcp_offset, size_t index_size) { 246 assert(cache != tmp, "must use different register"); 247 get_cache_index_at_bcp(tmp, bcp_offset, index_size); 248 assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below"); 249 // convert from field index to ConstantPoolCacheEntry index 250 // and from word offset to byte offset 251 shll(tmp, 2 + LogBytesPerWord); 252 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); 253 // skip past the header 254 addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset())); 255 addptr(cache, tmp); // construct pointer to cache entry 256 } 257 258 259 // Generate a subtype check: branch to ok_is_subtype if sub_klass is 260 // a subtype of super_klass. EAX holds the super_klass. Blows ECX. 261 // Resets EDI to locals. Register sub_klass cannot be any of the above. 262 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) { 263 assert( Rsub_klass != rax, "rax, holds superklass" ); 264 assert( Rsub_klass != rcx, "used as a temp" ); 265 assert( Rsub_klass != rdi, "used as a temp, restored from locals" ); 266 267 // Profile the not-null value's klass. 268 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi 269 270 // Do the check. 271 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx 272 273 // Profile the failure of the check. 274 profile_typecheck_failed(rcx); // blows rcx 275 } 276 277 void InterpreterMacroAssembler::f2ieee() { 278 if (IEEEPrecision) { 279 fstp_s(Address(rsp, 0)); 280 fld_s(Address(rsp, 0)); 281 } 282 } 283 284 285 void InterpreterMacroAssembler::d2ieee() { 286 if (IEEEPrecision) { 287 fstp_d(Address(rsp, 0)); 288 fld_d(Address(rsp, 0)); 289 } 290 } 291 292 // Java Expression Stack 293 294 void InterpreterMacroAssembler::pop_ptr(Register r) { 295 pop(r); 296 } 297 298 void InterpreterMacroAssembler::pop_i(Register r) { 299 pop(r); 300 } 301 302 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) { 303 pop(lo); 304 pop(hi); 305 } 306 307 void InterpreterMacroAssembler::pop_f() { 308 fld_s(Address(rsp, 0)); 309 addptr(rsp, 1 * wordSize); 310 } 311 312 void InterpreterMacroAssembler::pop_d() { 313 fld_d(Address(rsp, 0)); 314 addptr(rsp, 2 * wordSize); 315 } 316 317 318 void InterpreterMacroAssembler::pop(TosState state) { 319 switch (state) { 320 case atos: pop_ptr(rax); break; 321 case btos: // fall through 322 case ctos: // fall through 323 case stos: // fall through 324 case itos: pop_i(rax); break; 325 case ltos: pop_l(rax, rdx); break; 326 case ftos: pop_f(); break; 327 case dtos: pop_d(); break; 328 case vtos: /* nothing to do */ break; 329 default : ShouldNotReachHere(); 330 } 331 verify_oop(rax, state); 332 } 333 334 void InterpreterMacroAssembler::push_ptr(Register r) { 335 push(r); 336 } 337 338 void InterpreterMacroAssembler::push_i(Register r) { 339 push(r); 340 } 341 342 void InterpreterMacroAssembler::push_l(Register lo, Register hi) { 343 push(hi); 344 push(lo); 345 } 346 347 void InterpreterMacroAssembler::push_f() { 348 // Do not schedule for no AGI! Never write beyond rsp! 349 subptr(rsp, 1 * wordSize); 350 fstp_s(Address(rsp, 0)); 351 } 352 353 void InterpreterMacroAssembler::push_d(Register r) { 354 // Do not schedule for no AGI! Never write beyond rsp! 355 subptr(rsp, 2 * wordSize); 356 fstp_d(Address(rsp, 0)); 357 } 358 359 360 void InterpreterMacroAssembler::push(TosState state) { 361 verify_oop(rax, state); 362 switch (state) { 363 case atos: push_ptr(rax); break; 364 case btos: // fall through 365 case ctos: // fall through 366 case stos: // fall through 367 case itos: push_i(rax); break; 368 case ltos: push_l(rax, rdx); break; 369 case ftos: push_f(); break; 370 case dtos: push_d(rax); break; 371 case vtos: /* nothing to do */ break; 372 default : ShouldNotReachHere(); 373 } 374 } 375 376 377 // Helpers for swap and dup 378 void InterpreterMacroAssembler::load_ptr(int n, Register val) { 379 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); 380 } 381 382 void InterpreterMacroAssembler::store_ptr(int n, Register val) { 383 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); 384 } 385 386 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { 387 // set sender sp 388 lea(rsi, Address(rsp, wordSize)); 389 // record last_sp 390 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi); 391 } 392 393 394 // Jump to from_interpreted entry of a call unless single stepping is possible 395 // in this thread in which case we must call the i2i entry 396 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { 397 prepare_to_jump_from_interpreted(); 398 399 if (JvmtiExport::can_post_interpreter_events()) { 400 Label run_compiled_code; 401 // JVMTI events, such as single-stepping, are implemented partly by avoiding running 402 // compiled code in threads for which the event is enabled. Check here for 403 // interp_only_mode if these events CAN be enabled. 404 get_thread(temp); 405 // interp_only is an int, on little endian it is sufficient to test the byte only 406 // Is a cmpl faster (ce 407 cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0); 408 jcc(Assembler::zero, run_compiled_code); 409 jmp(Address(method, methodOopDesc::interpreter_entry_offset())); 410 bind(run_compiled_code); 411 } 412 413 jmp(Address(method, methodOopDesc::from_interpreted_offset())); 414 415 } 416 417 418 // The following two routines provide a hook so that an implementation 419 // can schedule the dispatch in two parts. Intel does not do this. 420 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { 421 // Nothing Intel-specific to be done here. 422 } 423 424 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { 425 dispatch_next(state, step); 426 } 427 428 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, 429 bool verifyoop) { 430 verify_FPU(1, state); 431 if (VerifyActivationFrameSize) { 432 Label L; 433 mov(rcx, rbp); 434 subptr(rcx, rsp); 435 int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize; 436 cmpptr(rcx, min_frame_size); 437 jcc(Assembler::greaterEqual, L); 438 stop("broken stack frame"); 439 bind(L); 440 } 441 if (verifyoop) verify_oop(rax, state); 442 Address index(noreg, rbx, Address::times_ptr); 443 ExternalAddress tbl((address)table); 444 ArrayAddress dispatch(tbl, index); 445 jump(dispatch); 446 } 447 448 449 void InterpreterMacroAssembler::dispatch_only(TosState state) { 450 dispatch_base(state, Interpreter::dispatch_table(state)); 451 } 452 453 454 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { 455 dispatch_base(state, Interpreter::normal_table(state)); 456 } 457 458 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { 459 dispatch_base(state, Interpreter::normal_table(state), false); 460 } 461 462 463 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) { 464 // load next bytecode (load before advancing rsi to prevent AGI) 465 load_unsigned_byte(rbx, Address(rsi, step)); 466 // advance rsi 467 increment(rsi, step); 468 dispatch_base(state, Interpreter::dispatch_table(state)); 469 } 470 471 472 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { 473 // load current bytecode 474 load_unsigned_byte(rbx, Address(rsi, 0)); 475 dispatch_base(state, table); 476 } 477 478 // remove activation 479 // 480 // Unlock the receiver if this is a synchronized method. 481 // Unlock any Java monitors from syncronized blocks. 482 // Remove the activation from the stack. 483 // 484 // If there are locked Java monitors 485 // If throw_monitor_exception 486 // throws IllegalMonitorStateException 487 // Else if install_monitor_exception 488 // installs IllegalMonitorStateException 489 // Else 490 // no error processing 491 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr, 492 bool throw_monitor_exception, 493 bool install_monitor_exception, 494 bool notify_jvmdi) { 495 // Note: Registers rax, rdx and FPU ST(0) may be in use for the result 496 // check if synchronized method 497 Label unlocked, unlock, no_unlock; 498 499 get_thread(rcx); 500 const Address do_not_unlock_if_synchronized(rcx, 501 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 502 503 movbool(rbx, do_not_unlock_if_synchronized); 504 mov(rdi,rbx); 505 movbool(do_not_unlock_if_synchronized, false); // reset the flag 506 507 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags 508 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset())); 509 510 testl(rcx, JVM_ACC_SYNCHRONIZED); 511 jcc(Assembler::zero, unlocked); 512 513 // Don't unlock anything if the _do_not_unlock_if_synchronized flag 514 // is set. 515 mov(rcx,rdi); 516 testbool(rcx); 517 jcc(Assembler::notZero, no_unlock); 518 519 // unlock monitor 520 push(state); // save result 521 522 // BasicObjectLock will be first in list, since this is a synchronized method. However, need 523 // to check that the object has not been unlocked by an explicit monitorexit bytecode. 524 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock)); 525 lea (rdx, monitor); // address of first monitor 526 527 movptr (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); 528 testptr(rax, rax); 529 jcc (Assembler::notZero, unlock); 530 531 pop(state); 532 if (throw_monitor_exception) { 533 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow 534 535 // Entry already unlocked, need to throw exception 536 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 537 should_not_reach_here(); 538 } else { 539 // Monitor already unlocked during a stack unroll. 540 // If requested, install an illegal_monitor_state_exception. 541 // Continue with stack unrolling. 542 if (install_monitor_exception) { 543 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow 544 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 545 } 546 jmp(unlocked); 547 } 548 549 bind(unlock); 550 unlock_object(rdx); 551 pop(state); 552 553 // Check that for block-structured locking (i.e., that all locked objects has been unlocked) 554 bind(unlocked); 555 556 // rax, rdx: Might contain return value 557 558 // Check that all monitors are unlocked 559 { 560 Label loop, exception, entry, restart; 561 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 562 const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); 563 const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset * wordSize); 564 565 bind(restart); 566 movptr(rcx, monitor_block_top); // points to current entry, starting with top-most entry 567 lea(rbx, monitor_block_bot); // points to word before bottom of monitor block 568 jmp(entry); 569 570 // Entry already locked, need to throw exception 571 bind(exception); 572 573 if (throw_monitor_exception) { 574 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow 575 576 // Throw exception 577 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 578 should_not_reach_here(); 579 } else { 580 // Stack unrolling. Unlock object and install illegal_monitor_exception 581 // Unlock does not block, so don't have to worry about the frame 582 583 push(state); 584 mov(rdx, rcx); 585 unlock_object(rdx); 586 pop(state); 587 588 if (install_monitor_exception) { 589 empty_FPU_stack(); // remove possible return value from FPU-stack, otherwise stack could overflow 590 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 591 } 592 593 jmp(restart); 594 } 595 596 bind(loop); 597 cmpptr(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); // check if current entry is used 598 jcc(Assembler::notEqual, exception); 599 600 addptr(rcx, entry_size); // otherwise advance to next entry 601 bind(entry); 602 cmpptr(rcx, rbx); // check if bottom reached 603 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry 604 } 605 606 bind(no_unlock); 607 608 // jvmti support 609 if (notify_jvmdi) { 610 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA 611 } else { 612 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA 613 } 614 615 // remove activation 616 movptr(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp 617 leave(); // remove frame anchor 618 pop(ret_addr); // get return address 619 mov(rsp, rbx); // set sp to sender sp 620 if (UseSSE) { 621 // float and double are returned in xmm register in SSE-mode 622 if (state == ftos && UseSSE >= 1) { 623 subptr(rsp, wordSize); 624 fstp_s(Address(rsp, 0)); 625 movflt(xmm0, Address(rsp, 0)); 626 addptr(rsp, wordSize); 627 } else if (state == dtos && UseSSE >= 2) { 628 subptr(rsp, 2*wordSize); 629 fstp_d(Address(rsp, 0)); 630 movdbl(xmm0, Address(rsp, 0)); 631 addptr(rsp, 2*wordSize); 632 } 633 } 634 } 635 636 #endif /* !CC_INTERP */ 637 638 639 // Lock object 640 // 641 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must 642 // be initialized with object to lock 643 void InterpreterMacroAssembler::lock_object(Register lock_reg) { 644 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx"); 645 646 if (UseHeavyMonitors) { 647 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); 648 } else { 649 650 Label done; 651 652 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction 653 const Register obj_reg = rcx; // Will contain the oop 654 655 const int obj_offset = BasicObjectLock::obj_offset_in_bytes(); 656 const int lock_offset = BasicObjectLock::lock_offset_in_bytes (); 657 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes(); 658 659 Label slow_case; 660 661 // Load object pointer into obj_reg %rcx 662 movptr(obj_reg, Address(lock_reg, obj_offset)); 663 664 if (UseBiasedLocking) { 665 // Note: we use noreg for the temporary register since it's hard 666 // to come up with a free register on all incoming code paths 667 biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case); 668 } 669 670 // Load immediate 1 into swap_reg %rax, 671 movptr(swap_reg, (int32_t)1); 672 673 // Load (object->mark() | 1) into swap_reg %rax, 674 orptr(swap_reg, Address(obj_reg, 0)); 675 676 // Save (object->mark() | 1) into BasicLock's displaced header 677 movptr(Address(lock_reg, mark_offset), swap_reg); 678 679 assert(lock_offset == 0, "displached header must be first word in BasicObjectLock"); 680 if (os::is_MP()) { 681 lock(); 682 } 683 cmpxchgptr(lock_reg, Address(obj_reg, 0)); 684 if (PrintBiasedLockingStatistics) { 685 cond_inc32(Assembler::zero, 686 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); 687 } 688 jcc(Assembler::zero, done); 689 690 // Test if the oopMark is an obvious stack pointer, i.e., 691 // 1) (mark & 3) == 0, and 692 // 2) rsp <= mark < mark + os::pagesize() 693 // 694 // These 3 tests can be done by evaluating the following 695 // expression: ((mark - rsp) & (3 - os::vm_page_size())), 696 // assuming both stack pointer and pagesize have their 697 // least significant 2 bits clear. 698 // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg 699 subptr(swap_reg, rsp); 700 andptr(swap_reg, 3 - os::vm_page_size()); 701 702 // Save the test result, for recursive case, the result is zero 703 movptr(Address(lock_reg, mark_offset), swap_reg); 704 705 if (PrintBiasedLockingStatistics) { 706 cond_inc32(Assembler::zero, 707 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); 708 } 709 jcc(Assembler::zero, done); 710 711 bind(slow_case); 712 713 // Call the runtime routine for slow case 714 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg); 715 716 bind(done); 717 } 718 } 719 720 721 // Unlocks an object. Used in monitorexit bytecode and remove_activation. 722 // 723 // Argument: rdx : Points to BasicObjectLock structure for lock 724 // Throw an IllegalMonitorException if object is not locked by current thread 725 // 726 // Uses: rax, rbx, rcx, rdx 727 void InterpreterMacroAssembler::unlock_object(Register lock_reg) { 728 assert(lock_reg == rdx, "The argument is only for looks. It must be rdx"); 729 730 if (UseHeavyMonitors) { 731 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 732 } else { 733 Label done; 734 735 const Register swap_reg = rax; // Must use rax, for cmpxchg instruction 736 const Register header_reg = rbx; // Will contain the old oopMark 737 const Register obj_reg = rcx; // Will contain the oop 738 739 save_bcp(); // Save in case of exception 740 741 // Convert from BasicObjectLock structure to object and BasicLock structure 742 // Store the BasicLock address into %rax, 743 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes())); 744 745 // Load oop into obj_reg(%rcx) 746 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ())); 747 748 // Free entry 749 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD); 750 751 if (UseBiasedLocking) { 752 biased_locking_exit(obj_reg, header_reg, done); 753 } 754 755 // Load the old header from BasicLock structure 756 movptr(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes())); 757 758 // Test for recursion 759 testptr(header_reg, header_reg); 760 761 // zero for recursive case 762 jcc(Assembler::zero, done); 763 764 // Atomic swap back the old header 765 if (os::is_MP()) lock(); 766 cmpxchgptr(header_reg, Address(obj_reg, 0)); 767 768 // zero for recursive case 769 jcc(Assembler::zero, done); 770 771 // Call the runtime routine for slow case. 772 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj 773 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); 774 775 bind(done); 776 777 restore_bcp(); 778 } 779 } 780 781 782 #ifndef CC_INTERP 783 784 // Test ImethodDataPtr. If it is null, continue at the specified label 785 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) { 786 assert(ProfileInterpreter, "must be profiling interpreter"); 787 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize)); 788 testptr(mdp, mdp); 789 jcc(Assembler::zero, zero_continue); 790 } 791 792 793 // Set the method data pointer for the current bcp. 794 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { 795 assert(ProfileInterpreter, "must be profiling interpreter"); 796 Label set_mdp; 797 push(rax); 798 push(rbx); 799 800 get_method(rbx); 801 // Test MDO to avoid the call if it is NULL. 802 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset()))); 803 testptr(rax, rax); 804 jcc(Assembler::zero, set_mdp); 805 // rbx,: method 806 // rsi: bcp 807 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi); 808 // rax,: mdi 809 // mdo is guaranteed to be non-zero here, we checked for it before the call. 810 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset()))); 811 addptr(rbx, in_bytes(methodDataOopDesc::data_offset())); 812 addptr(rax, rbx); 813 bind(set_mdp); 814 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax); 815 pop(rbx); 816 pop(rax); 817 } 818 819 void InterpreterMacroAssembler::verify_method_data_pointer() { 820 assert(ProfileInterpreter, "must be profiling interpreter"); 821 #ifdef ASSERT 822 Label verify_continue; 823 push(rax); 824 push(rbx); 825 push(rcx); 826 push(rdx); 827 test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue 828 get_method(rbx); 829 830 // If the mdp is valid, it will point to a DataLayout header which is 831 // consistent with the bcp. The converse is highly probable also. 832 load_unsigned_short(rdx, Address(rcx, in_bytes(DataLayout::bci_offset()))); 833 addptr(rdx, Address(rbx, methodOopDesc::const_offset())); 834 lea(rdx, Address(rdx, constMethodOopDesc::codes_offset())); 835 cmpptr(rdx, rsi); 836 jcc(Assembler::equal, verify_continue); 837 // rbx,: method 838 // rsi: bcp 839 // rcx: mdp 840 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx); 841 bind(verify_continue); 842 pop(rdx); 843 pop(rcx); 844 pop(rbx); 845 pop(rax); 846 #endif // ASSERT 847 } 848 849 850 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) { 851 // %%% this seems to be used to store counter data which is surely 32bits 852 // however 64bit side stores 64 bits which seems wrong 853 assert(ProfileInterpreter, "must be profiling interpreter"); 854 Address data(mdp_in, constant); 855 movptr(data, value); 856 } 857 858 859 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 860 int constant, 861 bool decrement) { 862 // Counter address 863 Address data(mdp_in, constant); 864 865 increment_mdp_data_at(data, decrement); 866 } 867 868 869 void InterpreterMacroAssembler::increment_mdp_data_at(Address data, 870 bool decrement) { 871 872 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" ); 873 assert(ProfileInterpreter, "must be profiling interpreter"); 874 875 // %%% 64bit treats this as 64 bit which seems unlikely 876 if (decrement) { 877 // Decrement the register. Set condition codes. 878 addl(data, -DataLayout::counter_increment); 879 // If the decrement causes the counter to overflow, stay negative 880 Label L; 881 jcc(Assembler::negative, L); 882 addl(data, DataLayout::counter_increment); 883 bind(L); 884 } else { 885 assert(DataLayout::counter_increment == 1, 886 "flow-free idiom only works with 1"); 887 // Increment the register. Set carry flag. 888 addl(data, DataLayout::counter_increment); 889 // If the increment causes the counter to overflow, pull back by 1. 890 sbbl(data, 0); 891 } 892 } 893 894 895 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 896 Register reg, 897 int constant, 898 bool decrement) { 899 Address data(mdp_in, reg, Address::times_1, constant); 900 901 increment_mdp_data_at(data, decrement); 902 } 903 904 905 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) { 906 assert(ProfileInterpreter, "must be profiling interpreter"); 907 int header_offset = in_bytes(DataLayout::header_offset()); 908 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant); 909 // Set the flag 910 orl(Address(mdp_in, header_offset), header_bits); 911 } 912 913 914 915 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, 916 int offset, 917 Register value, 918 Register test_value_out, 919 Label& not_equal_continue) { 920 assert(ProfileInterpreter, "must be profiling interpreter"); 921 if (test_value_out == noreg) { 922 cmpptr(value, Address(mdp_in, offset)); 923 } else { 924 // Put the test value into a register, so caller can use it: 925 movptr(test_value_out, Address(mdp_in, offset)); 926 cmpptr(test_value_out, value); 927 } 928 jcc(Assembler::notEqual, not_equal_continue); 929 } 930 931 932 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) { 933 assert(ProfileInterpreter, "must be profiling interpreter"); 934 Address disp_address(mdp_in, offset_of_disp); 935 addptr(mdp_in,disp_address); 936 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); 937 } 938 939 940 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) { 941 assert(ProfileInterpreter, "must be profiling interpreter"); 942 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); 943 addptr(mdp_in, disp_address); 944 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); 945 } 946 947 948 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) { 949 assert(ProfileInterpreter, "must be profiling interpreter"); 950 addptr(mdp_in, constant); 951 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); 952 } 953 954 955 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { 956 assert(ProfileInterpreter, "must be profiling interpreter"); 957 push(return_bci); // save/restore across call_VM 958 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci); 959 pop(return_bci); 960 } 961 962 963 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) { 964 if (ProfileInterpreter) { 965 Label profile_continue; 966 967 // If no method data exists, go to profile_continue. 968 // Otherwise, assign to mdp 969 test_method_data_pointer(mdp, profile_continue); 970 971 // We are taking a branch. Increment the taken count. 972 // We inline increment_mdp_data_at to return bumped_count in a register 973 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); 974 Address data(mdp, in_bytes(JumpData::taken_offset())); 975 976 // %%% 64bit treats these cells as 64 bit but they seem to be 32 bit 977 movl(bumped_count,data); 978 assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" ); 979 addl(bumped_count, DataLayout::counter_increment); 980 sbbl(bumped_count, 0); 981 movl(data,bumped_count); // Store back out 982 983 // The method data pointer needs to be updated to reflect the new target. 984 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); 985 bind (profile_continue); 986 } 987 } 988 989 990 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { 991 if (ProfileInterpreter) { 992 Label profile_continue; 993 994 // If no method data exists, go to profile_continue. 995 test_method_data_pointer(mdp, profile_continue); 996 997 // We are taking a branch. Increment the not taken count. 998 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); 999 1000 // The method data pointer needs to be updated to correspond to the next bytecode 1001 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); 1002 bind (profile_continue); 1003 } 1004 } 1005 1006 1007 void InterpreterMacroAssembler::profile_call(Register mdp) { 1008 if (ProfileInterpreter) { 1009 Label profile_continue; 1010 1011 // If no method data exists, go to profile_continue. 1012 test_method_data_pointer(mdp, profile_continue); 1013 1014 // We are making a call. Increment the count. 1015 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1016 1017 // The method data pointer needs to be updated to reflect the new target. 1018 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); 1019 bind (profile_continue); 1020 } 1021 } 1022 1023 1024 void InterpreterMacroAssembler::profile_final_call(Register mdp) { 1025 if (ProfileInterpreter) { 1026 Label profile_continue; 1027 1028 // If no method data exists, go to profile_continue. 1029 test_method_data_pointer(mdp, profile_continue); 1030 1031 // We are making a call. Increment the count. 1032 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1033 1034 // The method data pointer needs to be updated to reflect the new target. 1035 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); 1036 bind (profile_continue); 1037 } 1038 } 1039 1040 1041 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp, 1042 Register reg2, 1043 bool receiver_can_be_null) { 1044 if (ProfileInterpreter) { 1045 Label profile_continue; 1046 1047 // If no method data exists, go to profile_continue. 1048 test_method_data_pointer(mdp, profile_continue); 1049 1050 Label skip_receiver_profile; 1051 if (receiver_can_be_null) { 1052 Label not_null; 1053 testptr(receiver, receiver); 1054 jccb(Assembler::notZero, not_null); 1055 // We are making a call. Increment the count for null receiver. 1056 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1057 jmp(skip_receiver_profile); 1058 bind(not_null); 1059 } 1060 1061 // Record the receiver type. 1062 record_klass_in_profile(receiver, mdp, reg2, true); 1063 bind(skip_receiver_profile); 1064 1065 // The method data pointer needs to be updated to reflect the new target. 1066 update_mdp_by_constant(mdp, 1067 in_bytes(VirtualCallData:: 1068 virtual_call_data_size())); 1069 bind(profile_continue); 1070 } 1071 } 1072 1073 1074 void InterpreterMacroAssembler::record_klass_in_profile_helper( 1075 Register receiver, Register mdp, 1076 Register reg2, int start_row, 1077 Label& done, bool is_virtual_call) { 1078 if (TypeProfileWidth == 0) { 1079 if (is_virtual_call) { 1080 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1081 } 1082 return; 1083 } 1084 1085 int last_row = VirtualCallData::row_limit() - 1; 1086 assert(start_row <= last_row, "must be work left to do"); 1087 // Test this row for both the receiver and for null. 1088 // Take any of three different outcomes: 1089 // 1. found receiver => increment count and goto done 1090 // 2. found null => keep looking for case 1, maybe allocate this cell 1091 // 3. found something else => keep looking for cases 1 and 2 1092 // Case 3 is handled by a recursive call. 1093 for (int row = start_row; row <= last_row; row++) { 1094 Label next_test; 1095 bool test_for_null_also = (row == start_row); 1096 1097 // See if the receiver is receiver[n]. 1098 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); 1099 test_mdp_data_at(mdp, recvr_offset, receiver, 1100 (test_for_null_also ? reg2 : noreg), 1101 next_test); 1102 // (Reg2 now contains the receiver from the CallData.) 1103 1104 // The receiver is receiver[n]. Increment count[n]. 1105 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); 1106 increment_mdp_data_at(mdp, count_offset); 1107 jmp(done); 1108 bind(next_test); 1109 1110 if (row == start_row) { 1111 Label found_null; 1112 // Failed the equality check on receiver[n]... Test for null. 1113 testptr(reg2, reg2); 1114 if (start_row == last_row) { 1115 // The only thing left to do is handle the null case. 1116 if (is_virtual_call) { 1117 jccb(Assembler::zero, found_null); 1118 // Receiver did not match any saved receiver and there is no empty row for it. 1119 // Increment total counter to indicate polymorphic case. 1120 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1121 jmp(done); 1122 bind(found_null); 1123 } else { 1124 jcc(Assembler::notZero, done); 1125 } 1126 break; 1127 } 1128 // Since null is rare, make it be the branch-taken case. 1129 jcc(Assembler::zero, found_null); 1130 1131 // Put all the "Case 3" tests here. 1132 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call); 1133 1134 // Found a null. Keep searching for a matching receiver, 1135 // but remember that this is an empty (unused) slot. 1136 bind(found_null); 1137 } 1138 } 1139 1140 // In the fall-through case, we found no matching receiver, but we 1141 // observed the receiver[start_row] is NULL. 1142 1143 // Fill in the receiver field and increment the count. 1144 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); 1145 set_mdp_data_at(mdp, recvr_offset, receiver); 1146 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); 1147 movptr(reg2, (int32_t)DataLayout::counter_increment); 1148 set_mdp_data_at(mdp, count_offset, reg2); 1149 if (start_row > 0) { 1150 jmp(done); 1151 } 1152 } 1153 1154 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, 1155 Register mdp, Register reg2, 1156 bool is_virtual_call) { 1157 assert(ProfileInterpreter, "must be profiling"); 1158 Label done; 1159 1160 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); 1161 1162 bind (done); 1163 } 1164 1165 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) { 1166 if (ProfileInterpreter) { 1167 Label profile_continue; 1168 uint row; 1169 1170 // If no method data exists, go to profile_continue. 1171 test_method_data_pointer(mdp, profile_continue); 1172 1173 // Update the total ret count. 1174 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1175 1176 for (row = 0; row < RetData::row_limit(); row++) { 1177 Label next_test; 1178 1179 // See if return_bci is equal to bci[n]: 1180 test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci, 1181 noreg, next_test); 1182 1183 // return_bci is equal to bci[n]. Increment the count. 1184 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); 1185 1186 // The method data pointer needs to be updated to reflect the new target. 1187 update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row))); 1188 jmp(profile_continue); 1189 bind(next_test); 1190 } 1191 1192 update_mdp_for_ret(return_bci); 1193 1194 bind (profile_continue); 1195 } 1196 } 1197 1198 1199 void InterpreterMacroAssembler::profile_null_seen(Register mdp) { 1200 if (ProfileInterpreter) { 1201 Label profile_continue; 1202 1203 // If no method data exists, go to profile_continue. 1204 test_method_data_pointer(mdp, profile_continue); 1205 1206 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); 1207 1208 // The method data pointer needs to be updated. 1209 int mdp_delta = in_bytes(BitData::bit_data_size()); 1210 if (TypeProfileCasts) { 1211 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1212 } 1213 update_mdp_by_constant(mdp, mdp_delta); 1214 1215 bind (profile_continue); 1216 } 1217 } 1218 1219 1220 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) { 1221 if (ProfileInterpreter && TypeProfileCasts) { 1222 Label profile_continue; 1223 1224 // If no method data exists, go to profile_continue. 1225 test_method_data_pointer(mdp, profile_continue); 1226 1227 int count_offset = in_bytes(CounterData::count_offset()); 1228 // Back up the address, since we have already bumped the mdp. 1229 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); 1230 1231 // *Decrement* the counter. We expect to see zero or small negatives. 1232 increment_mdp_data_at(mdp, count_offset, true); 1233 1234 bind (profile_continue); 1235 } 1236 } 1237 1238 1239 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) 1240 { 1241 if (ProfileInterpreter) { 1242 Label profile_continue; 1243 1244 // If no method data exists, go to profile_continue. 1245 test_method_data_pointer(mdp, profile_continue); 1246 1247 // The method data pointer needs to be updated. 1248 int mdp_delta = in_bytes(BitData::bit_data_size()); 1249 if (TypeProfileCasts) { 1250 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1251 1252 // Record the object type. 1253 record_klass_in_profile(klass, mdp, reg2, false); 1254 assert(reg2 == rdi, "we know how to fix this blown reg"); 1255 restore_locals(); // Restore EDI 1256 } 1257 update_mdp_by_constant(mdp, mdp_delta); 1258 1259 bind(profile_continue); 1260 } 1261 } 1262 1263 1264 void InterpreterMacroAssembler::profile_switch_default(Register mdp) { 1265 if (ProfileInterpreter) { 1266 Label profile_continue; 1267 1268 // If no method data exists, go to profile_continue. 1269 test_method_data_pointer(mdp, profile_continue); 1270 1271 // Update the default case count 1272 increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset())); 1273 1274 // The method data pointer needs to be updated. 1275 update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset())); 1276 1277 bind (profile_continue); 1278 } 1279 } 1280 1281 1282 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) { 1283 if (ProfileInterpreter) { 1284 Label profile_continue; 1285 1286 // If no method data exists, go to profile_continue. 1287 test_method_data_pointer(mdp, profile_continue); 1288 1289 // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes() 1290 movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size())); 1291 // index is positive and so should have correct value if this code were 1292 // used on 64bits 1293 imulptr(index, reg2); 1294 addptr(index, in_bytes(MultiBranchData::case_array_offset())); 1295 1296 // Update the case count 1297 increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset())); 1298 1299 // The method data pointer needs to be updated. 1300 update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset())); 1301 1302 bind (profile_continue); 1303 } 1304 } 1305 1306 #endif // !CC_INTERP 1307 1308 1309 1310 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { 1311 if (state == atos) MacroAssembler::verify_oop(reg); 1312 } 1313 1314 1315 #ifndef CC_INTERP 1316 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { 1317 if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth); 1318 } 1319 1320 #endif /* CC_INTERP */ 1321 1322 1323 void InterpreterMacroAssembler::notify_method_entry() { 1324 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1325 // track stack depth. If it is possible to enter interp_only_mode we add 1326 // the code to check if the event should be sent. 1327 if (JvmtiExport::can_post_interpreter_events()) { 1328 Label L; 1329 get_thread(rcx); 1330 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset())); 1331 testl(rcx,rcx); 1332 jcc(Assembler::zero, L); 1333 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry)); 1334 bind(L); 1335 } 1336 1337 { 1338 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0); 1339 get_thread(rcx); 1340 get_method(rbx); 1341 call_VM_leaf( 1342 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx); 1343 } 1344 1345 // RedefineClasses() tracing support for obsolete method entry 1346 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { 1347 get_thread(rcx); 1348 get_method(rbx); 1349 call_VM_leaf( 1350 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), 1351 rcx, rbx); 1352 } 1353 } 1354 1355 1356 void InterpreterMacroAssembler::notify_method_exit( 1357 TosState state, NotifyMethodExitMode mode) { 1358 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to 1359 // track stack depth. If it is possible to enter interp_only_mode we add 1360 // the code to check if the event should be sent. 1361 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 1362 Label L; 1363 // Note: frame::interpreter_frame_result has a dependency on how the 1364 // method result is saved across the call to post_method_exit. If this 1365 // is changed then the interpreter_frame_result implementation will 1366 // need to be updated too. 1367 1368 // For c++ interpreter the result is always stored at a known location in the frame 1369 // template interpreter will leave it on the top of the stack. 1370 NOT_CC_INTERP(push(state);) 1371 get_thread(rcx); 1372 movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset())); 1373 testl(rcx,rcx); 1374 jcc(Assembler::zero, L); 1375 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); 1376 bind(L); 1377 NOT_CC_INTERP(pop(state);) 1378 } 1379 1380 { 1381 SkipIfEqual skip_if(this, &DTraceMethodProbes, 0); 1382 NOT_CC_INTERP(push(state)); 1383 get_thread(rbx); 1384 get_method(rcx); 1385 call_VM_leaf( 1386 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), 1387 rbx, rcx); 1388 NOT_CC_INTERP(pop(state)); 1389 } 1390 } 1391 1392 // Jump if ((*counter_addr += increment) & mask) satisfies the condition. 1393 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, 1394 int increment, int mask, 1395 Register scratch, bool preloaded, 1396 Condition cond, Label* where) { 1397 if (!preloaded) { 1398 movl(scratch, counter_addr); 1399 } 1400 incrementl(scratch, increment); 1401 movl(counter_addr, scratch); 1402 andl(scratch, mask); 1403 jcc(cond, *where); 1404 }