Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2016, Loongson Technology. 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 */
26 #include "precompiled.hpp"
27 #include "asm/macroAssembler.hpp"
28 #include "interpreter/bytecodeHistogram.hpp"
29 #include "interpreter/interpreter.hpp"
30 #include "interpreter/interpreterGenerator.hpp"
31 #include "interpreter/interpreterRuntime.hpp"
32 #include "interpreter/templateTable.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/methodData.hpp"
35 #include "oops/method.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "prims/jvmtiExport.hpp"
38 #include "prims/jvmtiThreadState.hpp"
39 #include "prims/methodHandles.hpp"
40 #include "runtime/arguments.hpp"
41 #include "runtime/deoptimization.hpp"
42 #include "runtime/frame.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/stubRoutines.hpp"
45 #include "runtime/synchronizer.hpp"
46 #include "runtime/timer.hpp"
47 #include "runtime/vframeArray.hpp"
48 #include "utilities/debug.hpp"
49 #ifdef COMPILER1
50 #include "c1/c1_Runtime1.hpp"
51 #endif
53 #define __ _masm->
56 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
57 address entry = __ pc();
59 // Rmethod: method
60 // LVP: pointer to locals
61 // T3: first stack arg - wordSize
62 __ move(T3, SP);
63 __ pushad();
64 __ call_VM(noreg,
65 CAST_FROM_FN_PTR(address,
66 InterpreterRuntime::slow_signature_handler),
67 Rmethod, LVP, T3);
68 __ move(S0, V0);
69 __ popad();
70 __ move(V0, S0);
72 // V0: result handler
74 // Stack layout:
75 // ...
77 // Do FP first so we can use c_rarg3 as temp
78 __ ld(T3, Address(SP, -1 * wordSize)); // float/double identifiers
80 // A0 is for env.
81 // If the mothed is not static, A1 will be corrected in generate_native_entry.
82 for ( int i= 1; i < Argument::n_register_parameters; i++ ) {
83 Register reg = as_Register(i + A0->encoding());
84 FloatRegister floatreg = as_FloatRegister(i + F12->encoding());
85 Label isfloatordouble, isdouble, next;
87 __ andi(AT, T3, 1 << (i*2)); // Float or Double?
88 __ bne(AT, R0, isfloatordouble);
89 __ delayed()->nop();
91 // Do Int register here
92 __ ld(reg, Address(SP, -(Argument::n_register_parameters + 1 -i) * wordSize));
93 __ b (next);
94 __ delayed()->nop();
96 __ bind(isfloatordouble);
97 __ andi(AT,T3, 1 << ((i*2)+1)); // Double?
98 __ bne(AT, R0, isdouble);
99 __ delayed()->nop();
101 // Do Float Here
102 __ lwc1(floatreg, Address(SP, -(Argument::n_float_register_parameters + 1 -i) * wordSize));
103 __ b(next);
104 __ delayed()->nop();
106 // Do Double here
107 __ bind(isdouble);
108 __ ldc1(floatreg, Address(SP, -(Argument::n_float_register_parameters + 1 -i) * wordSize));
110 __ bind(next);
111 }
113 __ jr(RA);
114 __ delayed()->nop();
115 return entry;
116 }
119 //
120 // Various method entries
121 //
123 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
125 // Rmethod: methodOop
126 // V0: scratrch
127 // esi: send 's sp, should we use Rsender @jerome
128 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
129 address entry_point = __ pc();
131 // These don't need a safepoint check because they aren't virtually
132 // callable. We won't enter these intrinsics from compiled code.
133 // If in the future we added an intrinsic which was virtually callable
134 // we'd have to worry about how to safepoint so that this code is used.
137 // mathematical functions inlined by compiler
138 // (interpreter must provide identical implementation
139 // in order to avoid monotonicity bugs when switching
140 // from interpreter to compiler in the middle of some
141 // computation)
142 //
143 // stack: [ lo(arg) ] <-- sp
144 // [ hi(arg) ]
145 /*
146 if (Universe::is_jdk12x_version()) {
147 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
148 // native methods. Interpreter::method_kind(...) does a check for
149 // native methods first before checking for intrinsic methods and
150 // thus will never select this entry point. Make sure it is not
151 // called accidentally since the SharedRuntime entry points will
152 // not work for JDK 1.2.
153 __ should_not_reach_here();
154 } else
155 */
156 {
157 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
158 // java methods. Interpreter::method_kind(...) will select
159 // this entry point for the corresponding methods in JDK 1.3.
160 //FIXME, @jerome
161 /*if (TaggedStackInterpreter) {
162 __ lw(AT, SP,3*wordSize);
163 __ push(AT);//push hi note ,SP -=wordSize
164 __ lw(AT, SP,2*wordSize);
165 __ push(AT);//push lo
166 __ lwc1(F12, SP, 2 * wordSize);
167 __ lwc1(F13, SP, 3 * wordSize);
168 __ sw(RA, SP, (1) * wordSize);
169 __ sw(FP, SP, (0) * wordSize);
170 __ addi(SP, SP, 2 * wordSize);
171 __ move(FP, SP);
173 }else {*/
174 __ ldc1(F12, SP, 0 * wordSize);
175 __ ldc1(F13, SP, 1 * wordSize);
176 __ sd(RA, SP, (-1) * wordSize);
177 __ sd(FP, SP, (-2) * wordSize);
178 __ move(FP, SP);
179 __ daddi(SP, SP, (-2) * wordSize);
181 // }
182 // [ fp ] <-- sp
183 // [ ra ]
184 // [ lo ] <-- fp
185 // [ hi ]
186 /*
187 switch (kind) {
188 case Interpreter::java_lang_math_sin :
189 __ sincos(true, true);
190 break;
191 case Interpreter::java_lang_math_cos :
192 __ sincos(false, true);
193 break;
194 case Interpreter::java_lang_math_sqrt:
195 __ sqrt_d(F0, F12);
196 break;
197 default :
198 ShouldNotReachHere();
199 }
200 */
201 //FIXME, need consider this
202 switch (kind) {
203 case Interpreter::java_lang_math_sin :
204 __ trigfunc('s');
205 break;
206 case Interpreter::java_lang_math_cos :
207 __ trigfunc('c');
208 break;
209 case Interpreter::java_lang_math_tan :
210 __ trigfunc('t');
211 break;
212 case Interpreter::java_lang_math_sqrt:
213 // __ fsqrt();
214 __ sqrt_d(F0, F12);
215 break;
216 case Interpreter::java_lang_math_abs:
217 // __ fabs();
218 __ abs_d(F0, F12);
219 break;
220 case Interpreter::java_lang_math_log:
221 // __ flog();
222 // Store to stack to convert 80bit precision back to 64bits
223 // __ push_fTOS();
224 // __ pop_fTOS();
225 break;
226 case Interpreter::java_lang_math_log10:
227 // __ flog10();
228 // Store to stack to convert 80bit precision back to 64bits
229 // __ push_fTOS();
230 // __ pop_fTOS();
231 break;
232 case Interpreter::java_lang_math_pow:
233 //__ fld_d(Address(rsp, 3*wordSize)); // second argument (one
234 // empty stack slot)
235 //__ pow_with_fallback(0);
236 break;
237 case Interpreter::java_lang_math_exp:
238 //__ exp_with_fallback(0);
239 break;
241 default :
242 ShouldNotReachHere();
243 }
245 // must maintain return value in F0:F1
246 __ ld(RA, FP, (-1) * wordSize);
247 //FIXME
248 __ move(SP, Rsender);
249 // __ move(SP, T0);
250 __ ld(FP, FP, (-2) * wordSize);
251 __ jr(RA);
252 __ delayed()->nop();
253 }
254 return entry_point;
255 }
258 // Abstract method entry
259 // Attempt to execute abstract method. Throw exception
260 address InterpreterGenerator::generate_abstract_entry(void) {
262 // Rmethod: methodOop
263 // V0: receiver (unused)
264 // esi: previous interpreter state (C++ interpreter) must preserve
265 // Rsender : sender 's sp
266 address entry_point = __ pc();
268 // abstract method entry
269 // throw exception
270 // adjust stack to what a normal return would do
272 //__ movl(esp, esi);
273 __ move(SP,Rsender); //FIXME, why jvm6 add this @jerome
274 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
275 // the call_VM checks for exception, so we should never return here.
276 __ should_not_reach_here();
278 return entry_point;
279 }
282 // Empty method, generate a very fast return.
284 address InterpreterGenerator::generate_empty_entry(void) {
286 // Rmethod: methodOop
287 // V0: receiver (unused)
288 // esi: previous interpreter state (C++ interpreter) must preserve
289 //Rsender: sender 's sp , must set sp to this value on return , on mips ,now use T0,as it right?
290 if (!UseFastEmptyMethods) return NULL;
292 address entry_point = __ pc();
294 Label slow_path;
295 __ li(RT0, SafepointSynchronize::address_of_state());
296 __ lw(AT, RT0, 0);
297 __ move(RT0, (SafepointSynchronize::_not_synchronized));
298 __ bne(AT, RT0,slow_path);
299 __ delayed()->nop();
300 __ move(SP, Rsender);
301 __ jr(RA);
302 __ delayed()->nop();
303 __ bind(slow_path);
304 (void) generate_normal_entry(false);
306 return entry_point;
308 }
310 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
312 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
313 // the days we had adapter frames. When we deoptimize a situation where a
314 // compiled caller calls a compiled caller will have registers it expects
315 // to survive the call to the callee. If we deoptimize the callee the only
316 // way we can restore these registers is to have the oldest interpreter
317 // frame that we create restore these values. That is what this routine
318 // will accomplish.
320 // At the moment we have modified c2 to not have any callee save registers
321 // so this problem does not exist and this routine is just a place holder.
323 assert(f->is_interpreted_frame(), "must be interpreted");
324 }