< prev index next >

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

Print this page

  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 #ifndef _WINDOWS
  27 #include "alloca.h"
  28 #endif
  29 #include "asm/macroAssembler.hpp"
  30 #include "asm/macroAssembler.inline.hpp"
  31 #include "code/compiledIC.hpp"
  32 #include "code/debugInfoRec.hpp"
  33 #include "code/nativeInst.hpp"

  34 #include "code/vtableStubs.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "gc/shared/collectedHeap.hpp"
  37 #include "gc/shared/gcLocker.hpp"
  38 #include "gc/shared/barrierSet.hpp"
  39 #include "gc/shared/barrierSetAssembler.hpp"
  40 #include "interpreter/interpreter.hpp"
  41 #include "logging/log.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "oops/klass.inline.hpp"
  45 #include "oops/method.inline.hpp"
  46 #include "prims/methodHandles.hpp"
  47 #include "runtime/continuation.hpp"
  48 #include "runtime/continuationEntry.inline.hpp"
  49 #include "runtime/globals.hpp"
  50 #include "runtime/jniHandles.hpp"
  51 #include "runtime/safepointMechanism.hpp"
  52 #include "runtime/sharedRuntime.hpp"
  53 #include "runtime/signature.hpp"

3588 // Results:
3589 //   rax: exception oop
3590 //   rdx: exception pc in caller or ???
3591 //   destination: exception handler of caller
3592 //
3593 // Note: the exception pc MUST be at a call (precise debug information)
3594 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3595 //
3596 
3597 void OptoRuntime::generate_exception_blob() {
3598   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3599   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3600   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3601 
3602   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3603 
3604   // Allocate space for the code
3605   ResourceMark rm;
3606   // Setup code generation tools
3607   CodeBuffer buffer("exception_blob", 2048, 1024);
3608   MacroAssembler* masm = new MacroAssembler(&buffer);



3609 




3610 

3611   address start = __ pc();
3612 
3613   // Exception pc is 'return address' for stack walker
3614   __ push(rdx);
3615   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3616 
3617   // Save callee-saved registers.  See x86_64.ad.
3618 
3619   // rbp is an implicitly saved callee saved register (i.e., the calling
3620   // convention will save/restore it in the prolog/epilog). Other than that
3621   // there are no callee save registers now that adapter frames are gone.
3622 
3623   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3624 
3625   // Store exception in Thread object. We cannot pass any arguments to the
3626   // handle_exception call, since we do not want to make any assumption
3627   // about the size of the frame where the exception happened in.
3628   // c_rarg0 is either rdi (Linux) or rcx (Windows).
3629   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3630   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

3636   // registers of the frame being removed.
3637   //
3638   // address OptoRuntime::handle_exception_C(JavaThread* thread)
3639 
3640   // At a method handle call, the stack may not be properly aligned
3641   // when returning with an exception.
3642   address the_pc = __ pc();
3643   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3644   __ mov(c_rarg0, r15_thread);
3645   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
3646   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3647 
3648   // Set an oopmap for the call site.  This oopmap will only be used if we
3649   // are unwinding the stack.  Hence, all locations will be dead.
3650   // Callee-saved registers will be the same as the frame above (i.e.,
3651   // handle_exception_stub), since they were restored when we got the
3652   // exception.
3653 
3654   OopMapSet* oop_maps = new OopMapSet();
3655 
3656   oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));

3657 
3658   __ reset_last_Java_frame(false);
3659 
3660   // Restore callee-saved registers
3661 
3662   // rbp is an implicitly saved callee-saved register (i.e., the calling
3663   // convention will save restore it in prolog/epilog) Other than that
3664   // there are no callee save registers now that adapter frames are gone.
3665 
3666   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3667 
3668   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3669   __ pop(rdx);                  // No need for exception pc anymore
3670 
3671   // rax: exception handler
3672 
3673   // We have a handler in rax (could be deopt blob).
3674   __ mov(r8, rax);
3675 
3676   // Get the exception oop
3677   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3678   // Get the exception pc in case we are deoptimized
3679   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3680 #ifdef ASSERT
3681   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3682   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3683 #endif
3684   // Clear the exception oop so GC no longer processes it as a root.
3685   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3686 
3687   // rax: exception oop
3688   // r8:  exception handler
3689   // rdx: exception pc
3690   // Jump to handler
3691 
3692   __ jmp(r8);
3693 
3694   // Make sure all code is generated
3695   masm->flush();
3696 

