< 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"

3625 // Results:
3626 //   rax: exception oop
3627 //   rdx: exception pc in caller or ???
3628 //   destination: exception handler of caller
3629 //
3630 // Note: the exception pc MUST be at a call (precise debug information)
3631 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3632 //
3633 
3634 void OptoRuntime::generate_exception_blob() {
3635   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3636   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3637   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3638 
3639   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3640 
3641   // Allocate space for the code
3642   ResourceMark rm;
3643   // Setup code generation tools
3644   CodeBuffer buffer("exception_blob", 2048, 1024);
3645   MacroAssembler* masm = new MacroAssembler(&buffer);



3646 




3647 

3648   address start = __ pc();
3649 
3650   // Exception pc is 'return address' for stack walker
3651   __ push(rdx);
3652   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3653 
3654   // Save callee-saved registers.  See x86_64.ad.
3655 
3656   // rbp is an implicitly saved callee saved register (i.e., the calling
3657   // convention will save/restore it in the prolog/epilog). Other than that
3658   // there are no callee save registers now that adapter frames are gone.
3659 
3660   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3661 
3662   // Store exception in Thread object. We cannot pass any arguments to the
3663   // handle_exception call, since we do not want to make any assumption
3664   // about the size of the frame where the exception happened in.
3665   // c_rarg0 is either rdi (Linux) or rcx (Windows).
3666   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3667   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

3673   // registers of the frame being removed.
3674   //
3675   // address OptoRuntime::handle_exception_C(JavaThread* thread)
3676 
3677   // At a method handle call, the stack may not be properly aligned
3678   // when returning with an exception.
3679   address the_pc = __ pc();
3680   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3681   __ mov(c_rarg0, r15_thread);
3682   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
3683   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3684 
3685   // Set an oopmap for the call site.  This oopmap will only be used if we
3686   // are unwinding the stack.  Hence, all locations will be dead.
3687   // Callee-saved registers will be the same as the frame above (i.e.,
3688   // handle_exception_stub), since they were restored when we got the
3689   // exception.
3690 
3691   OopMapSet* oop_maps = new OopMapSet();
3692 
3693   oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));

3694 
3695   __ reset_last_Java_frame(false);
3696 
3697   // Restore callee-saved registers
3698 
3699   // rbp is an implicitly saved callee-saved register (i.e., the calling
3700   // convention will save restore it in prolog/epilog) Other than that
3701   // there are no callee save registers now that adapter frames are gone.
3702 
3703   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3704 
3705   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3706   __ pop(rdx);                  // No need for exception pc anymore
3707 
3708   // rax: exception handler
3709 
3710   // We have a handler in rax (could be deopt blob).
3711   __ mov(r8, rax);
3712 
3713   // Get the exception oop
3714   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3715   // Get the exception pc in case we are deoptimized
3716   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3717 #ifdef ASSERT
3718   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3719   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3720 #endif
3721   // Clear the exception oop so GC no longer processes it as a root.
3722   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3723 
3724   // rax: exception oop
3725   // r8:  exception handler
3726   // rdx: exception pc
3727   // Jump to handler
3728 
3729   __ jmp(r8);
3730 
3731   // Make sure all code is generated
3732   masm->flush();
3733 

3734   // Set exception blob
3735   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3736 }
3737 #endif // COMPILER2

  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"

3626 // Results:
3627 //   rax: exception oop
3628 //   rdx: exception pc in caller or ???
3629 //   destination: exception handler of caller
3630 //
3631 // Note: the exception pc MUST be at a call (precise debug information)
3632 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3633 //
3634 
3635 void OptoRuntime::generate_exception_blob() {
3636   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3637   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3638   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3639 
3640   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3641 
3642   // Allocate space for the code
3643   ResourceMark rm;
3644   // Setup code generation tools
3645   CodeBuffer buffer("exception_blob", 2048, 1024);
3646   int pc_offset = 0;
3647   if (SCCache::load_exception_blob(&buffer, &pc_offset)) {
3648     OopMapSet* oop_maps = new OopMapSet();
3649     oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3650 
3651     // Set exception blob
3652     _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3653     return;
3654   }
3655 
3656   MacroAssembler* masm = new MacroAssembler(&buffer);
3657   address start = __ pc();
3658 
3659   // Exception pc is 'return address' for stack walker
3660   __ push(rdx);
3661   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3662 
3663   // Save callee-saved registers.  See x86_64.ad.
3664 
3665   // rbp is an implicitly saved callee saved register (i.e., the calling
3666   // convention will save/restore it in the prolog/epilog). Other than that
3667   // there are no callee save registers now that adapter frames are gone.
3668 
3669   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3670 
3671   // Store exception in Thread object. We cannot pass any arguments to the
3672   // handle_exception call, since we do not want to make any assumption
3673   // about the size of the frame where the exception happened in.
3674   // c_rarg0 is either rdi (Linux) or rcx (Windows).
3675   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3676   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

3682   // registers of the frame being removed.
3683   //
3684   // address OptoRuntime::handle_exception_C(JavaThread* thread)
3685 
3686   // At a method handle call, the stack may not be properly aligned
3687   // when returning with an exception.
3688   address the_pc = __ pc();
3689   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3690   __ mov(c_rarg0, r15_thread);
3691   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
3692   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3693 
3694   // Set an oopmap for the call site.  This oopmap will only be used if we
3695   // are unwinding the stack.  Hence, all locations will be dead.
3696   // Callee-saved registers will be the same as the frame above (i.e.,
3697   // handle_exception_stub), since they were restored when we got the
3698   // exception.
3699 
3700   OopMapSet* oop_maps = new OopMapSet();
3701 
3702   pc_offset = the_pc - start;
3703   oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3704 
3705   __ reset_last_Java_frame(false);
3706 
3707   // Restore callee-saved registers
3708 
3709   // rbp is an implicitly saved callee-saved register (i.e., the calling
3710   // convention will save restore it in prolog/epilog) Other than that
3711   // there are no callee save registers now that adapter frames are gone.
3712 
3713   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3714 
3715   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3716   __ pop(rdx);                  // No need for exception pc anymore
3717 
3718   // rax: exception handler
3719 
3720   // We have a handler in rax (could be deopt blob).
3721   __ mov(r8, rax);
3722 
3723   // Get the exception oop
3724   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3725   // Get the exception pc in case we are deoptimized
3726   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3727 #ifdef ASSERT
3728   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3729   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3730 #endif
3731   // Clear the exception oop so GC no longer processes it as a root.
3732   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3733 
3734   // rax: exception oop
3735   // r8:  exception handler
3736   // rdx: exception pc
3737   // Jump to handler
3738 
3739   __ jmp(r8);
3740 
3741   // Make sure all code is generated
3742   masm->flush();
3743 
3744   SCCache::store_exception_blob(&buffer, pc_offset);
3745   // Set exception blob
3746   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3747 }
3748 #endif // COMPILER2
< prev index next >