src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp
changeset 47881 0ce0ac68ace7
parent 47799 1772ebf07d1f
child 48172 e26fc5201707
equal deleted inserted replaced
47824:cf127be65014 47881:0ce0ac68ace7
    28 #endif
    28 #endif
    29 #include "asm/macroAssembler.hpp"
    29 #include "asm/macroAssembler.hpp"
    30 #include "asm/macroAssembler.inline.hpp"
    30 #include "asm/macroAssembler.inline.hpp"
    31 #include "code/debugInfoRec.hpp"
    31 #include "code/debugInfoRec.hpp"
    32 #include "code/icBuffer.hpp"
    32 #include "code/icBuffer.hpp"
       
    33 #include "code/nativeInst.hpp"
    33 #include "code/vtableStubs.hpp"
    34 #include "code/vtableStubs.hpp"
    34 #include "interpreter/interpreter.hpp"
    35 #include "interpreter/interpreter.hpp"
    35 #include "logging/log.hpp"
    36 #include "logging/log.hpp"
    36 #include "memory/resourceArea.hpp"
    37 #include "memory/resourceArea.hpp"
    37 #include "oops/compiledICHolder.hpp"
    38 #include "oops/compiledICHolder.hpp"
  2472   Label after_transition;
  2473   Label after_transition;
  2473 
  2474 
  2474   // check for safepoint operation in progress and/or pending suspend requests
  2475   // check for safepoint operation in progress and/or pending suspend requests
  2475   {
  2476   {
  2476     Label Continue;
  2477     Label Continue;
  2477 
  2478     Label slow_path;
  2478     __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
  2479 
  2479              SafepointSynchronize::_not_synchronized);
  2480     __ safepoint_poll(slow_path, r15_thread, rscratch1);
  2480 
  2481 
  2481     Label L;
       
  2482     __ jcc(Assembler::notEqual, L);
       
  2483     __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
  2482     __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
  2484     __ jcc(Assembler::equal, Continue);
  2483     __ jcc(Assembler::equal, Continue);
  2485     __ bind(L);
  2484     __ bind(slow_path);
  2486 
  2485 
  2487     // Don't use call_VM as it will see a possible pending exception and forward it
  2486     // Don't use call_VM as it will see a possible pending exception and forward it
  2488     // and never return here preventing us from clearing _last_native_pc down below.
  2487     // and never return here preventing us from clearing _last_native_pc down below.
  2489     // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
  2488     // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
  2490     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  2489     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  3353 
  3352 
  3354   // The return address must always be correct so that frame constructor never
  3353   // The return address must always be correct so that frame constructor never
  3355   // sees an invalid pc.
  3354   // sees an invalid pc.
  3356 
  3355 
  3357   if (!cause_return) {
  3356   if (!cause_return) {
  3358     // overwrite the dummy value we pushed on entry
  3357     // Get the return pc saved by the signal handler and stash it in its appropriate place on the stack.
  3359     __ movptr(c_rarg0, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
  3358     // Additionally, rbx is a callee saved register and we can look at it later to determine
  3360     __ movptr(Address(rbp, wordSize), c_rarg0);
  3359     // if someone changed the return address for us!
       
  3360     __ movptr(rbx, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
       
  3361     __ movptr(Address(rbp, wordSize), rbx);
  3361   }
  3362   }
  3362 
  3363 
  3363   // Do the call
  3364   // Do the call
  3364   __ mov(c_rarg0, r15_thread);
  3365   __ mov(c_rarg0, r15_thread);
  3365   __ call(RuntimeAddress(call_ptr));
  3366   __ call(RuntimeAddress(call_ptr));
  3385   __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
  3386   __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
  3386 
  3387 
  3387   // No exception case
  3388   // No exception case
  3388   __ bind(noException);
  3389   __ bind(noException);
  3389 
  3390 
       
  3391   Label no_adjust, bail;
       
  3392   if (SafepointMechanism::uses_thread_local_poll() && !cause_return) {
       
  3393     // If our stashed return pc was modified by the runtime we avoid touching it
       
  3394     __ cmpptr(rbx, Address(rbp, wordSize));
       
  3395     __ jccb(Assembler::notEqual, no_adjust);
       
  3396 
       
  3397 #ifdef ASSERT
       
  3398     // Verify the correct encoding of the poll we're about to skip.
       
  3399     // See NativeInstruction::is_safepoint_poll()
       
  3400     __ cmpb(Address(rbx, 0), NativeTstRegMem::instruction_rex_b_prefix);
       
  3401     __ jcc(Assembler::notEqual, bail);
       
  3402     __ cmpb(Address(rbx, 1), NativeTstRegMem::instruction_code_memXregl);
       
  3403     __ jcc(Assembler::notEqual, bail);
       
  3404     // Mask out the modrm bits
       
  3405     __ testb(Address(rbx, 2), NativeTstRegMem::modrm_mask);
       
  3406     // rax encodes to 0, so if the bits are nonzero it's incorrect
       
  3407     __ jcc(Assembler::notZero, bail);
       
  3408 #endif
       
  3409     // Adjust return pc forward to step over the safepoint poll instruction
       
  3410     __ addptr(Address(rbp, wordSize), 3);
       
  3411   }
       
  3412 
       
  3413   __ bind(no_adjust);
  3390   // Normal exit, restore registers and exit.
  3414   // Normal exit, restore registers and exit.
  3391   RegisterSaver::restore_live_registers(masm, save_vectors);
  3415   RegisterSaver::restore_live_registers(masm, save_vectors);
  3392 
       
  3393   __ ret(0);
  3416   __ ret(0);
       
  3417 
       
  3418 #ifdef ASSERT
       
  3419   __ bind(bail);
       
  3420   __ stop("Attempting to adjust pc to skip safepoint poll but the return point is not what we expected");
       
  3421 #endif
  3394 
  3422 
  3395   // Make sure all code is generated
  3423   // Make sure all code is generated
  3396   masm->flush();
  3424   masm->flush();
  3397 
  3425 
  3398   // Fill-out other meta info
  3426   // Fill-out other meta info