src/cpu/sparc/vm/interpreter_sparc.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial