|
1 /* |
|
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * Copyright 2012, 2013 SAP AG. All rights reserved. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 * |
|
24 */ |
|
25 |
|
26 #include "precompiled.hpp" |
|
27 #ifdef COMPILER2 |
|
28 #include "asm/assembler.inline.hpp" |
|
29 #include "asm/macroAssembler.inline.hpp" |
|
30 #include "classfile/systemDictionary.hpp" |
|
31 #include "code/vmreg.hpp" |
|
32 #include "interpreter/interpreter.hpp" |
|
33 #include "nativeInst_ppc.hpp" |
|
34 #include "opto/runtime.hpp" |
|
35 #include "runtime/interfaceSupport.hpp" |
|
36 #include "runtime/sharedRuntime.hpp" |
|
37 #include "runtime/stubRoutines.hpp" |
|
38 #include "runtime/vframeArray.hpp" |
|
39 #include "utilities/globalDefinitions.hpp" |
|
40 #include "vmreg_ppc.inline.hpp" |
|
41 #endif |
|
42 |
|
43 #define __ masm-> |
|
44 |
|
45 |
|
46 #ifdef COMPILER2 |
|
47 |
|
48 // SP adjustment (must use unextended SP) for method handle call sites |
|
49 // during exception handling. |
|
50 static intptr_t adjust_SP_for_methodhandle_callsite(JavaThread *thread) { |
|
51 RegisterMap map(thread, false); |
|
52 // The frame constructor will do the correction for us (see frame::adjust_unextended_SP). |
|
53 frame mh_caller_frame = thread->last_frame().sender(&map); |
|
54 assert(mh_caller_frame.is_compiled_frame(), "Only may reach here for compiled MH call sites"); |
|
55 return (intptr_t) mh_caller_frame.unextended_sp(); |
|
56 } |
|
57 |
|
58 //------------------------------generate_exception_blob--------------------------- |
|
59 // Creates exception blob at the end. |
|
60 // Using exception blob, this code is jumped from a compiled method. |
|
61 // |
|
62 // Given an exception pc at a call we call into the runtime for the |
|
63 // handler in this method. This handler might merely restore state |
|
64 // (i.e. callee save registers) unwind the frame and jump to the |
|
65 // exception handler for the nmethod if there is no Java level handler |
|
66 // for the nmethod. |
|
67 // |
|
68 // This code is entered with a jmp. |
|
69 // |
|
70 // Arguments: |
|
71 // R3_ARG1: exception oop |
|
72 // R4_ARG2: exception pc |
|
73 // |
|
74 // Results: |
|
75 // R3_ARG1: exception oop |
|
76 // R4_ARG2: exception pc in caller |
|
77 // destination: exception handler of caller |
|
78 // |
|
79 // Note: the exception pc MUST be at a call (precise debug information) |
|
80 // |
|
81 void OptoRuntime::generate_exception_blob() { |
|
82 // Allocate space for the code. |
|
83 ResourceMark rm; |
|
84 // Setup code generation tools. |
|
85 CodeBuffer buffer("exception_blob", 2048, 1024); |
|
86 InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer); |
|
87 |
|
88 address start = __ pc(); |
|
89 |
|
90 int frame_size_in_bytes = frame::abi_112_size; |
|
91 OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); |
|
92 |
|
93 // Exception pc is 'return address' for stack walker. |
|
94 __ std(R4_ARG2/*exception pc*/, _abi(lr), R1_SP); |
|
95 |
|
96 // Store the exception in the Thread object. |
|
97 __ std(R3_ARG1/*exception oop*/, in_bytes(JavaThread::exception_oop_offset()), R16_thread); |
|
98 __ std(R4_ARG2/*exception pc*/, in_bytes(JavaThread::exception_pc_offset()), R16_thread); |
|
99 |
|
100 // Save callee-saved registers. |
|
101 // Push a C frame for the exception blob. It is needed for the C call later on. |
|
102 __ push_frame_abi112(0, R11_scratch1); |
|
103 |
|
104 // This call does all the hard work. It checks if an exception handler |
|
105 // exists in the method. |
|
106 // If so, it returns the handler address. |
|
107 // If not, it prepares for stack-unwinding, restoring the callee-save |
|
108 // registers of the frame being removed. |
|
109 __ set_last_Java_frame(/*sp=*/R1_SP, noreg); |
|
110 |
|
111 __ mr(R3_ARG1, R16_thread); |
|
112 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, OptoRuntime::handle_exception_C), |
|
113 relocInfo::none); |
|
114 address calls_return_pc = __ last_calls_return_pc(); |
|
115 # ifdef ASSERT |
|
116 __ cmpdi(CCR0, R3_RET, 0); |
|
117 __ asm_assert_ne("handle_exception_C must not return NULL", 0x601); |
|
118 # endif |
|
119 |
|
120 // Set an oopmap for the call site. This oopmap will only be used if we |
|
121 // are unwinding the stack. Hence, all locations will be dead. |
|
122 // Callee-saved registers will be the same as the frame above (i.e., |
|
123 // handle_exception_stub), since they were restored when we got the |
|
124 // exception. |
|
125 OopMapSet* oop_maps = new OopMapSet(); |
|
126 oop_maps->add_gc_map(calls_return_pc - start, map); |
|
127 |
|
128 // Get unextended_sp for method handle call sites. |
|
129 Label mh_callsite, mh_done; // Use a 2nd c call if it's a method handle call site. |
|
130 __ lwa(R4_ARG2, in_bytes(JavaThread::is_method_handle_return_offset()), R16_thread); |
|
131 __ cmpwi(CCR0, R4_ARG2, 0); |
|
132 __ bne(CCR0, mh_callsite); |
|
133 |
|
134 __ mtctr(R3_RET); // Move address of exception handler to SR_CTR. |
|
135 __ reset_last_Java_frame(); |
|
136 __ pop_frame(); |
|
137 |
|
138 __ bind(mh_done); |
|
139 // We have a handler in register SR_CTR (could be deopt blob). |
|
140 |
|
141 // Get the exception oop. |
|
142 __ ld(R3_ARG1, in_bytes(JavaThread::exception_oop_offset()), R16_thread); |
|
143 |
|
144 // Get the exception pc in case we are deoptimized. |
|
145 __ ld(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread); |
|
146 |
|
147 // Reset thread values. |
|
148 __ li(R0, 0); |
|
149 #ifdef ASSERT |
|
150 __ std(R0, in_bytes(JavaThread::exception_handler_pc_offset()), R16_thread); |
|
151 __ std(R0, in_bytes(JavaThread::exception_pc_offset()), R16_thread); |
|
152 #endif |
|
153 // Clear the exception oop so GC no longer processes it as a root. |
|
154 __ std(R0, in_bytes(JavaThread::exception_oop_offset()), R16_thread); |
|
155 |
|
156 // Move exception pc into SR_LR. |
|
157 __ mtlr(R4_ARG2); |
|
158 __ bctr(); |
|
159 |
|
160 |
|
161 // Same as above, but also set sp to unextended_sp. |
|
162 __ bind(mh_callsite); |
|
163 __ mr(R31, R3_RET); // Save branch address. |
|
164 __ mr(R3_ARG1, R16_thread); |
|
165 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, adjust_SP_for_methodhandle_callsite), relocInfo::none); |
|
166 // Returns unextended_sp in R3_RET. |
|
167 |
|
168 __ mtctr(R31); // Move address of exception handler to SR_CTR. |
|
169 __ reset_last_Java_frame(); |
|
170 |
|
171 __ mr(R1_SP, R3_RET); // Set sp to unextended_sp. |
|
172 __ b(mh_done); |
|
173 |
|
174 |
|
175 // Make sure all code is generated. |
|
176 masm->flush(); |
|
177 |
|
178 // Set exception blob. |
|
179 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, |
|
180 frame_size_in_bytes/wordSize); |
|
181 } |
|
182 |
|
183 #endif // COMPILER2 |