aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "classfile/vmSymbols.hpp" aoqi@0: #include "compiler/compileBroker.hpp" aoqi@0: #include "compiler/disassembler.hpp" aoqi@0: #include "gc_interface/collectedHeap.hpp" aoqi@0: #include "interpreter/interpreter.hpp" aoqi@0: #include "interpreter/interpreterRuntime.hpp" aoqi@0: #include "interpreter/linkResolver.hpp" aoqi@0: #include "interpreter/templateTable.hpp" aoqi@0: #include "memory/oopFactory.hpp" aoqi@0: #include "memory/universe.inline.hpp" aoqi@0: #include "oops/constantPool.hpp" aoqi@0: #include "oops/instanceKlass.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "oops/objArrayKlass.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "oops/symbol.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "prims/nativeLookup.hpp" aoqi@0: #include "runtime/biasedLocking.hpp" aoqi@0: #include "runtime/compilationPolicy.hpp" aoqi@0: #include "runtime/deoptimization.hpp" aoqi@0: #include "runtime/fieldDescriptor.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/interfaceSupport.hpp" aoqi@0: #include "runtime/java.hpp" aoqi@0: #include "runtime/jfieldIDWorkaround.hpp" aoqi@0: #include "runtime/osThread.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/stubRoutines.hpp" aoqi@0: #include "runtime/synchronizer.hpp" aoqi@0: #include "runtime/threadCritical.hpp" aoqi@0: #include "utilities/events.hpp" aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "vm_version_x86.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "vm_version_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "vm_version_zero.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "vm_version_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "vm_version_ppc.hpp" aoqi@0: #endif aoqi@0: #ifdef COMPILER2 aoqi@0: #include "opto/runtime.hpp" aoqi@0: #endif aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: class UnlockFlagSaver { aoqi@0: private: aoqi@0: JavaThread* _thread; aoqi@0: bool _do_not_unlock; aoqi@0: public: aoqi@0: UnlockFlagSaver(JavaThread* t) { aoqi@0: _thread = t; aoqi@0: _do_not_unlock = t->do_not_unlock_if_synchronized(); aoqi@0: t->set_do_not_unlock_if_synchronized(false); aoqi@0: } aoqi@0: ~UnlockFlagSaver() { aoqi@0: _thread->set_do_not_unlock_if_synchronized(_do_not_unlock); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // State accessors aoqi@0: aoqi@0: void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) { aoqi@0: last_frame(thread).interpreter_frame_set_bcp(bcp); aoqi@0: if (ProfileInterpreter) { aoqi@0: // ProfileTraps uses MDOs independently of ProfileInterpreter. aoqi@0: // That is why we must check both ProfileInterpreter and mdo != NULL. aoqi@0: MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data(); aoqi@0: if (mdo != NULL) { aoqi@0: NEEDS_CLEANUP; aoqi@0: last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci())); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Constants aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide)) aoqi@0: // access constant pool aoqi@0: ConstantPool* pool = method(thread)->constants(); aoqi@0: int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc); aoqi@0: constantTag tag = pool->tag_at(index); aoqi@0: aoqi@0: assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call"); aoqi@0: Klass* klass = pool->klass_at(index, CHECK); aoqi@0: oop java_class = klass->java_mirror(); aoqi@0: thread->set_vm_result(java_class); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) { aoqi@0: assert(bytecode == Bytecodes::_fast_aldc || aoqi@0: bytecode == Bytecodes::_fast_aldc_w, "wrong bc"); aoqi@0: ResourceMark rm(thread); aoqi@0: methodHandle m (thread, method(thread)); aoqi@0: Bytecode_loadconstant ldc(m, bci(thread)); aoqi@0: oop result = ldc.resolve_constant(CHECK); aoqi@0: #ifdef ASSERT aoqi@0: { aoqi@0: // The bytecode wrappers aren't GC-safe so construct a new one aoqi@0: Bytecode_loadconstant ldc2(m, bci(thread)); aoqi@0: oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index()); aoqi@0: assert(result == coop, "expected result for assembly code"); aoqi@0: } aoqi@0: #endif aoqi@0: thread->set_vm_result(result); aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Allocation aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index)) aoqi@0: Klass* k_oop = pool->klass_at(index, CHECK); aoqi@0: instanceKlassHandle klass (THREAD, k_oop); aoqi@0: aoqi@0: // Make sure we are not instantiating an abstract klass aoqi@0: klass->check_valid_for_instantiation(true, CHECK); aoqi@0: aoqi@0: // Make sure klass is initialized aoqi@0: klass->initialize(CHECK); aoqi@0: aoqi@0: // At this point the class may not be fully initialized aoqi@0: // because of recursive initialization. If it is fully aoqi@0: // initialized & has_finalized is not set, we rewrite aoqi@0: // it into its fast version (Note: no locking is needed aoqi@0: // here since this is an atomic byte write and can be aoqi@0: // done more than once). aoqi@0: // aoqi@0: // Note: In case of classes with has_finalized we don't aoqi@0: // rewrite since that saves us an extra check in aoqi@0: // the fast version which then would call the aoqi@0: // slow version anyway (and do a call back into aoqi@0: // Java). aoqi@0: // If we have a breakpoint, then we don't rewrite aoqi@0: // because the _breakpoint bytecode would be lost. aoqi@0: oop obj = klass->allocate_instance(CHECK); aoqi@0: thread->set_vm_result(obj); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size)) aoqi@0: oop obj = oopFactory::new_typeArray(type, size, CHECK); aoqi@0: thread->set_vm_result(obj); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size)) aoqi@0: // Note: no oopHandle for pool & klass needed since they are not used aoqi@0: // anymore after new_objArray() and no GC can happen before. aoqi@0: // (This may have to change if this code changes!) aoqi@0: Klass* klass = pool->klass_at(index, CHECK); aoqi@0: objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK); aoqi@0: thread->set_vm_result(obj); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address)) aoqi@0: // We may want to pass in more arguments - could make this slightly faster aoqi@0: ConstantPool* constants = method(thread)->constants(); aoqi@0: int i = get_index_u2(thread, Bytecodes::_multianewarray); aoqi@0: Klass* klass = constants->klass_at(i, CHECK); aoqi@0: int nof_dims = number_of_dimensions(thread); aoqi@0: assert(klass->is_klass(), "not a class"); aoqi@0: assert(nof_dims >= 1, "multianewarray rank must be nonzero"); aoqi@0: aoqi@0: // We must create an array of jints to pass to multi_allocate. aoqi@0: ResourceMark rm(thread); aoqi@0: const int small_dims = 10; aoqi@0: jint dim_array[small_dims]; aoqi@0: jint *dims = &dim_array[0]; aoqi@0: if (nof_dims > small_dims) { aoqi@0: dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims); aoqi@0: } aoqi@0: for (int index = 0; index < nof_dims; index++) { aoqi@0: // offset from first_size_address is addressed as local[index] aoqi@0: int n = Interpreter::local_offset_in_bytes(index)/jintSize; aoqi@0: dims[index] = first_size_address[n]; aoqi@0: } aoqi@0: oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK); aoqi@0: thread->set_vm_result(obj); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) aoqi@0: assert(obj->is_oop(), "must be a valid oop"); aoqi@0: assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); aoqi@0: InstanceKlass::register_finalizer(instanceOop(obj), CHECK); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: // Quicken instance-of and check-cast bytecodes aoqi@0: IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread)) aoqi@0: // Force resolving; quicken the bytecode aoqi@0: int which = get_index_u2(thread, Bytecodes::_checkcast); aoqi@0: ConstantPool* cpool = method(thread)->constants(); aoqi@0: // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded aoqi@0: // program we might have seen an unquick'd bytecode in the interpreter but have another aoqi@0: // thread quicken the bytecode before we get here. aoqi@0: // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" ); aoqi@0: Klass* klass = cpool->klass_at(which, CHECK); aoqi@0: thread->set_vm_result_2(klass); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Exceptions aoqi@0: aoqi@0: void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason, aoqi@0: methodHandle trap_method, int trap_bci, TRAPS) { aoqi@0: if (trap_method.not_null()) { aoqi@0: MethodData* trap_mdo = trap_method->method_data(); aoqi@0: if (trap_mdo == NULL) { aoqi@0: Method::build_interpreter_method_data(trap_method, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), aoqi@0: "we expect only an OOM error here"); aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } aoqi@0: trap_mdo = trap_method->method_data(); aoqi@0: // and fall through... aoqi@0: } aoqi@0: if (trap_mdo != NULL) { aoqi@0: // Update per-method count of trap events. The interpreter aoqi@0: // is updating the MDO to simulate the effect of compiler traps. aoqi@0: Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Assume the compiler is (or will be) interested in this event. aoqi@0: // If necessary, create an MDO to hold the information, and record it. aoqi@0: void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) { aoqi@0: assert(ProfileTraps, "call me only if profiling"); aoqi@0: methodHandle trap_method(thread, method(thread)); aoqi@0: int trap_bci = trap_method->bci_from(bcp(thread)); aoqi@0: note_trap_inner(thread, reason, trap_method, trap_bci, THREAD); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: // As legacy note_trap, but we have more arguments. aoqi@0: IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci)) aoqi@0: methodHandle trap_method(method); aoqi@0: note_trap_inner(thread, reason, trap_method, trap_bci, THREAD); aoqi@0: IRT_END aoqi@0: aoqi@0: // Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper aoqi@0: // for each exception. aoqi@0: void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci) aoqi@0: { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); } aoqi@0: void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci) aoqi@0: { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); } aoqi@0: void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci) aoqi@0: { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); } aoqi@0: void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci) aoqi@0: { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); } aoqi@0: void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci) aoqi@0: { if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); } aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: aoqi@0: static Handle get_preinitialized_exception(Klass* k, TRAPS) { aoqi@0: // get klass aoqi@0: InstanceKlass* klass = InstanceKlass::cast(k); aoqi@0: assert(klass->is_initialized(), aoqi@0: "this klass should have been initialized during VM initialization"); aoqi@0: // create instance - do not call constructor since we may have no aoqi@0: // (java) stack space left (should assert constructor is empty) aoqi@0: Handle exception; aoqi@0: oop exception_oop = klass->allocate_instance(CHECK_(exception)); aoqi@0: exception = Handle(THREAD, exception_oop); aoqi@0: if (StackTraceInThrowable) { aoqi@0: java_lang_Throwable::fill_in_stack_trace(exception); aoqi@0: } aoqi@0: return exception; aoqi@0: } aoqi@0: aoqi@0: // Special handling for stack overflow: since we don't have any (java) stack aoqi@0: // space left we use the pre-allocated & pre-initialized StackOverflowError aoqi@0: // klass to create an stack overflow error instance. We do not call its aoqi@0: // constructor for the same reason (it is empty, anyway). aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread)) aoqi@0: Handle exception = get_preinitialized_exception( aoqi@0: SystemDictionary::StackOverflowError_klass(), aoqi@0: CHECK); aoqi@0: THROW_HANDLE(exception); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message)) aoqi@0: // lookup exception klass aoqi@0: TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); aoqi@0: if (ProfileTraps) { aoqi@0: if (s == vmSymbols::java_lang_ArithmeticException()) { aoqi@0: note_trap(thread, Deoptimization::Reason_div0_check, CHECK); aoqi@0: } else if (s == vmSymbols::java_lang_NullPointerException()) { aoqi@0: note_trap(thread, Deoptimization::Reason_null_check, CHECK); aoqi@0: } aoqi@0: } aoqi@0: // create exception aoqi@0: Handle exception = Exceptions::new_exception(thread, s, message); aoqi@0: thread->set_vm_result(exception()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj)) aoqi@0: ResourceMark rm(thread); aoqi@0: const char* klass_name = obj->klass()->external_name(); aoqi@0: // lookup exception klass aoqi@0: TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); aoqi@0: if (ProfileTraps) { aoqi@0: note_trap(thread, Deoptimization::Reason_class_check, CHECK); aoqi@0: } aoqi@0: // create exception, with klass name as detail message aoqi@0: Handle exception = Exceptions::new_exception(thread, s, klass_name); aoqi@0: thread->set_vm_result(exception()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index)) aoqi@0: char message[jintAsStringSize]; aoqi@0: // lookup exception klass aoqi@0: TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); aoqi@0: if (ProfileTraps) { aoqi@0: note_trap(thread, Deoptimization::Reason_range_check, CHECK); aoqi@0: } aoqi@0: // create exception aoqi@0: sprintf(message, "%d", index); aoqi@0: THROW_MSG(s, message); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException( aoqi@0: JavaThread* thread, oopDesc* obj)) aoqi@0: aoqi@0: ResourceMark rm(thread); aoqi@0: char* message = SharedRuntime::generate_class_cast_message( aoqi@0: thread, obj->klass()->external_name()); aoqi@0: aoqi@0: if (ProfileTraps) { aoqi@0: note_trap(thread, Deoptimization::Reason_class_check, CHECK); aoqi@0: } aoqi@0: aoqi@0: // create exception aoqi@0: THROW_MSG(vmSymbols::java_lang_ClassCastException(), message); aoqi@0: IRT_END aoqi@0: aoqi@0: // exception_handler_for_exception(...) returns the continuation address, aoqi@0: // the exception oop (via TLS) and sets the bci/bcp for the continuation. aoqi@0: // The exception oop is returned to make sure it is preserved over GC (it aoqi@0: // is only on the stack if the exception was thrown explicitly via athrow). aoqi@0: // During this operation, the expression stack contains the values for the aoqi@0: // bci where the exception happened. If the exception was propagated back aoqi@0: // from a call, the expression stack contains the values for the bci at the aoqi@0: // invoke w/o arguments (i.e., as if one were inside the call). aoqi@0: IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception)) aoqi@0: aoqi@0: Handle h_exception(thread, exception); aoqi@0: methodHandle h_method (thread, method(thread)); aoqi@0: constantPoolHandle h_constants(thread, h_method->constants()); aoqi@0: bool should_repeat; aoqi@0: int handler_bci; aoqi@0: int current_bci = bci(thread); aoqi@0: aoqi@0: // Need to do this check first since when _do_not_unlock_if_synchronized aoqi@0: // is set, we don't want to trigger any classloading which may make calls aoqi@0: // into java, or surprisingly find a matching exception handler for bci 0 aoqi@0: // since at this moment the method hasn't been "officially" entered yet. aoqi@0: if (thread->do_not_unlock_if_synchronized()) { aoqi@0: ResourceMark rm; aoqi@0: assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized"); aoqi@0: thread->set_vm_result(exception); aoqi@0: #ifdef CC_INTERP aoqi@0: return (address) -1; aoqi@0: #else aoqi@0: return Interpreter::remove_activation_entry(); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: do { aoqi@0: should_repeat = false; aoqi@0: aoqi@0: // assertions aoqi@0: #ifdef ASSERT aoqi@0: assert(h_exception.not_null(), "NULL exceptions should be handled by athrow"); aoqi@0: assert(h_exception->is_oop(), "just checking"); aoqi@0: // Check that exception is a subclass of Throwable, otherwise we have a VerifyError aoqi@0: if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) { aoqi@0: if (ExitVMOnVerifyError) vm_exit(-1); aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // tracing aoqi@0: if (TraceExceptions) { aoqi@0: ttyLocker ttyl; aoqi@0: ResourceMark rm(thread); aoqi@0: tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception()); aoqi@0: tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string()); aoqi@0: tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread); aoqi@0: } aoqi@0: // Don't go paging in something which won't be used. aoqi@0: // else if (extable->length() == 0) { aoqi@0: // // disabled for now - interpreter is not using shortcut yet aoqi@0: // // (shortcut is not to call runtime if we have no exception handlers) aoqi@0: // // warning("performance bug: should not call runtime if method has no exception handlers"); aoqi@0: // } aoqi@0: // for AbortVMOnException flag aoqi@0: NOT_PRODUCT(Exceptions::debug_check_abort(h_exception)); aoqi@0: aoqi@0: // exception handler lookup aoqi@0: KlassHandle h_klass(THREAD, h_exception->klass()); aoqi@0: handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: // We threw an exception while trying to find the exception handler. aoqi@0: // Transfer the new exception to the exception handle which will aoqi@0: // be set into thread local storage, and do another lookup for an aoqi@0: // exception handler for this exception, this time starting at the aoqi@0: // BCI of the exception handler which caused the exception to be aoqi@0: // thrown (bug 4307310). aoqi@0: h_exception = Handle(THREAD, PENDING_EXCEPTION); aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: if (handler_bci >= 0) { aoqi@0: current_bci = handler_bci; aoqi@0: should_repeat = true; aoqi@0: } aoqi@0: } aoqi@0: } while (should_repeat == true); aoqi@0: aoqi@0: // notify JVMTI of an exception throw; JVMTI will detect if this is a first aoqi@0: // time throw or a stack unwinding throw and accordingly notify the debugger aoqi@0: if (JvmtiExport::can_post_on_exceptions()) { aoqi@0: JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception()); aoqi@0: } aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: address continuation = (address)(intptr_t) handler_bci; aoqi@0: #else aoqi@0: address continuation = NULL; aoqi@0: #endif aoqi@0: address handler_pc = NULL; aoqi@0: if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) { aoqi@0: // Forward exception to callee (leaving bci/bcp untouched) because (a) no aoqi@0: // handler in this method, or (b) after a stack overflow there is not yet aoqi@0: // enough stack space available to reprotect the stack. aoqi@0: #ifndef CC_INTERP aoqi@0: continuation = Interpreter::remove_activation_entry(); aoqi@0: #endif aoqi@0: // Count this for compilation purposes aoqi@0: h_method->interpreter_throwout_increment(THREAD); aoqi@0: } else { aoqi@0: // handler in this method => change bci/bcp to handler bci/bcp and continue there aoqi@0: handler_pc = h_method->code_base() + handler_bci; aoqi@0: #ifndef CC_INTERP aoqi@0: set_bcp_and_mdp(handler_pc, thread); aoqi@0: continuation = Interpreter::dispatch_table(vtos)[*handler_pc]; aoqi@0: #endif aoqi@0: } aoqi@0: // notify debugger of an exception catch aoqi@0: // (this is good for exceptions caught in native methods as well) aoqi@0: if (JvmtiExport::can_post_on_exceptions()) { aoqi@0: JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL)); aoqi@0: } aoqi@0: aoqi@0: thread->set_vm_result(h_exception()); aoqi@0: return continuation; aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread)) aoqi@0: assert(thread->has_pending_exception(), "must only ne called if there's an exception pending"); aoqi@0: // nothing to do - eventually we should remove this code entirely (see comments @ call sites) aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread)) aoqi@0: THROW(vmSymbols::java_lang_AbstractMethodError()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread)) aoqi@0: THROW(vmSymbols::java_lang_IncompatibleClassChangeError()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Fields aoqi@0: // aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) aoqi@0: // resolve field aoqi@0: fieldDescriptor info; aoqi@0: constantPoolHandle pool(thread, method(thread)->constants()); aoqi@0: bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic); aoqi@0: bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); aoqi@0: aoqi@0: { aoqi@0: JvmtiHideSingleStepping jhss(thread); aoqi@0: LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode), aoqi@0: bytecode, CHECK); aoqi@0: } // end JvmtiHideSingleStepping aoqi@0: aoqi@0: // check if link resolution caused cpCache to be updated aoqi@0: if (already_resolved(thread)) return; aoqi@0: aoqi@0: // compute auxiliary field attributes aoqi@0: TosState state = as_TosState(info.field_type()); aoqi@0: aoqi@0: // We need to delay resolving put instructions on final fields aoqi@0: // until we actually invoke one. This is required so we throw aoqi@0: // exceptions at the correct place. If we do not resolve completely aoqi@0: // in the current pass, leaving the put_code set to zero will aoqi@0: // cause the next put instruction to reresolve. aoqi@0: Bytecodes::Code put_code = (Bytecodes::Code)0; aoqi@0: aoqi@0: // We also need to delay resolving getstatic instructions until the aoqi@0: // class is intitialized. This is required so that access to the static aoqi@0: // field will call the initialization function every time until the class aoqi@0: // is completely initialized ala. in 2.17.5 in JVM Specification. aoqi@0: InstanceKlass* klass = InstanceKlass::cast(info.field_holder()); aoqi@0: bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && aoqi@0: !klass->is_initialized()); aoqi@0: Bytecodes::Code get_code = (Bytecodes::Code)0; aoqi@0: aoqi@0: if (!uninitialized_static) { aoqi@0: get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield); aoqi@0: if (is_put || !info.access_flags().is_final()) { aoqi@0: put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: cache_entry(thread)->set_field( aoqi@0: get_code, aoqi@0: put_code, aoqi@0: info.field_holder(), aoqi@0: info.index(), aoqi@0: info.offset(), aoqi@0: state, aoqi@0: info.access_flags().is_final(), aoqi@0: info.access_flags().is_volatile(), aoqi@0: pool->pool_holder() aoqi@0: ); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Synchronization aoqi@0: // aoqi@0: // The interpreter's synchronization code is factored out so that it can aoqi@0: // be shared by method invocation and synchronized blocks. aoqi@0: //%note synchronization_3 aoqi@0: aoqi@0: //%note monitor_1 aoqi@0: IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem)) aoqi@0: #ifdef ASSERT aoqi@0: thread->last_frame().interpreter_frame_verify_monitor(elem); aoqi@0: #endif aoqi@0: if (PrintBiasedLockingStatistics) { aoqi@0: Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); aoqi@0: } aoqi@0: Handle h_obj(thread, elem->obj()); aoqi@0: assert(Universe::heap()->is_in_reserved_or_null(h_obj()), aoqi@0: "must be NULL or an object"); aoqi@0: if (UseBiasedLocking) { aoqi@0: // Retry fast entry if bias is revoked to avoid unnecessary inflation aoqi@0: ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK); aoqi@0: } else { aoqi@0: ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK); aoqi@0: } aoqi@0: assert(Universe::heap()->is_in_reserved_or_null(elem->obj()), aoqi@0: "must be NULL or an object"); aoqi@0: #ifdef ASSERT aoqi@0: thread->last_frame().interpreter_frame_verify_monitor(elem); aoqi@0: #endif aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //%note monitor_1 aoqi@0: IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem)) aoqi@0: #ifdef ASSERT aoqi@0: thread->last_frame().interpreter_frame_verify_monitor(elem); aoqi@0: #endif aoqi@0: Handle h_obj(thread, elem->obj()); aoqi@0: assert(Universe::heap()->is_in_reserved_or_null(h_obj()), aoqi@0: "must be NULL or an object"); aoqi@0: if (elem == NULL || h_obj()->is_unlocked()) { aoqi@0: THROW(vmSymbols::java_lang_IllegalMonitorStateException()); aoqi@0: } aoqi@0: ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread); aoqi@0: // Free entry. This must be done here, since a pending exception might be installed on aoqi@0: // exit. If it is not cleared, the exception handling code will try to unlock the monitor again. aoqi@0: elem->set_obj(NULL); aoqi@0: #ifdef ASSERT aoqi@0: thread->last_frame().interpreter_frame_verify_monitor(elem); aoqi@0: #endif aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread)) aoqi@0: THROW(vmSymbols::java_lang_IllegalMonitorStateException()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread)) aoqi@0: // Returns an illegal exception to install into the current thread. The aoqi@0: // pending_exception flag is cleared so normal exception handling does not aoqi@0: // trigger. Any current installed exception will be overwritten. This aoqi@0: // method will be called during an exception unwind. aoqi@0: aoqi@0: assert(!HAS_PENDING_EXCEPTION, "no pending exception"); aoqi@0: Handle exception(thread, thread->vm_result()); aoqi@0: assert(exception() != NULL, "vm result should be set"); aoqi@0: thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures) aoqi@0: if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) { aoqi@0: exception = get_preinitialized_exception( aoqi@0: SystemDictionary::IllegalMonitorStateException_klass(), aoqi@0: CATCH); aoqi@0: } aoqi@0: thread->set_vm_result(exception()); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Invokes aoqi@0: aoqi@0: IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp)) aoqi@0: return method->orig_bytecode_at(method->bci_from(bcp)); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code)) aoqi@0: method->set_orig_bytecode_at(method->bci_from(bcp), new_code); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp)) aoqi@0: JvmtiExport::post_raw_breakpoint(thread, method, bcp); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) { aoqi@0: // extract receiver from the outgoing argument list if necessary aoqi@0: Handle receiver(thread, NULL); aoqi@0: if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) { aoqi@0: ResourceMark rm(thread); aoqi@0: methodHandle m (thread, method(thread)); aoqi@0: Bytecode_invoke call(m, bci(thread)); aoqi@0: Symbol* signature = call.signature(); aoqi@0: receiver = Handle(thread, aoqi@0: thread->last_frame().interpreter_callee_receiver(signature)); aoqi@0: assert(Universe::heap()->is_in_reserved_or_null(receiver()), aoqi@0: "sanity check"); aoqi@0: assert(receiver.is_null() || aoqi@0: !Universe::heap()->is_in_reserved(receiver->klass()), aoqi@0: "sanity check"); aoqi@0: } aoqi@0: aoqi@0: // resolve method aoqi@0: CallInfo info; aoqi@0: constantPoolHandle pool(thread, method(thread)->constants()); aoqi@0: aoqi@0: { aoqi@0: JvmtiHideSingleStepping jhss(thread); aoqi@0: LinkResolver::resolve_invoke(info, receiver, pool, aoqi@0: get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); aoqi@0: if (JvmtiExport::can_hotswap_or_post_breakpoint()) { aoqi@0: int retry_count = 0; aoqi@0: while (info.resolved_method()->is_old()) { aoqi@0: // It is very unlikely that method is redefined more than 100 times aoqi@0: // in the middle of resolve. If it is looping here more than 100 times aoqi@0: // means then there could be a bug here. aoqi@0: guarantee((retry_count++ < 100), aoqi@0: "Could not resolve to latest version of redefined method"); aoqi@0: // method is redefined in the middle of resolve so re-try. aoqi@0: LinkResolver::resolve_invoke(info, receiver, pool, aoqi@0: get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); aoqi@0: } aoqi@0: } aoqi@0: } // end JvmtiHideSingleStepping aoqi@0: aoqi@0: // check if link resolution caused cpCache to be updated aoqi@0: if (already_resolved(thread)) return; aoqi@0: aoqi@0: if (bytecode == Bytecodes::_invokeinterface) { aoqi@0: if (TraceItables && Verbose) { aoqi@0: ResourceMark rm(thread); aoqi@0: tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); aoqi@0: } aoqi@0: } aoqi@0: #ifdef ASSERT aoqi@0: if (bytecode == Bytecodes::_invokeinterface) { aoqi@0: if (info.resolved_method()->method_holder() == aoqi@0: SystemDictionary::Object_klass()) { aoqi@0: // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec aoqi@0: // (see also CallInfo::set_interface for details) aoqi@0: assert(info.call_kind() == CallInfo::vtable_call || aoqi@0: info.call_kind() == CallInfo::direct_call, ""); aoqi@0: methodHandle rm = info.resolved_method(); aoqi@0: assert(rm->is_final() || info.has_vtable_index(), aoqi@0: "should have been set already"); aoqi@0: } else if (!info.resolved_method()->has_itable_index()) { aoqi@0: // Resolved something like CharSequence.toString. Use vtable not itable. aoqi@0: assert(info.call_kind() != CallInfo::itable_call, ""); aoqi@0: } else { aoqi@0: // Setup itable entry aoqi@0: assert(info.call_kind() == CallInfo::itable_call, ""); aoqi@0: int index = info.resolved_method()->itable_index(); aoqi@0: assert(info.itable_index() == index, ""); aoqi@0: } aoqi@0: } else { aoqi@0: assert(info.call_kind() == CallInfo::direct_call || aoqi@0: info.call_kind() == CallInfo::vtable_call, ""); aoqi@0: } aoqi@0: #endif aoqi@0: switch (info.call_kind()) { aoqi@0: case CallInfo::direct_call: aoqi@0: cache_entry(thread)->set_direct_call( aoqi@0: bytecode, aoqi@0: info.resolved_method()); aoqi@0: break; aoqi@0: case CallInfo::vtable_call: aoqi@0: cache_entry(thread)->set_vtable_call( aoqi@0: bytecode, aoqi@0: info.resolved_method(), aoqi@0: info.vtable_index()); aoqi@0: break; aoqi@0: case CallInfo::itable_call: aoqi@0: cache_entry(thread)->set_itable_call( aoqi@0: bytecode, aoqi@0: info.resolved_method(), aoqi@0: info.itable_index()); aoqi@0: break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: // First time execution: Resolve symbols, create a permanent MethodType object. aoqi@0: IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) { aoqi@0: assert(EnableInvokeDynamic, ""); aoqi@0: const Bytecodes::Code bytecode = Bytecodes::_invokehandle; aoqi@0: aoqi@0: // resolve method aoqi@0: CallInfo info; aoqi@0: constantPoolHandle pool(thread, method(thread)->constants()); aoqi@0: aoqi@0: { aoqi@0: JvmtiHideSingleStepping jhss(thread); aoqi@0: LinkResolver::resolve_invoke(info, Handle(), pool, aoqi@0: get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); aoqi@0: } // end JvmtiHideSingleStepping aoqi@0: aoqi@0: cache_entry(thread)->set_method_handle(pool, info); aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: // First time execution: Resolve symbols, create a permanent CallSite object. aoqi@0: IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) { aoqi@0: assert(EnableInvokeDynamic, ""); aoqi@0: const Bytecodes::Code bytecode = Bytecodes::_invokedynamic; aoqi@0: aoqi@0: //TO DO: consider passing BCI to Java. aoqi@0: // int caller_bci = method(thread)->bci_from(bcp(thread)); aoqi@0: aoqi@0: // resolve method aoqi@0: CallInfo info; aoqi@0: constantPoolHandle pool(thread, method(thread)->constants()); aoqi@0: int index = get_index_u4(thread, bytecode); aoqi@0: { aoqi@0: JvmtiHideSingleStepping jhss(thread); aoqi@0: LinkResolver::resolve_invoke(info, Handle(), pool, aoqi@0: index, bytecode, CHECK); aoqi@0: } // end JvmtiHideSingleStepping aoqi@0: aoqi@0: ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index); aoqi@0: cp_cache_entry->set_dynamic_call(pool, info); aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Miscellaneous aoqi@0: aoqi@0: aoqi@0: nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) { aoqi@0: nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp); aoqi@0: assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests"); aoqi@0: if (branch_bcp != NULL && nm != NULL) { aoqi@0: // This was a successful request for an OSR nmethod. Because aoqi@0: // frequency_counter_overflow_inner ends with a safepoint check, aoqi@0: // nm could have been unloaded so look it up again. It's unsafe aoqi@0: // to examine nm directly since it might have been freed and used aoqi@0: // for something else. aoqi@0: frame fr = thread->last_frame(); aoqi@0: Method* method = fr.interpreter_frame_method(); aoqi@0: int bci = method->bci_from(fr.interpreter_frame_bcp()); aoqi@0: nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false); aoqi@0: } aoqi@0: #ifndef PRODUCT aoqi@0: if (TraceOnStackReplacement) { aoqi@0: if (nm != NULL) { aoqi@0: tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry()); aoqi@0: nm->print(); aoqi@0: } aoqi@0: } aoqi@0: #endif aoqi@0: return nm; aoqi@0: } aoqi@0: aoqi@0: IRT_ENTRY(nmethod*, aoqi@0: InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp)) aoqi@0: // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized aoqi@0: // flag, in case this method triggers classloading which will call into Java. aoqi@0: UnlockFlagSaver fs(thread); aoqi@0: aoqi@0: frame fr = thread->last_frame(); aoqi@0: assert(fr.is_interpreted_frame(), "must come from interpreter"); aoqi@0: methodHandle method(thread, fr.interpreter_frame_method()); aoqi@0: const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci; aoqi@0: const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci; aoqi@0: aoqi@0: assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending"); aoqi@0: nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread); aoqi@0: assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions"); aoqi@0: aoqi@0: if (osr_nm != NULL) { aoqi@0: // We may need to do on-stack replacement which requires that no aoqi@0: // monitors in the activation are biased because their aoqi@0: // BasicObjectLocks will need to migrate during OSR. Force aoqi@0: // unbiasing of all monitors in the activation now (even though aoqi@0: // the OSR nmethod might be invalidated) because we don't have a aoqi@0: // safepoint opportunity later once the migration begins. aoqi@0: if (UseBiasedLocking) { aoqi@0: ResourceMark rm; aoqi@0: GrowableArray* objects_to_revoke = new GrowableArray(); aoqi@0: for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end(); aoqi@0: kptr < fr.interpreter_frame_monitor_begin(); aoqi@0: kptr = fr.next_monitor_in_interpreter_frame(kptr) ) { aoqi@0: if( kptr->obj() != NULL ) { aoqi@0: objects_to_revoke->append(Handle(THREAD, kptr->obj())); aoqi@0: } aoqi@0: } aoqi@0: BiasedLocking::revoke(objects_to_revoke); aoqi@0: } aoqi@0: } aoqi@0: return osr_nm; aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp)) aoqi@0: assert(ProfileInterpreter, "must be profiling interpreter"); aoqi@0: int bci = method->bci_from(cur_bcp); aoqi@0: MethodData* mdo = method->method_data(); aoqi@0: if (mdo == NULL) return 0; aoqi@0: return mdo->bci_to_di(bci); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread)) aoqi@0: // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized aoqi@0: // flag, in case this method triggers classloading which will call into Java. aoqi@0: UnlockFlagSaver fs(thread); aoqi@0: aoqi@0: assert(ProfileInterpreter, "must be profiling interpreter"); aoqi@0: frame fr = thread->last_frame(); aoqi@0: assert(fr.is_interpreted_frame(), "must come from interpreter"); aoqi@0: methodHandle method(thread, fr.interpreter_frame_method()); aoqi@0: Method::build_interpreter_method_data(method, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: // and fall through... aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp)) aoqi@0: assert(ProfileInterpreter, "must be profiling interpreter"); aoqi@0: aoqi@0: MethodData* mdo = method->method_data(); aoqi@0: assert(mdo != NULL, "must not be null"); aoqi@0: aoqi@0: int bci = method->bci_from(bcp); aoqi@0: aoqi@0: address mdp2 = mdo->bci_to_dp(bci); aoqi@0: if (mdp != mdp2) { aoqi@0: ResourceMark rm; aoqi@0: ResetNoHandleMark rnm; // In a LEAF entry. aoqi@0: HandleMark hm; aoqi@0: tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci); aoqi@0: int current_di = mdo->dp_to_di(mdp); aoqi@0: int expected_di = mdo->dp_to_di(mdp2); aoqi@0: tty->print_cr(" actual di %d expected di %d", current_di, expected_di); aoqi@0: int expected_approx_bci = mdo->data_at(expected_di)->bci(); aoqi@0: int approx_bci = -1; aoqi@0: if (current_di >= 0) { aoqi@0: approx_bci = mdo->data_at(current_di)->bci(); aoqi@0: } aoqi@0: tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci); aoqi@0: mdo->print_on(tty); aoqi@0: method->print_codes(); aoqi@0: } aoqi@0: assert(mdp == mdp2, "wrong mdp"); aoqi@0: IRT_END aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci)) aoqi@0: assert(ProfileInterpreter, "must be profiling interpreter"); aoqi@0: ResourceMark rm(thread); aoqi@0: HandleMark hm(thread); aoqi@0: frame fr = thread->last_frame(); aoqi@0: assert(fr.is_interpreted_frame(), "must come from interpreter"); aoqi@0: MethodData* h_mdo = fr.interpreter_frame_method()->method_data(); aoqi@0: aoqi@0: // Grab a lock to ensure atomic access to setting the return bci and aoqi@0: // the displacement. This can block and GC, invalidating all naked oops. aoqi@0: MutexLocker ml(RetData_lock); aoqi@0: aoqi@0: // ProfileData is essentially a wrapper around a derived oop, so we aoqi@0: // need to take the lock before making any ProfileData structures. aoqi@0: ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp())); aoqi@0: RetData* rdata = data->as_RetData(); aoqi@0: address new_mdp = rdata->fixup_ret(return_bci, h_mdo); aoqi@0: fr.interpreter_frame_set_mdp(new_mdp); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m)) aoqi@0: MethodCounters* mcs = Method::build_method_counters(m, thread); aoqi@0: if (HAS_PENDING_EXCEPTION) { aoqi@0: assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); aoqi@0: CLEAR_PENDING_EXCEPTION; aoqi@0: } aoqi@0: return mcs; aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread)) aoqi@0: // We used to need an explict preserve_arguments here for invoke bytecodes. However, aoqi@0: // stack traversal automatically takes care of preserving arguments for invoke, so aoqi@0: // this is no longer needed. aoqi@0: aoqi@0: // IRT_END does an implicit safepoint check, hence we are guaranteed to block aoqi@0: // if this is called during a safepoint aoqi@0: aoqi@0: if (JvmtiExport::should_post_single_step()) { aoqi@0: // We are called during regular safepoints and when the VM is aoqi@0: // single stepping. If any thread is marked for single stepping, aoqi@0: // then we may have JVMTI work to do. aoqi@0: JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread)); aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj, aoqi@0: ConstantPoolCacheEntry *cp_entry)) aoqi@0: aoqi@0: // check the access_flags for the field in the klass aoqi@0: aoqi@0: InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass()); aoqi@0: int index = cp_entry->field_index(); aoqi@0: if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return; aoqi@0: aoqi@0: switch(cp_entry->flag_state()) { aoqi@0: case btos: // fall through aoqi@0: case ctos: // fall through aoqi@0: case stos: // fall through aoqi@0: case itos: // fall through aoqi@0: case ftos: // fall through aoqi@0: case ltos: // fall through aoqi@0: case dtos: // fall through aoqi@0: case atos: break; aoqi@0: default: ShouldNotReachHere(); return; aoqi@0: } aoqi@0: bool is_static = (obj == NULL); aoqi@0: HandleMark hm(thread); aoqi@0: aoqi@0: Handle h_obj; aoqi@0: if (!is_static) { aoqi@0: // non-static field accessors have an object, but we need a handle aoqi@0: h_obj = Handle(thread, obj); aoqi@0: } aoqi@0: instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass()); aoqi@0: jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static); aoqi@0: JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread, aoqi@0: oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value)) aoqi@0: aoqi@0: Klass* k = (Klass*)cp_entry->f1_as_klass(); aoqi@0: aoqi@0: // check the access_flags for the field in the klass aoqi@0: InstanceKlass* ik = InstanceKlass::cast(k); aoqi@0: int index = cp_entry->field_index(); aoqi@0: // bail out if field modifications are not watched aoqi@0: if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return; aoqi@0: aoqi@0: char sig_type = '\0'; aoqi@0: aoqi@0: switch(cp_entry->flag_state()) { aoqi@0: case btos: sig_type = 'Z'; break; aoqi@0: case ctos: sig_type = 'C'; break; aoqi@0: case stos: sig_type = 'S'; break; aoqi@0: case itos: sig_type = 'I'; break; aoqi@0: case ftos: sig_type = 'F'; break; aoqi@0: case atos: sig_type = 'L'; break; aoqi@0: case ltos: sig_type = 'J'; break; aoqi@0: case dtos: sig_type = 'D'; break; aoqi@0: default: ShouldNotReachHere(); return; aoqi@0: } aoqi@0: bool is_static = (obj == NULL); aoqi@0: aoqi@0: HandleMark hm(thread); aoqi@0: instanceKlassHandle h_klass(thread, k); aoqi@0: jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static); aoqi@0: jvalue fvalue; aoqi@0: #ifdef _LP64 aoqi@0: fvalue = *value; aoqi@0: #else aoqi@0: // Long/double values are stored unaligned and also noncontiguously with aoqi@0: // tagged stacks. We can't just do a simple assignment even in the non- aoqi@0: // J/D cases because a C++ compiler is allowed to assume that a jvalue is aoqi@0: // 8-byte aligned, and interpreter stack slots are only 4-byte aligned. aoqi@0: // We assume that the two halves of longs/doubles are stored in interpreter aoqi@0: // stack slots in platform-endian order. aoqi@0: jlong_accessor u; aoqi@0: jint* newval = (jint*)value; aoqi@0: u.words[0] = newval[0]; aoqi@0: u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag aoqi@0: fvalue.j = u.long_value; aoqi@0: #endif // _LP64 aoqi@0: aoqi@0: Handle h_obj; aoqi@0: if (!is_static) { aoqi@0: // non-static field accessors have an object, but we need a handle aoqi@0: h_obj = Handle(thread, obj); aoqi@0: } aoqi@0: aoqi@0: JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj, aoqi@0: fid, sig_type, &fvalue); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread)) aoqi@0: JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread)) aoqi@0: JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); aoqi@0: IRT_END aoqi@0: aoqi@0: IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc)) aoqi@0: { aoqi@0: return (Interpreter::contains(pc) ? 1 : 0); aoqi@0: } aoqi@0: IRT_END aoqi@0: aoqi@0: aoqi@0: // Implementation of SignatureHandlerLibrary aoqi@0: aoqi@0: address SignatureHandlerLibrary::set_handler_blob() { aoqi@0: BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size); aoqi@0: if (handler_blob == NULL) { aoqi@0: return NULL; aoqi@0: } aoqi@0: address handler = handler_blob->code_begin(); aoqi@0: _handler_blob = handler_blob; aoqi@0: _handler = handler; aoqi@0: return handler; aoqi@0: } aoqi@0: aoqi@0: void SignatureHandlerLibrary::initialize() { aoqi@0: if (_fingerprints != NULL) { aoqi@0: return; aoqi@0: } aoqi@0: if (set_handler_blob() == NULL) { aoqi@0: vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers"); aoqi@0: } aoqi@0: aoqi@0: BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer", aoqi@0: SignatureHandlerLibrary::buffer_size); aoqi@0: _buffer = bb->code_begin(); aoqi@0: aoqi@0: _fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray(32, true); aoqi@0: _handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray
(32, true); aoqi@0: } aoqi@0: aoqi@0: address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) { aoqi@0: address handler = _handler; aoqi@0: int insts_size = buffer->pure_insts_size(); aoqi@0: if (handler + insts_size > _handler_blob->code_end()) { aoqi@0: // get a new handler blob aoqi@0: handler = set_handler_blob(); aoqi@0: } aoqi@0: if (handler != NULL) { aoqi@0: memcpy(handler, buffer->insts_begin(), insts_size); aoqi@0: pd_set_handler(handler); aoqi@0: ICache::invalidate_range(handler, insts_size); aoqi@0: _handler = handler + insts_size; aoqi@0: } aoqi@0: return handler; aoqi@0: } aoqi@0: aoqi@0: void SignatureHandlerLibrary::add(methodHandle method) { aoqi@0: if (method->signature_handler() == NULL) { aoqi@0: // use slow signature handler if we can't do better aoqi@0: int handler_index = -1; aoqi@0: // check if we can use customized (fast) signature handler aoqi@0: if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { aoqi@0: // use customized signature handler aoqi@0: MutexLocker mu(SignatureHandlerLibrary_lock); aoqi@0: // make sure data structure is initialized aoqi@0: initialize(); aoqi@0: // lookup method signature's fingerprint aoqi@0: uint64_t fingerprint = Fingerprinter(method).fingerprint(); aoqi@0: handler_index = _fingerprints->find(fingerprint); aoqi@0: // create handler if necessary aoqi@0: if (handler_index < 0) { aoqi@0: ResourceMark rm; aoqi@0: ptrdiff_t align_offset = (address) aoqi@0: round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; aoqi@0: CodeBuffer buffer((address)(_buffer + align_offset), aoqi@0: SignatureHandlerLibrary::buffer_size - align_offset); aoqi@0: InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); aoqi@0: // copy into code heap aoqi@0: address handler = set_handler(&buffer); aoqi@0: if (handler == NULL) { aoqi@0: // use slow signature handler aoqi@0: } else { aoqi@0: // debugging suppport aoqi@0: if (PrintSignatureHandlers) { aoqi@0: tty->cr(); aoqi@0: tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", aoqi@0: _handlers->length(), aoqi@0: (method->is_static() ? "static" : "receiver"), aoqi@0: method->name_and_sig_as_C_string(), aoqi@0: fingerprint, aoqi@0: buffer.insts_size()); aoqi@0: Disassembler::decode(handler, handler + buffer.insts_size()); aoqi@0: #ifndef PRODUCT aoqi@0: tty->print_cr(" --- associated result handler ---"); aoqi@0: address rh_begin = Interpreter::result_handler(method()->result_type()); aoqi@0: address rh_end = rh_begin; aoqi@0: while (*(int*)rh_end != 0) { aoqi@0: rh_end += sizeof(int); aoqi@0: } aoqi@0: Disassembler::decode(rh_begin, rh_end); aoqi@0: #endif aoqi@0: } aoqi@0: // add handler to library aoqi@0: _fingerprints->append(fingerprint); aoqi@0: _handlers->append(handler); aoqi@0: // set handler index aoqi@0: assert(_fingerprints->length() == _handlers->length(), "sanity check"); aoqi@0: handler_index = _fingerprints->length() - 1; aoqi@0: } aoqi@0: } aoqi@0: // Set handler under SignatureHandlerLibrary_lock aoqi@0: if (handler_index < 0) { aoqi@0: // use generic signature handler aoqi@0: method->set_signature_handler(Interpreter::slow_signature_handler()); aoqi@0: } else { aoqi@0: // set handler aoqi@0: method->set_signature_handler(_handlers->at(handler_index)); aoqi@0: } aoqi@0: } else { aoqi@0: CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); aoqi@0: // use generic signature handler aoqi@0: method->set_signature_handler(Interpreter::slow_signature_handler()); aoqi@0: } aoqi@0: } aoqi@0: #ifdef ASSERT aoqi@0: int handler_index = -1; aoqi@0: int fingerprint_index = -2; aoqi@0: { aoqi@0: // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized aoqi@0: // in any way if accessed from multiple threads. To avoid races with another aoqi@0: // thread which may change the arrays in the above, mutex protected block, we aoqi@0: // have to protect this read access here with the same mutex as well! aoqi@0: MutexLocker mu(SignatureHandlerLibrary_lock); aoqi@0: if (_handlers != NULL) { aoqi@0: handler_index = _handlers->find(method->signature_handler()); aoqi@0: fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint()); aoqi@0: } aoqi@0: } aoqi@0: assert(method->signature_handler() == Interpreter::slow_signature_handler() || aoqi@0: handler_index == fingerprint_index, "sanity check"); aoqi@0: #endif // ASSERT aoqi@0: } aoqi@0: aoqi@0: aoqi@0: BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; aoqi@0: address SignatureHandlerLibrary::_handler = NULL; aoqi@0: GrowableArray* SignatureHandlerLibrary::_fingerprints = NULL; aoqi@0: GrowableArray
* SignatureHandlerLibrary::_handlers = NULL; aoqi@0: address SignatureHandlerLibrary::_buffer = NULL; aoqi@0: aoqi@0: aoqi@0: IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method)) aoqi@0: methodHandle m(thread, method); aoqi@0: assert(m->is_native(), "sanity check"); aoqi@0: // lookup native function entry point if it doesn't exist aoqi@0: bool in_base_library; aoqi@0: if (!m->has_native_function()) { aoqi@0: NativeLookup::lookup(m, in_base_library, CHECK); aoqi@0: } aoqi@0: // make sure signature handler is installed aoqi@0: SignatureHandlerLibrary::add(m); aoqi@0: // The interpreter entry point checks the signature handler first, aoqi@0: // before trying to fetch the native entry point and klass mirror. aoqi@0: // We must set the signature handler last, so that multiple processors aoqi@0: // preparing the same method will be sure to see non-null entry & mirror. aoqi@0: IRT_END aoqi@0: aoqi@0: #if defined(IA32) || defined(AMD64) || defined(ARM) aoqi@0: IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address)) aoqi@0: if (src_address == dest_address) { aoqi@0: return; aoqi@0: } aoqi@0: ResetNoHandleMark rnm; // In a LEAF entry. aoqi@0: HandleMark hm; aoqi@0: ResourceMark rm; aoqi@0: frame fr = thread->last_frame(); aoqi@0: assert(fr.is_interpreted_frame(), ""); aoqi@0: jint bci = fr.interpreter_frame_bci(); aoqi@0: methodHandle mh(thread, fr.interpreter_frame_method()); aoqi@0: Bytecode_invoke invoke(mh, bci); aoqi@0: ArgumentSizeComputer asc(invoke.signature()); aoqi@0: int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver aoqi@0: Copy::conjoint_jbytes(src_address, dest_address, aoqi@0: size_of_arguments * Interpreter::stackElementSize); aoqi@0: IRT_END aoqi@0: #endif aoqi@0: aoqi@0: #if INCLUDE_JVMTI aoqi@0: // This is a support of the JVMTI PopFrame interface. aoqi@0: // Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument aoqi@0: // and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters. aoqi@0: // The dmh argument is a reference to a DirectMethoHandle that has a member name field. aoqi@0: IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address dmh, aoqi@0: Method* method, address bcp)) aoqi@0: Bytecodes::Code code = Bytecodes::code_at(method, bcp); aoqi@0: if (code != Bytecodes::_invokestatic) { aoqi@0: return; aoqi@0: } aoqi@0: ConstantPool* cpool = method->constants(); aoqi@0: int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG; aoqi@0: Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index)); aoqi@0: Symbol* mname = cpool->name_ref_at(cp_index); aoqi@0: aoqi@0: if (MethodHandles::has_member_arg(cname, mname)) { aoqi@0: oop member_name = java_lang_invoke_DirectMethodHandle::member((oop)dmh); aoqi@0: thread->set_vm_result(member_name); aoqi@0: } aoqi@0: IRT_END aoqi@0: #endif // INCLUDE_JVMTI