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