Wed, 21 Jan 2015 12:38:11 +0100
8068013: [TESTBUG] Aix support in hotspot jtreg tests
Reviewed-by: ctornqvi, fzhinkin, farvidsson
duke@435 | 1 | /* |
never@2950 | 2 | * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #ifdef COMPILER2 |
twisti@4318 | 27 | #include "asm/macroAssembler.hpp" |
twisti@4318 | 28 | #include "asm/macroAssembler.inline.hpp" |
stefank@2314 | 29 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 30 | #include "code/vmreg.hpp" |
stefank@2314 | 31 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 32 | #include "opto/runtime.hpp" |
stefank@2314 | 33 | #include "runtime/interfaceSupport.hpp" |
stefank@2314 | 34 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 35 | #include "runtime/stubRoutines.hpp" |
stefank@2314 | 36 | #include "runtime/vframeArray.hpp" |
stefank@2314 | 37 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 38 | #include "vmreg_x86.inline.hpp" |
stefank@2314 | 39 | #endif |
duke@435 | 40 | |
duke@435 | 41 | |
duke@435 | 42 | #define __ masm-> |
duke@435 | 43 | |
duke@435 | 44 | //------------------------------generate_exception_blob--------------------------- |
duke@435 | 45 | // creates exception blob at the end |
duke@435 | 46 | // Using exception blob, this code is jumped from a compiled method. |
duke@435 | 47 | // |
duke@435 | 48 | // Given an exception pc at a call we call into the runtime for the |
duke@435 | 49 | // handler in this method. This handler might merely restore state |
duke@435 | 50 | // (i.e. callee save registers) unwind the frame and jump to the |
duke@435 | 51 | // exception handler for the nmethod if there is no Java level handler |
duke@435 | 52 | // for the nmethod. |
duke@435 | 53 | // |
duke@435 | 54 | // This code is entered with a jmp. |
duke@435 | 55 | // |
duke@435 | 56 | // Arguments: |
twisti@1570 | 57 | // rax: exception oop |
duke@435 | 58 | // rdx: exception pc |
duke@435 | 59 | // |
duke@435 | 60 | // Results: |
twisti@1570 | 61 | // rax: exception oop |
duke@435 | 62 | // rdx: exception pc in caller or ??? |
duke@435 | 63 | // destination: exception handler of caller |
duke@435 | 64 | // |
duke@435 | 65 | // Note: the exception pc MUST be at a call (precise debug information) |
duke@435 | 66 | // Only register rax, rdx, rcx are not callee saved. |
duke@435 | 67 | // |
duke@435 | 68 | |
duke@435 | 69 | void OptoRuntime::generate_exception_blob() { |
duke@435 | 70 | |
duke@435 | 71 | // Capture info about frame layout |
duke@435 | 72 | enum layout { |
duke@435 | 73 | thread_off, // last_java_sp |
duke@435 | 74 | // The frame sender code expects that rbp will be in the "natural" place and |
duke@435 | 75 | // will override any oopMap setting for it. We must therefore force the layout |
duke@435 | 76 | // so that it agrees with the frame sender code. |
duke@435 | 77 | rbp_off, |
duke@435 | 78 | return_off, // slot for return address |
duke@435 | 79 | framesize |
duke@435 | 80 | }; |
duke@435 | 81 | |
duke@435 | 82 | // allocate space for the code |
duke@435 | 83 | ResourceMark rm; |
duke@435 | 84 | // setup code generation tools |
duke@435 | 85 | CodeBuffer buffer("exception_blob", 512, 512); |
duke@435 | 86 | MacroAssembler* masm = new MacroAssembler(&buffer); |
duke@435 | 87 | |
duke@435 | 88 | OopMapSet *oop_maps = new OopMapSet(); |
duke@435 | 89 | |
duke@435 | 90 | address start = __ pc(); |
duke@435 | 91 | |
never@739 | 92 | __ push(rdx); |
never@739 | 93 | __ subptr(rsp, return_off * wordSize); // Prolog! |
duke@435 | 94 | |
duke@435 | 95 | // rbp, location is implicitly known |
never@739 | 96 | __ movptr(Address(rsp,rbp_off *wordSize), rbp); |
duke@435 | 97 | |
duke@435 | 98 | // Store exception in Thread object. We cannot pass any arguments to the |
duke@435 | 99 | // handle_exception call, since we do not want to make any assumption |
duke@435 | 100 | // about the size of the frame where the exception happened in. |
duke@435 | 101 | __ get_thread(rcx); |
never@739 | 102 | __ movptr(Address(rcx, JavaThread::exception_oop_offset()), rax); |
never@739 | 103 | __ movptr(Address(rcx, JavaThread::exception_pc_offset()), rdx); |
duke@435 | 104 | |
duke@435 | 105 | // This call does all the hard work. It checks if an exception handler |
duke@435 | 106 | // exists in the method. |
duke@435 | 107 | // If so, it returns the handler address. |
duke@435 | 108 | // If not, it prepares for stack-unwinding, restoring the callee-save |
duke@435 | 109 | // registers of the frame being removed. |
duke@435 | 110 | // |
never@739 | 111 | __ movptr(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument |
duke@435 | 112 | __ set_last_Java_frame(rcx, noreg, noreg, NULL); |
duke@435 | 113 | |
duke@435 | 114 | __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C))); |
duke@435 | 115 | |
duke@435 | 116 | // No registers to map, rbp is known implicitly |
duke@435 | 117 | oop_maps->add_gc_map( __ pc() - start, new OopMap( framesize, 0 )); |
duke@435 | 118 | __ get_thread(rcx); |
duke@435 | 119 | __ reset_last_Java_frame(rcx, false, false); |
duke@435 | 120 | |
duke@435 | 121 | // Restore callee-saved registers |
never@739 | 122 | __ movptr(rbp, Address(rsp, rbp_off * wordSize)); |
duke@435 | 123 | |
never@739 | 124 | __ addptr(rsp, return_off * wordSize); // Epilog! |
never@739 | 125 | __ pop(rdx); // Exception pc |
duke@435 | 126 | |
twisti@1570 | 127 | // rax: exception handler for given <exception oop/exception pc> |
duke@435 | 128 | |
twisti@1803 | 129 | // Restore SP from BP if the exception PC is a MethodHandle call site. |
twisti@1803 | 130 | __ cmpl(Address(rcx, JavaThread::is_method_handle_return_offset()), 0); |
twisti@1922 | 131 | __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save); |
duke@435 | 132 | |
duke@435 | 133 | // We have a handler in rax, (could be deopt blob) |
duke@435 | 134 | // rdx - throwing pc, deopt blob will need it. |
duke@435 | 135 | |
never@739 | 136 | __ push(rax); |
duke@435 | 137 | |
duke@435 | 138 | // Get the exception |
never@739 | 139 | __ movptr(rax, Address(rcx, JavaThread::exception_oop_offset())); |
duke@435 | 140 | // Get the exception pc in case we are deoptimized |
never@739 | 141 | __ movptr(rdx, Address(rcx, JavaThread::exception_pc_offset())); |
duke@435 | 142 | #ifdef ASSERT |
xlu@947 | 143 | __ movptr(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD); |
xlu@947 | 144 | __ movptr(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD); |
duke@435 | 145 | #endif |
duke@435 | 146 | // Clear the exception oop so GC no longer processes it as a root. |
xlu@947 | 147 | __ movptr(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD); |
duke@435 | 148 | |
never@739 | 149 | __ pop(rcx); |
duke@435 | 150 | |
twisti@1570 | 151 | // rax: exception oop |
duke@435 | 152 | // rcx: exception handler |
duke@435 | 153 | // rdx: exception pc |
duke@435 | 154 | __ jmp (rcx); |
duke@435 | 155 | |
duke@435 | 156 | // ------------- |
duke@435 | 157 | // make sure all code is generated |
duke@435 | 158 | masm->flush(); |
duke@435 | 159 | |
duke@435 | 160 | _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize); |
duke@435 | 161 | } |