src/cpu/sparc/vm/interpreter_sparc.cpp

Thu, 07 Apr 2011 09:53:20 -0700

author
johnc
date
Thu, 07 Apr 2011 09:53:20 -0700
changeset 2781
e1162778c1c8
parent 2639
8033953d67ff
child 2784
92add02409c9
permissions
-rw-r--r--

7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
Summary: A referent object that is only weakly reachable at the start of concurrent marking but is re-attached to the strongly reachable object graph during marking may not be marked as live. This can cause the reference object to be processed prematurely and leave dangling pointers to the referent object. Implement a read barrier for the java.lang.ref.Reference::referent field by intrinsifying the Reference.get() method, and intercepting accesses though JNI, reflection, and Unsafe, so that when a non-null referent object is read it is also logged in an SATB buffer.
Reviewed-by: kvn, iveresov, never, tonyp, dholmes

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.
duke@435 194 __ tst(G4_scratch);
duke@435 195 __ brx(Assembler::zero, false, Assembler::pt, done);
duke@435 196 __ delayed()->nop();
duke@435 197
duke@435 198 }
duke@435 199 __ ba(false, NextArg);
duke@435 200 __ delayed()->srl( G4_scratch, 2, G4_scratch );
duke@435 201
duke@435 202 __ bind(LoadFloatArg);
duke@435 203 __ ldf( FloatRegisterImpl::S, a, ldarg.as_float_register(), 4);
duke@435 204 __ ba(false, NextArg);
duke@435 205 __ delayed()->srl( G4_scratch, 2, G4_scratch );
duke@435 206
duke@435 207 __ bind(LoadDoubleArg);
duke@435 208 __ ldf( FloatRegisterImpl::D, a, ldarg.as_double_register() );
duke@435 209 __ ba(false, NextArg);
duke@435 210 __ delayed()->srl( G4_scratch, 2, G4_scratch );
duke@435 211
duke@435 212 __ bind(NextArg);
duke@435 213
duke@435 214 }
duke@435 215
duke@435 216 __ bind(done);
duke@435 217 __ ret();
duke@435 218 __ delayed()->
duke@435 219 restore(O0, 0, Lscratch); // caller's Lscratch gets the result handler
duke@435 220 return entry;
duke@435 221 }
duke@435 222 #endif
duke@435 223
duke@435 224 void InterpreterGenerator::generate_counter_overflow(Label& Lcontinue) {
duke@435 225
duke@435 226 // Generate code to initiate compilation on the counter overflow.
duke@435 227
duke@435 228 // InterpreterRuntime::frequency_counter_overflow takes two arguments,
duke@435 229 // the first indicates if the counter overflow occurs at a backwards branch (NULL bcp)
duke@435 230 // and the second is only used when the first is true. We pass zero for both.
duke@435 231 // The call returns the address of the verified entry point for the method or NULL
duke@435 232 // if the compilation did not complete (either went background or bailed out).
duke@435 233 __ set((int)false, O2);
duke@435 234 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), O2, O2, true);
duke@435 235 // returns verified_entry_point or NULL
duke@435 236 // we ignore it in any case
duke@435 237 __ ba(false, Lcontinue);
duke@435 238 __ delayed()->nop();
duke@435 239
duke@435 240 }
duke@435 241
duke@435 242
duke@435 243 // End of helpers
duke@435 244
duke@435 245 // Various method entries
duke@435 246
duke@435 247 // Abstract method entry
duke@435 248 // Attempt to execute abstract method. Throw exception
duke@435 249 //
duke@435 250 address InterpreterGenerator::generate_abstract_entry(void) {
duke@435 251 address entry = __ pc();
duke@435 252 // abstract method entry
duke@435 253 // throw exception
duke@435 254 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
duke@435 255 // the call_VM checks for exception, so we should never return here.
duke@435 256 __ should_not_reach_here();
duke@435 257 return entry;
duke@435 258
duke@435 259 }
duke@435 260
duke@435 261
jrose@1145 262 // Method handle invoker
jrose@2639 263 // Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...)
jrose@1145 264 address InterpreterGenerator::generate_method_handle_entry(void) {
jrose@1145 265 if (!EnableMethodHandles) {
jrose@1145 266 return generate_abstract_entry();
jrose@1145 267 }
twisti@1858 268
twisti@1858 269 return MethodHandles::generate_method_handle_interpreter_entry(_masm);
jrose@1145 270 }
jrose@1145 271
jrose@1145 272
duke@435 273 //----------------------------------------------------------------------------------------------------
duke@435 274 // Entry points & stack frame layout
duke@435 275 //
duke@435 276 // Here we generate the various kind of entries into the interpreter.
duke@435 277 // The two main entry type are generic bytecode methods and native call method.
duke@435 278 // These both come in synchronized and non-synchronized versions but the
duke@435 279 // frame layout they create is very similar. The other method entry
duke@435 280 // types are really just special purpose entries that are really entry
duke@435 281 // and interpretation all in one. These are for trivial methods like
duke@435 282 // accessor, empty, or special math methods.
duke@435 283 //
duke@435 284 // When control flow reaches any of the entry types for the interpreter
duke@435 285 // the following holds ->
duke@435 286 //
duke@435 287 // C2 Calling Conventions:
duke@435 288 //
duke@435 289 // The entry code below assumes that the following registers are set
duke@435 290 // when coming in:
duke@435 291 // G5_method: holds the methodOop of the method to call
duke@435 292 // Lesp: points to the TOS of the callers expression stack
duke@435 293 // after having pushed all the parameters
duke@435 294 //
duke@435 295 // The entry code does the following to setup an interpreter frame
duke@435 296 // pop parameters from the callers stack by adjusting Lesp
duke@435 297 // set O0 to Lesp
duke@435 298 // compute X = (max_locals - num_parameters)
duke@435 299 // bump SP up by X to accomadate the extra locals
duke@435 300 // compute X = max_expression_stack
duke@435 301 // + vm_local_words
duke@435 302 // + 16 words of register save area
duke@435 303 // save frame doing a save sp, -X, sp growing towards lower addresses
duke@435 304 // set Lbcp, Lmethod, LcpoolCache
duke@435 305 // set Llocals to i0
duke@435 306 // set Lmonitors to FP - rounded_vm_local_words
duke@435 307 // set Lesp to Lmonitors - 4
duke@435 308 //
duke@435 309 // The frame has now been setup to do the rest of the entry code
duke@435 310
duke@435 311 // Try this optimization: Most method entries could live in a
duke@435 312 // "one size fits all" stack frame without all the dynamic size
duke@435 313 // calculations. It might be profitable to do all this calculation
duke@435 314 // statically and approximately for "small enough" methods.
duke@435 315
duke@435 316 //-----------------------------------------------------------------------------------------------
duke@435 317
duke@435 318 // C1 Calling conventions
duke@435 319 //
duke@435 320 // Upon method entry, the following registers are setup:
duke@435 321 //
duke@435 322 // g2 G2_thread: current thread
duke@435 323 // g5 G5_method: method to activate
duke@435 324 // g4 Gargs : pointer to last argument
duke@435 325 //
duke@435 326 //
duke@435 327 // Stack:
duke@435 328 //
duke@435 329 // +---------------+ <--- sp
duke@435 330 // | |
duke@435 331 // : reg save area :
duke@435 332 // | |
duke@435 333 // +---------------+ <--- sp + 0x40
duke@435 334 // | |
duke@435 335 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@435 336 // | |
duke@435 337 // +---------------+ <--- sp + 0x5c
duke@435 338 // | |
duke@435 339 // : free :
duke@435 340 // | |
duke@435 341 // +---------------+ <--- Gargs
duke@435 342 // | |
duke@435 343 // : arguments :
duke@435 344 // | |
duke@435 345 // +---------------+
duke@435 346 // | |
duke@435 347 //
duke@435 348 //
duke@435 349 //
duke@435 350 // AFTER FRAME HAS BEEN SETUP for method interpretation the stack looks like:
duke@435 351 //
duke@435 352 // +---------------+ <--- sp
duke@435 353 // | |
duke@435 354 // : reg save area :
duke@435 355 // | |
duke@435 356 // +---------------+ <--- sp + 0x40
duke@435 357 // | |
duke@435 358 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@435 359 // | |
duke@435 360 // +---------------+ <--- sp + 0x5c
duke@435 361 // | |
duke@435 362 // : :
duke@435 363 // | | <--- Lesp
duke@435 364 // +---------------+ <--- Lmonitors (fp - 0x18)
duke@435 365 // | VM locals |
duke@435 366 // +---------------+ <--- fp
duke@435 367 // | |
duke@435 368 // : reg save area :
duke@435 369 // | |
duke@435 370 // +---------------+ <--- fp + 0x40
duke@435 371 // | |
duke@435 372 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@435 373 // | |
duke@435 374 // +---------------+ <--- fp + 0x5c
duke@435 375 // | |
duke@435 376 // : free :
duke@435 377 // | |
duke@435 378 // +---------------+
duke@435 379 // | |
duke@435 380 // : nonarg locals :
duke@435 381 // | |
duke@435 382 // +---------------+
duke@435 383 // | |
duke@435 384 // : arguments :
duke@435 385 // | | <--- Llocals
duke@435 386 // +---------------+ <--- Gargs
duke@435 387 // | |
duke@435 388
duke@435 389 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
duke@435 390 // determine code generation flags
duke@435 391 bool synchronized = false;
duke@435 392 address entry_point = NULL;
duke@435 393
duke@435 394 switch (kind) {
duke@435 395 case Interpreter::zerolocals : break;
duke@435 396 case Interpreter::zerolocals_synchronized: synchronized = true; break;
duke@435 397 case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
duke@435 398 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
duke@435 399 case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
duke@435 400 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
duke@435 401 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
jrose@1145 402 case Interpreter::method_handle : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
duke@435 403 case Interpreter::java_lang_math_sin : break;
duke@435 404 case Interpreter::java_lang_math_cos : break;
duke@435 405 case Interpreter::java_lang_math_tan : break;
duke@435 406 case Interpreter::java_lang_math_sqrt : break;
duke@435 407 case Interpreter::java_lang_math_abs : break;
duke@435 408 case Interpreter::java_lang_math_log : break;
duke@435 409 case Interpreter::java_lang_math_log10 : break;
johnc@2781 410 case Interpreter::java_lang_ref_reference_get
johnc@2781 411 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
duke@435 412 default : ShouldNotReachHere(); break;
duke@435 413 }
duke@435 414
duke@435 415 if (entry_point) return entry_point;
duke@435 416
duke@435 417 return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
duke@435 418 }
duke@435 419
duke@435 420
never@1609 421 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
never@1609 422 // No special entry points that preclude compilation
never@1609 423 return true;
never@1609 424 }
never@1609 425
duke@435 426 // This method tells the deoptimizer how big an interpreted frame must be:
duke@435 427 int AbstractInterpreter::size_activation(methodOop method,
duke@435 428 int tempcount,
duke@435 429 int popframe_extra_args,
duke@435 430 int moncount,
duke@435 431 int callee_param_count,
duke@435 432 int callee_locals,
duke@435 433 bool is_top_frame) {
duke@435 434 return layout_activation(method,
duke@435 435 tempcount,
duke@435 436 popframe_extra_args,
duke@435 437 moncount,
duke@435 438 callee_param_count,
duke@435 439 callee_locals,
duke@435 440 (frame*)NULL,
duke@435 441 (frame*)NULL,
duke@435 442 is_top_frame);
duke@435 443 }
duke@435 444
duke@435 445 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
duke@435 446
duke@435 447 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
duke@435 448 // the days we had adapter frames. When we deoptimize a situation where a
duke@435 449 // compiled caller calls a compiled caller will have registers it expects
duke@435 450 // to survive the call to the callee. If we deoptimize the callee the only
duke@435 451 // way we can restore these registers is to have the oldest interpreter
duke@435 452 // frame that we create restore these values. That is what this routine
duke@435 453 // will accomplish.
duke@435 454
duke@435 455 // At the moment we have modified c2 to not have any callee save registers
duke@435 456 // so this problem does not exist and this routine is just a place holder.
duke@435 457
duke@435 458 assert(f->is_interpreted_frame(), "must be interpreted");
duke@435 459 }
duke@435 460
duke@435 461
duke@435 462 //----------------------------------------------------------------------------------------------------
duke@435 463 // Exceptions

mercurial