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

3606 // Results:
3607 //   rax: exception oop
3608 //   rdx: exception pc in caller or ???
3609 //   destination: exception handler of caller
3610 //
3611 // Note: the exception pc MUST be at a call (precise debug information)
3612 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3613 //
3614 
3615 void OptoRuntime::generate_exception_blob() {
3616   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3617   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3618   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3619 
3620   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3621 
3622   // Allocate space for the code
3623   ResourceMark rm;
3624   // Setup code generation tools
3625   CodeBuffer buffer("exception_blob", 2048, 1024);
3626   MacroAssembler* masm = new MacroAssembler(&buffer);



3627 




3628 

3629   address start = __ pc();
3630 
3631   // Exception pc is 'return address' for stack walker
3632   __ push(rdx);
3633   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3634 
3635   // Save callee-saved registers.  See x86_64.ad.
3636 
3637   // rbp is an implicitly saved callee saved register (i.e., the calling
3638   // convention will save/restore it in the prolog/epilog). Other than that
3639   // there are no callee save registers now that adapter frames are gone.
3640 
3641   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3642 
3643   // Store exception in Thread object. We cannot pass any arguments to the
3644   // handle_exception call, since we do not want to make any assumption
3645   // about the size of the frame where the exception happened in.
3646   // c_rarg0 is either rdi (Linux) or rcx (Windows).
3647   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3648   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

3654   // registers of the frame being removed.
3655   //
3656   // address OptoRuntime::handle_exception_C(JavaThread* thread)
3657 
3658   // At a method handle call, the stack may not be properly aligned
3659   // when returning with an exception.
3660   address the_pc = __ pc();
3661   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3662   __ mov(c_rarg0, r15_thread);
3663   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
3664   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3665 
3666   // Set an oopmap for the call site.  This oopmap will only be used if we
3667   // are unwinding the stack.  Hence, all locations will be dead.
3668   // Callee-saved registers will be the same as the frame above (i.e.,
3669   // handle_exception_stub), since they were restored when we got the
3670   // exception.
3671 
3672   OopMapSet* oop_maps = new OopMapSet();
3673 
3674   oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));

3675 
3676   __ reset_last_Java_frame(false);
3677 
3678   // Restore callee-saved registers
3679 
3680   // rbp is an implicitly saved callee-saved register (i.e., the calling
3681   // convention will save restore it in prolog/epilog) Other than that
3682   // there are no callee save registers now that adapter frames are gone.
3683 
3684   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3685 
3686   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3687   __ pop(rdx);                  // No need for exception pc anymore
3688 
3689   // rax: exception handler
3690 
3691   // We have a handler in rax (could be deopt blob).
3692   __ mov(r8, rax);
3693 
3694   // Get the exception oop
3695   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3696   // Get the exception pc in case we are deoptimized
3697   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3698 #ifdef ASSERT
3699   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3700   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3701 #endif
3702   // Clear the exception oop so GC no longer processes it as a root.
3703   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3704 
3705   // rax: exception oop
3706   // r8:  exception handler
3707   // rdx: exception pc
3708   // Jump to handler
3709 
3710   __ jmp(r8);
3711 
3712   // Make sure all code is generated
3713   masm->flush();
3714 

3715   // Set exception blob
3716   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3717 }
3718 #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"

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

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