Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/interpreterRuntime.cpp
32285 views
/*1* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/systemDictionary.hpp"26#include "classfile/vmSymbols.hpp"27#include "compiler/compileBroker.hpp"28#include "compiler/disassembler.hpp"29#include "gc_interface/collectedHeap.hpp"30#include "interpreter/interpreter.hpp"31#include "interpreter/interpreterRuntime.hpp"32#include "interpreter/linkResolver.hpp"33#include "interpreter/templateTable.hpp"34#include "memory/oopFactory.hpp"35#include "memory/universe.inline.hpp"36#include "oops/constantPool.hpp"37#include "oops/instanceKlass.hpp"38#include "oops/methodData.hpp"39#include "oops/objArrayKlass.hpp"40#include "oops/oop.inline.hpp"41#include "oops/symbol.hpp"42#include "prims/jvmtiExport.hpp"43#include "prims/nativeLookup.hpp"44#include "runtime/biasedLocking.hpp"45#include "runtime/compilationPolicy.hpp"46#include "runtime/deoptimization.hpp"47#include "runtime/fieldDescriptor.hpp"48#include "runtime/handles.inline.hpp"49#include "runtime/interfaceSupport.hpp"50#include "runtime/java.hpp"51#include "runtime/jfieldIDWorkaround.hpp"52#include "runtime/osThread.hpp"53#include "runtime/sharedRuntime.hpp"54#include "runtime/stubRoutines.hpp"55#include "runtime/synchronizer.hpp"56#include "runtime/threadCritical.hpp"57#include "utilities/events.hpp"58#ifdef TARGET_ARCH_x8659# include "vm_version_x86.hpp"60#endif61#ifdef TARGET_ARCH_aarch3262# include "vm_version_aarch32.hpp"63#endif64#ifdef TARGET_ARCH_aarch6465# include "vm_version_aarch64.hpp"66#endif67#ifdef TARGET_ARCH_sparc68# include "vm_version_sparc.hpp"69#endif70#ifdef TARGET_ARCH_zero71# include "vm_version_zero.hpp"72#endif73#ifdef TARGET_ARCH_arm74# include "vm_version_arm.hpp"75#endif76#ifdef TARGET_ARCH_ppc77# include "vm_version_ppc.hpp"78#endif79#ifdef COMPILER280#include "opto/runtime.hpp"81#endif8283PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC8485class UnlockFlagSaver {86private:87JavaThread* _thread;88bool _do_not_unlock;89public:90UnlockFlagSaver(JavaThread* t) {91_thread = t;92_do_not_unlock = t->do_not_unlock_if_synchronized();93t->set_do_not_unlock_if_synchronized(false);94}95~UnlockFlagSaver() {96_thread->set_do_not_unlock_if_synchronized(_do_not_unlock);97}98};99100//------------------------------------------------------------------------------------------------------------------------101// State accessors102103void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {104last_frame(thread).interpreter_frame_set_bcp(bcp);105if (ProfileInterpreter) {106// ProfileTraps uses MDOs independently of ProfileInterpreter.107// That is why we must check both ProfileInterpreter and mdo != NULL.108MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data();109if (mdo != NULL) {110NEEDS_CLEANUP;111last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));112}113}114}115116//------------------------------------------------------------------------------------------------------------------------117// Constants118119120IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))121// access constant pool122ConstantPool* pool = method(thread)->constants();123int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);124constantTag tag = pool->tag_at(index);125126assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");127Klass* klass = pool->klass_at(index, CHECK);128oop java_class = klass->java_mirror();129thread->set_vm_result(java_class);130IRT_END131132IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {133assert(bytecode == Bytecodes::_fast_aldc ||134bytecode == Bytecodes::_fast_aldc_w, "wrong bc");135ResourceMark rm(thread);136methodHandle m (thread, method(thread));137Bytecode_loadconstant ldc(m, bci(thread));138oop result = ldc.resolve_constant(CHECK);139#ifdef ASSERT140{141// The bytecode wrappers aren't GC-safe so construct a new one142Bytecode_loadconstant ldc2(m, bci(thread));143oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index());144assert(result == coop, "expected result for assembly code");145}146#endif147thread->set_vm_result(result);148}149IRT_END150151152//------------------------------------------------------------------------------------------------------------------------153// Allocation154155IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))156Klass* k_oop = pool->klass_at(index, CHECK);157instanceKlassHandle klass (THREAD, k_oop);158159// Make sure we are not instantiating an abstract klass160klass->check_valid_for_instantiation(true, CHECK);161162// Make sure klass is initialized163klass->initialize(CHECK);164165// At this point the class may not be fully initialized166// because of recursive initialization. If it is fully167// initialized & has_finalized is not set, we rewrite168// it into its fast version (Note: no locking is needed169// here since this is an atomic byte write and can be170// done more than once).171//172// Note: In case of classes with has_finalized we don't173// rewrite since that saves us an extra check in174// the fast version which then would call the175// slow version anyway (and do a call back into176// Java).177// If we have a breakpoint, then we don't rewrite178// because the _breakpoint bytecode would be lost.179oop obj = klass->allocate_instance(CHECK);180thread->set_vm_result(obj);181IRT_END182183184IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))185oop obj = oopFactory::new_typeArray(type, size, CHECK);186thread->set_vm_result(obj);187IRT_END188189190IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))191// Note: no oopHandle for pool & klass needed since they are not used192// anymore after new_objArray() and no GC can happen before.193// (This may have to change if this code changes!)194Klass* klass = pool->klass_at(index, CHECK);195objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);196thread->set_vm_result(obj);197IRT_END198199200IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))201// We may want to pass in more arguments - could make this slightly faster202ConstantPool* constants = method(thread)->constants();203int i = get_index_u2(thread, Bytecodes::_multianewarray);204Klass* klass = constants->klass_at(i, CHECK);205int nof_dims = number_of_dimensions(thread);206assert(klass->is_klass(), "not a class");207assert(nof_dims >= 1, "multianewarray rank must be nonzero");208209// We must create an array of jints to pass to multi_allocate.210ResourceMark rm(thread);211const int small_dims = 10;212jint dim_array[small_dims];213jint *dims = &dim_array[0];214if (nof_dims > small_dims) {215dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);216}217for (int index = 0; index < nof_dims; index++) {218// offset from first_size_address is addressed as local[index]219int n = Interpreter::local_offset_in_bytes(index)/jintSize;220dims[index] = first_size_address[n];221}222oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);223thread->set_vm_result(obj);224IRT_END225226227IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))228assert(obj->is_oop(), "must be a valid oop");229assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");230InstanceKlass::register_finalizer(instanceOop(obj), CHECK);231IRT_END232233234// Quicken instance-of and check-cast bytecodes235IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))236// Force resolving; quicken the bytecode237int which = get_index_u2(thread, Bytecodes::_checkcast);238ConstantPool* cpool = method(thread)->constants();239// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded240// program we might have seen an unquick'd bytecode in the interpreter but have another241// thread quicken the bytecode before we get here.242// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );243Klass* klass = cpool->klass_at(which, CHECK);244thread->set_vm_result_2(klass);245IRT_END246247248//------------------------------------------------------------------------------------------------------------------------249// Exceptions250251void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,252methodHandle trap_method, int trap_bci, TRAPS) {253if (trap_method.not_null()) {254MethodData* trap_mdo = trap_method->method_data();255if (trap_mdo == NULL) {256Method::build_interpreter_method_data(trap_method, THREAD);257if (HAS_PENDING_EXCEPTION) {258assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())),259"we expect only an OOM error here");260CLEAR_PENDING_EXCEPTION;261}262trap_mdo = trap_method->method_data();263// and fall through...264}265if (trap_mdo != NULL) {266// Update per-method count of trap events. The interpreter267// is updating the MDO to simulate the effect of compiler traps.268Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);269}270}271}272273// Assume the compiler is (or will be) interested in this event.274// If necessary, create an MDO to hold the information, and record it.275void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {276assert(ProfileTraps, "call me only if profiling");277methodHandle trap_method(thread, method(thread));278int trap_bci = trap_method->bci_from(bcp(thread));279note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);280}281282#ifdef CC_INTERP283// As legacy note_trap, but we have more arguments.284IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))285methodHandle trap_method(method);286note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);287IRT_END288289// Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper290// for each exception.291void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)292{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }293void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)294{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }295void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)296{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }297void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)298{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }299void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)300{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }301#endif // CC_INTERP302303304static Handle get_preinitialized_exception(Klass* k, TRAPS) {305// get klass306InstanceKlass* klass = InstanceKlass::cast(k);307assert(klass->is_initialized(),308"this klass should have been initialized during VM initialization");309// create instance - do not call constructor since we may have no310// (java) stack space left (should assert constructor is empty)311Handle exception;312oop exception_oop = klass->allocate_instance(CHECK_(exception));313exception = Handle(THREAD, exception_oop);314if (StackTraceInThrowable) {315java_lang_Throwable::fill_in_stack_trace(exception);316}317return exception;318}319320// Special handling for stack overflow: since we don't have any (java) stack321// space left we use the pre-allocated & pre-initialized StackOverflowError322// klass to create an stack overflow error instance. We do not call its323// constructor for the same reason (it is empty, anyway).324IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))325Handle exception = get_preinitialized_exception(326SystemDictionary::StackOverflowError_klass(),327CHECK);328// Increment counter for hs_err file reporting329Atomic::inc(&Exceptions::_stack_overflow_errors);330THROW_HANDLE(exception);331IRT_END332333334IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))335// lookup exception klass336TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);337if (ProfileTraps) {338if (s == vmSymbols::java_lang_ArithmeticException()) {339note_trap(thread, Deoptimization::Reason_div0_check, CHECK);340} else if (s == vmSymbols::java_lang_NullPointerException()) {341note_trap(thread, Deoptimization::Reason_null_check, CHECK);342}343}344// create exception345Handle exception = Exceptions::new_exception(thread, s, message);346thread->set_vm_result(exception());347IRT_END348349350IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))351ResourceMark rm(thread);352const char* klass_name = obj->klass()->external_name();353// lookup exception klass354TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);355if (ProfileTraps) {356note_trap(thread, Deoptimization::Reason_class_check, CHECK);357}358// create exception, with klass name as detail message359Handle exception = Exceptions::new_exception(thread, s, klass_name);360thread->set_vm_result(exception());361IRT_END362363364IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))365char message[jintAsStringSize];366// lookup exception klass367TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);368if (ProfileTraps) {369note_trap(thread, Deoptimization::Reason_range_check, CHECK);370}371// create exception372sprintf(message, "%d", index);373THROW_MSG(s, message);374IRT_END375376IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(377JavaThread* thread, oopDesc* obj))378379ResourceMark rm(thread);380char* message = SharedRuntime::generate_class_cast_message(381thread, obj->klass()->external_name());382383if (ProfileTraps) {384note_trap(thread, Deoptimization::Reason_class_check, CHECK);385}386387// create exception388THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);389IRT_END390391// exception_handler_for_exception(...) returns the continuation address,392// the exception oop (via TLS) and sets the bci/bcp for the continuation.393// The exception oop is returned to make sure it is preserved over GC (it394// is only on the stack if the exception was thrown explicitly via athrow).395// During this operation, the expression stack contains the values for the396// bci where the exception happened. If the exception was propagated back397// from a call, the expression stack contains the values for the bci at the398// invoke w/o arguments (i.e., as if one were inside the call).399IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))400401Handle h_exception(thread, exception);402methodHandle h_method (thread, method(thread));403constantPoolHandle h_constants(thread, h_method->constants());404bool should_repeat;405int handler_bci;406int current_bci = bci(thread);407408if (thread->frames_to_pop_failed_realloc() > 0) {409// Allocation of scalar replaced object used in this frame410// failed. Unconditionally pop the frame.411thread->dec_frames_to_pop_failed_realloc();412thread->set_vm_result(h_exception());413// If the method is synchronized we already unlocked the monitor414// during deoptimization so the interpreter needs to skip it when415// the frame is popped.416thread->set_do_not_unlock_if_synchronized(true);417#ifdef CC_INTERP418return (address) -1;419#else420return Interpreter::remove_activation_entry();421#endif422}423424// Need to do this check first since when _do_not_unlock_if_synchronized425// is set, we don't want to trigger any classloading which may make calls426// into java, or surprisingly find a matching exception handler for bci 0427// since at this moment the method hasn't been "officially" entered yet.428if (thread->do_not_unlock_if_synchronized()) {429ResourceMark rm;430assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");431thread->set_vm_result(exception);432#ifdef CC_INTERP433return (address) -1;434#else435return Interpreter::remove_activation_entry();436#endif437}438439do {440should_repeat = false;441442// assertions443#ifdef ASSERT444assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");445assert(h_exception->is_oop(), "just checking");446// Check that exception is a subclass of Throwable, otherwise we have a VerifyError447if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {448if (ExitVMOnVerifyError) vm_exit(-1);449ShouldNotReachHere();450}451#endif452453// tracing454if (TraceExceptions) {455ResourceMark rm(thread);456Symbol* message = java_lang_Throwable::detail_message(h_exception());457ttyLocker ttyl; // Lock after getting the detail message458if (message != NULL) {459tty->print_cr("Exception <%s: %s> (" INTPTR_FORMAT ")",460h_exception->print_value_string(), message->as_C_string(),461(address)h_exception());462} else {463tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")",464h_exception->print_value_string(),465(address)h_exception());466}467tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());468tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);469}470// Don't go paging in something which won't be used.471// else if (extable->length() == 0) {472// // disabled for now - interpreter is not using shortcut yet473// // (shortcut is not to call runtime if we have no exception handlers)474// // warning("performance bug: should not call runtime if method has no exception handlers");475// }476// for AbortVMOnException flag477NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));478479// exception handler lookup480KlassHandle h_klass(THREAD, h_exception->klass());481handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);482if (HAS_PENDING_EXCEPTION) {483// We threw an exception while trying to find the exception handler.484// Transfer the new exception to the exception handle which will485// be set into thread local storage, and do another lookup for an486// exception handler for this exception, this time starting at the487// BCI of the exception handler which caused the exception to be488// thrown (bug 4307310).489h_exception = Handle(THREAD, PENDING_EXCEPTION);490CLEAR_PENDING_EXCEPTION;491if (handler_bci >= 0) {492current_bci = handler_bci;493should_repeat = true;494}495}496} while (should_repeat == true);497498// notify JVMTI of an exception throw; JVMTI will detect if this is a first499// time throw or a stack unwinding throw and accordingly notify the debugger500if (JvmtiExport::can_post_on_exceptions()) {501JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());502}503504#ifdef CC_INTERP505address continuation = (address)(intptr_t) handler_bci;506#else507address continuation = NULL;508#endif509address handler_pc = NULL;510if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {511// Forward exception to callee (leaving bci/bcp untouched) because (a) no512// handler in this method, or (b) after a stack overflow there is not yet513// enough stack space available to reprotect the stack.514#ifndef CC_INTERP515continuation = Interpreter::remove_activation_entry();516#endif517// Count this for compilation purposes518h_method->interpreter_throwout_increment(THREAD);519} else {520// handler in this method => change bci/bcp to handler bci/bcp and continue there521handler_pc = h_method->code_base() + handler_bci;522#ifndef CC_INTERP523set_bcp_and_mdp(handler_pc, thread);524continuation = Interpreter::dispatch_table(vtos)[*handler_pc];525#endif526}527// notify debugger of an exception catch528// (this is good for exceptions caught in native methods as well)529if (JvmtiExport::can_post_on_exceptions()) {530JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));531}532533thread->set_vm_result(h_exception());534return continuation;535IRT_END536537538IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))539assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");540// nothing to do - eventually we should remove this code entirely (see comments @ call sites)541IRT_END542543544IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))545THROW(vmSymbols::java_lang_AbstractMethodError());546IRT_END547548549IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))550THROW(vmSymbols::java_lang_IncompatibleClassChangeError());551IRT_END552553554//------------------------------------------------------------------------------------------------------------------------555// Fields556//557558IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))559// resolve field560fieldDescriptor info;561constantPoolHandle pool(thread, method(thread)->constants());562bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic);563bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);564565{566JvmtiHideSingleStepping jhss(thread);567LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),568bytecode, CHECK);569} // end JvmtiHideSingleStepping570571// check if link resolution caused cpCache to be updated572if (already_resolved(thread)) return;573574// compute auxiliary field attributes575TosState state = as_TosState(info.field_type());576577// We need to delay resolving put instructions on final fields578// until we actually invoke one. This is required so we throw579// exceptions at the correct place. If we do not resolve completely580// in the current pass, leaving the put_code set to zero will581// cause the next put instruction to reresolve.582Bytecodes::Code put_code = (Bytecodes::Code)0;583584// We also need to delay resolving getstatic instructions until the585// class is intitialized. This is required so that access to the static586// field will call the initialization function every time until the class587// is completely initialized ala. in 2.17.5 in JVM Specification.588InstanceKlass* klass = InstanceKlass::cast(info.field_holder());589bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&590!klass->is_initialized());591Bytecodes::Code get_code = (Bytecodes::Code)0;592593if (!uninitialized_static) {594get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);595if (is_put || !info.access_flags().is_final()) {596put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);597}598}599600cache_entry(thread)->set_field(601get_code,602put_code,603info.field_holder(),604info.index(),605info.offset(),606state,607info.access_flags().is_final(),608info.access_flags().is_volatile(),609pool->pool_holder()610);611IRT_END612613614//------------------------------------------------------------------------------------------------------------------------615// Synchronization616//617// The interpreter's synchronization code is factored out so that it can618// be shared by method invocation and synchronized blocks.619//%note synchronization_3620621//%note monitor_1622IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))623#ifdef ASSERT624thread->last_frame().interpreter_frame_verify_monitor(elem);625#endif626if (PrintBiasedLockingStatistics) {627Atomic::inc(BiasedLocking::slow_path_entry_count_addr());628}629Handle h_obj(thread, elem->obj());630assert(Universe::heap()->is_in_reserved_or_null(h_obj()),631"must be NULL or an object");632if (UseBiasedLocking) {633// Retry fast entry if bias is revoked to avoid unnecessary inflation634ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);635} else {636ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);637}638assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),639"must be NULL or an object");640#ifdef ASSERT641thread->last_frame().interpreter_frame_verify_monitor(elem);642#endif643IRT_END644645646//%note monitor_1647IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))648#ifdef ASSERT649thread->last_frame().interpreter_frame_verify_monitor(elem);650#endif651Handle h_obj(thread, elem->obj());652assert(Universe::heap()->is_in_reserved_or_null(h_obj()),653"must be NULL or an object");654if (elem == NULL || h_obj()->is_unlocked()) {655THROW(vmSymbols::java_lang_IllegalMonitorStateException());656}657ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);658// Free entry. This must be done here, since a pending exception might be installed on659// exit. If it is not cleared, the exception handling code will try to unlock the monitor again.660elem->set_obj(NULL);661#ifdef ASSERT662thread->last_frame().interpreter_frame_verify_monitor(elem);663#endif664IRT_END665666667IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))668THROW(vmSymbols::java_lang_IllegalMonitorStateException());669IRT_END670671672IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))673// Returns an illegal exception to install into the current thread. The674// pending_exception flag is cleared so normal exception handling does not675// trigger. Any current installed exception will be overwritten. This676// method will be called during an exception unwind.677678assert(!HAS_PENDING_EXCEPTION, "no pending exception");679Handle exception(thread, thread->vm_result());680assert(exception() != NULL, "vm result should be set");681thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)682if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {683exception = get_preinitialized_exception(684SystemDictionary::IllegalMonitorStateException_klass(),685CATCH);686}687thread->set_vm_result(exception());688IRT_END689690691//------------------------------------------------------------------------------------------------------------------------692// Invokes693694IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp))695return method->orig_bytecode_at(method->bci_from(bcp));696IRT_END697698IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))699method->set_orig_bytecode_at(method->bci_from(bcp), new_code);700IRT_END701702IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))703JvmtiExport::post_raw_breakpoint(thread, method, bcp);704IRT_END705706IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {707// extract receiver from the outgoing argument list if necessary708Handle receiver(thread, NULL);709if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||710bytecode == Bytecodes::_invokespecial) {711ResourceMark rm(thread);712methodHandle m (thread, method(thread));713Bytecode_invoke call(m, bci(thread));714Symbol* signature = call.signature();715receiver = Handle(thread,716thread->last_frame().interpreter_callee_receiver(signature));717assert(Universe::heap()->is_in_reserved_or_null(receiver()),718"sanity check");719assert(receiver.is_null() ||720!Universe::heap()->is_in_reserved(receiver->klass()),721"sanity check");722}723724// resolve method725CallInfo info;726constantPoolHandle pool(thread, method(thread)->constants());727728{729JvmtiHideSingleStepping jhss(thread);730LinkResolver::resolve_invoke(info, receiver, pool,731get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);732if (JvmtiExport::can_hotswap_or_post_breakpoint()) {733int retry_count = 0;734while (info.resolved_method()->is_old()) {735// It is very unlikely that method is redefined more than 100 times736// in the middle of resolve. If it is looping here more than 100 times737// means then there could be a bug here.738guarantee((retry_count++ < 100),739"Could not resolve to latest version of redefined method");740// method is redefined in the middle of resolve so re-try.741LinkResolver::resolve_invoke(info, receiver, pool,742get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);743}744}745} // end JvmtiHideSingleStepping746747// check if link resolution caused cpCache to be updated748if (already_resolved(thread)) return;749750if (bytecode == Bytecodes::_invokeinterface) {751if (TraceItables && Verbose) {752ResourceMark rm(thread);753tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());754}755}756#ifdef ASSERT757if (bytecode == Bytecodes::_invokeinterface) {758if (info.resolved_method()->method_holder() ==759SystemDictionary::Object_klass()) {760// NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec761// (see also CallInfo::set_interface for details)762assert(info.call_kind() == CallInfo::vtable_call ||763info.call_kind() == CallInfo::direct_call, "");764methodHandle rm = info.resolved_method();765assert(rm->is_final() || info.has_vtable_index(),766"should have been set already");767} else if (!info.resolved_method()->has_itable_index()) {768// Resolved something like CharSequence.toString. Use vtable not itable.769assert(info.call_kind() != CallInfo::itable_call, "");770} else {771// Setup itable entry772assert(info.call_kind() == CallInfo::itable_call, "");773int index = info.resolved_method()->itable_index();774assert(info.itable_index() == index, "");775}776} else if (bytecode == Bytecodes::_invokespecial) {777assert(info.call_kind() == CallInfo::direct_call, "must be direct call");778} else {779assert(info.call_kind() == CallInfo::direct_call ||780info.call_kind() == CallInfo::vtable_call, "");781}782#endif783// Get sender or sender's host_klass, and only set cpCache entry to resolved if784// it is not an interface. The receiver for invokespecial calls within interface785// methods must be checked for every call.786InstanceKlass* sender = pool->pool_holder();787sender = sender->has_host_klass() ? InstanceKlass::cast(sender->host_klass()) : sender;788789switch (info.call_kind()) {790case CallInfo::direct_call:791cache_entry(thread)->set_direct_call(792bytecode,793info.resolved_method(),794sender->is_interface());795break;796case CallInfo::vtable_call:797cache_entry(thread)->set_vtable_call(798bytecode,799info.resolved_method(),800info.vtable_index());801break;802case CallInfo::itable_call:803cache_entry(thread)->set_itable_call(804bytecode,805info.resolved_klass(),806info.resolved_method(),807info.itable_index());808break;809default: ShouldNotReachHere();810}811}812IRT_END813814815// First time execution: Resolve symbols, create a permanent MethodType object.816IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) {817assert(EnableInvokeDynamic, "");818const Bytecodes::Code bytecode = Bytecodes::_invokehandle;819820// resolve method821CallInfo info;822constantPoolHandle pool(thread, method(thread)->constants());823824{825JvmtiHideSingleStepping jhss(thread);826LinkResolver::resolve_invoke(info, Handle(), pool,827get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);828} // end JvmtiHideSingleStepping829830cache_entry(thread)->set_method_handle(pool, info);831}832IRT_END833834835// First time execution: Resolve symbols, create a permanent CallSite object.836IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {837assert(EnableInvokeDynamic, "");838const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;839840//TO DO: consider passing BCI to Java.841// int caller_bci = method(thread)->bci_from(bcp(thread));842843// resolve method844CallInfo info;845constantPoolHandle pool(thread, method(thread)->constants());846int index = get_index_u4(thread, bytecode);847{848JvmtiHideSingleStepping jhss(thread);849LinkResolver::resolve_invoke(info, Handle(), pool,850index, bytecode, CHECK);851} // end JvmtiHideSingleStepping852853ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);854cp_cache_entry->set_dynamic_call(pool, info);855}856IRT_END857858859//------------------------------------------------------------------------------------------------------------------------860// Miscellaneous861862863nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {864// Enable WXWrite: the function is called directly by interpreter.865MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread));866867nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);868assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");869if (branch_bcp != NULL && nm != NULL) {870// This was a successful request for an OSR nmethod. Because871// frequency_counter_overflow_inner ends with a safepoint check,872// nm could have been unloaded so look it up again. It's unsafe873// to examine nm directly since it might have been freed and used874// for something else.875frame fr = thread->last_frame();876Method* method = fr.interpreter_frame_method();877int bci = method->bci_from(fr.interpreter_frame_bcp());878nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);879}880#ifndef PRODUCT881if (TraceOnStackReplacement) {882if (nm != NULL) {883tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry());884nm->print();885}886}887#endif888return nm;889}890891IRT_ENTRY(nmethod*,892InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))893// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized894// flag, in case this method triggers classloading which will call into Java.895UnlockFlagSaver fs(thread);896897frame fr = thread->last_frame();898assert(fr.is_interpreted_frame(), "must come from interpreter");899methodHandle method(thread, fr.interpreter_frame_method());900const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;901const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;902903assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");904nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);905assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");906907if (osr_nm != NULL) {908// We may need to do on-stack replacement which requires that no909// monitors in the activation are biased because their910// BasicObjectLocks will need to migrate during OSR. Force911// unbiasing of all monitors in the activation now (even though912// the OSR nmethod might be invalidated) because we don't have a913// safepoint opportunity later once the migration begins.914if (UseBiasedLocking) {915ResourceMark rm;916GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();917for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();918kptr < fr.interpreter_frame_monitor_begin();919kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {920if( kptr->obj() != NULL ) {921objects_to_revoke->append(Handle(THREAD, kptr->obj()));922}923}924BiasedLocking::revoke(objects_to_revoke);925}926}927return osr_nm;928IRT_END929930IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))931assert(ProfileInterpreter, "must be profiling interpreter");932int bci = method->bci_from(cur_bcp);933MethodData* mdo = method->method_data();934if (mdo == NULL) return 0;935return mdo->bci_to_di(bci);936IRT_END937938IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))939// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized940// flag, in case this method triggers classloading which will call into Java.941UnlockFlagSaver fs(thread);942943assert(ProfileInterpreter, "must be profiling interpreter");944frame fr = thread->last_frame();945assert(fr.is_interpreted_frame(), "must come from interpreter");946methodHandle method(thread, fr.interpreter_frame_method());947Method::build_interpreter_method_data(method, THREAD);948if (HAS_PENDING_EXCEPTION) {949assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");950CLEAR_PENDING_EXCEPTION;951// and fall through...952}953IRT_END954955956#ifdef ASSERT957IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))958assert(ProfileInterpreter, "must be profiling interpreter");959960MethodData* mdo = method->method_data();961assert(mdo != NULL, "must not be null");962963int bci = method->bci_from(bcp);964965address mdp2 = mdo->bci_to_dp(bci);966if (mdp != mdp2) {967ResourceMark rm;968ResetNoHandleMark rnm; // In a LEAF entry.969HandleMark hm;970tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);971int current_di = mdo->dp_to_di(mdp);972int expected_di = mdo->dp_to_di(mdp2);973tty->print_cr(" actual di %d expected di %d", current_di, expected_di);974int expected_approx_bci = mdo->data_at(expected_di)->bci();975int approx_bci = -1;976if (current_di >= 0) {977approx_bci = mdo->data_at(current_di)->bci();978}979tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);980mdo->print_on(tty);981method->print_codes();982}983assert(mdp == mdp2, "wrong mdp");984IRT_END985#endif // ASSERT986987IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))988assert(ProfileInterpreter, "must be profiling interpreter");989ResourceMark rm(thread);990HandleMark hm(thread);991frame fr = thread->last_frame();992assert(fr.is_interpreted_frame(), "must come from interpreter");993MethodData* h_mdo = fr.interpreter_frame_method()->method_data();994995// Grab a lock to ensure atomic access to setting the return bci and996// the displacement. This can block and GC, invalidating all naked oops.997MutexLocker ml(RetData_lock);998999// ProfileData is essentially a wrapper around a derived oop, so we1000// need to take the lock before making any ProfileData structures.1001ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));1002guarantee(data != NULL, "profile data must be valid");1003RetData* rdata = data->as_RetData();1004address new_mdp = rdata->fixup_ret(return_bci, h_mdo);1005fr.interpreter_frame_set_mdp(new_mdp);1006IRT_END10071008IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))1009MethodCounters* mcs = Method::build_method_counters(m, thread);1010if (HAS_PENDING_EXCEPTION) {1011assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");1012CLEAR_PENDING_EXCEPTION;1013}1014return mcs;1015IRT_END101610171018IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))1019// We used to need an explict preserve_arguments here for invoke bytecodes. However,1020// stack traversal automatically takes care of preserving arguments for invoke, so1021// this is no longer needed.10221023// IRT_END does an implicit safepoint check, hence we are guaranteed to block1024// if this is called during a safepoint10251026if (JvmtiExport::should_post_single_step()) {1027// We are called during regular safepoints and when the VM is1028// single stepping. If any thread is marked for single stepping,1029// then we may have JVMTI work to do.1030JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));1031}1032IRT_END10331034IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,1035ConstantPoolCacheEntry *cp_entry))10361037// check the access_flags for the field in the klass10381039InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());1040int index = cp_entry->field_index();1041if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;10421043switch(cp_entry->flag_state()) {1044case btos: // fall through1045case ztos: // fall through1046case ctos: // fall through1047case stos: // fall through1048case itos: // fall through1049case ftos: // fall through1050case ltos: // fall through1051case dtos: // fall through1052case atos: break;1053default: ShouldNotReachHere(); return;1054}1055bool is_static = (obj == NULL);1056HandleMark hm(thread);10571058Handle h_obj;1059if (!is_static) {1060// non-static field accessors have an object, but we need a handle1061h_obj = Handle(thread, obj);1062}1063instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass());1064jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static);1065JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);1066IRT_END10671068IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,1069oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))10701071Klass* k = (Klass*)cp_entry->f1_as_klass();10721073// check the access_flags for the field in the klass1074InstanceKlass* ik = InstanceKlass::cast(k);1075int index = cp_entry->field_index();1076// bail out if field modifications are not watched1077if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;10781079char sig_type = '\0';10801081switch(cp_entry->flag_state()) {1082case btos: sig_type = 'B'; break;1083case ztos: sig_type = 'Z'; break;1084case ctos: sig_type = 'C'; break;1085case stos: sig_type = 'S'; break;1086case itos: sig_type = 'I'; break;1087case ftos: sig_type = 'F'; break;1088case atos: sig_type = 'L'; break;1089case ltos: sig_type = 'J'; break;1090case dtos: sig_type = 'D'; break;1091default: ShouldNotReachHere(); return;1092}1093bool is_static = (obj == NULL);10941095HandleMark hm(thread);1096instanceKlassHandle h_klass(thread, k);1097jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static);1098jvalue fvalue;1099#ifdef _LP641100fvalue = *value;1101#else1102// Long/double values are stored unaligned and also noncontiguously with1103// tagged stacks. We can't just do a simple assignment even in the non-1104// J/D cases because a C++ compiler is allowed to assume that a jvalue is1105// 8-byte aligned, and interpreter stack slots are only 4-byte aligned.1106// We assume that the two halves of longs/doubles are stored in interpreter1107// stack slots in platform-endian order.1108jlong_accessor u;1109jint* newval = (jint*)value;1110u.words[0] = newval[0];1111u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag1112fvalue.j = u.long_value;1113#endif // _LP6411141115Handle h_obj;1116if (!is_static) {1117// non-static field accessors have an object, but we need a handle1118h_obj = Handle(thread, obj);1119}11201121JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,1122fid, sig_type, &fvalue);1123IRT_END11241125IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))1126JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));1127IRT_END112811291130IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))1131JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));1132IRT_END11331134IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))1135{1136return (Interpreter::contains(pc) ? 1 : 0);1137}1138IRT_END113911401141// Implementation of SignatureHandlerLibrary11421143address SignatureHandlerLibrary::set_handler_blob() {1144BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);1145if (handler_blob == NULL) {1146return NULL;1147}1148address handler = handler_blob->code_begin();1149_handler_blob = handler_blob;1150_handler = handler;1151return handler;1152}11531154void SignatureHandlerLibrary::initialize() {1155if (_fingerprints != NULL) {1156return;1157}1158if (set_handler_blob() == NULL) {1159vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");1160}11611162BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",1163SignatureHandlerLibrary::buffer_size);1164_buffer = bb->code_begin();11651166_fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);1167_handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);1168}11691170address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {1171address handler = _handler;1172int insts_size = buffer->pure_insts_size();1173if (handler + insts_size > _handler_blob->code_end()) {1174// get a new handler blob1175handler = set_handler_blob();1176}1177if (handler != NULL) {1178memcpy(handler, buffer->insts_begin(), insts_size);1179pd_set_handler(handler);1180ICache::invalidate_range(handler, insts_size);1181_handler = handler + insts_size;1182}1183return handler;1184}11851186void SignatureHandlerLibrary::add(methodHandle method) {1187if (method->signature_handler() == NULL) {1188// use slow signature handler if we can't do better1189int handler_index = -1;1190// check if we can use customized (fast) signature handler1191if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {1192// use customized signature handler1193MutexLocker mu(SignatureHandlerLibrary_lock);1194// make sure data structure is initialized1195initialize();1196// lookup method signature's fingerprint1197uint64_t fingerprint = Fingerprinter(method).fingerprint();1198handler_index = _fingerprints->find(fingerprint);1199// create handler if necessary1200if (handler_index < 0) {1201ResourceMark rm;1202ptrdiff_t align_offset = (address)1203round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;1204CodeBuffer buffer((address)(_buffer + align_offset),1205SignatureHandlerLibrary::buffer_size - align_offset);1206InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);1207// copy into code heap1208address handler = set_handler(&buffer);1209if (handler == NULL) {1210// use slow signature handler1211} else {1212// debugging suppport1213if (PrintSignatureHandlers) {1214ttyLocker ttyl;1215tty->cr();1216tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",1217_handlers->length(),1218(method->is_static() ? "static" : "receiver"),1219method->name_and_sig_as_C_string(),1220fingerprint,1221buffer.insts_size());1222Disassembler::decode(handler, handler + buffer.insts_size());1223#ifndef PRODUCT1224tty->print_cr(" --- associated result handler ---");1225address rh_begin = Interpreter::result_handler(method()->result_type());1226address rh_end = rh_begin;1227while (*(int*)rh_end != 0) {1228rh_end += sizeof(int);1229}1230Disassembler::decode(rh_begin, rh_end);1231#endif1232}1233// add handler to library1234_fingerprints->append(fingerprint);1235_handlers->append(handler);1236// set handler index1237assert(_fingerprints->length() == _handlers->length(), "sanity check");1238handler_index = _fingerprints->length() - 1;1239}1240}1241// Set handler under SignatureHandlerLibrary_lock1242if (handler_index < 0) {1243// use generic signature handler1244method->set_signature_handler(Interpreter::slow_signature_handler());1245} else {1246// set handler1247method->set_signature_handler(_handlers->at(handler_index));1248}1249} else {1250CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());1251// use generic signature handler1252method->set_signature_handler(Interpreter::slow_signature_handler());1253}1254}1255#ifdef ASSERT1256int handler_index = -1;1257int fingerprint_index = -2;1258{1259// '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized1260// in any way if accessed from multiple threads. To avoid races with another1261// thread which may change the arrays in the above, mutex protected block, we1262// have to protect this read access here with the same mutex as well!1263MutexLocker mu(SignatureHandlerLibrary_lock);1264if (_handlers != NULL) {1265handler_index = _handlers->find(method->signature_handler());1266fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());1267}1268}1269assert(method->signature_handler() == Interpreter::slow_signature_handler() ||1270handler_index == fingerprint_index, "sanity check");1271#endif // ASSERT1272}127312741275BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;1276address SignatureHandlerLibrary::_handler = NULL;1277GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;1278GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;1279address SignatureHandlerLibrary::_buffer = NULL;128012811282IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))1283methodHandle m(thread, method);1284assert(m->is_native(), "sanity check");1285// lookup native function entry point if it doesn't exist1286bool in_base_library;1287if (!m->has_native_function()) {1288NativeLookup::lookup(m, in_base_library, CHECK);1289}1290// make sure signature handler is installed1291SignatureHandlerLibrary::add(m);1292// The interpreter entry point checks the signature handler first,1293// before trying to fetch the native entry point and klass mirror.1294// We must set the signature handler last, so that multiple processors1295// preparing the same method will be sure to see non-null entry & mirror.1296IRT_END12971298#if defined(IA32) || defined(AMD64) || defined(ARM) || defined(AARCH64)1299IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))1300if (src_address == dest_address) {1301return;1302}1303ResetNoHandleMark rnm; // In a LEAF entry.1304HandleMark hm;1305ResourceMark rm;1306frame fr = thread->last_frame();1307assert(fr.is_interpreted_frame(), "");1308jint bci = fr.interpreter_frame_bci();1309methodHandle mh(thread, fr.interpreter_frame_method());1310Bytecode_invoke invoke(mh, bci);1311ArgumentSizeComputer asc(invoke.signature());1312int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver1313Copy::conjoint_jbytes(src_address, dest_address,1314size_of_arguments * Interpreter::stackElementSize);1315IRT_END1316#endif13171318#if INCLUDE_JVMTI1319// This is a support of the JVMTI PopFrame interface.1320// Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument1321// and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.1322// The member_name argument is a saved reference (in local#0) to the member_name.1323// For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.1324// FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.1325IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name,1326Method* method, address bcp))1327Bytecodes::Code code = Bytecodes::code_at(method, bcp);1328if (code != Bytecodes::_invokestatic) {1329return;1330}1331ConstantPool* cpool = method->constants();1332int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;1333Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));1334Symbol* mname = cpool->name_ref_at(cp_index);13351336if (MethodHandles::has_member_arg(cname, mname)) {1337oop member_name_oop = (oop) member_name;1338if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {1339// FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.1340member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);1341}1342thread->set_vm_result(member_name_oop);1343} else {1344thread->set_vm_result(NULL);1345}1346IRT_END1347#endif // INCLUDE_JVMTI134813491350