annotate src/share/vm/interpreter/interpreter.cpp @ 2488:e1162778c1c8

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
author johnc
date Thu, 07 Apr 2011 09:53:20 -0700
parents 3582bf76420e
children 6759698e3140
rev   line source
duke@0 1 /*
never@2155 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1992 25 #include "precompiled.hpp"
stefank@1992 26 #include "asm/assembler.hpp"
stefank@1992 27 #include "interpreter/bytecodeHistogram.hpp"
stefank@1992 28 #include "interpreter/bytecodeInterpreter.hpp"
stefank@1992 29 #include "interpreter/interpreter.hpp"
stefank@1992 30 #include "interpreter/interpreterRuntime.hpp"
stefank@1992 31 #include "interpreter/templateTable.hpp"
stefank@1992 32 #include "memory/allocation.inline.hpp"
stefank@1992 33 #include "memory/resourceArea.hpp"
stefank@1992 34 #include "oops/arrayOop.hpp"
stefank@1992 35 #include "oops/methodDataOop.hpp"
stefank@1992 36 #include "oops/methodOop.hpp"
stefank@1992 37 #include "oops/oop.inline.hpp"
stefank@1992 38 #include "prims/forte.hpp"
stefank@1992 39 #include "prims/jvmtiExport.hpp"
stefank@1992 40 #include "runtime/handles.inline.hpp"
stefank@1992 41 #include "runtime/sharedRuntime.hpp"
stefank@1992 42 #include "runtime/stubRoutines.hpp"
stefank@1992 43 #include "runtime/timer.hpp"
duke@0 44
duke@0 45 # define __ _masm->
duke@0 46
duke@0 47
duke@0 48 //------------------------------------------------------------------------------------------------------------------------
duke@0 49 // Implementation of InterpreterCodelet
duke@0 50
duke@0 51 void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) {
duke@0 52 _description = description;
duke@0 53 _bytecode = bytecode;
duke@0 54 }
duke@0 55
duke@0 56
duke@0 57 void InterpreterCodelet::verify() {
duke@0 58 }
duke@0 59
duke@0 60
bobv@1703 61 void InterpreterCodelet::print_on(outputStream* st) const {
duke@0 62 if (PrintInterpreter) {
bobv@1703 63 st->cr();
bobv@1703 64 st->print_cr("----------------------------------------------------------------------");
duke@0 65 }
duke@0 66
bobv@1703 67 if (description() != NULL) st->print("%s ", description());
bobv@1703 68 if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode()));
bobv@1703 69 st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes",
duke@0 70 code_begin(), code_end(), code_size());
duke@0 71
duke@0 72 if (PrintInterpreter) {
bobv@1703 73 st->cr();
bobv@1703 74 Disassembler::decode(code_begin(), code_end(), st);
duke@0 75 }
duke@0 76 }
duke@0 77
duke@0 78
duke@0 79 //------------------------------------------------------------------------------------------------------------------------
duke@0 80 // Implementation of platform independent aspects of Interpreter
duke@0 81
duke@0 82 void AbstractInterpreter::initialize() {
duke@0 83 if (_code != NULL) return;
duke@0 84
duke@0 85 // make sure 'imported' classes are initialized
duke@0 86 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset();
duke@0 87 if (PrintBytecodeHistogram) BytecodeHistogram::reset();
duke@0 88 if (PrintBytecodePairHistogram) BytecodePairHistogram::reset();
duke@0 89
duke@0 90 InvocationCounter::reinitialize(DelayCompilationDuringStartup);
duke@0 91
duke@0 92 }
duke@0 93
duke@0 94 void AbstractInterpreter::print() {
duke@0 95 tty->cr();
duke@0 96 tty->print_cr("----------------------------------------------------------------------");
duke@0 97 tty->print_cr("Interpreter");
duke@0 98 tty->cr();
duke@0 99 tty->print_cr("code size = %6dK bytes", (int)_code->used_space()/1024);
duke@0 100 tty->print_cr("total space = %6dK bytes", (int)_code->total_space()/1024);
duke@0 101 tty->print_cr("wasted space = %6dK bytes", (int)_code->available_space()/1024);
duke@0 102 tty->cr();
duke@0 103 tty->print_cr("# of codelets = %6d" , _code->number_of_stubs());
duke@0 104 tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs());
duke@0 105 tty->cr();
duke@0 106 _code->print();
duke@0 107 tty->print_cr("----------------------------------------------------------------------");
duke@0 108 tty->cr();
duke@0 109 }
duke@0 110
duke@0 111
duke@0 112 void interpreter_init() {
duke@0 113 Interpreter::initialize();
duke@0 114 #ifndef PRODUCT
duke@0 115 if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure());
duke@0 116 #endif // PRODUCT
duke@0 117 // need to hit every safepoint in order to call zapping routine
duke@0 118 // register the interpreter
duke@0 119 Forte::register_stub(
duke@0 120 "Interpreter",
duke@0 121 AbstractInterpreter::code()->code_start(),
duke@0 122 AbstractInterpreter::code()->code_end()
duke@0 123 );
duke@0 124
duke@0 125 // notify JVMTI profiler
duke@0 126 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@0 127 JvmtiExport::post_dynamic_code_generated("Interpreter",
duke@0 128 AbstractInterpreter::code()->code_start(),
duke@0 129 AbstractInterpreter::code()->code_end());
duke@0 130 }
duke@0 131 }
duke@0 132
duke@0 133 //------------------------------------------------------------------------------------------------------------------------
duke@0 134 // Implementation of interpreter
duke@0 135
duke@0 136 StubQueue* AbstractInterpreter::_code = NULL;
duke@0 137 bool AbstractInterpreter::_notice_safepoints = false;
duke@0 138 address AbstractInterpreter::_rethrow_exception_entry = NULL;
duke@0 139
duke@0 140 address AbstractInterpreter::_native_entry_begin = NULL;
duke@0 141 address AbstractInterpreter::_native_entry_end = NULL;
duke@0 142 address AbstractInterpreter::_slow_signature_handler;
duke@0 143 address AbstractInterpreter::_entry_table [AbstractInterpreter::number_of_method_entries];
duke@0 144 address AbstractInterpreter::_native_abi_to_tosca [AbstractInterpreter::number_of_result_handlers];
duke@0 145
duke@0 146 //------------------------------------------------------------------------------------------------------------------------
duke@0 147 // Generation of complete interpreter
duke@0 148
duke@0 149 AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) {
duke@0 150 _masm = NULL;
duke@0 151 }
duke@0 152
duke@0 153
duke@0 154 static const BasicType types[Interpreter::number_of_result_handlers] = {
duke@0 155 T_BOOLEAN,
duke@0 156 T_CHAR ,
duke@0 157 T_BYTE ,
duke@0 158 T_SHORT ,
duke@0 159 T_INT ,
duke@0 160 T_LONG ,
duke@0 161 T_VOID ,
duke@0 162 T_FLOAT ,
duke@0 163 T_DOUBLE ,
duke@0 164 T_OBJECT
duke@0 165 };
duke@0 166
duke@0 167 void AbstractInterpreterGenerator::generate_all() {
duke@0 168
duke@0 169
duke@0 170 { CodeletMark cm(_masm, "slow signature handler");
duke@0 171 Interpreter::_slow_signature_handler = generate_slow_signature_handler();
duke@0 172 }
duke@0 173
duke@0 174 }
duke@0 175
duke@0 176 //------------------------------------------------------------------------------------------------------------------------
duke@0 177 // Entry points
duke@0 178
duke@0 179 AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) {
duke@0 180 // Abstract method?
duke@0 181 if (m->is_abstract()) return abstract;
duke@0 182
jrose@748 183 // Invoker for method handles?
jrose@748 184 if (m->is_method_handle_invoke()) return method_handle;
jrose@748 185
duke@0 186 // Native method?
duke@0 187 // Note: This test must come _before_ the test for intrinsic
duke@0 188 // methods. See also comments below.
duke@0 189 if (m->is_native()) {
jrose@748 190 assert(!m->is_method_handle_invoke(), "overlapping bits here, watch out");
duke@0 191 return m->is_synchronized() ? native_synchronized : native;
duke@0 192 }
duke@0 193
duke@0 194 // Synchronized?
duke@0 195 if (m->is_synchronized()) {
duke@0 196 return zerolocals_synchronized;
duke@0 197 }
duke@0 198
duke@0 199 if (RegisterFinalizersAtInit && m->code_size() == 1 &&
duke@0 200 m->intrinsic_id() == vmIntrinsics::_Object_init) {
duke@0 201 // We need to execute the special return bytecode to check for
duke@0 202 // finalizer registration so create a normal frame.
duke@0 203 return zerolocals;
duke@0 204 }
duke@0 205
duke@0 206 // Empty method?
duke@0 207 if (m->is_empty_method()) {
duke@0 208 return empty;
duke@0 209 }
duke@0 210
duke@0 211 // Special intrinsic method?
duke@0 212 // Note: This test must come _after_ the test for native methods,
duke@0 213 // otherwise we will run into problems with JDK 1.2, see also
duke@0 214 // AbstractInterpreterGenerator::generate_method_entry() for
duke@0 215 // for details.
duke@0 216 switch (m->intrinsic_id()) {
duke@0 217 case vmIntrinsics::_dsin : return java_lang_math_sin ;
duke@0 218 case vmIntrinsics::_dcos : return java_lang_math_cos ;
duke@0 219 case vmIntrinsics::_dtan : return java_lang_math_tan ;
duke@0 220 case vmIntrinsics::_dabs : return java_lang_math_abs ;
duke@0 221 case vmIntrinsics::_dsqrt : return java_lang_math_sqrt ;
duke@0 222 case vmIntrinsics::_dlog : return java_lang_math_log ;
duke@0 223 case vmIntrinsics::_dlog10: return java_lang_math_log10;
johnc@2488 224
johnc@2488 225 case vmIntrinsics::_Reference_get:
johnc@2488 226 return java_lang_ref_reference_get;
johnc@2488 227 }
johnc@2488 228
johnc@2488 229 // Accessor method?
johnc@2488 230 if (m->is_accessor()) {
johnc@2488 231 assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1");
johnc@2488 232 return accessor;
duke@0 233 }
duke@0 234
duke@0 235 // Note: for now: zero locals for all non-empty methods
duke@0 236 return zerolocals;
duke@0 237 }
duke@0 238
duke@0 239
duke@0 240 // Return true if the interpreter can prove that the given bytecode has
duke@0 241 // not yet been executed (in Java semantics, not in actual operation).
duke@0 242 bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) {
never@2155 243 Bytecodes::Code code = method()->code_at(bci);
duke@0 244
never@2155 245 if (!Bytecodes::must_rewrite(code)) {
duke@0 246 // might have been reached
duke@0 247 return false;
duke@0 248 }
duke@0 249
duke@0 250 // the bytecode might not be rewritten if the method is an accessor, etc.
duke@0 251 address ientry = method->interpreter_entry();
duke@0 252 if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) &&
duke@0 253 ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized))
duke@0 254 return false; // interpreter does not run this method!
duke@0 255
duke@0 256 // otherwise, we can be sure this bytecode has never been executed
duke@0 257 return true;
duke@0 258 }
duke@0 259
duke@0 260
duke@0 261 #ifndef PRODUCT
duke@0 262 void AbstractInterpreter::print_method_kind(MethodKind kind) {
duke@0 263 switch (kind) {
duke@0 264 case zerolocals : tty->print("zerolocals" ); break;
duke@0 265 case zerolocals_synchronized: tty->print("zerolocals_synchronized"); break;
duke@0 266 case native : tty->print("native" ); break;
duke@0 267 case native_synchronized : tty->print("native_synchronized" ); break;
duke@0 268 case empty : tty->print("empty" ); break;
duke@0 269 case accessor : tty->print("accessor" ); break;
duke@0 270 case abstract : tty->print("abstract" ); break;
jrose@748 271 case method_handle : tty->print("method_handle" ); break;
duke@0 272 case java_lang_math_sin : tty->print("java_lang_math_sin" ); break;
duke@0 273 case java_lang_math_cos : tty->print("java_lang_math_cos" ); break;
duke@0 274 case java_lang_math_tan : tty->print("java_lang_math_tan" ); break;
duke@0 275 case java_lang_math_abs : tty->print("java_lang_math_abs" ); break;
duke@0 276 case java_lang_math_sqrt : tty->print("java_lang_math_sqrt" ); break;
duke@0 277 case java_lang_math_log : tty->print("java_lang_math_log" ); break;
duke@0 278 case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break;
duke@0 279 default : ShouldNotReachHere();
duke@0 280 }
duke@0 281 }
duke@0 282 #endif // PRODUCT
duke@0 283
duke@0 284
duke@0 285 //------------------------------------------------------------------------------------------------------------------------
duke@0 286 // Deoptimization support
duke@0 287
cfang@951 288 // If deoptimization happens, this function returns the point of next bytecode to continue execution
cfang@951 289 address AbstractInterpreter::deopt_continue_after_entry(methodOop method, address bcp, int callee_parameters, bool is_top_frame) {
duke@0 290 assert(method->contains(bcp), "just checkin'");
never@2155 291 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);
cfang@951 292 assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute");
duke@0 293 int bci = method->bci_from(bcp);
duke@0 294 int length = -1; // initial value for debugging
duke@0 295 // compute continuation length
never@2155 296 length = Bytecodes::length_at(method, bcp);
duke@0 297 // compute result type
duke@0 298 BasicType type = T_ILLEGAL;
cfang@951 299
duke@0 300 switch (code) {
duke@0 301 case Bytecodes::_invokevirtual :
duke@0 302 case Bytecodes::_invokespecial :
duke@0 303 case Bytecodes::_invokestatic :
duke@0 304 case Bytecodes::_invokeinterface: {
duke@0 305 Thread *thread = Thread::current();
duke@0 306 ResourceMark rm(thread);
duke@0 307 methodHandle mh(thread, method);
coleenp@2190 308 type = Bytecode_invoke(mh, bci).result_type();
duke@0 309 // since the cache entry might not be initialized:
duke@0 310 // (NOT needed for the old calling convension)
duke@0 311 if (!is_top_frame) {
duke@0 312 int index = Bytes::get_native_u2(bcp+1);
duke@0 313 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters);
duke@0 314 }
duke@0 315 break;
duke@0 316 }
duke@0 317
jrose@1133 318 case Bytecodes::_invokedynamic: {
jrose@1133 319 Thread *thread = Thread::current();
jrose@1133 320 ResourceMark rm(thread);
jrose@1133 321 methodHandle mh(thread, method);
coleenp@2190 322 type = Bytecode_invoke(mh, bci).result_type();
jrose@1133 323 // since the cache entry might not be initialized:
jrose@1133 324 // (NOT needed for the old calling convension)
jrose@1133 325 if (!is_top_frame) {
jrose@1133 326 int index = Bytes::get_native_u4(bcp+1);
twisti@1212 327 method->constants()->cache()->secondary_entry_at(index)->set_parameter_size(callee_parameters);
jrose@1133 328 }
jrose@1133 329 break;
jrose@1133 330 }
jrose@1133 331
duke@0 332 case Bytecodes::_ldc :
duke@0 333 case Bytecodes::_ldc_w : // fall through
duke@0 334 case Bytecodes::_ldc2_w:
jrose@1617 335 {
jrose@1617 336 Thread *thread = Thread::current();
jrose@1617 337 ResourceMark rm(thread);
jrose@1617 338 methodHandle mh(thread, method);
never@2155 339 type = Bytecode_loadconstant(mh, bci).result_type();
jrose@1617 340 break;
jrose@1617 341 }
duke@0 342
duke@0 343 default:
duke@0 344 type = Bytecodes::result_type(code);
duke@0 345 break;
duke@0 346 }
duke@0 347
duke@0 348 // return entry point for computed continuation state & bytecode length
duke@0 349 return
duke@0 350 is_top_frame
duke@0 351 ? Interpreter::deopt_entry (as_TosState(type), length)
duke@0 352 : Interpreter::return_entry(as_TosState(type), length);
duke@0 353 }
duke@0 354
cfang@951 355 // If deoptimization happens, this function returns the point where the interpreter reexecutes
cfang@951 356 // the bytecode.
cfang@951 357 // Note: Bytecodes::_athrow is a special case in that it does not return
cfang@951 358 // Interpreter::deopt_entry(vtos, 0) like others
cfang@951 359 address AbstractInterpreter::deopt_reexecute_entry(methodOop method, address bcp) {
cfang@951 360 assert(method->contains(bcp), "just checkin'");
never@2155 361 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);
cfang@951 362 #ifdef COMPILER1
cfang@951 363 if(code == Bytecodes::_athrow ) {
cfang@951 364 return Interpreter::rethrow_exception_entry();
cfang@951 365 }
cfang@951 366 #endif /* COMPILER1 */
cfang@951 367 return Interpreter::deopt_entry(vtos, 0);
cfang@951 368 }
cfang@951 369
cfang@951 370 // If deoptimization happens, the interpreter should reexecute these bytecodes.
cfang@951 371 // This function mainly helps the compilers to set up the reexecute bit.
cfang@951 372 bool AbstractInterpreter::bytecode_should_reexecute(Bytecodes::Code code) {
cfang@951 373 switch (code) {
cfang@951 374 case Bytecodes::_lookupswitch:
cfang@951 375 case Bytecodes::_tableswitch:
cfang@951 376 case Bytecodes::_fast_binaryswitch:
cfang@951 377 case Bytecodes::_fast_linearswitch:
cfang@951 378 // recompute condtional expression folded into _if<cond>
cfang@951 379 case Bytecodes::_lcmp :
cfang@951 380 case Bytecodes::_fcmpl :
cfang@951 381 case Bytecodes::_fcmpg :
cfang@951 382 case Bytecodes::_dcmpl :
cfang@951 383 case Bytecodes::_dcmpg :
cfang@951 384 case Bytecodes::_ifnull :
cfang@951 385 case Bytecodes::_ifnonnull :
cfang@951 386 case Bytecodes::_goto :
cfang@951 387 case Bytecodes::_goto_w :
cfang@951 388 case Bytecodes::_ifeq :
cfang@951 389 case Bytecodes::_ifne :
cfang@951 390 case Bytecodes::_iflt :
cfang@951 391 case Bytecodes::_ifge :
cfang@951 392 case Bytecodes::_ifgt :
cfang@951 393 case Bytecodes::_ifle :
cfang@951 394 case Bytecodes::_if_icmpeq :
cfang@951 395 case Bytecodes::_if_icmpne :
cfang@951 396 case Bytecodes::_if_icmplt :
cfang@951 397 case Bytecodes::_if_icmpge :
cfang@951 398 case Bytecodes::_if_icmpgt :
cfang@951 399 case Bytecodes::_if_icmple :
cfang@951 400 case Bytecodes::_if_acmpeq :
cfang@951 401 case Bytecodes::_if_acmpne :
cfang@951 402 // special cases
cfang@951 403 case Bytecodes::_getfield :
cfang@951 404 case Bytecodes::_putfield :
cfang@951 405 case Bytecodes::_getstatic :
cfang@951 406 case Bytecodes::_putstatic :
cfang@951 407 case Bytecodes::_aastore :
cfang@951 408 #ifdef COMPILER1
cfang@951 409 //special case of reexecution
cfang@951 410 case Bytecodes::_athrow :
cfang@951 411 #endif
cfang@951 412 return true;
cfang@951 413
cfang@951 414 default:
cfang@951 415 return false;
cfang@951 416 }
cfang@951 417 }
cfang@951 418
duke@0 419 void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
duke@0 420 // Quick & dirty stack overflow checking: bang the stack & handle trap.
duke@0 421 // Note that we do the banging after the frame is setup, since the exception
duke@0 422 // handling code expects to find a valid interpreter frame on the stack.
duke@0 423 // Doing the banging earlier fails if the caller frame is not an interpreter
duke@0 424 // frame.
duke@0 425 // (Also, the exception throwing code expects to unlock any synchronized
duke@0 426 // method receiever, so do the banging after locking the receiver.)
duke@0 427
duke@0 428 // Bang each page in the shadow zone. We can't assume it's been done for
duke@0 429 // an interpreter frame with greater than a page of locals, so each page
duke@0 430 // needs to be checked. Only true for non-native.
duke@0 431 if (UseStackBanging) {
duke@0 432 const int start_page = native_call ? StackShadowPages : 1;
duke@0 433 const int page_size = os::vm_page_size();
duke@0 434 for (int pages = start_page; pages <= StackShadowPages ; pages++) {
duke@0 435 __ bang_stack_with_offset(pages*page_size);
duke@0 436 }
duke@0 437 }
duke@0 438 }