|
Java example source code file (interpreterRuntime.cpp)
The interpreterRuntime.cpp Java example source code/* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" #include "compiler/compileBroker.hpp" #include "compiler/disassembler.hpp" #include "gc_interface/collectedHeap.hpp" #include "interpreter/interpreter.hpp" #include "interpreter/interpreterRuntime.hpp" #include "interpreter/linkResolver.hpp" #include "interpreter/templateTable.hpp" #include "memory/oopFactory.hpp" #include "memory/universe.inline.hpp" #include "oops/constantPool.hpp" #include "oops/instanceKlass.hpp" #include "oops/methodData.hpp" #include "oops/objArrayKlass.hpp" #include "oops/oop.inline.hpp" #include "oops/symbol.hpp" #include "prims/jvmtiExport.hpp" #include "prims/nativeLookup.hpp" #include "runtime/biasedLocking.hpp" #include "runtime/compilationPolicy.hpp" #include "runtime/deoptimization.hpp" #include "runtime/fieldDescriptor.hpp" #include "runtime/handles.inline.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/jfieldIDWorkaround.hpp" #include "runtime/osThread.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" #include "runtime/threadCritical.hpp" #include "utilities/events.hpp" #ifdef TARGET_ARCH_x86 # include "vm_version_x86.hpp" #endif #ifdef TARGET_ARCH_sparc # include "vm_version_sparc.hpp" #endif #ifdef TARGET_ARCH_zero # include "vm_version_zero.hpp" #endif #ifdef TARGET_ARCH_arm # include "vm_version_arm.hpp" #endif #ifdef TARGET_ARCH_ppc # include "vm_version_ppc.hpp" #endif #ifdef COMPILER2 #include "opto/runtime.hpp" #endif class UnlockFlagSaver { private: JavaThread* _thread; bool _do_not_unlock; public: UnlockFlagSaver(JavaThread* t) { _thread = t; _do_not_unlock = t->do_not_unlock_if_synchronized(); t->set_do_not_unlock_if_synchronized(false); } ~UnlockFlagSaver() { _thread->set_do_not_unlock_if_synchronized(_do_not_unlock); } }; //------------------------------------------------------------------------------------------------------------------------ // State accessors void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) { last_frame(thread).interpreter_frame_set_bcp(bcp); if (ProfileInterpreter) { // ProfileTraps uses MDOs independently of ProfileInterpreter. // That is why we must check both ProfileInterpreter and mdo != NULL. MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data(); if (mdo != NULL) { NEEDS_CLEANUP; last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci())); } } } //------------------------------------------------------------------------------------------------------------------------ // Constants IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide)) // access constant pool ConstantPool* pool = method(thread)->constants(); int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc); constantTag tag = pool->tag_at(index); assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call"); Klass* klass = pool->klass_at(index, CHECK); oop java_class = klass->java_mirror(); thread->set_vm_result(java_class); IRT_END IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) { assert(bytecode == Bytecodes::_fast_aldc || bytecode == Bytecodes::_fast_aldc_w, "wrong bc"); ResourceMark rm(thread); methodHandle m (thread, method(thread)); Bytecode_loadconstant ldc(m, bci(thread)); oop result = ldc.resolve_constant(CHECK); #ifdef ASSERT { // The bytecode wrappers aren't GC-safe so construct a new one Bytecode_loadconstant ldc2(m, bci(thread)); oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index()); assert(result == coop, "expected result for assembly code"); } #endif thread->set_vm_result(result); } IRT_END //------------------------------------------------------------------------------------------------------------------------ // Allocation IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index)) Klass* k_oop = pool->klass_at(index, CHECK); instanceKlassHandle klass (THREAD, k_oop); // Make sure we are not instantiating an abstract klass klass->check_valid_for_instantiation(true, CHECK); // Make sure klass is initialized klass->initialize(CHECK); // At this point the class may not be fully initialized // because of recursive initialization. If it is fully // initialized & has_finalized is not set, we rewrite // it into its fast version (Note: no locking is needed // here since this is an atomic byte write and can be // done more than once). // // Note: In case of classes with has_finalized we don't // rewrite since that saves us an extra check in // the fast version which then would call the // slow version anyway (and do a call back into // Java). // If we have a breakpoint, then we don't rewrite // because the _breakpoint bytecode would be lost. oop obj = klass->allocate_instance(CHECK); thread->set_vm_result(obj); IRT_END IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size)) oop obj = oopFactory::new_typeArray(type, size, CHECK); thread->set_vm_result(obj); IRT_END IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size)) // Note: no oopHandle for pool & klass needed since they are not used // anymore after new_objArray() and no GC can happen before. // (This may have to change if this code changes!) Klass* klass = pool->klass_at(index, CHECK); objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK); thread->set_vm_result(obj); IRT_END IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address)) // We may want to pass in more arguments - could make this slightly faster ConstantPool* constants = method(thread)->constants(); int i = get_index_u2(thread, Bytecodes::_multianewarray); Klass* klass = constants->klass_at(i, CHECK); int nof_dims = number_of_dimensions(thread); assert(klass->is_klass(), "not a class"); assert(nof_dims >= 1, "multianewarray rank must be nonzero"); // We must create an array of jints to pass to multi_allocate. ResourceMark rm(thread); const int small_dims = 10; jint dim_array[small_dims]; jint *dims = &dim_array[0]; if (nof_dims > small_dims) { dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims); } for (int index = 0; index < nof_dims; index++) { // offset from first_size_address is addressed as local[index] int n = Interpreter::local_offset_in_bytes(index)/jintSize; dims[index] = first_size_address[n]; } oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK); thread->set_vm_result(obj); IRT_END IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) assert(obj->is_oop(), "must be a valid oop"); assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise"); InstanceKlass::register_finalizer(instanceOop(obj), CHECK); IRT_END // Quicken instance-of and check-cast bytecodes IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread)) // Force resolving; quicken the bytecode int which = get_index_u2(thread, Bytecodes::_checkcast); ConstantPool* cpool = method(thread)->constants(); // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded // program we might have seen an unquick'd bytecode in the interpreter but have another // thread quicken the bytecode before we get here. // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" ); Klass* klass = cpool->klass_at(which, CHECK); thread->set_vm_result_2(klass); IRT_END //------------------------------------------------------------------------------------------------------------------------ // Exceptions // Assume the compiler is (or will be) interested in this event. // If necessary, create an MDO to hold the information, and record it. void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) { assert(ProfileTraps, "call me only if profiling"); methodHandle trap_method(thread, method(thread)); if (trap_method.not_null()) { MethodData* trap_mdo = trap_method->method_data(); if (trap_mdo == NULL) { Method::build_interpreter_method_data(trap_method, THREAD); if (HAS_PENDING_EXCEPTION) { assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); CLEAR_PENDING_EXCEPTION; } trap_mdo = trap_method->method_data(); // and fall through... } if (trap_mdo != NULL) { // Update per-method count of trap events. The interpreter // is updating the MDO to simulate the effect of compiler traps. int trap_bci = trap_method->bci_from(bcp(thread)); Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason); } } } static Handle get_preinitialized_exception(Klass* k, TRAPS) { // get klass InstanceKlass* klass = InstanceKlass::cast(k); assert(klass->is_initialized(), "this klass should have been initialized during VM initialization"); // create instance - do not call constructor since we may have no // (java) stack space left (should assert constructor is empty) Handle exception; oop exception_oop = klass->allocate_instance(CHECK_(exception)); exception = Handle(THREAD, exception_oop); if (StackTraceInThrowable) { java_lang_Throwable::fill_in_stack_trace(exception); } return exception; } // Special handling for stack overflow: since we don't have any (java) stack // space left we use the pre-allocated & pre-initialized StackOverflowError // klass to create an stack overflow error instance. We do not call its // constructor for the same reason (it is empty, anyway). IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread)) Handle exception = get_preinitialized_exception( SystemDictionary::StackOverflowError_klass(), CHECK); THROW_HANDLE(exception); IRT_END IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message)) // lookup exception klass TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); if (ProfileTraps) { if (s == vmSymbols::java_lang_ArithmeticException()) { note_trap(thread, Deoptimization::Reason_div0_check, CHECK); } else if (s == vmSymbols::java_lang_NullPointerException()) { note_trap(thread, Deoptimization::Reason_null_check, CHECK); } } // create exception Handle exception = Exceptions::new_exception(thread, s, message); thread->set_vm_result(exception()); IRT_END IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj)) ResourceMark rm(thread); const char* klass_name = obj->klass()->external_name(); // lookup exception klass TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); if (ProfileTraps) { note_trap(thread, Deoptimization::Reason_class_check, CHECK); } // create exception, with klass name as detail message Handle exception = Exceptions::new_exception(thread, s, klass_name); thread->set_vm_result(exception()); IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index)) char message[jintAsStringSize]; // lookup exception klass TempNewSymbol s = SymbolTable::new_symbol(name, CHECK); if (ProfileTraps) { note_trap(thread, Deoptimization::Reason_range_check, CHECK); } // create exception sprintf(message, "%d", index); THROW_MSG(s, message); IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException( JavaThread* thread, oopDesc* obj)) ResourceMark rm(thread); char* message = SharedRuntime::generate_class_cast_message( thread, obj->klass()->external_name()); if (ProfileTraps) { note_trap(thread, Deoptimization::Reason_class_check, CHECK); } // create exception THROW_MSG(vmSymbols::java_lang_ClassCastException(), message); IRT_END // exception_handler_for_exception(...) returns the continuation address, // the exception oop (via TLS) and sets the bci/bcp for the continuation. // The exception oop is returned to make sure it is preserved over GC (it // is only on the stack if the exception was thrown explicitly via athrow). // During this operation, the expression stack contains the values for the // bci where the exception happened. If the exception was propagated back // from a call, the expression stack contains the values for the bci at the // invoke w/o arguments (i.e., as if one were inside the call). IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception)) Handle h_exception(thread, exception); methodHandle h_method (thread, method(thread)); constantPoolHandle h_constants(thread, h_method->constants()); bool should_repeat; int handler_bci; int current_bci = bci(thread); // Need to do this check first since when _do_not_unlock_if_synchronized // is set, we don't want to trigger any classloading which may make calls // into java, or surprisingly find a matching exception handler for bci 0 // since at this moment the method hasn't been "officially" entered yet. if (thread->do_not_unlock_if_synchronized()) { ResourceMark rm; assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized"); thread->set_vm_result(exception); #ifdef CC_INTERP return (address) -1; #else return Interpreter::remove_activation_entry(); #endif } do { should_repeat = false; // assertions #ifdef ASSERT assert(h_exception.not_null(), "NULL exceptions should be handled by athrow"); assert(h_exception->is_oop(), "just checking"); // Check that exception is a subclass of Throwable, otherwise we have a VerifyError if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) { if (ExitVMOnVerifyError) vm_exit(-1); ShouldNotReachHere(); } #endif // tracing if (TraceExceptions) { ttyLocker ttyl; ResourceMark rm(thread); tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception()); tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string()); tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread); } // Don't go paging in something which won't be used. // else if (extable->length() == 0) { // // disabled for now - interpreter is not using shortcut yet // // (shortcut is not to call runtime if we have no exception handlers) // // warning("performance bug: should not call runtime if method has no exception handlers"); // } // for AbortVMOnException flag NOT_PRODUCT(Exceptions::debug_check_abort(h_exception)); // exception handler lookup KlassHandle h_klass(THREAD, h_exception->klass()); handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD); if (HAS_PENDING_EXCEPTION) { // We threw an exception while trying to find the exception handler. // Transfer the new exception to the exception handle which will // be set into thread local storage, and do another lookup for an // exception handler for this exception, this time starting at the // BCI of the exception handler which caused the exception to be // thrown (bug 4307310). h_exception = Handle(THREAD, PENDING_EXCEPTION); CLEAR_PENDING_EXCEPTION; if (handler_bci >= 0) { current_bci = handler_bci; should_repeat = true; } } } while (should_repeat == true); // notify JVMTI of an exception throw; JVMTI will detect if this is a first // time throw or a stack unwinding throw and accordingly notify the debugger if (JvmtiExport::can_post_on_exceptions()) { JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception()); } #ifdef CC_INTERP address continuation = (address)(intptr_t) handler_bci; #else address continuation = NULL; #endif address handler_pc = NULL; if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) { // Forward exception to callee (leaving bci/bcp untouched) because (a) no // handler in this method, or (b) after a stack overflow there is not yet // enough stack space available to reprotect the stack. #ifndef CC_INTERP continuation = Interpreter::remove_activation_entry(); #endif // Count this for compilation purposes h_method->interpreter_throwout_increment(THREAD); } else { // handler in this method => change bci/bcp to handler bci/bcp and continue there handler_pc = h_method->code_base() + handler_bci; #ifndef CC_INTERP set_bcp_and_mdp(handler_pc, thread); continuation = Interpreter::dispatch_table(vtos)[*handler_pc]; #endif } // notify debugger of an exception catch // (this is good for exceptions caught in native methods as well) if (JvmtiExport::can_post_on_exceptions()) { JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL)); } thread->set_vm_result(h_exception()); return continuation; IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread)) assert(thread->has_pending_exception(), "must only ne called if there's an exception pending"); // nothing to do - eventually we should remove this code entirely (see comments @ call sites) IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread)) THROW(vmSymbols::java_lang_AbstractMethodError()); IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread)) THROW(vmSymbols::java_lang_IncompatibleClassChangeError()); IRT_END //------------------------------------------------------------------------------------------------------------------------ // Fields // IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) // resolve field fieldDescriptor info; constantPoolHandle pool(thread, method(thread)->constants()); bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic); bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); { JvmtiHideSingleStepping jhss(thread); LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); } // end JvmtiHideSingleStepping // check if link resolution caused cpCache to be updated if (already_resolved(thread)) return; // compute auxiliary field attributes TosState state = as_TosState(info.field_type()); // We need to delay resolving put instructions on final fields // until we actually invoke one. This is required so we throw // exceptions at the correct place. If we do not resolve completely // in the current pass, leaving the put_code set to zero will // cause the next put instruction to reresolve. Bytecodes::Code put_code = (Bytecodes::Code)0; // We also need to delay resolving getstatic instructions until the // class is intitialized. This is required so that access to the static // field will call the initialization function every time until the class // is completely initialized ala. in 2.17.5 in JVM Specification. InstanceKlass* klass = InstanceKlass::cast(info.field_holder()); bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && !klass->is_initialized()); Bytecodes::Code get_code = (Bytecodes::Code)0; if (!uninitialized_static) { get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield); if (is_put || !info.access_flags().is_final()) { put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield); } } cache_entry(thread)->set_field( get_code, put_code, info.field_holder(), info.index(), info.offset(), state, info.access_flags().is_final(), info.access_flags().is_volatile(), pool->pool_holder() ); IRT_END //------------------------------------------------------------------------------------------------------------------------ // Synchronization // // The interpreter's synchronization code is factored out so that it can // be shared by method invocation and synchronized blocks. //%note synchronization_3 //%note monitor_1 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem)) #ifdef ASSERT thread->last_frame().interpreter_frame_verify_monitor(elem); #endif if (PrintBiasedLockingStatistics) { Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); } Handle h_obj(thread, elem->obj()); assert(Universe::heap()->is_in_reserved_or_null(h_obj()), "must be NULL or an object"); if (UseBiasedLocking) { // Retry fast entry if bias is revoked to avoid unnecessary inflation ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK); } else { ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK); } assert(Universe::heap()->is_in_reserved_or_null(elem->obj()), "must be NULL or an object"); #ifdef ASSERT thread->last_frame().interpreter_frame_verify_monitor(elem); #endif IRT_END //%note monitor_1 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem)) #ifdef ASSERT thread->last_frame().interpreter_frame_verify_monitor(elem); #endif Handle h_obj(thread, elem->obj()); assert(Universe::heap()->is_in_reserved_or_null(h_obj()), "must be NULL or an object"); if (elem == NULL || h_obj()->is_unlocked()) { THROW(vmSymbols::java_lang_IllegalMonitorStateException()); } ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread); // Free entry. This must be done here, since a pending exception might be installed on // exit. If it is not cleared, the exception handling code will try to unlock the monitor again. elem->set_obj(NULL); #ifdef ASSERT thread->last_frame().interpreter_frame_verify_monitor(elem); #endif IRT_END IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread)) THROW(vmSymbols::java_lang_IllegalMonitorStateException()); IRT_END IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread)) // Returns an illegal exception to install into the current thread. The // pending_exception flag is cleared so normal exception handling does not // trigger. Any current installed exception will be overwritten. This // method will be called during an exception unwind. assert(!HAS_PENDING_EXCEPTION, "no pending exception"); Handle exception(thread, thread->vm_result()); assert(exception() != NULL, "vm result should be set"); thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures) if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) { exception = get_preinitialized_exception( SystemDictionary::IllegalMonitorStateException_klass(), CATCH); } thread->set_vm_result(exception()); IRT_END //------------------------------------------------------------------------------------------------------------------------ // Invokes IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp)) return method->orig_bytecode_at(method->bci_from(bcp)); IRT_END IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code)) method->set_orig_bytecode_at(method->bci_from(bcp), new_code); IRT_END IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp)) JvmtiExport::post_raw_breakpoint(thread, method, bcp); IRT_END IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) { // extract receiver from the outgoing argument list if necessary Handle receiver(thread, NULL); if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) { ResourceMark rm(thread); methodHandle m (thread, method(thread)); Bytecode_invoke call(m, bci(thread)); Symbol* signature = call.signature(); receiver = Handle(thread, thread->last_frame().interpreter_callee_receiver(signature)); assert(Universe::heap()->is_in_reserved_or_null(receiver()), "sanity check"); assert(receiver.is_null() || !Universe::heap()->is_in_reserved(receiver->klass()), "sanity check"); } // resolve method CallInfo info; constantPoolHandle pool(thread, method(thread)->constants()); { JvmtiHideSingleStepping jhss(thread); LinkResolver::resolve_invoke(info, receiver, pool, get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); if (JvmtiExport::can_hotswap_or_post_breakpoint()) { int retry_count = 0; while (info.resolved_method()->is_old()) { // It is very unlikely that method is redefined more than 100 times // in the middle of resolve. If it is looping here more than 100 times // means then there could be a bug here. guarantee((retry_count++ < 100), "Could not resolve to latest version of redefined method"); // method is redefined in the middle of resolve so re-try. LinkResolver::resolve_invoke(info, receiver, pool, get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); } } } // end JvmtiHideSingleStepping // check if link resolution caused cpCache to be updated if (already_resolved(thread)) return; if (bytecode == Bytecodes::_invokeinterface) { if (TraceItables && Verbose) { ResourceMark rm(thread); tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); } } #ifdef ASSERT if (bytecode == Bytecodes::_invokeinterface) { if (info.resolved_method()->method_holder() == SystemDictionary::Object_klass()) { // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec // (see also CallInfo::set_interface for details) assert(info.call_kind() == CallInfo::vtable_call || info.call_kind() == CallInfo::direct_call, ""); methodHandle rm = info.resolved_method(); assert(rm->is_final() || info.has_vtable_index(), "should have been set already"); } else if (!info.resolved_method()->has_itable_index()) { // Resolved something like CharSequence.toString. Use vtable not itable. assert(info.call_kind() != CallInfo::itable_call, ""); } else { // Setup itable entry assert(info.call_kind() == CallInfo::itable_call, ""); int index = info.resolved_method()->itable_index(); assert(info.itable_index() == index, ""); } } else { assert(info.call_kind() == CallInfo::direct_call || info.call_kind() == CallInfo::vtable_call, ""); } #endif switch (info.call_kind()) { case CallInfo::direct_call: cache_entry(thread)->set_direct_call( bytecode, info.resolved_method()); break; case CallInfo::vtable_call: cache_entry(thread)->set_vtable_call( bytecode, info.resolved_method(), info.vtable_index()); break; case CallInfo::itable_call: cache_entry(thread)->set_itable_call( bytecode, info.resolved_method(), info.itable_index()); break; default: ShouldNotReachHere(); } } IRT_END // First time execution: Resolve symbols, create a permanent MethodType object. IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) { assert(EnableInvokeDynamic, ""); const Bytecodes::Code bytecode = Bytecodes::_invokehandle; // resolve method CallInfo info; constantPoolHandle pool(thread, method(thread)->constants()); { JvmtiHideSingleStepping jhss(thread); LinkResolver::resolve_invoke(info, Handle(), pool, get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); } // end JvmtiHideSingleStepping cache_entry(thread)->set_method_handle(pool, info); } IRT_END // First time execution: Resolve symbols, create a permanent CallSite object. IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) { assert(EnableInvokeDynamic, ""); const Bytecodes::Code bytecode = Bytecodes::_invokedynamic; //TO DO: consider passing BCI to Java. // int caller_bci = method(thread)->bci_from(bcp(thread)); // resolve method CallInfo info; constantPoolHandle pool(thread, method(thread)->constants()); int index = get_index_u4(thread, bytecode); { JvmtiHideSingleStepping jhss(thread); LinkResolver::resolve_invoke(info, Handle(), pool, index, bytecode, CHECK); } // end JvmtiHideSingleStepping ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index); cp_cache_entry->set_dynamic_call(pool, info); } IRT_END //------------------------------------------------------------------------------------------------------------------------ // Miscellaneous nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) { nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp); assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests"); if (branch_bcp != NULL && nm != NULL) { // This was a successful request for an OSR nmethod. Because // frequency_counter_overflow_inner ends with a safepoint check, // nm could have been unloaded so look it up again. It's unsafe // to examine nm directly since it might have been freed and used // for something else. frame fr = thread->last_frame(); Method* method = fr.interpreter_frame_method(); int bci = method->bci_from(fr.interpreter_frame_bcp()); nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false); } #ifndef PRODUCT if (TraceOnStackReplacement) { if (nm != NULL) { tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry()); nm->print(); } } #endif return nm; } IRT_ENTRY(nmethod*, InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp)) // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized // flag, in case this method triggers classloading which will call into Java. UnlockFlagSaver fs(thread); frame fr = thread->last_frame(); assert(fr.is_interpreted_frame(), "must come from interpreter"); methodHandle method(thread, fr.interpreter_frame_method()); const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci; const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci; assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending"); nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread); assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions"); if (osr_nm != NULL) { // We may need to do on-stack replacement which requires that no // monitors in the activation are biased because their // BasicObjectLocks will need to migrate during OSR. Force // unbiasing of all monitors in the activation now (even though // the OSR nmethod might be invalidated) because we don't have a // safepoint opportunity later once the migration begins. if (UseBiasedLocking) { ResourceMark rm; GrowableArray<Handle>* objects_to_revoke = new GrowableArray Other Java examples (source code examples)Here is a short list of links related to this Java interpreterRuntime.cpp source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.