3697   // Set exception blob
3698   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3699 }
3700 #endif // COMPILER2
3701 

  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 #ifndef _WINDOWS
  27 #include "alloca.h"
  28 #endif
  29 #include "asm/macroAssembler.hpp"
  30 #include "asm/macroAssembler.inline.hpp"
  31 #include "code/compiledIC.hpp"
  32 #include "code/debugInfoRec.hpp"
  33 #include "code/nativeInst.hpp"
  34 #include "code/SCCache.hpp"
  35 #include "code/vtableStubs.hpp"
  36 #include "compiler/oopMap.hpp"
  37 #include "gc/shared/collectedHeap.hpp"
  38 #include "gc/shared/gcLocker.hpp"
  39 #include "gc/shared/barrierSet.hpp"
  40 #include "gc/shared/barrierSetAssembler.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "oops/klass.inline.hpp"
  46 #include "oops/method.inline.hpp"
  47 #include "prims/methodHandles.hpp"
  48 #include "runtime/continuation.hpp"
  49 #include "runtime/continuationEntry.inline.hpp"
  50 #include "runtime/globals.hpp"
  51 #include "runtime/jniHandles.hpp"
  52 #include "runtime/safepointMechanism.hpp"
  53 #include "runtime/sharedRuntime.hpp"
  54 #include "runtime/signature.hpp"

3589 // Results:
3590 //   rax: exception oop
3591 //   rdx: exception pc in caller or ???
3592 //   destination: exception handler of caller
3593 //
3594 // Note: the exception pc MUST be at a call (precise debug information)
3595 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3596 //
3597 
3598 void OptoRuntime::generate_exception_blob() {
3599   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3600   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3601   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3602 
3603   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3604 
3605   // Allocate space for the code
3606   ResourceMark rm;
3607   // Setup code generation tools
3608   CodeBuffer buffer("exception_blob", 2048, 1024);
3609   int pc_offset = 0;
3610   if (SCCache::load_exception_blob(&buffer, &pc_offset)) {
3611     OopMapSet* oop_maps = new OopMapSet();
3612     oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3613 
3614     // Set exception blob
3615     _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3616     return;
3617   }
3618 
3619   MacroAssembler* masm = new MacroAssembler(&buffer);
3620   address start = __ pc();
3621 
3622   // Exception pc is 'return address' for stack walker
3623   __ push(rdx);
3624   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3625 
3626   // Save callee-saved registers.  See x86_64.ad.
3627 
3628   // rbp is an implicitly saved callee saved register (i.e., the calling
3629   // convention will save/restore it in the prolog/epilog). Other than that
3630   // there are no callee save registers now that adapter frames are gone.
3631 
3632   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3633 
3634   // Store exception in Thread object. We cannot pass any arguments to the
3635   // handle_exception call, since we do not want to make any assumption
3636   // about the size of the frame where the exception happened in.
3637   // c_rarg0 is either rdi (Linux) or rcx (Windows).
3638   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3639   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

3645   // registers of the frame being removed.
3646   //
3647   // address OptoRuntime::handle_exception_C(JavaThread* thread)
3648 
3649   // At a method handle call, the stack may not be properly aligned
3650   // when returning with an exception.
3651   address the_pc = __ pc();
3652   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3653   __ mov(c_rarg0, r15_thread);
3654   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
3655   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3656 
3657   // Set an oopmap for the call site.  This oopmap will only be used if we
3658   // are unwinding the stack.  Hence, all locations will be dead.
3659   // Callee-saved registers will be the same as the frame above (i.e.,
3660   // handle_exception_stub), since they were restored when we got the
3661   // exception.
3662 
3663   OopMapSet* oop_maps = new OopMapSet();
3664 
3665   pc_offset = the_pc - start;
3666   oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3667 
3668   __ reset_last_Java_frame(false);
3669 
3670   // Restore callee-saved registers
3671 
3672   // rbp is an implicitly saved callee-saved register (i.e., the calling
3673   // convention will save restore it in prolog/epilog) Other than that
3674   // there are no callee save registers now that adapter frames are gone.
3675 
3676   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3677 
3678   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3679   __ pop(rdx);                  // No need for exception pc anymore
3680 
3681   // rax: exception handler
3682 
3683   // We have a handler in rax (could be deopt blob).
3684   __ mov(r8, rax);
3685 
3686   // Get the exception oop
3687   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3688   // Get the exception pc in case we are deoptimized
3689   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3690 #ifdef ASSERT
3691   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3692   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3693 #endif
3694   // Clear the exception oop so GC no longer processes it as a root.
3695   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3696 
3697   // rax: exception oop
3698   // r8:  exception handler
3699   // rdx: exception pc
3700   // Jump to handler
3701 
3702   __ jmp(r8);
3703 
3704   // Make sure all code is generated
3705   masm->flush();
3706 
3707   SCCache::store_exception_blob(&buffer, pc_offset);
3708   // Set exception blob
3709   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3710 }
3711 #endif // COMPILER2
3712 
< prev index next >