src/share/vm/interpreter/interpreterRuntime.cpp

Wed, 28 May 2008 21:06:24 -0700

author
coleenp
date
Wed, 28 May 2008 21:06:24 -0700
changeset 602
feeb96a45707
parent 435
a61af66fc99e
child 1145
e5b0439ef4ae
permissions
-rw-r--r--

6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
Summary: decouple set_klass() with zeroing the gap when compressed.
Reviewed-by: kvn, ysr, jrose

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

mercurial