src/cpu/sparc/vm/interpreter_sparc.cpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 3787
6759698e3140
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

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

mercurial