src/share/vm/interpreter/interpreterRuntime.cpp

Wed, 20 Jul 2011 18:04:17 -0700

author
iveresov
date
Wed, 20 Jul 2011 18:04:17 -0700
changeset 3035
43f9d800f276
parent 2988
2c359f27615c
child 3050
fdb992d83a87
permissions
-rw-r--r--

7066339: Tiered: policy should make consistent decisions about osr levels
Summary: Added feedback disabling flag to common(), fixed handling of TieredStopAtLevel.
Reviewed-by: kvn, never

duke@435 1 /*
never@2462 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 "classfile/systemDictionary.hpp"
stefank@2314 27 #include "classfile/vmSymbols.hpp"
stefank@2314 28 #include "compiler/compileBroker.hpp"
stefank@2314 29 #include "gc_interface/collectedHeap.hpp"
stefank@2314 30 #include "interpreter/interpreter.hpp"
stefank@2314 31 #include "interpreter/interpreterRuntime.hpp"
stefank@2314 32 #include "interpreter/linkResolver.hpp"
stefank@2314 33 #include "interpreter/templateTable.hpp"
stefank@2314 34 #include "memory/oopFactory.hpp"
stefank@2314 35 #include "memory/universe.inline.hpp"
stefank@2314 36 #include "oops/constantPoolOop.hpp"
stefank@2314 37 #include "oops/cpCacheOop.hpp"
stefank@2314 38 #include "oops/instanceKlass.hpp"
stefank@2314 39 #include "oops/methodDataOop.hpp"
stefank@2314 40 #include "oops/objArrayKlass.hpp"
stefank@2314 41 #include "oops/oop.inline.hpp"
coleenp@2497 42 #include "oops/symbol.hpp"
stefank@2314 43 #include "prims/jvmtiExport.hpp"
stefank@2314 44 #include "prims/nativeLookup.hpp"
stefank@2314 45 #include "runtime/biasedLocking.hpp"
stefank@2314 46 #include "runtime/compilationPolicy.hpp"
stefank@2314 47 #include "runtime/deoptimization.hpp"
stefank@2314 48 #include "runtime/fieldDescriptor.hpp"
stefank@2314 49 #include "runtime/handles.inline.hpp"
stefank@2314 50 #include "runtime/interfaceSupport.hpp"
stefank@2314 51 #include "runtime/java.hpp"
stefank@2314 52 #include "runtime/jfieldIDWorkaround.hpp"
stefank@2314 53 #include "runtime/osThread.hpp"
stefank@2314 54 #include "runtime/sharedRuntime.hpp"
stefank@2314 55 #include "runtime/stubRoutines.hpp"
stefank@2314 56 #include "runtime/synchronizer.hpp"
stefank@2314 57 #include "runtime/threadCritical.hpp"
stefank@2314 58 #include "utilities/events.hpp"
stefank@2314 59 #ifdef TARGET_ARCH_x86
stefank@2314 60 # include "vm_version_x86.hpp"
stefank@2314 61 #endif
stefank@2314 62 #ifdef TARGET_ARCH_sparc
stefank@2314 63 # include "vm_version_sparc.hpp"
stefank@2314 64 #endif
stefank@2314 65 #ifdef TARGET_ARCH_zero
stefank@2314 66 # include "vm_version_zero.hpp"
stefank@2314 67 #endif
bobv@2508 68 #ifdef TARGET_ARCH_arm
bobv@2508 69 # include "vm_version_arm.hpp"
bobv@2508 70 #endif
bobv@2508 71 #ifdef TARGET_ARCH_ppc
bobv@2508 72 # include "vm_version_ppc.hpp"
bobv@2508 73 #endif
stefank@2314 74 #ifdef COMPILER2
stefank@2314 75 #include "opto/runtime.hpp"
stefank@2314 76 #endif
duke@435 77
duke@435 78 class UnlockFlagSaver {
duke@435 79 private:
duke@435 80 JavaThread* _thread;
duke@435 81 bool _do_not_unlock;
duke@435 82 public:
duke@435 83 UnlockFlagSaver(JavaThread* t) {
duke@435 84 _thread = t;
duke@435 85 _do_not_unlock = t->do_not_unlock_if_synchronized();
duke@435 86 t->set_do_not_unlock_if_synchronized(false);
duke@435 87 }
duke@435 88 ~UnlockFlagSaver() {
duke@435 89 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
duke@435 90 }
duke@435 91 };
duke@435 92
duke@435 93 //------------------------------------------------------------------------------------------------------------------------
duke@435 94 // State accessors
duke@435 95
duke@435 96 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
duke@435 97 last_frame(thread).interpreter_frame_set_bcp(bcp);
duke@435 98 if (ProfileInterpreter) {
duke@435 99 // ProfileTraps uses MDOs independently of ProfileInterpreter.
duke@435 100 // That is why we must check both ProfileInterpreter and mdo != NULL.
duke@435 101 methodDataOop mdo = last_frame(thread).interpreter_frame_method()->method_data();
duke@435 102 if (mdo != NULL) {
duke@435 103 NEEDS_CLEANUP;
duke@435 104 last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
duke@435 105 }
duke@435 106 }
duke@435 107 }
duke@435 108
duke@435 109 //------------------------------------------------------------------------------------------------------------------------
duke@435 110 // Constants
duke@435 111
duke@435 112
duke@435 113 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
duke@435 114 // access constant pool
duke@435 115 constantPoolOop pool = method(thread)->constants();
jrose@1920 116 int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
duke@435 117 constantTag tag = pool->tag_at(index);
duke@435 118
duke@435 119 if (tag.is_unresolved_klass() || tag.is_klass()) {
duke@435 120 klassOop klass = pool->klass_at(index, CHECK);
never@2658 121 oop java_class = klass->java_mirror();
duke@435 122 thread->set_vm_result(java_class);
duke@435 123 } else {
duke@435 124 #ifdef ASSERT
duke@435 125 // If we entered this runtime routine, we believed the tag contained
duke@435 126 // an unresolved string, an unresolved class or a resolved class.
duke@435 127 // However, another thread could have resolved the unresolved string
duke@435 128 // or class by the time we go there.
duke@435 129 assert(tag.is_unresolved_string()|| tag.is_string(), "expected string");
duke@435 130 #endif
duke@435 131 oop s_oop = pool->string_at(index, CHECK);
duke@435 132 thread->set_vm_result(s_oop);
duke@435 133 }
duke@435 134 IRT_END
duke@435 135
jrose@1957 136 IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
jrose@1957 137 assert(bytecode == Bytecodes::_fast_aldc ||
jrose@1957 138 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
jrose@1957 139 ResourceMark rm(thread);
jrose@1957 140 methodHandle m (thread, method(thread));
never@2462 141 Bytecode_loadconstant ldc(m, bci(thread));
never@2934 142 oop result = ldc.resolve_constant(CHECK);
never@2934 143 #ifdef ASSERT
never@2934 144 {
never@2934 145 // The bytecode wrappers aren't GC-safe so construct a new one
never@2934 146 Bytecode_loadconstant ldc2(m, bci(thread));
never@2934 147 ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc2.cache_index());
never@2934 148 assert(result == cpce->f1(), "expected result for assembly code");
never@2934 149 }
never@2934 150 #endif
jrose@1957 151 }
jrose@1957 152 IRT_END
jrose@1957 153
duke@435 154
duke@435 155 //------------------------------------------------------------------------------------------------------------------------
duke@435 156 // Allocation
duke@435 157
duke@435 158 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, constantPoolOopDesc* pool, int index))
duke@435 159 klassOop k_oop = pool->klass_at(index, CHECK);
duke@435 160 instanceKlassHandle klass (THREAD, k_oop);
duke@435 161
duke@435 162 // Make sure we are not instantiating an abstract klass
duke@435 163 klass->check_valid_for_instantiation(true, CHECK);
duke@435 164
duke@435 165 // Make sure klass is initialized
duke@435 166 klass->initialize(CHECK);
duke@435 167
duke@435 168 // At this point the class may not be fully initialized
duke@435 169 // because of recursive initialization. If it is fully
duke@435 170 // initialized & has_finalized is not set, we rewrite
duke@435 171 // it into its fast version (Note: no locking is needed
duke@435 172 // here since this is an atomic byte write and can be
duke@435 173 // done more than once).
duke@435 174 //
duke@435 175 // Note: In case of classes with has_finalized we don't
duke@435 176 // rewrite since that saves us an extra check in
duke@435 177 // the fast version which then would call the
duke@435 178 // slow version anyway (and do a call back into
duke@435 179 // Java).
duke@435 180 // If we have a breakpoint, then we don't rewrite
duke@435 181 // because the _breakpoint bytecode would be lost.
duke@435 182 oop obj = klass->allocate_instance(CHECK);
duke@435 183 thread->set_vm_result(obj);
duke@435 184 IRT_END
duke@435 185
duke@435 186
duke@435 187 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
duke@435 188 oop obj = oopFactory::new_typeArray(type, size, CHECK);
duke@435 189 thread->set_vm_result(obj);
duke@435 190 IRT_END
duke@435 191
duke@435 192
duke@435 193 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, constantPoolOopDesc* pool, int index, jint size))
duke@435 194 // Note: no oopHandle for pool & klass needed since they are not used
duke@435 195 // anymore after new_objArray() and no GC can happen before.
duke@435 196 // (This may have to change if this code changes!)
duke@435 197 klassOop klass = pool->klass_at(index, CHECK);
duke@435 198 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
duke@435 199 thread->set_vm_result(obj);
duke@435 200 IRT_END
duke@435 201
duke@435 202
duke@435 203 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
duke@435 204 // We may want to pass in more arguments - could make this slightly faster
duke@435 205 constantPoolOop constants = method(thread)->constants();
jrose@1920 206 int i = get_index_u2(thread, Bytecodes::_multianewarray);
duke@435 207 klassOop klass = constants->klass_at(i, CHECK);
duke@435 208 int nof_dims = number_of_dimensions(thread);
duke@435 209 assert(oop(klass)->is_klass(), "not a class");
duke@435 210 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
duke@435 211
duke@435 212 // We must create an array of jints to pass to multi_allocate.
duke@435 213 ResourceMark rm(thread);
duke@435 214 const int small_dims = 10;
duke@435 215 jint dim_array[small_dims];
duke@435 216 jint *dims = &dim_array[0];
duke@435 217 if (nof_dims > small_dims) {
duke@435 218 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
duke@435 219 }
duke@435 220 for (int index = 0; index < nof_dims; index++) {
duke@435 221 // offset from first_size_address is addressed as local[index]
duke@435 222 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
duke@435 223 dims[index] = first_size_address[n];
duke@435 224 }
duke@435 225 oop obj = arrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
duke@435 226 thread->set_vm_result(obj);
duke@435 227 IRT_END
duke@435 228
duke@435 229
duke@435 230 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
duke@435 231 assert(obj->is_oop(), "must be a valid oop");
duke@435 232 assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
duke@435 233 instanceKlass::register_finalizer(instanceOop(obj), CHECK);
duke@435 234 IRT_END
duke@435 235
duke@435 236
duke@435 237 // Quicken instance-of and check-cast bytecodes
duke@435 238 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
duke@435 239 // Force resolving; quicken the bytecode
jrose@1920 240 int which = get_index_u2(thread, Bytecodes::_checkcast);
duke@435 241 constantPoolOop cpool = method(thread)->constants();
duke@435 242 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
duke@435 243 // program we might have seen an unquick'd bytecode in the interpreter but have another
duke@435 244 // thread quicken the bytecode before we get here.
duke@435 245 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
duke@435 246 klassOop klass = cpool->klass_at(which, CHECK);
duke@435 247 thread->set_vm_result(klass);
duke@435 248 IRT_END
duke@435 249
duke@435 250
duke@435 251 //------------------------------------------------------------------------------------------------------------------------
duke@435 252 // Exceptions
duke@435 253
duke@435 254 // Assume the compiler is (or will be) interested in this event.
duke@435 255 // If necessary, create an MDO to hold the information, and record it.
duke@435 256 void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
duke@435 257 assert(ProfileTraps, "call me only if profiling");
duke@435 258 methodHandle trap_method(thread, method(thread));
jrose@2148 259
duke@435 260 if (trap_method.not_null()) {
duke@435 261 methodDataHandle trap_mdo(thread, trap_method->method_data());
duke@435 262 if (trap_mdo.is_null()) {
duke@435 263 methodOopDesc::build_interpreter_method_data(trap_method, THREAD);
duke@435 264 if (HAS_PENDING_EXCEPTION) {
duke@435 265 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
duke@435 266 CLEAR_PENDING_EXCEPTION;
duke@435 267 }
duke@435 268 trap_mdo = methodDataHandle(thread, trap_method->method_data());
duke@435 269 // and fall through...
duke@435 270 }
duke@435 271 if (trap_mdo.not_null()) {
duke@435 272 // Update per-method count of trap events. The interpreter
duke@435 273 // is updating the MDO to simulate the effect of compiler traps.
duke@435 274 int trap_bci = trap_method->bci_from(bcp(thread));
duke@435 275 Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
duke@435 276 }
duke@435 277 }
duke@435 278 }
duke@435 279
duke@435 280 static Handle get_preinitialized_exception(klassOop k, TRAPS) {
duke@435 281 // get klass
duke@435 282 instanceKlass* klass = instanceKlass::cast(k);
duke@435 283 assert(klass->is_initialized(),
duke@435 284 "this klass should have been initialized during VM initialization");
duke@435 285 // create instance - do not call constructor since we may have no
duke@435 286 // (java) stack space left (should assert constructor is empty)
duke@435 287 Handle exception;
duke@435 288 oop exception_oop = klass->allocate_instance(CHECK_(exception));
duke@435 289 exception = Handle(THREAD, exception_oop);
duke@435 290 if (StackTraceInThrowable) {
duke@435 291 java_lang_Throwable::fill_in_stack_trace(exception);
duke@435 292 }
duke@435 293 return exception;
duke@435 294 }
duke@435 295
duke@435 296 // Special handling for stack overflow: since we don't have any (java) stack
duke@435 297 // space left we use the pre-allocated & pre-initialized StackOverflowError
duke@435 298 // klass to create an stack overflow error instance. We do not call its
duke@435 299 // constructor for the same reason (it is empty, anyway).
duke@435 300 IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
duke@435 301 Handle exception = get_preinitialized_exception(
duke@435 302 SystemDictionary::StackOverflowError_klass(),
duke@435 303 CHECK);
duke@435 304 THROW_HANDLE(exception);
duke@435 305 IRT_END
duke@435 306
duke@435 307
duke@435 308 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
duke@435 309 // lookup exception klass
coleenp@2497 310 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
duke@435 311 if (ProfileTraps) {
duke@435 312 if (s == vmSymbols::java_lang_ArithmeticException()) {
duke@435 313 note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
duke@435 314 } else if (s == vmSymbols::java_lang_NullPointerException()) {
duke@435 315 note_trap(thread, Deoptimization::Reason_null_check, CHECK);
duke@435 316 }
duke@435 317 }
duke@435 318 // create exception
coleenp@2497 319 Handle exception = Exceptions::new_exception(thread, s, message);
duke@435 320 thread->set_vm_result(exception());
duke@435 321 IRT_END
duke@435 322
duke@435 323
duke@435 324 IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
duke@435 325 ResourceMark rm(thread);
duke@435 326 const char* klass_name = Klass::cast(obj->klass())->external_name();
duke@435 327 // lookup exception klass
coleenp@2497 328 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
duke@435 329 if (ProfileTraps) {
duke@435 330 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
duke@435 331 }
duke@435 332 // create exception, with klass name as detail message
coleenp@2497 333 Handle exception = Exceptions::new_exception(thread, s, klass_name);
duke@435 334 thread->set_vm_result(exception());
duke@435 335 IRT_END
duke@435 336
duke@435 337
duke@435 338 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
duke@435 339 char message[jintAsStringSize];
duke@435 340 // lookup exception klass
coleenp@2497 341 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
duke@435 342 if (ProfileTraps) {
duke@435 343 note_trap(thread, Deoptimization::Reason_range_check, CHECK);
duke@435 344 }
duke@435 345 // create exception
duke@435 346 sprintf(message, "%d", index);
coleenp@2497 347 THROW_MSG(s, message);
duke@435 348 IRT_END
duke@435 349
duke@435 350 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
duke@435 351 JavaThread* thread, oopDesc* obj))
duke@435 352
duke@435 353 ResourceMark rm(thread);
duke@435 354 char* message = SharedRuntime::generate_class_cast_message(
duke@435 355 thread, Klass::cast(obj->klass())->external_name());
duke@435 356
duke@435 357 if (ProfileTraps) {
duke@435 358 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
duke@435 359 }
duke@435 360
duke@435 361 // create exception
duke@435 362 THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
duke@435 363 IRT_END
duke@435 364
duke@435 365 // exception_handler_for_exception(...) returns the continuation address,
duke@435 366 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
duke@435 367 // The exception oop is returned to make sure it is preserved over GC (it
duke@435 368 // is only on the stack if the exception was thrown explicitly via athrow).
duke@435 369 // During this operation, the expression stack contains the values for the
duke@435 370 // bci where the exception happened. If the exception was propagated back
duke@435 371 // from a call, the expression stack contains the values for the bci at the
duke@435 372 // invoke w/o arguments (i.e., as if one were inside the call).
duke@435 373 IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
duke@435 374
duke@435 375 Handle h_exception(thread, exception);
duke@435 376 methodHandle h_method (thread, method(thread));
duke@435 377 constantPoolHandle h_constants(thread, h_method->constants());
duke@435 378 typeArrayHandle h_extable (thread, h_method->exception_table());
duke@435 379 bool should_repeat;
duke@435 380 int handler_bci;
jrose@1957 381 int current_bci = bci(thread);
duke@435 382
duke@435 383 // Need to do this check first since when _do_not_unlock_if_synchronized
duke@435 384 // is set, we don't want to trigger any classloading which may make calls
duke@435 385 // into java, or surprisingly find a matching exception handler for bci 0
duke@435 386 // since at this moment the method hasn't been "officially" entered yet.
duke@435 387 if (thread->do_not_unlock_if_synchronized()) {
duke@435 388 ResourceMark rm;
duke@435 389 assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");
duke@435 390 thread->set_vm_result(exception);
duke@435 391 #ifdef CC_INTERP
duke@435 392 return (address) -1;
duke@435 393 #else
duke@435 394 return Interpreter::remove_activation_entry();
duke@435 395 #endif
duke@435 396 }
duke@435 397
duke@435 398 do {
duke@435 399 should_repeat = false;
duke@435 400
duke@435 401 // assertions
duke@435 402 #ifdef ASSERT
duke@435 403 assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
duke@435 404 assert(h_exception->is_oop(), "just checking");
duke@435 405 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
never@1577 406 if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
duke@435 407 if (ExitVMOnVerifyError) vm_exit(-1);
duke@435 408 ShouldNotReachHere();
duke@435 409 }
duke@435 410 #endif
duke@435 411
duke@435 412 // tracing
duke@435 413 if (TraceExceptions) {
duke@435 414 ttyLocker ttyl;
duke@435 415 ResourceMark rm(thread);
duke@435 416 tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
duke@435 417 tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
duke@435 418 tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
duke@435 419 }
duke@435 420 // Don't go paging in something which won't be used.
duke@435 421 // else if (h_extable->length() == 0) {
duke@435 422 // // disabled for now - interpreter is not using shortcut yet
duke@435 423 // // (shortcut is not to call runtime if we have no exception handlers)
duke@435 424 // // warning("performance bug: should not call runtime if method has no exception handlers");
duke@435 425 // }
duke@435 426 // for AbortVMOnException flag
duke@435 427 NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
duke@435 428
duke@435 429 // exception handler lookup
duke@435 430 KlassHandle h_klass(THREAD, h_exception->klass());
duke@435 431 handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD);
duke@435 432 if (HAS_PENDING_EXCEPTION) {
duke@435 433 // We threw an exception while trying to find the exception handler.
duke@435 434 // Transfer the new exception to the exception handle which will
duke@435 435 // be set into thread local storage, and do another lookup for an
duke@435 436 // exception handler for this exception, this time starting at the
duke@435 437 // BCI of the exception handler which caused the exception to be
duke@435 438 // thrown (bug 4307310).
duke@435 439 h_exception = Handle(THREAD, PENDING_EXCEPTION);
duke@435 440 CLEAR_PENDING_EXCEPTION;
duke@435 441 if (handler_bci >= 0) {
duke@435 442 current_bci = handler_bci;
duke@435 443 should_repeat = true;
duke@435 444 }
duke@435 445 }
duke@435 446 } while (should_repeat == true);
duke@435 447
duke@435 448 // notify JVMTI of an exception throw; JVMTI will detect if this is a first
duke@435 449 // time throw or a stack unwinding throw and accordingly notify the debugger
dcubed@1648 450 if (JvmtiExport::can_post_on_exceptions()) {
duke@435 451 JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
duke@435 452 }
duke@435 453
duke@435 454 #ifdef CC_INTERP
duke@435 455 address continuation = (address)(intptr_t) handler_bci;
duke@435 456 #else
duke@435 457 address continuation = NULL;
duke@435 458 #endif
duke@435 459 address handler_pc = NULL;
duke@435 460 if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
duke@435 461 // Forward exception to callee (leaving bci/bcp untouched) because (a) no
duke@435 462 // handler in this method, or (b) after a stack overflow there is not yet
duke@435 463 // enough stack space available to reprotect the stack.
duke@435 464 #ifndef CC_INTERP
duke@435 465 continuation = Interpreter::remove_activation_entry();
duke@435 466 #endif
duke@435 467 // Count this for compilation purposes
duke@435 468 h_method->interpreter_throwout_increment();
duke@435 469 } else {
duke@435 470 // handler in this method => change bci/bcp to handler bci/bcp and continue there
duke@435 471 handler_pc = h_method->code_base() + handler_bci;
duke@435 472 #ifndef CC_INTERP
duke@435 473 set_bcp_and_mdp(handler_pc, thread);
duke@435 474 continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
duke@435 475 #endif
duke@435 476 }
duke@435 477 // notify debugger of an exception catch
duke@435 478 // (this is good for exceptions caught in native methods as well)
dcubed@1648 479 if (JvmtiExport::can_post_on_exceptions()) {
duke@435 480 JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
duke@435 481 }
duke@435 482
duke@435 483 thread->set_vm_result(h_exception());
duke@435 484 return continuation;
duke@435 485 IRT_END
duke@435 486
duke@435 487
duke@435 488 IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
duke@435 489 assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
duke@435 490 // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
duke@435 491 IRT_END
duke@435 492
duke@435 493
duke@435 494 IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
duke@435 495 THROW(vmSymbols::java_lang_AbstractMethodError());
duke@435 496 IRT_END
duke@435 497
duke@435 498
duke@435 499 IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
duke@435 500 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
duke@435 501 IRT_END
duke@435 502
duke@435 503
duke@435 504 //------------------------------------------------------------------------------------------------------------------------
duke@435 505 // Fields
duke@435 506 //
duke@435 507
duke@435 508 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
duke@435 509 // resolve field
duke@435 510 FieldAccessInfo info;
duke@435 511 constantPoolHandle pool(thread, method(thread)->constants());
duke@435 512 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
duke@435 513
duke@435 514 {
duke@435 515 JvmtiHideSingleStepping jhss(thread);
jrose@1920 516 LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode),
duke@435 517 bytecode, false, CHECK);
duke@435 518 } // end JvmtiHideSingleStepping
duke@435 519
duke@435 520 // check if link resolution caused cpCache to be updated
duke@435 521 if (already_resolved(thread)) return;
duke@435 522
duke@435 523 // compute auxiliary field attributes
duke@435 524 TosState state = as_TosState(info.field_type());
duke@435 525
duke@435 526 // We need to delay resolving put instructions on final fields
duke@435 527 // until we actually invoke one. This is required so we throw
duke@435 528 // exceptions at the correct place. If we do not resolve completely
duke@435 529 // in the current pass, leaving the put_code set to zero will
duke@435 530 // cause the next put instruction to reresolve.
duke@435 531 bool is_put = (bytecode == Bytecodes::_putfield ||
duke@435 532 bytecode == Bytecodes::_putstatic);
duke@435 533 Bytecodes::Code put_code = (Bytecodes::Code)0;
duke@435 534
duke@435 535 // We also need to delay resolving getstatic instructions until the
duke@435 536 // class is intitialized. This is required so that access to the static
duke@435 537 // field will call the initialization function every time until the class
duke@435 538 // is completely initialized ala. in 2.17.5 in JVM Specification.
duke@435 539 instanceKlass *klass = instanceKlass::cast(info.klass()->as_klassOop());
duke@435 540 bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
duke@435 541 !klass->is_initialized());
duke@435 542 Bytecodes::Code get_code = (Bytecodes::Code)0;
duke@435 543
duke@435 544
duke@435 545 if (!uninitialized_static) {
duke@435 546 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
duke@435 547 if (is_put || !info.access_flags().is_final()) {
duke@435 548 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
duke@435 549 }
duke@435 550 }
duke@435 551
duke@435 552 cache_entry(thread)->set_field(
duke@435 553 get_code,
duke@435 554 put_code,
duke@435 555 info.klass(),
duke@435 556 info.field_index(),
duke@435 557 info.field_offset(),
duke@435 558 state,
duke@435 559 info.access_flags().is_final(),
duke@435 560 info.access_flags().is_volatile()
duke@435 561 );
duke@435 562 IRT_END
duke@435 563
duke@435 564
duke@435 565 //------------------------------------------------------------------------------------------------------------------------
duke@435 566 // Synchronization
duke@435 567 //
duke@435 568 // The interpreter's synchronization code is factored out so that it can
duke@435 569 // be shared by method invocation and synchronized blocks.
duke@435 570 //%note synchronization_3
duke@435 571
duke@435 572 static void trace_locking(Handle& h_locking_obj, bool is_locking) {
duke@435 573 ObjectSynchronizer::trace_locking(h_locking_obj, false, true, is_locking);
duke@435 574 }
duke@435 575
duke@435 576
duke@435 577 //%note monitor_1
duke@435 578 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
duke@435 579 #ifdef ASSERT
duke@435 580 thread->last_frame().interpreter_frame_verify_monitor(elem);
duke@435 581 #endif
duke@435 582 if (PrintBiasedLockingStatistics) {
duke@435 583 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
duke@435 584 }
duke@435 585 Handle h_obj(thread, elem->obj());
duke@435 586 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
duke@435 587 "must be NULL or an object");
duke@435 588 if (UseBiasedLocking) {
duke@435 589 // Retry fast entry if bias is revoked to avoid unnecessary inflation
duke@435 590 ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
duke@435 591 } else {
duke@435 592 ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
duke@435 593 }
duke@435 594 assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
duke@435 595 "must be NULL or an object");
duke@435 596 #ifdef ASSERT
duke@435 597 thread->last_frame().interpreter_frame_verify_monitor(elem);
duke@435 598 #endif
duke@435 599 IRT_END
duke@435 600
duke@435 601
duke@435 602 //%note monitor_1
duke@435 603 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
duke@435 604 #ifdef ASSERT
duke@435 605 thread->last_frame().interpreter_frame_verify_monitor(elem);
duke@435 606 #endif
duke@435 607 Handle h_obj(thread, elem->obj());
duke@435 608 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
duke@435 609 "must be NULL or an object");
duke@435 610 if (elem == NULL || h_obj()->is_unlocked()) {
duke@435 611 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
duke@435 612 }
duke@435 613 ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
duke@435 614 // Free entry. This must be done here, since a pending exception might be installed on
duke@435 615 // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
duke@435 616 elem->set_obj(NULL);
duke@435 617 #ifdef ASSERT
duke@435 618 thread->last_frame().interpreter_frame_verify_monitor(elem);
duke@435 619 #endif
duke@435 620 IRT_END
duke@435 621
duke@435 622
duke@435 623 IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
duke@435 624 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
duke@435 625 IRT_END
duke@435 626
duke@435 627
duke@435 628 IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
duke@435 629 // Returns an illegal exception to install into the current thread. The
duke@435 630 // pending_exception flag is cleared so normal exception handling does not
duke@435 631 // trigger. Any current installed exception will be overwritten. This
duke@435 632 // method will be called during an exception unwind.
duke@435 633
duke@435 634 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
duke@435 635 Handle exception(thread, thread->vm_result());
duke@435 636 assert(exception() != NULL, "vm result should be set");
duke@435 637 thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
never@1577 638 if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
duke@435 639 exception = get_preinitialized_exception(
duke@435 640 SystemDictionary::IllegalMonitorStateException_klass(),
duke@435 641 CATCH);
duke@435 642 }
duke@435 643 thread->set_vm_result(exception());
duke@435 644 IRT_END
duke@435 645
duke@435 646
duke@435 647 //------------------------------------------------------------------------------------------------------------------------
duke@435 648 // Invokes
duke@435 649
duke@435 650 IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp))
duke@435 651 return method->orig_bytecode_at(method->bci_from(bcp));
duke@435 652 IRT_END
duke@435 653
duke@435 654 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code))
duke@435 655 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
duke@435 656 IRT_END
duke@435 657
duke@435 658 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp))
duke@435 659 JvmtiExport::post_raw_breakpoint(thread, method, bcp);
duke@435 660 IRT_END
duke@435 661
duke@435 662 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
duke@435 663 // extract receiver from the outgoing argument list if necessary
duke@435 664 Handle receiver(thread, NULL);
duke@435 665 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
duke@435 666 ResourceMark rm(thread);
duke@435 667 methodHandle m (thread, method(thread));
never@2462 668 Bytecode_invoke call(m, bci(thread));
coleenp@2497 669 Symbol* signature = call.signature();
duke@435 670 receiver = Handle(thread,
duke@435 671 thread->last_frame().interpreter_callee_receiver(signature));
duke@435 672 assert(Universe::heap()->is_in_reserved_or_null(receiver()),
duke@435 673 "sanity check");
duke@435 674 assert(receiver.is_null() ||
duke@435 675 Universe::heap()->is_in_reserved(receiver->klass()),
duke@435 676 "sanity check");
duke@435 677 }
duke@435 678
duke@435 679 // resolve method
duke@435 680 CallInfo info;
duke@435 681 constantPoolHandle pool(thread, method(thread)->constants());
duke@435 682
duke@435 683 {
duke@435 684 JvmtiHideSingleStepping jhss(thread);
duke@435 685 LinkResolver::resolve_invoke(info, receiver, pool,
jrose@1920 686 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
duke@435 687 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
duke@435 688 int retry_count = 0;
duke@435 689 while (info.resolved_method()->is_old()) {
duke@435 690 // It is very unlikely that method is redefined more than 100 times
duke@435 691 // in the middle of resolve. If it is looping here more than 100 times
duke@435 692 // means then there could be a bug here.
duke@435 693 guarantee((retry_count++ < 100),
duke@435 694 "Could not resolve to latest version of redefined method");
duke@435 695 // method is redefined in the middle of resolve so re-try.
duke@435 696 LinkResolver::resolve_invoke(info, receiver, pool,
jrose@1920 697 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
duke@435 698 }
duke@435 699 }
duke@435 700 } // end JvmtiHideSingleStepping
duke@435 701
duke@435 702 // check if link resolution caused cpCache to be updated
duke@435 703 if (already_resolved(thread)) return;
duke@435 704
duke@435 705 if (bytecode == Bytecodes::_invokeinterface) {
duke@435 706
duke@435 707 if (TraceItables && Verbose) {
duke@435 708 ResourceMark rm(thread);
duke@435 709 tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
duke@435 710 }
duke@435 711 if (info.resolved_method()->method_holder() ==
never@1577 712 SystemDictionary::Object_klass()) {
duke@435 713 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
duke@435 714 // (see also cpCacheOop.cpp for details)
duke@435 715 methodHandle rm = info.resolved_method();
duke@435 716 assert(rm->is_final() || info.has_vtable_index(),
duke@435 717 "should have been set already");
duke@435 718 cache_entry(thread)->set_method(bytecode, rm, info.vtable_index());
duke@435 719 } else {
duke@435 720 // Setup itable entry
duke@435 721 int index = klassItable::compute_itable_index(info.resolved_method()());
duke@435 722 cache_entry(thread)->set_interface_call(info.resolved_method(), index);
duke@435 723 }
duke@435 724 } else {
duke@435 725 cache_entry(thread)->set_method(
duke@435 726 bytecode,
duke@435 727 info.resolved_method(),
duke@435 728 info.vtable_index());
duke@435 729 }
duke@435 730 IRT_END
duke@435 731
duke@435 732
jrose@1494 733 // First time execution: Resolve symbols, create a permanent CallSite object.
jrose@1161 734 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
jrose@1161 735 ResourceMark rm(thread);
jrose@1161 736
jrose@1161 737 assert(EnableInvokeDynamic, "");
jrose@1161 738
jrose@1161 739 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
jrose@1161 740
jrose@1161 741 methodHandle caller_method(thread, method(thread));
jrose@1161 742
jrose@1161 743 constantPoolHandle pool(thread, caller_method->constants());
jrose@1161 744 pool->set_invokedynamic(); // mark header to flag active call sites
jrose@1161 745
jrose@1862 746 int caller_bci = 0;
jrose@1862 747 int site_index = 0;
jrose@1862 748 { address caller_bcp = bcp(thread);
jrose@1862 749 caller_bci = caller_method->bci_from(caller_bcp);
jrose@1862 750 site_index = Bytes::get_native_u4(caller_bcp+1);
jrose@1862 751 }
never@2462 752 assert(site_index == InterpreterRuntime::bytecode(thread).get_index_u4(bytecode), "");
jrose@1862 753 assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format");
jrose@1494 754 // there is a second CPC entries that is of interest; it caches signature info:
jrose@1494 755 int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index();
jrose@2268 756 int pool_index = pool->cache()->entry_at(main_index)->constant_pool_index();
jrose@1161 757
jrose@1161 758 // first resolve the signature to a MH.invoke methodOop
jrose@1161 759 if (!pool->cache()->entry_at(main_index)->is_resolved(bytecode)) {
jrose@1161 760 JvmtiHideSingleStepping jhss(thread);
twisti@2258 761 CallInfo callinfo;
twisti@2258 762 LinkResolver::resolve_invoke(callinfo, Handle(), pool,
jrose@1494 763 site_index, bytecode, CHECK);
jrose@2015 764 // The main entry corresponds to a JVM_CONSTANT_InvokeDynamic, and serves
jrose@1161 765 // as a common reference point for all invokedynamic call sites with
jrose@1161 766 // that exact call descriptor. We will link it in the CP cache exactly
jrose@1161 767 // as if it were an invokevirtual of MethodHandle.invoke.
jrose@1161 768 pool->cache()->entry_at(main_index)->set_method(
jrose@1161 769 bytecode,
twisti@2258 770 callinfo.resolved_method(),
twisti@2258 771 callinfo.vtable_index());
jrose@1161 772 }
jrose@1161 773
jrose@1161 774 // The method (f2 entry) of the main entry is the MH.invoke for the
jrose@1161 775 // invokedynamic target call signature.
jrose@2015 776 oop f1_value = pool->cache()->entry_at(main_index)->f1();
jrose@2015 777 methodHandle signature_invoker(THREAD, (methodOop) f1_value);
jrose@1862 778 assert(signature_invoker.not_null() && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
jrose@1161 779 "correct result from LinkResolver::resolve_invokedynamic");
jrose@1161 780
jrose@2268 781 Handle info; // optional argument(s) in JVM_CONSTANT_InvokeDynamic
jrose@2015 782 Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci,
jrose@2268 783 main_index, info, CHECK);
jrose@2639 784 if (!java_lang_invoke_MethodHandle::is_instance(bootm())) {
jrose@2015 785 THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
jrose@2015 786 "no bootstrap method found for invokedynamic");
jrose@2015 787 }
jrose@2015 788
jrose@2015 789 // Short circuit if CallSite has been bound already:
jrose@2015 790 if (!pool->cache()->secondary_entry_at(site_index)->is_f1_null())
jrose@2015 791 return;
jrose@2015 792
coleenp@2497 793 Symbol* call_site_name = pool->name_ref_at(site_index);
jrose@1862 794
jrose@1161 795 Handle call_site
jrose@1862 796 = SystemDictionary::make_dynamic_call_site(bootm,
jrose@1862 797 // Callee information:
jrose@1161 798 call_site_name,
jrose@1862 799 signature_invoker,
jrose@1862 800 info,
jrose@1862 801 // Caller information:
jrose@1862 802 caller_method,
jrose@1862 803 caller_bci,
jrose@1161 804 CHECK);
jrose@1161 805
jrose@1161 806 // In the secondary entry, the f1 field is the call site, and the f2 (index)
jrose@1862 807 // field is some data about the invoke site. Currently, it is just the BCI.
jrose@1862 808 // Later, it might be changed to help manage inlining dependencies.
jrose@1862 809 pool->cache()->secondary_entry_at(site_index)->set_dynamic_call(call_site, signature_invoker);
jrose@1161 810 }
jrose@1161 811 IRT_END
jrose@1161 812
jrose@1161 813
duke@435 814 //------------------------------------------------------------------------------------------------------------------------
duke@435 815 // Miscellaneous
duke@435 816
duke@435 817
ysr@1376 818 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
ysr@1376 819 nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
ysr@1376 820 assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
ysr@1376 821 if (branch_bcp != NULL && nm != NULL) {
ysr@1376 822 // This was a successful request for an OSR nmethod. Because
ysr@1376 823 // frequency_counter_overflow_inner ends with a safepoint check,
ysr@1376 824 // nm could have been unloaded so look it up again. It's unsafe
ysr@1376 825 // to examine nm directly since it might have been freed and used
ysr@1376 826 // for something else.
ysr@1376 827 frame fr = thread->last_frame();
ysr@1376 828 methodOop method = fr.interpreter_frame_method();
ysr@1376 829 int bci = method->bci_from(fr.interpreter_frame_bcp());
iveresov@2138 830 nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
ysr@1376 831 }
ysr@1376 832 return nm;
ysr@1376 833 }
ysr@1376 834
duke@435 835 IRT_ENTRY(nmethod*,
ysr@1376 836 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
duke@435 837 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
duke@435 838 // flag, in case this method triggers classloading which will call into Java.
duke@435 839 UnlockFlagSaver fs(thread);
duke@435 840
duke@435 841 frame fr = thread->last_frame();
duke@435 842 assert(fr.is_interpreted_frame(), "must come from interpreter");
duke@435 843 methodHandle method(thread, fr.interpreter_frame_method());
iveresov@2138 844 const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
iveresov@2138 845 const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
duke@435 846
iveresov@2988 847 nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
iveresov@2138 848
iveresov@2138 849 if (osr_nm != NULL) {
iveresov@2138 850 // We may need to do on-stack replacement which requires that no
iveresov@2138 851 // monitors in the activation are biased because their
iveresov@2138 852 // BasicObjectLocks will need to migrate during OSR. Force
iveresov@2138 853 // unbiasing of all monitors in the activation now (even though
iveresov@2138 854 // the OSR nmethod might be invalidated) because we don't have a
iveresov@2138 855 // safepoint opportunity later once the migration begins.
iveresov@2138 856 if (UseBiasedLocking) {
iveresov@2138 857 ResourceMark rm;
iveresov@2138 858 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
iveresov@2138 859 for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
iveresov@2138 860 kptr < fr.interpreter_frame_monitor_begin();
iveresov@2138 861 kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
iveresov@2138 862 if( kptr->obj() != NULL ) {
iveresov@2138 863 objects_to_revoke->append(Handle(THREAD, kptr->obj()));
iveresov@2138 864 }
duke@435 865 }
iveresov@2138 866 BiasedLocking::revoke(objects_to_revoke);
duke@435 867 }
duke@435 868 }
iveresov@2138 869 return osr_nm;
duke@435 870 IRT_END
duke@435 871
duke@435 872 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(methodOopDesc* method, address cur_bcp))
duke@435 873 assert(ProfileInterpreter, "must be profiling interpreter");
duke@435 874 int bci = method->bci_from(cur_bcp);
duke@435 875 methodDataOop mdo = method->method_data();
duke@435 876 if (mdo == NULL) return 0;
duke@435 877 return mdo->bci_to_di(bci);
duke@435 878 IRT_END
duke@435 879
iveresov@2438 880 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
duke@435 881 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
duke@435 882 // flag, in case this method triggers classloading which will call into Java.
duke@435 883 UnlockFlagSaver fs(thread);
duke@435 884
duke@435 885 assert(ProfileInterpreter, "must be profiling interpreter");
duke@435 886 frame fr = thread->last_frame();
duke@435 887 assert(fr.is_interpreted_frame(), "must come from interpreter");
duke@435 888 methodHandle method(thread, fr.interpreter_frame_method());
duke@435 889 methodOopDesc::build_interpreter_method_data(method, THREAD);
duke@435 890 if (HAS_PENDING_EXCEPTION) {
duke@435 891 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
duke@435 892 CLEAR_PENDING_EXCEPTION;
duke@435 893 // and fall through...
duke@435 894 }
duke@435 895 IRT_END
duke@435 896
duke@435 897
duke@435 898 #ifdef ASSERT
duke@435 899 IRT_LEAF(void, InterpreterRuntime::verify_mdp(methodOopDesc* method, address bcp, address mdp))
duke@435 900 assert(ProfileInterpreter, "must be profiling interpreter");
duke@435 901
duke@435 902 methodDataOop mdo = method->method_data();
duke@435 903 assert(mdo != NULL, "must not be null");
duke@435 904
duke@435 905 int bci = method->bci_from(bcp);
duke@435 906
duke@435 907 address mdp2 = mdo->bci_to_dp(bci);
duke@435 908 if (mdp != mdp2) {
duke@435 909 ResourceMark rm;
duke@435 910 ResetNoHandleMark rnm; // In a LEAF entry.
duke@435 911 HandleMark hm;
duke@435 912 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
duke@435 913 int current_di = mdo->dp_to_di(mdp);
duke@435 914 int expected_di = mdo->dp_to_di(mdp2);
duke@435 915 tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
duke@435 916 int expected_approx_bci = mdo->data_at(expected_di)->bci();
duke@435 917 int approx_bci = -1;
duke@435 918 if (current_di >= 0) {
duke@435 919 approx_bci = mdo->data_at(current_di)->bci();
duke@435 920 }
duke@435 921 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
duke@435 922 mdo->print_on(tty);
duke@435 923 method->print_codes();
duke@435 924 }
duke@435 925 assert(mdp == mdp2, "wrong mdp");
duke@435 926 IRT_END
duke@435 927 #endif // ASSERT
duke@435 928
duke@435 929 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
duke@435 930 assert(ProfileInterpreter, "must be profiling interpreter");
duke@435 931 ResourceMark rm(thread);
duke@435 932 HandleMark hm(thread);
duke@435 933 frame fr = thread->last_frame();
duke@435 934 assert(fr.is_interpreted_frame(), "must come from interpreter");
duke@435 935 methodDataHandle h_mdo(thread, fr.interpreter_frame_method()->method_data());
duke@435 936
duke@435 937 // Grab a lock to ensure atomic access to setting the return bci and
duke@435 938 // the displacement. This can block and GC, invalidating all naked oops.
duke@435 939 MutexLocker ml(RetData_lock);
duke@435 940
duke@435 941 // ProfileData is essentially a wrapper around a derived oop, so we
duke@435 942 // need to take the lock before making any ProfileData structures.
duke@435 943 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
duke@435 944 RetData* rdata = data->as_RetData();
duke@435 945 address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
duke@435 946 fr.interpreter_frame_set_mdp(new_mdp);
duke@435 947 IRT_END
duke@435 948
duke@435 949
duke@435 950 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
duke@435 951 // We used to need an explict preserve_arguments here for invoke bytecodes. However,
duke@435 952 // stack traversal automatically takes care of preserving arguments for invoke, so
duke@435 953 // this is no longer needed.
duke@435 954
duke@435 955 // IRT_END does an implicit safepoint check, hence we are guaranteed to block
duke@435 956 // if this is called during a safepoint
duke@435 957
duke@435 958 if (JvmtiExport::should_post_single_step()) {
duke@435 959 // We are called during regular safepoints and when the VM is
duke@435 960 // single stepping. If any thread is marked for single stepping,
duke@435 961 // then we may have JVMTI work to do.
duke@435 962 JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
duke@435 963 }
duke@435 964 IRT_END
duke@435 965
duke@435 966 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
duke@435 967 ConstantPoolCacheEntry *cp_entry))
duke@435 968
duke@435 969 // check the access_flags for the field in the klass
never@2658 970
never@2658 971 instanceKlass* ik = instanceKlass::cast(java_lang_Class::as_klassOop(cp_entry->f1()));
duke@435 972 typeArrayOop fields = ik->fields();
duke@435 973 int index = cp_entry->field_index();
duke@435 974 assert(index < fields->length(), "holders field index is out of range");
duke@435 975 // bail out if field accesses are not watched
duke@435 976 if ((fields->ushort_at(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
duke@435 977
duke@435 978 switch(cp_entry->flag_state()) {
duke@435 979 case btos: // fall through
duke@435 980 case ctos: // fall through
duke@435 981 case stos: // fall through
duke@435 982 case itos: // fall through
duke@435 983 case ftos: // fall through
duke@435 984 case ltos: // fall through
duke@435 985 case dtos: // fall through
duke@435 986 case atos: break;
duke@435 987 default: ShouldNotReachHere(); return;
duke@435 988 }
duke@435 989 bool is_static = (obj == NULL);
duke@435 990 HandleMark hm(thread);
duke@435 991
duke@435 992 Handle h_obj;
duke@435 993 if (!is_static) {
duke@435 994 // non-static field accessors have an object, but we need a handle
duke@435 995 h_obj = Handle(thread, obj);
duke@435 996 }
never@2658 997 instanceKlassHandle h_cp_entry_f1(thread, java_lang_Class::as_klassOop(cp_entry->f1()));
duke@435 998 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2(), is_static);
duke@435 999 JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
duke@435 1000 IRT_END
duke@435 1001
duke@435 1002 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
duke@435 1003 oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
duke@435 1004
never@2658 1005 klassOop k = java_lang_Class::as_klassOop(cp_entry->f1());
duke@435 1006
duke@435 1007 // check the access_flags for the field in the klass
duke@435 1008 instanceKlass* ik = instanceKlass::cast(k);
duke@435 1009 typeArrayOop fields = ik->fields();
duke@435 1010 int index = cp_entry->field_index();
duke@435 1011 assert(index < fields->length(), "holders field index is out of range");
duke@435 1012 // bail out if field modifications are not watched
duke@435 1013 if ((fields->ushort_at(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
duke@435 1014
duke@435 1015 char sig_type = '\0';
duke@435 1016
duke@435 1017 switch(cp_entry->flag_state()) {
duke@435 1018 case btos: sig_type = 'Z'; break;
duke@435 1019 case ctos: sig_type = 'C'; break;
duke@435 1020 case stos: sig_type = 'S'; break;
duke@435 1021 case itos: sig_type = 'I'; break;
duke@435 1022 case ftos: sig_type = 'F'; break;
duke@435 1023 case atos: sig_type = 'L'; break;
duke@435 1024 case ltos: sig_type = 'J'; break;
duke@435 1025 case dtos: sig_type = 'D'; break;
duke@435 1026 default: ShouldNotReachHere(); return;
duke@435 1027 }
duke@435 1028 bool is_static = (obj == NULL);
duke@435 1029
duke@435 1030 HandleMark hm(thread);
duke@435 1031 instanceKlassHandle h_klass(thread, k);
duke@435 1032 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2(), is_static);
duke@435 1033 jvalue fvalue;
duke@435 1034 #ifdef _LP64
duke@435 1035 fvalue = *value;
duke@435 1036 #else
duke@435 1037 // Long/double values are stored unaligned and also noncontiguously with
duke@435 1038 // tagged stacks. We can't just do a simple assignment even in the non-
duke@435 1039 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
duke@435 1040 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
duke@435 1041 // We assume that the two halves of longs/doubles are stored in interpreter
duke@435 1042 // stack slots in platform-endian order.
duke@435 1043 jlong_accessor u;
duke@435 1044 jint* newval = (jint*)value;
duke@435 1045 u.words[0] = newval[0];
twisti@1861 1046 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
duke@435 1047 fvalue.j = u.long_value;
duke@435 1048 #endif // _LP64
duke@435 1049
duke@435 1050 Handle h_obj;
duke@435 1051 if (!is_static) {
duke@435 1052 // non-static field accessors have an object, but we need a handle
duke@435 1053 h_obj = Handle(thread, obj);
duke@435 1054 }
duke@435 1055
duke@435 1056 JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
duke@435 1057 fid, sig_type, &fvalue);
duke@435 1058 IRT_END
duke@435 1059
duke@435 1060 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
duke@435 1061 JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
duke@435 1062 IRT_END
duke@435 1063
duke@435 1064
duke@435 1065 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
duke@435 1066 JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
duke@435 1067 IRT_END
duke@435 1068
duke@435 1069 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
duke@435 1070 {
duke@435 1071 return (Interpreter::contains(pc) ? 1 : 0);
duke@435 1072 }
duke@435 1073 IRT_END
duke@435 1074
duke@435 1075
duke@435 1076 // Implementation of SignatureHandlerLibrary
duke@435 1077
duke@435 1078 address SignatureHandlerLibrary::set_handler_blob() {
duke@435 1079 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
duke@435 1080 if (handler_blob == NULL) {
duke@435 1081 return NULL;
duke@435 1082 }
twisti@2103 1083 address handler = handler_blob->code_begin();
duke@435 1084 _handler_blob = handler_blob;
duke@435 1085 _handler = handler;
duke@435 1086 return handler;
duke@435 1087 }
duke@435 1088
duke@435 1089 void SignatureHandlerLibrary::initialize() {
duke@435 1090 if (_fingerprints != NULL) {
duke@435 1091 return;
duke@435 1092 }
duke@435 1093 if (set_handler_blob() == NULL) {
duke@435 1094 vm_exit_out_of_memory(blob_size, "native signature handlers");
duke@435 1095 }
duke@435 1096
duke@435 1097 BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
duke@435 1098 SignatureHandlerLibrary::buffer_size);
twisti@2103 1099 _buffer = bb->code_begin();
duke@435 1100
duke@435 1101 _fingerprints = new(ResourceObj::C_HEAP)GrowableArray<uint64_t>(32, true);
duke@435 1102 _handlers = new(ResourceObj::C_HEAP)GrowableArray<address>(32, true);
duke@435 1103 }
duke@435 1104
duke@435 1105 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
duke@435 1106 address handler = _handler;
twisti@2103 1107 int insts_size = buffer->pure_insts_size();
twisti@2103 1108 if (handler + insts_size > _handler_blob->code_end()) {
duke@435 1109 // get a new handler blob
duke@435 1110 handler = set_handler_blob();
duke@435 1111 }
duke@435 1112 if (handler != NULL) {
twisti@2103 1113 memcpy(handler, buffer->insts_begin(), insts_size);
duke@435 1114 pd_set_handler(handler);
twisti@2103 1115 ICache::invalidate_range(handler, insts_size);
twisti@2103 1116 _handler = handler + insts_size;
duke@435 1117 }
duke@435 1118 return handler;
duke@435 1119 }
duke@435 1120
duke@435 1121 void SignatureHandlerLibrary::add(methodHandle method) {
duke@435 1122 if (method->signature_handler() == NULL) {
duke@435 1123 // use slow signature handler if we can't do better
duke@435 1124 int handler_index = -1;
duke@435 1125 // check if we can use customized (fast) signature handler
duke@435 1126 if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
duke@435 1127 // use customized signature handler
duke@435 1128 MutexLocker mu(SignatureHandlerLibrary_lock);
duke@435 1129 // make sure data structure is initialized
duke@435 1130 initialize();
duke@435 1131 // lookup method signature's fingerprint
duke@435 1132 uint64_t fingerprint = Fingerprinter(method).fingerprint();
duke@435 1133 handler_index = _fingerprints->find(fingerprint);
duke@435 1134 // create handler if necessary
duke@435 1135 if (handler_index < 0) {
duke@435 1136 ResourceMark rm;
duke@435 1137 ptrdiff_t align_offset = (address)
duke@435 1138 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
duke@435 1139 CodeBuffer buffer((address)(_buffer + align_offset),
duke@435 1140 SignatureHandlerLibrary::buffer_size - align_offset);
duke@435 1141 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
duke@435 1142 // copy into code heap
duke@435 1143 address handler = set_handler(&buffer);
duke@435 1144 if (handler == NULL) {
duke@435 1145 // use slow signature handler
duke@435 1146 } else {
duke@435 1147 // debugging suppport
duke@435 1148 if (PrintSignatureHandlers) {
duke@435 1149 tty->cr();
duke@435 1150 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
duke@435 1151 _handlers->length(),
duke@435 1152 (method->is_static() ? "static" : "receiver"),
duke@435 1153 method->name_and_sig_as_C_string(),
duke@435 1154 fingerprint,
twisti@2103 1155 buffer.insts_size());
twisti@2103 1156 Disassembler::decode(handler, handler + buffer.insts_size());
duke@435 1157 #ifndef PRODUCT
duke@435 1158 tty->print_cr(" --- associated result handler ---");
duke@435 1159 address rh_begin = Interpreter::result_handler(method()->result_type());
duke@435 1160 address rh_end = rh_begin;
duke@435 1161 while (*(int*)rh_end != 0) {
duke@435 1162 rh_end += sizeof(int);
duke@435 1163 }
duke@435 1164 Disassembler::decode(rh_begin, rh_end);
duke@435 1165 #endif
duke@435 1166 }
duke@435 1167 // add handler to library
duke@435 1168 _fingerprints->append(fingerprint);
duke@435 1169 _handlers->append(handler);
duke@435 1170 // set handler index
duke@435 1171 assert(_fingerprints->length() == _handlers->length(), "sanity check");
duke@435 1172 handler_index = _fingerprints->length() - 1;
duke@435 1173 }
duke@435 1174 }
coleenp@2510 1175 // Set handler under SignatureHandlerLibrary_lock
duke@435 1176 if (handler_index < 0) {
duke@435 1177 // use generic signature handler
duke@435 1178 method->set_signature_handler(Interpreter::slow_signature_handler());
duke@435 1179 } else {
duke@435 1180 // set handler
duke@435 1181 method->set_signature_handler(_handlers->at(handler_index));
duke@435 1182 }
coleenp@2510 1183 } else {
coleenp@2510 1184 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
coleenp@2510 1185 // use generic signature handler
coleenp@2510 1186 method->set_signature_handler(Interpreter::slow_signature_handler());
coleenp@2510 1187 }
duke@435 1188 }
coleenp@2328 1189 #ifdef ASSERT
coleenp@2510 1190 int handler_index = -1;
coleenp@2510 1191 int fingerprint_index = -2;
coleenp@2328 1192 {
coleenp@2328 1193 // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
coleenp@2328 1194 // in any way if accessed from multiple threads. To avoid races with another
coleenp@2328 1195 // thread which may change the arrays in the above, mutex protected block, we
coleenp@2328 1196 // have to protect this read access here with the same mutex as well!
coleenp@2328 1197 MutexLocker mu(SignatureHandlerLibrary_lock);
coleenp@2510 1198 if (_handlers != NULL) {
coleenp@2328 1199 handler_index = _handlers->find(method->signature_handler());
coleenp@2328 1200 fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
coleenp@2328 1201 }
coleenp@2510 1202 }
duke@435 1203 assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
coleenp@2328 1204 handler_index == fingerprint_index, "sanity check");
coleenp@2510 1205 #endif // ASSERT
duke@435 1206 }
duke@435 1207
duke@435 1208
duke@435 1209 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;
duke@435 1210 address SignatureHandlerLibrary::_handler = NULL;
duke@435 1211 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
duke@435 1212 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;
duke@435 1213 address SignatureHandlerLibrary::_buffer = NULL;
duke@435 1214
duke@435 1215
duke@435 1216 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, methodOopDesc* method))
duke@435 1217 methodHandle m(thread, method);
duke@435 1218 assert(m->is_native(), "sanity check");
duke@435 1219 // lookup native function entry point if it doesn't exist
duke@435 1220 bool in_base_library;
duke@435 1221 if (!m->has_native_function()) {
duke@435 1222 NativeLookup::lookup(m, in_base_library, CHECK);
duke@435 1223 }
duke@435 1224 // make sure signature handler is installed
duke@435 1225 SignatureHandlerLibrary::add(m);
duke@435 1226 // The interpreter entry point checks the signature handler first,
duke@435 1227 // before trying to fetch the native entry point and klass mirror.
duke@435 1228 // We must set the signature handler last, so that multiple processors
duke@435 1229 // preparing the same method will be sure to see non-null entry & mirror.
duke@435 1230 IRT_END
duke@435 1231
duke@435 1232 #if defined(IA32) || defined(AMD64)
duke@435 1233 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
duke@435 1234 if (src_address == dest_address) {
duke@435 1235 return;
duke@435 1236 }
duke@435 1237 ResetNoHandleMark rnm; // In a LEAF entry.
duke@435 1238 HandleMark hm;
duke@435 1239 ResourceMark rm;
duke@435 1240 frame fr = thread->last_frame();
duke@435 1241 assert(fr.is_interpreted_frame(), "");
duke@435 1242 jint bci = fr.interpreter_frame_bci();
duke@435 1243 methodHandle mh(thread, fr.interpreter_frame_method());
never@2462 1244 Bytecode_invoke invoke(mh, bci);
never@2462 1245 ArgumentSizeComputer asc(invoke.signature());
never@2462 1246 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
kvn@1958 1247 Copy::conjoint_jbytes(src_address, dest_address,
twisti@1861 1248 size_of_arguments * Interpreter::stackElementSize);
duke@435 1249 IRT_END
duke@435 1250 #endif

mercurial