Print this page
rev 2237 : [mq]: initial-intrinsification-changes
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/sparc/vm/interpreter_sparc.cpp
+++ new/src/cpu/sparc/vm/interpreter_sparc.cpp
1 1 /*
2 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "asm/assembler.hpp"
27 27 #include "interpreter/bytecodeHistogram.hpp"
28 28 #include "interpreter/interpreter.hpp"
29 29 #include "interpreter/interpreterGenerator.hpp"
30 30 #include "interpreter/interpreterRuntime.hpp"
31 31 #include "interpreter/templateTable.hpp"
32 32 #include "oops/arrayOop.hpp"
33 33 #include "oops/methodDataOop.hpp"
34 34 #include "oops/methodOop.hpp"
35 35 #include "oops/oop.inline.hpp"
36 36 #include "prims/jvmtiExport.hpp"
37 37 #include "prims/jvmtiThreadState.hpp"
38 38 #include "prims/methodHandles.hpp"
39 39 #include "runtime/arguments.hpp"
40 40 #include "runtime/deoptimization.hpp"
41 41 #include "runtime/frame.inline.hpp"
42 42 #include "runtime/sharedRuntime.hpp"
43 43 #include "runtime/stubRoutines.hpp"
44 44 #include "runtime/synchronizer.hpp"
45 45 #include "runtime/timer.hpp"
46 46 #include "runtime/vframeArray.hpp"
47 47 #include "utilities/debug.hpp"
48 48 #ifdef COMPILER1
49 49 #include "c1/c1_Runtime1.hpp"
50 50 #endif
51 51
52 52
53 53
54 54 // Generation of Interpreter
55 55 //
56 56 // The InterpreterGenerator generates the interpreter into Interpreter::_code.
57 57
58 58
59 59 #define __ _masm->
60 60
61 61
62 62 //----------------------------------------------------------------------------------------------------
63 63
64 64
65 65
66 66
67 67 int AbstractInterpreter::BasicType_as_index(BasicType type) {
68 68 int i = 0;
69 69 switch (type) {
70 70 case T_BOOLEAN: i = 0; break;
71 71 case T_CHAR : i = 1; break;
72 72 case T_BYTE : i = 2; break;
73 73 case T_SHORT : i = 3; break;
74 74 case T_INT : i = 4; break;
75 75 case T_LONG : i = 5; break;
76 76 case T_VOID : i = 6; break;
77 77 case T_FLOAT : i = 7; break;
78 78 case T_DOUBLE : i = 8; break;
79 79 case T_OBJECT : i = 9; break;
80 80 case T_ARRAY : i = 9; break;
81 81 default : ShouldNotReachHere();
82 82 }
83 83 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
84 84 return i;
85 85 }
86 86
87 87
88 88 #ifndef _LP64
89 89 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
90 90 address entry = __ pc();
91 91 Argument argv(0, true);
92 92
93 93 // We are in the jni transition frame. Save the last_java_frame corresponding to the
94 94 // outer interpreter frame
95 95 //
96 96 __ set_last_Java_frame(FP, noreg);
97 97 // make sure the interpreter frame we've pushed has a valid return pc
98 98 __ mov(O7, I7);
99 99 __ mov(Lmethod, G3_scratch);
100 100 __ mov(Llocals, G4_scratch);
101 101 __ save_frame(0);
102 102 __ mov(G2_thread, L7_thread_cache);
103 103 __ add(argv.address_in_frame(), O3);
104 104 __ mov(G2_thread, O0);
105 105 __ mov(G3_scratch, O1);
106 106 __ call(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), relocInfo::runtime_call_type);
107 107 __ delayed()->mov(G4_scratch, O2);
108 108 __ mov(L7_thread_cache, G2_thread);
109 109 __ reset_last_Java_frame();
110 110
111 111 // load the register arguments (the C code packed them as varargs)
112 112 for (Argument ldarg = argv.successor(); ldarg.is_register(); ldarg = ldarg.successor()) {
113 113 __ ld_ptr(ldarg.address_in_frame(), ldarg.as_register());
114 114 }
115 115 __ ret();
116 116 __ delayed()->
117 117 restore(O0, 0, Lscratch); // caller's Lscratch gets the result handler
118 118 return entry;
119 119 }
120 120
121 121
122 122 #else
123 123 // LP64 passes floating point arguments in F1, F3, F5, etc. instead of
124 124 // O0, O1, O2 etc..
125 125 // Doubles are passed in D0, D2, D4
126 126 // We store the signature of the first 16 arguments in the first argument
127 127 // slot because it will be overwritten prior to calling the native
128 128 // function, with the pointer to the JNIEnv.
129 129 // If LP64 there can be up to 16 floating point arguments in registers
130 130 // or 6 integer registers.
131 131 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
132 132
133 133 enum {
134 134 non_float = 0,
135 135 float_sig = 1,
136 136 double_sig = 2,
137 137 sig_mask = 3
138 138 };
139 139
140 140 address entry = __ pc();
141 141 Argument argv(0, true);
142 142
143 143 // We are in the jni transition frame. Save the last_java_frame corresponding to the
144 144 // outer interpreter frame
145 145 //
146 146 __ set_last_Java_frame(FP, noreg);
147 147 // make sure the interpreter frame we've pushed has a valid return pc
148 148 __ mov(O7, I7);
149 149 __ mov(Lmethod, G3_scratch);
150 150 __ mov(Llocals, G4_scratch);
151 151 __ save_frame(0);
152 152 __ mov(G2_thread, L7_thread_cache);
153 153 __ add(argv.address_in_frame(), O3);
154 154 __ mov(G2_thread, O0);
155 155 __ mov(G3_scratch, O1);
156 156 __ call(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), relocInfo::runtime_call_type);
157 157 __ delayed()->mov(G4_scratch, O2);
158 158 __ mov(L7_thread_cache, G2_thread);
159 159 __ reset_last_Java_frame();
160 160
161 161
162 162 // load the register arguments (the C code packed them as varargs)
163 163 Address Sig = argv.address_in_frame(); // Argument 0 holds the signature
164 164 __ ld_ptr( Sig, G3_scratch ); // Get register argument signature word into G3_scratch
165 165 __ mov( G3_scratch, G4_scratch);
166 166 __ srl( G4_scratch, 2, G4_scratch); // Skip Arg 0
167 167 Label done;
168 168 for (Argument ldarg = argv.successor(); ldarg.is_float_register(); ldarg = ldarg.successor()) {
169 169 Label NonFloatArg;
170 170 Label LoadFloatArg;
171 171 Label LoadDoubleArg;
172 172 Label NextArg;
173 173 Address a = ldarg.address_in_frame();
174 174 __ andcc(G4_scratch, sig_mask, G3_scratch);
175 175 __ br(Assembler::zero, false, Assembler::pt, NonFloatArg);
176 176 __ delayed()->nop();
177 177
178 178 __ cmp(G3_scratch, float_sig );
179 179 __ br(Assembler::equal, false, Assembler::pt, LoadFloatArg);
180 180 __ delayed()->nop();
181 181
182 182 __ cmp(G3_scratch, double_sig );
183 183 __ br(Assembler::equal, false, Assembler::pt, LoadDoubleArg);
184 184 __ delayed()->nop();
185 185
186 186 __ bind(NonFloatArg);
187 187 // There are only 6 integer register arguments!
188 188 if ( ldarg.is_register() )
189 189 __ ld_ptr(ldarg.address_in_frame(), ldarg.as_register());
190 190 else {
191 191 // Optimization, see if there are any more args and get out prior to checking
192 192 // all 16 float registers. My guess is that this is rare.
193 193 // If is_register is false, then we are done the first six integer args.
194 194 __ tst(G4_scratch);
195 195 __ brx(Assembler::zero, false, Assembler::pt, done);
196 196 __ delayed()->nop();
197 197
198 198 }
199 199 __ ba(false, NextArg);
200 200 __ delayed()->srl( G4_scratch, 2, G4_scratch );
201 201
202 202 __ bind(LoadFloatArg);
203 203 __ ldf( FloatRegisterImpl::S, a, ldarg.as_float_register(), 4);
204 204 __ ba(false, NextArg);
205 205 __ delayed()->srl( G4_scratch, 2, G4_scratch );
206 206
207 207 __ bind(LoadDoubleArg);
208 208 __ ldf( FloatRegisterImpl::D, a, ldarg.as_double_register() );
209 209 __ ba(false, NextArg);
210 210 __ delayed()->srl( G4_scratch, 2, G4_scratch );
211 211
212 212 __ bind(NextArg);
213 213
214 214 }
215 215
216 216 __ bind(done);
217 217 __ ret();
218 218 __ delayed()->
219 219 restore(O0, 0, Lscratch); // caller's Lscratch gets the result handler
220 220 return entry;
221 221 }
222 222 #endif
223 223
224 224 void InterpreterGenerator::generate_counter_overflow(Label& Lcontinue) {
225 225
226 226 // Generate code to initiate compilation on the counter overflow.
227 227
228 228 // InterpreterRuntime::frequency_counter_overflow takes two arguments,
229 229 // the first indicates if the counter overflow occurs at a backwards branch (NULL bcp)
230 230 // and the second is only used when the first is true. We pass zero for both.
231 231 // The call returns the address of the verified entry point for the method or NULL
232 232 // if the compilation did not complete (either went background or bailed out).
233 233 __ set((int)false, O2);
234 234 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), O2, O2, true);
235 235 // returns verified_entry_point or NULL
236 236 // we ignore it in any case
237 237 __ ba(false, Lcontinue);
238 238 __ delayed()->nop();
239 239
240 240 }
241 241
242 242
243 243 // End of helpers
244 244
245 245 // Various method entries
246 246
247 247 // Abstract method entry
248 248 // Attempt to execute abstract method. Throw exception
249 249 //
250 250 address InterpreterGenerator::generate_abstract_entry(void) {
251 251 address entry = __ pc();
252 252 // abstract method entry
253 253 // throw exception
254 254 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
255 255 // the call_VM checks for exception, so we should never return here.
256 256 __ should_not_reach_here();
257 257 return entry;
258 258
259 259 }
260 260
261 261
262 262 // Method handle invoker
263 263 // Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...)
264 264 address InterpreterGenerator::generate_method_handle_entry(void) {
265 265 if (!EnableMethodHandles) {
266 266 return generate_abstract_entry();
267 267 }
268 268
269 269 return MethodHandles::generate_method_handle_interpreter_entry(_masm);
270 270 }
271 271
272 272
273 273 //----------------------------------------------------------------------------------------------------
274 274 // Entry points & stack frame layout
275 275 //
276 276 // Here we generate the various kind of entries into the interpreter.
277 277 // The two main entry type are generic bytecode methods and native call method.
278 278 // These both come in synchronized and non-synchronized versions but the
279 279 // frame layout they create is very similar. The other method entry
280 280 // types are really just special purpose entries that are really entry
281 281 // and interpretation all in one. These are for trivial methods like
282 282 // accessor, empty, or special math methods.
283 283 //
284 284 // When control flow reaches any of the entry types for the interpreter
285 285 // the following holds ->
286 286 //
287 287 // C2 Calling Conventions:
288 288 //
289 289 // The entry code below assumes that the following registers are set
290 290 // when coming in:
291 291 // G5_method: holds the methodOop of the method to call
292 292 // Lesp: points to the TOS of the callers expression stack
293 293 // after having pushed all the parameters
294 294 //
295 295 // The entry code does the following to setup an interpreter frame
296 296 // pop parameters from the callers stack by adjusting Lesp
297 297 // set O0 to Lesp
298 298 // compute X = (max_locals - num_parameters)
299 299 // bump SP up by X to accomadate the extra locals
300 300 // compute X = max_expression_stack
301 301 // + vm_local_words
302 302 // + 16 words of register save area
303 303 // save frame doing a save sp, -X, sp growing towards lower addresses
304 304 // set Lbcp, Lmethod, LcpoolCache
305 305 // set Llocals to i0
306 306 // set Lmonitors to FP - rounded_vm_local_words
307 307 // set Lesp to Lmonitors - 4
308 308 //
309 309 // The frame has now been setup to do the rest of the entry code
310 310
311 311 // Try this optimization: Most method entries could live in a
312 312 // "one size fits all" stack frame without all the dynamic size
313 313 // calculations. It might be profitable to do all this calculation
314 314 // statically and approximately for "small enough" methods.
315 315
316 316 //-----------------------------------------------------------------------------------------------
317 317
318 318 // C1 Calling conventions
319 319 //
320 320 // Upon method entry, the following registers are setup:
321 321 //
322 322 // g2 G2_thread: current thread
323 323 // g5 G5_method: method to activate
324 324 // g4 Gargs : pointer to last argument
325 325 //
326 326 //
327 327 // Stack:
328 328 //
329 329 // +---------------+ <--- sp
330 330 // | |
331 331 // : reg save area :
332 332 // | |
333 333 // +---------------+ <--- sp + 0x40
334 334 // | |
335 335 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
336 336 // | |
337 337 // +---------------+ <--- sp + 0x5c
338 338 // | |
339 339 // : free :
340 340 // | |
341 341 // +---------------+ <--- Gargs
342 342 // | |
343 343 // : arguments :
344 344 // | |
345 345 // +---------------+
346 346 // | |
347 347 //
348 348 //
349 349 //
350 350 // AFTER FRAME HAS BEEN SETUP for method interpretation the stack looks like:
351 351 //
352 352 // +---------------+ <--- sp
353 353 // | |
354 354 // : reg save area :
355 355 // | |
356 356 // +---------------+ <--- sp + 0x40
357 357 // | |
358 358 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
359 359 // | |
360 360 // +---------------+ <--- sp + 0x5c
361 361 // | |
362 362 // : :
363 363 // | | <--- Lesp
364 364 // +---------------+ <--- Lmonitors (fp - 0x18)
365 365 // | VM locals |
366 366 // +---------------+ <--- fp
367 367 // | |
368 368 // : reg save area :
369 369 // | |
370 370 // +---------------+ <--- fp + 0x40
371 371 // | |
372 372 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
373 373 // | |
374 374 // +---------------+ <--- fp + 0x5c
375 375 // | |
376 376 // : free :
377 377 // | |
378 378 // +---------------+
379 379 // | |
380 380 // : nonarg locals :
381 381 // | |
382 382 // +---------------+
383 383 // | |
384 384 // : arguments :
385 385 // | | <--- Llocals
386 386 // +---------------+ <--- Gargs
387 387 // | |
388 388
389 389 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
390 390 // determine code generation flags
391 391 bool synchronized = false;
392 392 address entry_point = NULL;
393 393
394 394 switch (kind) {
395 395 case Interpreter::zerolocals : break;
396 396 case Interpreter::zerolocals_synchronized: synchronized = true; break;
397 397 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
398 398 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
399 399 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
↓ open down ↓ |
399 lines elided |
↑ open up ↑ |
400 400 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
401 401 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
402 402 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
403 403 case Interpreter::java_lang_math_sin : break;
404 404 case Interpreter::java_lang_math_cos : break;
405 405 case Interpreter::java_lang_math_tan : break;
406 406 case Interpreter::java_lang_math_sqrt : break;
407 407 case Interpreter::java_lang_math_abs : break;
408 408 case Interpreter::java_lang_math_log : break;
409 409 case Interpreter::java_lang_math_log10 : break;
410 + case Interpreter::java_lang_ref_reference_get
411 + : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
410 412 default : ShouldNotReachHere(); break;
411 413 }
412 414
413 415 if (entry_point) return entry_point;
414 416
415 417 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
416 418 }
417 419
418 420
419 421 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
420 422 // No special entry points that preclude compilation
421 423 return true;
422 424 }
423 425
424 426 // This method tells the deoptimizer how big an interpreted frame must be:
425 427 int AbstractInterpreter::size_activation(methodOop method,
426 428 int tempcount,
427 429 int popframe_extra_args,
428 430 int moncount,
429 431 int callee_param_count,
430 432 int callee_locals,
431 433 bool is_top_frame) {
432 434 return layout_activation(method,
433 435 tempcount,
434 436 popframe_extra_args,
435 437 moncount,
436 438 callee_param_count,
437 439 callee_locals,
438 440 (frame*)NULL,
439 441 (frame*)NULL,
440 442 is_top_frame);
441 443 }
442 444
443 445 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
444 446
445 447 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
446 448 // the days we had adapter frames. When we deoptimize a situation where a
447 449 // compiled caller calls a compiled caller will have registers it expects
448 450 // to survive the call to the callee. If we deoptimize the callee the only
449 451 // way we can restore these registers is to have the oldest interpreter
450 452 // frame that we create restore these values. That is what this routine
451 453 // will accomplish.
452 454
453 455 // At the moment we have modified c2 to not have any callee save registers
454 456 // so this problem does not exist and this routine is just a place holder.
455 457
456 458 assert(f->is_interpreted_frame(), "must be interpreted");
457 459 }
458 460
459 461
460 462 //----------------------------------------------------------------------------------------------------
461 463 // Exceptions
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX