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"
3692 // Results:
3693 // rax: exception oop
3694 // rdx: exception pc in caller or ???
3695 // destination: exception handler of caller
3696 //
3697 // Note: the exception pc MUST be at a call (precise debug information)
3698 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3699 //
3700
3701 void OptoRuntime::generate_exception_blob() {
3702 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3703 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3704 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3705
3706 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3707
3708 // Allocate space for the code
3709 ResourceMark rm;
3710 // Setup code generation tools
3711 CodeBuffer buffer("exception_blob", 2048, 1024);
3712 MacroAssembler* masm = new MacroAssembler(&buffer);
3713
3714
3715 address start = __ pc();
3716
3717 // Exception pc is 'return address' for stack walker
3718 __ push(rdx);
3719 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3720
3721 // Save callee-saved registers. See x86_64.ad.
3722
3723 // rbp is an implicitly saved callee saved register (i.e., the calling
3724 // convention will save/restore it in the prolog/epilog). Other than that
3725 // there are no callee save registers now that adapter frames are gone.
3726
3727 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3728
3729 // Store exception in Thread object. We cannot pass any arguments to the
3730 // handle_exception call, since we do not want to make any assumption
3731 // about the size of the frame where the exception happened in.
3732 // c_rarg0 is either rdi (Linux) or rcx (Windows).
3733 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3734 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
3740 // registers of the frame being removed.
3741 //
3742 // address OptoRuntime::handle_exception_C(JavaThread* thread)
3743
3744 // At a method handle call, the stack may not be properly aligned
3745 // when returning with an exception.
3746 address the_pc = __ pc();
3747 __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3748 __ mov(c_rarg0, r15_thread);
3749 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
3750 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3751
3752 // Set an oopmap for the call site. This oopmap will only be used if we
3753 // are unwinding the stack. Hence, all locations will be dead.
3754 // Callee-saved registers will be the same as the frame above (i.e.,
3755 // handle_exception_stub), since they were restored when we got the
3756 // exception.
3757
3758 OopMapSet* oop_maps = new OopMapSet();
3759
3760 oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
3761
3762 __ reset_last_Java_frame(false);
3763
3764 // Restore callee-saved registers
3765
3766 // rbp is an implicitly saved callee-saved register (i.e., the calling
3767 // convention will save restore it in prolog/epilog) Other than that
3768 // there are no callee save registers now that adapter frames are gone.
3769
3770 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3771
3772 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3773 __ pop(rdx); // No need for exception pc anymore
3774
3775 // rax: exception handler
3776
3777 // We have a handler in rax (could be deopt blob).
3778 __ mov(r8, rax);
3779
3780 // Get the exception oop
3781 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3782 // Get the exception pc in case we are deoptimized
3783 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3784 #ifdef ASSERT
3785 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3786 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3787 #endif
3788 // Clear the exception oop so GC no longer processes it as a root.
3789 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3790
3791 // rax: exception oop
3792 // r8: exception handler
3793 // rdx: exception pc
3794 // Jump to handler
3795
3796 __ jmp(r8);
3797
3798 // Make sure all code is generated
3799 masm->flush();
3800
3801 // Set exception blob
3802 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3803 }
3804 #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"
3693 // Results:
3694 // rax: exception oop
3695 // rdx: exception pc in caller or ???
3696 // destination: exception handler of caller
3697 //
3698 // Note: the exception pc MUST be at a call (precise debug information)
3699 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3700 //
3701
3702 void OptoRuntime::generate_exception_blob() {
3703 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3704 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3705 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3706
3707 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3708
3709 // Allocate space for the code
3710 ResourceMark rm;
3711 // Setup code generation tools
3712 CodeBuffer buffer("exception_blob", 2048, 1024);
3713 int pc_offset = 0;
3714 if (SCCache::load_exception_blob(&buffer, &pc_offset)) {
3715 OopMapSet* oop_maps = new OopMapSet();
3716 oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3717
3718 // Set exception blob
3719 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3720 return;
3721 }
3722
3723 MacroAssembler* masm = new MacroAssembler(&buffer);
3724 address start = __ pc();
3725
3726 // Exception pc is 'return address' for stack walker
3727 __ push(rdx);
3728 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3729
3730 // Save callee-saved registers. See x86_64.ad.
3731
3732 // rbp is an implicitly saved callee saved register (i.e., the calling
3733 // convention will save/restore it in the prolog/epilog). Other than that
3734 // there are no callee save registers now that adapter frames are gone.
3735
3736 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3737
3738 // Store exception in Thread object. We cannot pass any arguments to the
3739 // handle_exception call, since we do not want to make any assumption
3740 // about the size of the frame where the exception happened in.
3741 // c_rarg0 is either rdi (Linux) or rcx (Windows).
3742 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3743 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
3749 // registers of the frame being removed.
3750 //
3751 // address OptoRuntime::handle_exception_C(JavaThread* thread)
3752
3753 // At a method handle call, the stack may not be properly aligned
3754 // when returning with an exception.
3755 address the_pc = __ pc();
3756 __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
3757 __ mov(c_rarg0, r15_thread);
3758 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
3759 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3760
3761 // Set an oopmap for the call site. This oopmap will only be used if we
3762 // are unwinding the stack. Hence, all locations will be dead.
3763 // Callee-saved registers will be the same as the frame above (i.e.,
3764 // handle_exception_stub), since they were restored when we got the
3765 // exception.
3766
3767 OopMapSet* oop_maps = new OopMapSet();
3768
3769 pc_offset = the_pc - start;
3770 oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
3771
3772 __ reset_last_Java_frame(false);
3773
3774 // Restore callee-saved registers
3775
3776 // rbp is an implicitly saved callee-saved register (i.e., the calling
3777 // convention will save restore it in prolog/epilog) Other than that
3778 // there are no callee save registers now that adapter frames are gone.
3779
3780 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3781
3782 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3783 __ pop(rdx); // No need for exception pc anymore
3784
3785 // rax: exception handler
3786
3787 // We have a handler in rax (could be deopt blob).
3788 __ mov(r8, rax);
3789
3790 // Get the exception oop
3791 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3792 // Get the exception pc in case we are deoptimized
3793 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3794 #ifdef ASSERT
3795 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
3796 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
3797 #endif
3798 // Clear the exception oop so GC no longer processes it as a root.
3799 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
3800
3801 // rax: exception oop
3802 // r8: exception handler
3803 // rdx: exception pc
3804 // Jump to handler
3805
3806 __ jmp(r8);
3807
3808 // Make sure all code is generated
3809 masm->flush();
3810
3811 SCCache::store_exception_blob(&buffer, pc_offset);
3812 // Set exception blob
3813 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3814 }
3815 #endif // COMPILER2
|