Path: blob/master/src/hotspot/share/interpreter/interpreterRuntime.cpp
40949 views
/*1* Copyright (c) 1997, 2021, 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 "jvm_io.h"26#include "classfile/javaClasses.inline.hpp"27#include "classfile/symbolTable.hpp"28#include "classfile/vmClasses.hpp"29#include "classfile/vmSymbols.hpp"30#include "code/codeCache.hpp"31#include "compiler/compilationPolicy.hpp"32#include "compiler/compileBroker.hpp"33#include "compiler/disassembler.hpp"34#include "gc/shared/barrierSetNMethod.hpp"35#include "gc/shared/collectedHeap.hpp"36#include "interpreter/interpreter.hpp"37#include "interpreter/interpreterRuntime.hpp"38#include "interpreter/linkResolver.hpp"39#include "interpreter/templateTable.hpp"40#include "logging/log.hpp"41#include "memory/oopFactory.hpp"42#include "memory/resourceArea.hpp"43#include "memory/universe.hpp"44#include "oops/constantPool.hpp"45#include "oops/cpCache.inline.hpp"46#include "oops/instanceKlass.inline.hpp"47#include "oops/klass.inline.hpp"48#include "oops/methodData.hpp"49#include "oops/objArrayKlass.hpp"50#include "oops/objArrayOop.inline.hpp"51#include "oops/oop.inline.hpp"52#include "oops/symbol.hpp"53#include "prims/jvmtiExport.hpp"54#include "prims/methodHandles.hpp"55#include "prims/nativeLookup.hpp"56#include "runtime/atomic.hpp"57#include "runtime/biasedLocking.hpp"58#include "runtime/deoptimization.hpp"59#include "runtime/fieldDescriptor.inline.hpp"60#include "runtime/frame.inline.hpp"61#include "runtime/handles.inline.hpp"62#include "runtime/icache.hpp"63#include "runtime/interfaceSupport.inline.hpp"64#include "runtime/java.hpp"65#include "runtime/javaCalls.hpp"66#include "runtime/jfieldIDWorkaround.hpp"67#include "runtime/osThread.hpp"68#include "runtime/sharedRuntime.hpp"69#include "runtime/stackWatermarkSet.hpp"70#include "runtime/stubRoutines.hpp"71#include "runtime/synchronizer.hpp"72#include "runtime/threadCritical.hpp"73#include "utilities/align.hpp"74#include "utilities/copy.hpp"75#include "utilities/events.hpp"76#ifdef COMPILER277#include "opto/runtime.hpp"78#endif7980// Helper class to access current interpreter state81class LastFrameAccessor : public StackObj {82frame _last_frame;83public:84LastFrameAccessor(JavaThread* current) {85assert(current == Thread::current(), "sanity");86_last_frame = current->last_frame();87}88bool is_interpreted_frame() const { return _last_frame.is_interpreted_frame(); }89Method* method() const { return _last_frame.interpreter_frame_method(); }90address bcp() const { return _last_frame.interpreter_frame_bcp(); }91int bci() const { return _last_frame.interpreter_frame_bci(); }92address mdp() const { return _last_frame.interpreter_frame_mdp(); }9394void set_bcp(address bcp) { _last_frame.interpreter_frame_set_bcp(bcp); }95void set_mdp(address dp) { _last_frame.interpreter_frame_set_mdp(dp); }9697// pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)98Bytecodes::Code code() const { return Bytecodes::code_at(method(), bcp()); }99100Bytecode bytecode() const { return Bytecode(method(), bcp()); }101int get_index_u1(Bytecodes::Code bc) const { return bytecode().get_index_u1(bc); }102int get_index_u2(Bytecodes::Code bc) const { return bytecode().get_index_u2(bc); }103int get_index_u2_cpcache(Bytecodes::Code bc) const104{ return bytecode().get_index_u2_cpcache(bc); }105int get_index_u4(Bytecodes::Code bc) const { return bytecode().get_index_u4(bc); }106int number_of_dimensions() const { return bcp()[3]; }107ConstantPoolCacheEntry* cache_entry_at(int i) const108{ return method()->constants()->cache()->entry_at(i); }109ConstantPoolCacheEntry* cache_entry() const { return cache_entry_at(Bytes::get_native_u2(bcp() + 1)); }110111oop callee_receiver(Symbol* signature) {112return _last_frame.interpreter_callee_receiver(signature);113}114BasicObjectLock* monitor_begin() const {115return _last_frame.interpreter_frame_monitor_begin();116}117BasicObjectLock* monitor_end() const {118return _last_frame.interpreter_frame_monitor_end();119}120BasicObjectLock* next_monitor(BasicObjectLock* current) const {121return _last_frame.next_monitor_in_interpreter_frame(current);122}123124frame& get_frame() { return _last_frame; }125};126127//------------------------------------------------------------------------------------------------------------------------128// State accessors129130void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {131LastFrameAccessor last_frame(current);132last_frame.set_bcp(bcp);133if (ProfileInterpreter) {134// ProfileTraps uses MDOs independently of ProfileInterpreter.135// That is why we must check both ProfileInterpreter and mdo != NULL.136MethodData* mdo = last_frame.method()->method_data();137if (mdo != NULL) {138NEEDS_CLEANUP;139last_frame.set_mdp(mdo->bci_to_dp(last_frame.bci()));140}141}142}143144//------------------------------------------------------------------------------------------------------------------------145// Constants146147148JRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* current, bool wide))149// access constant pool150LastFrameAccessor last_frame(current);151ConstantPool* pool = last_frame.method()->constants();152int index = wide ? last_frame.get_index_u2(Bytecodes::_ldc_w) : last_frame.get_index_u1(Bytecodes::_ldc);153constantTag tag = pool->tag_at(index);154155assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");156Klass* klass = pool->klass_at(index, CHECK);157oop java_class = klass->java_mirror();158current->set_vm_result(java_class);159JRT_END160161JRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* current, Bytecodes::Code bytecode)) {162assert(bytecode == Bytecodes::_ldc ||163bytecode == Bytecodes::_ldc_w ||164bytecode == Bytecodes::_ldc2_w ||165bytecode == Bytecodes::_fast_aldc ||166bytecode == Bytecodes::_fast_aldc_w, "wrong bc");167ResourceMark rm(current);168const bool is_fast_aldc = (bytecode == Bytecodes::_fast_aldc ||169bytecode == Bytecodes::_fast_aldc_w);170LastFrameAccessor last_frame(current);171methodHandle m (current, last_frame.method());172Bytecode_loadconstant ldc(m, last_frame.bci());173174// Double-check the size. (Condy can have any type.)175BasicType type = ldc.result_type();176switch (type2size[type]) {177case 2: guarantee(bytecode == Bytecodes::_ldc2_w, ""); break;178case 1: guarantee(bytecode != Bytecodes::_ldc2_w, ""); break;179default: ShouldNotReachHere();180}181182// Resolve the constant. This does not do unboxing.183// But it does replace Universe::the_null_sentinel by null.184oop result = ldc.resolve_constant(CHECK);185assert(result != NULL || is_fast_aldc, "null result only valid for fast_aldc");186187#ifdef ASSERT188{189// The bytecode wrappers aren't GC-safe so construct a new one190Bytecode_loadconstant ldc2(m, last_frame.bci());191int rindex = ldc2.cache_index();192if (rindex < 0)193rindex = m->constants()->cp_to_object_index(ldc2.pool_index());194if (rindex >= 0) {195oop coop = m->constants()->resolved_references()->obj_at(rindex);196oop roop = (result == NULL ? Universe::the_null_sentinel() : result);197assert(roop == coop, "expected result for assembly code");198}199}200#endif201current->set_vm_result(result);202if (!is_fast_aldc) {203// Tell the interpreter how to unbox the primitive.204guarantee(java_lang_boxing_object::is_instance(result, type), "");205int offset = java_lang_boxing_object::value_offset(type);206intptr_t flags = ((as_TosState(type) << ConstantPoolCacheEntry::tos_state_shift)207| (offset & ConstantPoolCacheEntry::field_index_mask));208current->set_vm_result_2((Metadata*)flags);209}210}211JRT_END212213214//------------------------------------------------------------------------------------------------------------------------215// Allocation216217JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))218Klass* k = pool->klass_at(index, CHECK);219InstanceKlass* klass = InstanceKlass::cast(k);220221// Make sure we are not instantiating an abstract klass222klass->check_valid_for_instantiation(true, CHECK);223224// Make sure klass is initialized225klass->initialize(CHECK);226227// At this point the class may not be fully initialized228// because of recursive initialization. If it is fully229// initialized & has_finalized is not set, we rewrite230// it into its fast version (Note: no locking is needed231// here since this is an atomic byte write and can be232// done more than once).233//234// Note: In case of classes with has_finalized we don't235// rewrite since that saves us an extra check in236// the fast version which then would call the237// slow version anyway (and do a call back into238// Java).239// If we have a breakpoint, then we don't rewrite240// because the _breakpoint bytecode would be lost.241oop obj = klass->allocate_instance(CHECK);242current->set_vm_result(obj);243JRT_END244245246JRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* current, BasicType type, jint size))247oop obj = oopFactory::new_typeArray(type, size, CHECK);248current->set_vm_result(obj);249JRT_END250251252JRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* current, ConstantPool* pool, int index, jint size))253Klass* klass = pool->klass_at(index, CHECK);254objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);255current->set_vm_result(obj);256JRT_END257258259JRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* current, jint* first_size_address))260// We may want to pass in more arguments - could make this slightly faster261LastFrameAccessor last_frame(current);262ConstantPool* constants = last_frame.method()->constants();263int i = last_frame.get_index_u2(Bytecodes::_multianewarray);264Klass* klass = constants->klass_at(i, CHECK);265int nof_dims = last_frame.number_of_dimensions();266assert(klass->is_klass(), "not a class");267assert(nof_dims >= 1, "multianewarray rank must be nonzero");268269// We must create an array of jints to pass to multi_allocate.270ResourceMark rm(current);271const int small_dims = 10;272jint dim_array[small_dims];273jint *dims = &dim_array[0];274if (nof_dims > small_dims) {275dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);276}277for (int index = 0; index < nof_dims; index++) {278// offset from first_size_address is addressed as local[index]279int n = Interpreter::local_offset_in_bytes(index)/jintSize;280dims[index] = first_size_address[n];281}282oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);283current->set_vm_result(obj);284JRT_END285286287JRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* current, oopDesc* obj))288assert(oopDesc::is_oop(obj), "must be a valid oop");289assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");290InstanceKlass::register_finalizer(instanceOop(obj), CHECK);291JRT_END292293294// Quicken instance-of and check-cast bytecodes295JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))296// Force resolving; quicken the bytecode297LastFrameAccessor last_frame(current);298int which = last_frame.get_index_u2(Bytecodes::_checkcast);299ConstantPool* cpool = last_frame.method()->constants();300// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded301// program we might have seen an unquick'd bytecode in the interpreter but have another302// thread quicken the bytecode before we get here.303// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );304Klass* klass = cpool->klass_at(which, CHECK);305current->set_vm_result_2(klass);306JRT_END307308309//------------------------------------------------------------------------------------------------------------------------310// Exceptions311312void InterpreterRuntime::note_trap_inner(JavaThread* current, int reason,313const methodHandle& trap_method, int trap_bci) {314if (trap_method.not_null()) {315MethodData* trap_mdo = trap_method->method_data();316if (trap_mdo == NULL) {317ExceptionMark em(current);318JavaThread* THREAD = current; // For exception macros.319Method::build_interpreter_method_data(trap_method, THREAD);320if (HAS_PENDING_EXCEPTION) {321// Only metaspace OOM is expected. No Java code executed.322assert((PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())),323"we expect only an OOM error here");324CLEAR_PENDING_EXCEPTION;325}326trap_mdo = trap_method->method_data();327// and fall through...328}329if (trap_mdo != NULL) {330// Update per-method count of trap events. The interpreter331// is updating the MDO to simulate the effect of compiler traps.332Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);333}334}335}336337// Assume the compiler is (or will be) interested in this event.338// If necessary, create an MDO to hold the information, and record it.339void InterpreterRuntime::note_trap(JavaThread* current, int reason) {340assert(ProfileTraps, "call me only if profiling");341LastFrameAccessor last_frame(current);342methodHandle trap_method(current, last_frame.method());343int trap_bci = trap_method->bci_from(last_frame.bcp());344note_trap_inner(current, reason, trap_method, trap_bci);345}346347static Handle get_preinitialized_exception(Klass* k, TRAPS) {348// get klass349InstanceKlass* klass = InstanceKlass::cast(k);350assert(klass->is_initialized(),351"this klass should have been initialized during VM initialization");352// create instance - do not call constructor since we may have no353// (java) stack space left (should assert constructor is empty)354Handle exception;355oop exception_oop = klass->allocate_instance(CHECK_(exception));356exception = Handle(THREAD, exception_oop);357if (StackTraceInThrowable) {358java_lang_Throwable::fill_in_stack_trace(exception);359}360return exception;361}362363// Special handling for stack overflow: since we don't have any (java) stack364// space left we use the pre-allocated & pre-initialized StackOverflowError365// klass to create an stack overflow error instance. We do not call its366// constructor for the same reason (it is empty, anyway).367JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current))368Handle exception = get_preinitialized_exception(369vmClasses::StackOverflowError_klass(),370CHECK);371// Increment counter for hs_err file reporting372Atomic::inc(&Exceptions::_stack_overflow_errors);373THROW_HANDLE(exception);374JRT_END375376JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread* current))377Handle exception = get_preinitialized_exception(378vmClasses::StackOverflowError_klass(),379CHECK);380java_lang_Throwable::set_message(exception(),381Universe::delayed_stack_overflow_error_message());382// Increment counter for hs_err file reporting383Atomic::inc(&Exceptions::_stack_overflow_errors);384THROW_HANDLE(exception);385JRT_END386387JRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* current, char* name, char* message))388// lookup exception klass389TempNewSymbol s = SymbolTable::new_symbol(name);390if (ProfileTraps) {391if (s == vmSymbols::java_lang_ArithmeticException()) {392note_trap(current, Deoptimization::Reason_div0_check);393} else if (s == vmSymbols::java_lang_NullPointerException()) {394note_trap(current, Deoptimization::Reason_null_check);395}396}397// create exception398Handle exception = Exceptions::new_exception(current, s, message);399current->set_vm_result(exception());400JRT_END401402403JRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* current, char* name, oopDesc* obj))404// Produce the error message first because note_trap can safepoint405ResourceMark rm(current);406const char* klass_name = obj->klass()->external_name();407// lookup exception klass408TempNewSymbol s = SymbolTable::new_symbol(name);409if (ProfileTraps) {410note_trap(current, Deoptimization::Reason_class_check);411}412// create exception, with klass name as detail message413Handle exception = Exceptions::new_exception(current, s, klass_name);414current->set_vm_result(exception());415JRT_END416417JRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* current, arrayOopDesc* a, jint index))418// Produce the error message first because note_trap can safepoint419ResourceMark rm(current);420stringStream ss;421ss.print("Index %d out of bounds for length %d", index, a->length());422423if (ProfileTraps) {424note_trap(current, Deoptimization::Reason_range_check);425}426427THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), ss.as_string());428JRT_END429430JRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(431JavaThread* current, oopDesc* obj))432433// Produce the error message first because note_trap can safepoint434ResourceMark rm(current);435char* message = SharedRuntime::generate_class_cast_message(436current, obj->klass());437438if (ProfileTraps) {439note_trap(current, Deoptimization::Reason_class_check);440}441442// create exception443THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);444JRT_END445446// exception_handler_for_exception(...) returns the continuation address,447// the exception oop (via TLS) and sets the bci/bcp for the continuation.448// The exception oop is returned to make sure it is preserved over GC (it449// is only on the stack if the exception was thrown explicitly via athrow).450// During this operation, the expression stack contains the values for the451// bci where the exception happened. If the exception was propagated back452// from a call, the expression stack contains the values for the bci at the453// invoke w/o arguments (i.e., as if one were inside the call).454JRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* current, oopDesc* exception))455// We get here after we have unwound from a callee throwing an exception456// into the interpreter. Any deferred stack processing is notified of457// the event via the StackWatermarkSet.458StackWatermarkSet::after_unwind(current);459460LastFrameAccessor last_frame(current);461Handle h_exception(current, exception);462methodHandle h_method (current, last_frame.method());463constantPoolHandle h_constants(current, h_method->constants());464bool should_repeat;465int handler_bci;466int current_bci = last_frame.bci();467468if (current->frames_to_pop_failed_realloc() > 0) {469// Allocation of scalar replaced object used in this frame470// failed. Unconditionally pop the frame.471current->dec_frames_to_pop_failed_realloc();472current->set_vm_result(h_exception());473// If the method is synchronized we already unlocked the monitor474// during deoptimization so the interpreter needs to skip it when475// the frame is popped.476current->set_do_not_unlock_if_synchronized(true);477return Interpreter::remove_activation_entry();478}479480// Need to do this check first since when _do_not_unlock_if_synchronized481// is set, we don't want to trigger any classloading which may make calls482// into java, or surprisingly find a matching exception handler for bci 0483// since at this moment the method hasn't been "officially" entered yet.484if (current->do_not_unlock_if_synchronized()) {485ResourceMark rm;486assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");487current->set_vm_result(exception);488return Interpreter::remove_activation_entry();489}490491do {492should_repeat = false;493494// assertions495assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");496// Check that exception is a subclass of Throwable.497assert(h_exception->is_a(vmClasses::Throwable_klass()),498"Exception not subclass of Throwable");499500// tracing501if (log_is_enabled(Info, exceptions)) {502ResourceMark rm(current);503stringStream tempst;504tempst.print("interpreter method <%s>\n"505" at bci %d for thread " INTPTR_FORMAT " (%s)",506h_method->print_value_string(), current_bci, p2i(current), current->name());507Exceptions::log_exception(h_exception, tempst.as_string());508}509// Don't go paging in something which won't be used.510// else if (extable->length() == 0) {511// // disabled for now - interpreter is not using shortcut yet512// // (shortcut is not to call runtime if we have no exception handlers)513// // warning("performance bug: should not call runtime if method has no exception handlers");514// }515// for AbortVMOnException flag516Exceptions::debug_check_abort(h_exception);517518// exception handler lookup519Klass* klass = h_exception->klass();520handler_bci = Method::fast_exception_handler_bci_for(h_method, klass, current_bci, THREAD);521if (HAS_PENDING_EXCEPTION) {522// We threw an exception while trying to find the exception handler.523// Transfer the new exception to the exception handle which will524// be set into thread local storage, and do another lookup for an525// exception handler for this exception, this time starting at the526// BCI of the exception handler which caused the exception to be527// thrown (bug 4307310).528h_exception = Handle(THREAD, PENDING_EXCEPTION);529CLEAR_PENDING_EXCEPTION;530if (handler_bci >= 0) {531current_bci = handler_bci;532should_repeat = true;533}534}535} while (should_repeat == true);536537#if INCLUDE_JVMCI538if (EnableJVMCI && h_method->method_data() != NULL) {539ResourceMark rm(current);540ProfileData* pdata = h_method->method_data()->allocate_bci_to_data(current_bci, NULL);541if (pdata != NULL && pdata->is_BitData()) {542BitData* bit_data = (BitData*) pdata;543bit_data->set_exception_seen();544}545}546#endif547548// notify JVMTI of an exception throw; JVMTI will detect if this is a first549// time throw or a stack unwinding throw and accordingly notify the debugger550if (JvmtiExport::can_post_on_exceptions()) {551JvmtiExport::post_exception_throw(current, h_method(), last_frame.bcp(), h_exception());552}553554address continuation = NULL;555address handler_pc = NULL;556if (handler_bci < 0 || !current->stack_overflow_state()->reguard_stack((address) &continuation)) {557// Forward exception to callee (leaving bci/bcp untouched) because (a) no558// handler in this method, or (b) after a stack overflow there is not yet559// enough stack space available to reprotect the stack.560continuation = Interpreter::remove_activation_entry();561#if COMPILER2_OR_JVMCI562// Count this for compilation purposes563h_method->interpreter_throwout_increment(THREAD);564#endif565} else {566// handler in this method => change bci/bcp to handler bci/bcp and continue there567handler_pc = h_method->code_base() + handler_bci;568#ifndef ZERO569set_bcp_and_mdp(handler_pc, current);570continuation = Interpreter::dispatch_table(vtos)[*handler_pc];571#else572continuation = (address)(intptr_t) handler_bci;573#endif574}575576// notify debugger of an exception catch577// (this is good for exceptions caught in native methods as well)578if (JvmtiExport::can_post_on_exceptions()) {579JvmtiExport::notice_unwind_due_to_exception(current, h_method(), handler_pc, h_exception(), (handler_pc != NULL));580}581582current->set_vm_result(h_exception());583return continuation;584JRT_END585586587JRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* current))588assert(current->has_pending_exception(), "must only be called if there's an exception pending");589// nothing to do - eventually we should remove this code entirely (see comments @ call sites)590JRT_END591592593JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* current))594THROW(vmSymbols::java_lang_AbstractMethodError());595JRT_END596597// This method is called from the "abstract_entry" of the interpreter.598// At that point, the arguments have already been removed from the stack599// and therefore we don't have the receiver object at our fingertips. (Though,600// on some platforms the receiver still resides in a register...). Thus,601// we have no choice but print an error message not containing the receiver602// type.603JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorWithMethod(JavaThread* current,604Method* missingMethod))605ResourceMark rm(current);606assert(missingMethod != NULL, "sanity");607methodHandle m(current, missingMethod);608LinkResolver::throw_abstract_method_error(m, THREAD);609JRT_END610611JRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodErrorVerbose(JavaThread* current,612Klass* recvKlass,613Method* missingMethod))614ResourceMark rm(current);615methodHandle mh = methodHandle(current, missingMethod);616LinkResolver::throw_abstract_method_error(mh, recvKlass, THREAD);617JRT_END618619620JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* current))621THROW(vmSymbols::java_lang_IncompatibleClassChangeError());622JRT_END623624JRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(JavaThread* current,625Klass* recvKlass,626Klass* interfaceKlass))627ResourceMark rm(current);628char buf[1000];629buf[0] = '\0';630jio_snprintf(buf, sizeof(buf),631"Class %s does not implement the requested interface %s",632recvKlass ? recvKlass->external_name() : "NULL",633interfaceKlass ? interfaceKlass->external_name() : "NULL");634THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);635JRT_END636637JRT_ENTRY(void, InterpreterRuntime::throw_NullPointerException(JavaThread* current))638THROW(vmSymbols::java_lang_NullPointerException());639JRT_END640641//------------------------------------------------------------------------------------------------------------------------642// Fields643//644645void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {646// resolve field647fieldDescriptor info;648LastFrameAccessor last_frame(current);649constantPoolHandle pool(current, last_frame.method()->constants());650methodHandle m(current, last_frame.method());651bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_nofast_putfield ||652bytecode == Bytecodes::_putstatic);653bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);654655{656JvmtiHideSingleStepping jhss(current);657JavaThread* THREAD = current; // For exception macros.658LinkResolver::resolve_field_access(info, pool, last_frame.get_index_u2_cpcache(bytecode),659m, bytecode, CHECK);660} // end JvmtiHideSingleStepping661662// check if link resolution caused cpCache to be updated663ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();664if (cp_cache_entry->is_resolved(bytecode)) return;665666// compute auxiliary field attributes667TosState state = as_TosState(info.field_type());668669// Resolution of put instructions on final fields is delayed. That is required so that670// exceptions are thrown at the correct place (when the instruction is actually invoked).671// If we do not resolve an instruction in the current pass, leaving the put_code672// set to zero will cause the next put instruction to the same field to reresolve.673674// Resolution of put instructions to final instance fields with invalid updates (i.e.,675// to final instance fields with updates originating from a method different than <init>)676// is inhibited. A putfield instruction targeting an instance final field must throw677// an IllegalAccessError if the instruction is not in an instance678// initializer method <init>. If resolution were not inhibited, a putfield679// in an initializer method could be resolved in the initializer. Subsequent680// putfield instructions to the same field would then use cached information.681// As a result, those instructions would not pass through the VM. That is,682// checks in resolve_field_access() would not be executed for those instructions683// and the required IllegalAccessError would not be thrown.684//685// Also, we need to delay resolving getstatic and putstatic instructions until the686// class is initialized. This is required so that access to the static687// field will call the initialization function every time until the class688// is completely initialized ala. in 2.17.5 in JVM Specification.689InstanceKlass* klass = info.field_holder();690bool uninitialized_static = is_static && !klass->is_initialized();691bool has_initialized_final_update = info.field_holder()->major_version() >= 53 &&692info.has_initialized_final_update();693assert(!(has_initialized_final_update && !info.access_flags().is_final()), "Fields with initialized final updates must be final");694695Bytecodes::Code get_code = (Bytecodes::Code)0;696Bytecodes::Code put_code = (Bytecodes::Code)0;697if (!uninitialized_static) {698get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);699if ((is_put && !has_initialized_final_update) || !info.access_flags().is_final()) {700put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);701}702}703704cp_cache_entry->set_field(705get_code,706put_code,707info.field_holder(),708info.index(),709info.offset(),710state,711info.access_flags().is_final(),712info.access_flags().is_volatile()713);714}715716717//------------------------------------------------------------------------------------------------------------------------718// Synchronization719//720// The interpreter's synchronization code is factored out so that it can721// be shared by method invocation and synchronized blocks.722//%note synchronization_3723724//%note monitor_1725JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* current, BasicObjectLock* elem))726#ifdef ASSERT727current->last_frame().interpreter_frame_verify_monitor(elem);728#endif729if (PrintBiasedLockingStatistics) {730Atomic::inc(BiasedLocking::slow_path_entry_count_addr());731}732Handle h_obj(current, elem->obj());733assert(Universe::heap()->is_in_or_null(h_obj()),734"must be NULL or an object");735ObjectSynchronizer::enter(h_obj, elem->lock(), current);736assert(Universe::heap()->is_in_or_null(elem->obj()),737"must be NULL or an object");738#ifdef ASSERT739current->last_frame().interpreter_frame_verify_monitor(elem);740#endif741JRT_END742743744JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))745oop obj = elem->obj();746assert(Universe::heap()->is_in(obj), "must be an object");747// The object could become unlocked through a JNI call, which we have no other checks for.748// Give a fatal message if CheckJNICalls. Otherwise we ignore it.749if (obj->is_unlocked()) {750if (CheckJNICalls) {751fatal("Object has been unlocked by JNI");752}753return;754}755ObjectSynchronizer::exit(obj, elem->lock(), JavaThread::current());756// Free entry. If it is not cleared, the exception handling code will try to unlock the monitor757// again at method exit or in the case of an exception.758elem->set_obj(NULL);759JRT_END760761762JRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* current))763THROW(vmSymbols::java_lang_IllegalMonitorStateException());764JRT_END765766767JRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* current))768// Returns an illegal exception to install into the current thread. The769// pending_exception flag is cleared so normal exception handling does not770// trigger. Any current installed exception will be overwritten. This771// method will be called during an exception unwind.772773assert(!HAS_PENDING_EXCEPTION, "no pending exception");774Handle exception(current, current->vm_result());775assert(exception() != NULL, "vm result should be set");776current->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)777if (!exception->is_a(vmClasses::ThreadDeath_klass())) {778exception = get_preinitialized_exception(779vmClasses::IllegalMonitorStateException_klass(),780CATCH);781}782current->set_vm_result(exception());783JRT_END784785786//------------------------------------------------------------------------------------------------------------------------787// Invokes788789JRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* current, Method* method, address bcp))790return method->orig_bytecode_at(method->bci_from(bcp));791JRT_END792793JRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* current, Method* method, address bcp, Bytecodes::Code new_code))794method->set_orig_bytecode_at(method->bci_from(bcp), new_code);795JRT_END796797JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* method, address bcp))798JvmtiExport::post_raw_breakpoint(current, method, bcp);799JRT_END800801void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {802LastFrameAccessor last_frame(current);803// extract receiver from the outgoing argument list if necessary804Handle receiver(current, NULL);805if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||806bytecode == Bytecodes::_invokespecial) {807ResourceMark rm(current);808methodHandle m (current, last_frame.method());809Bytecode_invoke call(m, last_frame.bci());810Symbol* signature = call.signature();811receiver = Handle(current, last_frame.callee_receiver(signature));812813assert(Universe::heap()->is_in_or_null(receiver()),814"sanity check");815assert(receiver.is_null() ||816!Universe::heap()->is_in(receiver->klass()),817"sanity check");818}819820// resolve method821CallInfo info;822constantPoolHandle pool(current, last_frame.method()->constants());823824methodHandle resolved_method;825826{827JvmtiHideSingleStepping jhss(current);828JavaThread* THREAD = current; // For exception macros.829LinkResolver::resolve_invoke(info, receiver, pool,830last_frame.get_index_u2_cpcache(bytecode), bytecode,831CHECK);832if (JvmtiExport::can_hotswap_or_post_breakpoint() && info.resolved_method()->is_old()) {833resolved_method = methodHandle(current, info.resolved_method()->get_new_method());834} else {835resolved_method = methodHandle(current, info.resolved_method());836}837} // end JvmtiHideSingleStepping838839// check if link resolution caused cpCache to be updated840ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();841if (cp_cache_entry->is_resolved(bytecode)) return;842843#ifdef ASSERT844if (bytecode == Bytecodes::_invokeinterface) {845if (resolved_method->method_holder() == vmClasses::Object_klass()) {846// NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec847// (see also CallInfo::set_interface for details)848assert(info.call_kind() == CallInfo::vtable_call ||849info.call_kind() == CallInfo::direct_call, "");850assert(resolved_method->is_final() || info.has_vtable_index(),851"should have been set already");852} else if (!resolved_method->has_itable_index()) {853// Resolved something like CharSequence.toString. Use vtable not itable.854assert(info.call_kind() != CallInfo::itable_call, "");855} else {856// Setup itable entry857assert(info.call_kind() == CallInfo::itable_call, "");858int index = resolved_method->itable_index();859assert(info.itable_index() == index, "");860}861} else if (bytecode == Bytecodes::_invokespecial) {862assert(info.call_kind() == CallInfo::direct_call, "must be direct call");863} else {864assert(info.call_kind() == CallInfo::direct_call ||865info.call_kind() == CallInfo::vtable_call, "");866}867#endif868// Get sender and only set cpCache entry to resolved if it is not an869// interface. The receiver for invokespecial calls within interface870// methods must be checked for every call.871InstanceKlass* sender = pool->pool_holder();872873switch (info.call_kind()) {874case CallInfo::direct_call:875cp_cache_entry->set_direct_call(876bytecode,877resolved_method,878sender->is_interface());879break;880case CallInfo::vtable_call:881cp_cache_entry->set_vtable_call(882bytecode,883resolved_method,884info.vtable_index());885break;886case CallInfo::itable_call:887cp_cache_entry->set_itable_call(888bytecode,889info.resolved_klass(),890resolved_method,891info.itable_index());892break;893default: ShouldNotReachHere();894}895}896897898// First time execution: Resolve symbols, create a permanent MethodType object.899void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {900const Bytecodes::Code bytecode = Bytecodes::_invokehandle;901LastFrameAccessor last_frame(current);902903// resolve method904CallInfo info;905constantPoolHandle pool(current, last_frame.method()->constants());906{907JvmtiHideSingleStepping jhss(current);908JavaThread* THREAD = current; // For exception macros.909LinkResolver::resolve_invoke(info, Handle(), pool,910last_frame.get_index_u2_cpcache(bytecode), bytecode,911CHECK);912} // end JvmtiHideSingleStepping913914ConstantPoolCacheEntry* cp_cache_entry = last_frame.cache_entry();915cp_cache_entry->set_method_handle(pool, info);916}917918// First time execution: Resolve symbols, create a permanent CallSite object.919void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {920LastFrameAccessor last_frame(current);921const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;922923// resolve method924CallInfo info;925constantPoolHandle pool(current, last_frame.method()->constants());926int index = last_frame.get_index_u4(bytecode);927{928JvmtiHideSingleStepping jhss(current);929JavaThread* THREAD = current; // For exception macros.930LinkResolver::resolve_invoke(info, Handle(), pool,931index, bytecode, CHECK);932} // end JvmtiHideSingleStepping933934ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);935cp_cache_entry->set_dynamic_call(pool, info);936}937938// This function is the interface to the assembly code. It returns the resolved939// cpCache entry. This doesn't safepoint, but the helper routines safepoint.940// This function will check for redefinition!941JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Bytecodes::Code bytecode)) {942switch (bytecode) {943case Bytecodes::_getstatic:944case Bytecodes::_putstatic:945case Bytecodes::_getfield:946case Bytecodes::_putfield:947resolve_get_put(current, bytecode);948break;949case Bytecodes::_invokevirtual:950case Bytecodes::_invokespecial:951case Bytecodes::_invokestatic:952case Bytecodes::_invokeinterface:953resolve_invoke(current, bytecode);954break;955case Bytecodes::_invokehandle:956resolve_invokehandle(current);957break;958case Bytecodes::_invokedynamic:959resolve_invokedynamic(current);960break;961default:962fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));963break;964}965}966JRT_END967968//------------------------------------------------------------------------------------------------------------------------969// Miscellaneous970971972nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {973// Enable WXWrite: the function is called directly by interpreter.974MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current));975976// frequency_counter_overflow_inner can throw async exception.977nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);978assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");979if (branch_bcp != NULL && nm != NULL) {980// This was a successful request for an OSR nmethod. Because981// frequency_counter_overflow_inner ends with a safepoint check,982// nm could have been unloaded so look it up again. It's unsafe983// to examine nm directly since it might have been freed and used984// for something else.985LastFrameAccessor last_frame(current);986Method* method = last_frame.method();987int bci = method->bci_from(last_frame.bcp());988nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);989BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();990if (nm != NULL && bs_nm != NULL) {991// in case the transition passed a safepoint we need to barrier this again992if (!bs_nm->nmethod_osr_entry_barrier(nm)) {993nm = NULL;994}995}996}997if (nm != NULL && current->is_interp_only_mode()) {998// Normally we never get an nm if is_interp_only_mode() is true, because999// policy()->event has a check for this and won't compile the method when1000// true. However, it's possible for is_interp_only_mode() to become true1001// during the compilation. We don't want to return the nm in that case1002// because we want to continue to execute interpreted.1003nm = NULL;1004}1005#ifndef PRODUCT1006if (TraceOnStackReplacement) {1007if (nm != NULL) {1008tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", p2i(nm->osr_entry()));1009nm->print();1010}1011}1012#endif1013return nm;1014}10151016JRT_ENTRY(nmethod*,1017InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* current, address branch_bcp))1018// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized1019// flag, in case this method triggers classloading which will call into Java.1020UnlockFlagSaver fs(current);10211022LastFrameAccessor last_frame(current);1023assert(last_frame.is_interpreted_frame(), "must come from interpreter");1024methodHandle method(current, last_frame.method());1025const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;1026const int bci = branch_bcp != NULL ? method->bci_from(last_frame.bcp()) : InvocationEntryBci;10271028nmethod* osr_nm = CompilationPolicy::event(method, method, branch_bci, bci, CompLevel_none, NULL, CHECK_NULL);10291030BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();1031if (osr_nm != NULL && bs_nm != NULL) {1032if (!bs_nm->nmethod_osr_entry_barrier(osr_nm)) {1033osr_nm = NULL;1034}1035}10361037if (osr_nm != NULL) {1038// We may need to do on-stack replacement which requires that no1039// monitors in the activation are biased because their1040// BasicObjectLocks will need to migrate during OSR. Force1041// unbiasing of all monitors in the activation now (even though1042// the OSR nmethod might be invalidated) because we don't have a1043// safepoint opportunity later once the migration begins.1044if (UseBiasedLocking) {1045ResourceMark rm;1046GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();1047for( BasicObjectLock *kptr = last_frame.monitor_end();1048kptr < last_frame.monitor_begin();1049kptr = last_frame.next_monitor(kptr) ) {1050if( kptr->obj() != NULL ) {1051objects_to_revoke->append(Handle(current, kptr->obj()));1052}1053}1054BiasedLocking::revoke(objects_to_revoke, current);1055}1056}1057return osr_nm;1058JRT_END10591060JRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))1061assert(ProfileInterpreter, "must be profiling interpreter");1062int bci = method->bci_from(cur_bcp);1063MethodData* mdo = method->method_data();1064if (mdo == NULL) return 0;1065return mdo->bci_to_di(bci);1066JRT_END10671068#ifdef ASSERT1069JRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))1070assert(ProfileInterpreter, "must be profiling interpreter");10711072MethodData* mdo = method->method_data();1073assert(mdo != NULL, "must not be null");10741075int bci = method->bci_from(bcp);10761077address mdp2 = mdo->bci_to_dp(bci);1078if (mdp != mdp2) {1079ResourceMark rm;1080tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);1081int current_di = mdo->dp_to_di(mdp);1082int expected_di = mdo->dp_to_di(mdp2);1083tty->print_cr(" actual di %d expected di %d", current_di, expected_di);1084int expected_approx_bci = mdo->data_at(expected_di)->bci();1085int approx_bci = -1;1086if (current_di >= 0) {1087approx_bci = mdo->data_at(current_di)->bci();1088}1089tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);1090mdo->print_on(tty);1091method->print_codes();1092}1093assert(mdp == mdp2, "wrong mdp");1094JRT_END1095#endif // ASSERT10961097JRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* current, int return_bci))1098assert(ProfileInterpreter, "must be profiling interpreter");1099ResourceMark rm(current);1100LastFrameAccessor last_frame(current);1101assert(last_frame.is_interpreted_frame(), "must come from interpreter");1102MethodData* h_mdo = last_frame.method()->method_data();11031104// Grab a lock to ensure atomic access to setting the return bci and1105// the displacement. This can block and GC, invalidating all naked oops.1106MutexLocker ml(RetData_lock);11071108// ProfileData is essentially a wrapper around a derived oop, so we1109// need to take the lock before making any ProfileData structures.1110ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(last_frame.mdp()));1111guarantee(data != NULL, "profile data must be valid");1112RetData* rdata = data->as_RetData();1113address new_mdp = rdata->fixup_ret(return_bci, h_mdo);1114last_frame.set_mdp(new_mdp);1115JRT_END11161117JRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* current, Method* m))1118return Method::build_method_counters(current, m);1119JRT_END112011211122JRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* current))1123// We used to need an explict preserve_arguments here for invoke bytecodes. However,1124// stack traversal automatically takes care of preserving arguments for invoke, so1125// this is no longer needed.11261127// JRT_END does an implicit safepoint check, hence we are guaranteed to block1128// if this is called during a safepoint11291130if (JvmtiExport::should_post_single_step()) {1131// This function is called by the interpreter when single stepping. Such single1132// stepping could unwind a frame. Then, it is important that we process any frames1133// that we might return into.1134StackWatermarkSet::before_unwind(current);11351136// We are called during regular safepoints and when the VM is1137// single stepping. If any thread is marked for single stepping,1138// then we may have JVMTI work to do.1139LastFrameAccessor last_frame(current);1140JvmtiExport::at_single_stepping_point(current, last_frame.method(), last_frame.bcp());1141}1142JRT_END11431144JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))1145// This function is called by the interpreter when the return poll found a reason1146// to call the VM. The reason could be that we are returning into a not yet safe1147// to access frame. We handle that below.1148// Note that this path does not check for single stepping, because we do not want1149// to single step when unwinding frames for an exception being thrown. Instead,1150// such single stepping code will use the safepoint table, which will use the1151// InterpreterRuntime::at_safepoint callback.1152StackWatermarkSet::before_unwind(current);1153JRT_END11541155JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,1156ConstantPoolCacheEntry *cp_entry))11571158// check the access_flags for the field in the klass11591160InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());1161int index = cp_entry->field_index();1162if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;11631164bool is_static = (obj == NULL);1165HandleMark hm(current);11661167Handle h_obj;1168if (!is_static) {1169// non-static field accessors have an object, but we need a handle1170h_obj = Handle(current, obj);1171}1172InstanceKlass* cp_entry_f1 = InstanceKlass::cast(cp_entry->f1_as_klass());1173jfieldID fid = jfieldIDWorkaround::to_jfieldID(cp_entry_f1, cp_entry->f2_as_index(), is_static);1174LastFrameAccessor last_frame(current);1175JvmtiExport::post_field_access(current, last_frame.method(), last_frame.bcp(), cp_entry_f1, h_obj, fid);1176JRT_END11771178JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current, oopDesc* obj,1179ConstantPoolCacheEntry *cp_entry, jvalue *value))11801181Klass* k = cp_entry->f1_as_klass();11821183// check the access_flags for the field in the klass1184InstanceKlass* ik = InstanceKlass::cast(k);1185int index = cp_entry->field_index();1186// bail out if field modifications are not watched1187if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;11881189char sig_type = '\0';11901191switch(cp_entry->flag_state()) {1192case btos: sig_type = JVM_SIGNATURE_BYTE; break;1193case ztos: sig_type = JVM_SIGNATURE_BOOLEAN; break;1194case ctos: sig_type = JVM_SIGNATURE_CHAR; break;1195case stos: sig_type = JVM_SIGNATURE_SHORT; break;1196case itos: sig_type = JVM_SIGNATURE_INT; break;1197case ftos: sig_type = JVM_SIGNATURE_FLOAT; break;1198case atos: sig_type = JVM_SIGNATURE_CLASS; break;1199case ltos: sig_type = JVM_SIGNATURE_LONG; break;1200case dtos: sig_type = JVM_SIGNATURE_DOUBLE; break;1201default: ShouldNotReachHere(); return;1202}1203bool is_static = (obj == NULL);12041205HandleMark hm(current);1206jfieldID fid = jfieldIDWorkaround::to_jfieldID(ik, cp_entry->f2_as_index(), is_static);1207jvalue fvalue;1208#ifdef _LP641209fvalue = *value;1210#else1211// Long/double values are stored unaligned and also noncontiguously with1212// tagged stacks. We can't just do a simple assignment even in the non-1213// J/D cases because a C++ compiler is allowed to assume that a jvalue is1214// 8-byte aligned, and interpreter stack slots are only 4-byte aligned.1215// We assume that the two halves of longs/doubles are stored in interpreter1216// stack slots in platform-endian order.1217jlong_accessor u;1218jint* newval = (jint*)value;1219u.words[0] = newval[0];1220u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag1221fvalue.j = u.long_value;1222#endif // _LP6412231224Handle h_obj;1225if (!is_static) {1226// non-static field accessors have an object, but we need a handle1227h_obj = Handle(current, obj);1228}12291230LastFrameAccessor last_frame(current);1231JvmtiExport::post_raw_field_modification(current, last_frame.method(), last_frame.bcp(), ik, h_obj,1232fid, sig_type, &fvalue);1233JRT_END12341235JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread* current))1236LastFrameAccessor last_frame(current);1237JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());1238JRT_END123912401241// This is a JRT_BLOCK_ENTRY because we have to stash away the return oop1242// before transitioning to VM, and restore it after transitioning back1243// to Java. The return oop at the top-of-stack, is not walked by the GC.1244JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread* current))1245LastFrameAccessor last_frame(current);1246JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());1247JRT_END12481249JRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))1250{1251return (Interpreter::contains(pc) ? 1 : 0);1252}1253JRT_END125412551256// Implementation of SignatureHandlerLibrary12571258#ifndef SHARING_FAST_NATIVE_FINGERPRINTS1259// Dummy definition (else normalization method is defined in CPU1260// dependant code)1261uint64_t InterpreterRuntime::normalize_fast_native_fingerprint(uint64_t fingerprint) {1262return fingerprint;1263}1264#endif12651266address SignatureHandlerLibrary::set_handler_blob() {1267BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);1268if (handler_blob == NULL) {1269return NULL;1270}1271address handler = handler_blob->code_begin();1272_handler_blob = handler_blob;1273_handler = handler;1274return handler;1275}12761277void SignatureHandlerLibrary::initialize() {1278if (_fingerprints != NULL) {1279return;1280}1281if (set_handler_blob() == NULL) {1282vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");1283}12841285BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",1286SignatureHandlerLibrary::buffer_size);1287_buffer = bb->code_begin();12881289_fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, mtCode);1290_handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, mtCode);1291}12921293address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {1294address handler = _handler;1295int insts_size = buffer->pure_insts_size();1296if (handler + insts_size > _handler_blob->code_end()) {1297// get a new handler blob1298handler = set_handler_blob();1299}1300if (handler != NULL) {1301memcpy(handler, buffer->insts_begin(), insts_size);1302pd_set_handler(handler);1303ICache::invalidate_range(handler, insts_size);1304_handler = handler + insts_size;1305}1306return handler;1307}13081309void SignatureHandlerLibrary::add(const methodHandle& method) {1310if (method->signature_handler() == NULL) {1311// use slow signature handler if we can't do better1312int handler_index = -1;1313// check if we can use customized (fast) signature handler1314if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::fp_max_size_of_parameters) {1315// use customized signature handler1316MutexLocker mu(SignatureHandlerLibrary_lock);1317// make sure data structure is initialized1318initialize();1319// lookup method signature's fingerprint1320uint64_t fingerprint = Fingerprinter(method).fingerprint();1321// allow CPU dependant code to optimize the fingerprints for the fast handler1322fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);1323handler_index = _fingerprints->find(fingerprint);1324// create handler if necessary1325if (handler_index < 0) {1326ResourceMark rm;1327ptrdiff_t align_offset = align_up(_buffer, CodeEntryAlignment) - (address)_buffer;1328CodeBuffer buffer((address)(_buffer + align_offset),1329SignatureHandlerLibrary::buffer_size - align_offset);1330InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);1331// copy into code heap1332address handler = set_handler(&buffer);1333if (handler == NULL) {1334// use slow signature handler (without memorizing it in the fingerprints)1335} else {1336// debugging suppport1337if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {1338ttyLocker ttyl;1339tty->cr();1340tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",1341_handlers->length(),1342(method->is_static() ? "static" : "receiver"),1343method->name_and_sig_as_C_string(),1344fingerprint,1345buffer.insts_size());1346if (buffer.insts_size() > 0) {1347Disassembler::decode(handler, handler + buffer.insts_size());1348}1349#ifndef PRODUCT1350address rh_begin = Interpreter::result_handler(method()->result_type());1351if (CodeCache::contains(rh_begin)) {1352// else it might be special platform dependent values1353tty->print_cr(" --- associated result handler ---");1354address rh_end = rh_begin;1355while (*(int*)rh_end != 0) {1356rh_end += sizeof(int);1357}1358Disassembler::decode(rh_begin, rh_end);1359} else {1360tty->print_cr(" associated result handler: " PTR_FORMAT, p2i(rh_begin));1361}1362#endif1363}1364// add handler to library1365_fingerprints->append(fingerprint);1366_handlers->append(handler);1367// set handler index1368assert(_fingerprints->length() == _handlers->length(), "sanity check");1369handler_index = _fingerprints->length() - 1;1370}1371}1372// Set handler under SignatureHandlerLibrary_lock1373if (handler_index < 0) {1374// use generic signature handler1375method->set_signature_handler(Interpreter::slow_signature_handler());1376} else {1377// set handler1378method->set_signature_handler(_handlers->at(handler_index));1379}1380} else {1381DEBUG_ONLY(JavaThread::current()->check_possible_safepoint());1382// use generic signature handler1383method->set_signature_handler(Interpreter::slow_signature_handler());1384}1385}1386#ifdef ASSERT1387int handler_index = -1;1388int fingerprint_index = -2;1389{1390// '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized1391// in any way if accessed from multiple threads. To avoid races with another1392// thread which may change the arrays in the above, mutex protected block, we1393// have to protect this read access here with the same mutex as well!1394MutexLocker mu(SignatureHandlerLibrary_lock);1395if (_handlers != NULL) {1396handler_index = _handlers->find(method->signature_handler());1397uint64_t fingerprint = Fingerprinter(method).fingerprint();1398fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);1399fingerprint_index = _fingerprints->find(fingerprint);1400}1401}1402assert(method->signature_handler() == Interpreter::slow_signature_handler() ||1403handler_index == fingerprint_index, "sanity check");1404#endif // ASSERT1405}14061407void SignatureHandlerLibrary::add(uint64_t fingerprint, address handler) {1408int handler_index = -1;1409// use customized signature handler1410MutexLocker mu(SignatureHandlerLibrary_lock);1411// make sure data structure is initialized1412initialize();1413fingerprint = InterpreterRuntime::normalize_fast_native_fingerprint(fingerprint);1414handler_index = _fingerprints->find(fingerprint);1415// create handler if necessary1416if (handler_index < 0) {1417if (PrintSignatureHandlers && (handler != Interpreter::slow_signature_handler())) {1418tty->cr();1419tty->print_cr("argument handler #%d at " PTR_FORMAT " for fingerprint " UINT64_FORMAT,1420_handlers->length(),1421p2i(handler),1422fingerprint);1423}1424_fingerprints->append(fingerprint);1425_handlers->append(handler);1426} else {1427if (PrintSignatureHandlers) {1428tty->cr();1429tty->print_cr("duplicate argument handler #%d for fingerprint " UINT64_FORMAT "(old: " PTR_FORMAT ", new : " PTR_FORMAT ")",1430_handlers->length(),1431fingerprint,1432p2i(_handlers->at(handler_index)),1433p2i(handler));1434}1435}1436}143714381439BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;1440address SignatureHandlerLibrary::_handler = NULL;1441GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;1442GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;1443address SignatureHandlerLibrary::_buffer = NULL;144414451446JRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* current, Method* method))1447methodHandle m(current, method);1448assert(m->is_native(), "sanity check");1449// lookup native function entry point if it doesn't exist1450if (!m->has_native_function()) {1451NativeLookup::lookup(m, CHECK);1452}1453// make sure signature handler is installed1454SignatureHandlerLibrary::add(m);1455// The interpreter entry point checks the signature handler first,1456// before trying to fetch the native entry point and klass mirror.1457// We must set the signature handler last, so that multiple processors1458// preparing the same method will be sure to see non-null entry & mirror.1459JRT_END14601461#if defined(IA32) || defined(AMD64) || defined(ARM)1462JRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* current, void* src_address, void* dest_address))1463if (src_address == dest_address) {1464return;1465}1466ResourceMark rm;1467LastFrameAccessor last_frame(current);1468assert(last_frame.is_interpreted_frame(), "");1469jint bci = last_frame.bci();1470methodHandle mh(current, last_frame.method());1471Bytecode_invoke invoke(mh, bci);1472ArgumentSizeComputer asc(invoke.signature());1473int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver1474Copy::conjoint_jbytes(src_address, dest_address,1475size_of_arguments * Interpreter::stackElementSize);1476JRT_END1477#endif14781479#if INCLUDE_JVMTI1480// This is a support of the JVMTI PopFrame interface.1481// Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument1482// and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.1483// The member_name argument is a saved reference (in local#0) to the member_name.1484// For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.1485// FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.1486JRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* current, address member_name,1487Method* method, address bcp))1488Bytecodes::Code code = Bytecodes::code_at(method, bcp);1489if (code != Bytecodes::_invokestatic) {1490return;1491}1492ConstantPool* cpool = method->constants();1493int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;1494Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));1495Symbol* mname = cpool->name_ref_at(cp_index);14961497if (MethodHandles::has_member_arg(cname, mname)) {1498oop member_name_oop = cast_to_oop(member_name);1499if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {1500// FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.1501member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);1502}1503current->set_vm_result(member_name_oop);1504} else {1505current->set_vm_result(NULL);1506}1507JRT_END1508#endif // INCLUDE_JVMTI15091510#ifndef PRODUCT1511// This must be a JRT_LEAF function because the interpreter must save registers on x86 to1512// call this, which changes rsp and makes the interpreter's expression stack not walkable.1513// The generated code still uses call_VM because that will set up the frame pointer for1514// bcp and method.1515JRT_LEAF(intptr_t, InterpreterRuntime::trace_bytecode(JavaThread* current, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))1516LastFrameAccessor last_frame(current);1517assert(last_frame.is_interpreted_frame(), "must be an interpreted frame");1518methodHandle mh(current, last_frame.method());1519BytecodeTracer::trace(mh, last_frame.bcp(), tos, tos2);1520return preserve_this_value;1521JRT_END1522#endif // !PRODUCT152315241525