/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "compiler/compileBroker.hpp"
#include "gc_interface/collectedHeap.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "interpreter/linkResolver.hpp"
#include "interpreter/templateTable.hpp"
#include "memory/oopFactory.hpp"
#include "memory/universe.inline.hpp"
#include "oops/constantPoolOop.hpp"
#include "oops/cpCacheOop.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/methodDataOop.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "oops/symbol.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/compilationPolicy.hpp"
#include "runtime/deoptimization.hpp"
#include "runtime/fieldDescriptor.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/jfieldIDWorkaround.hpp"
#include "runtime/osThread.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/threadCritical.hpp"
#include "utilities/events.hpp"
#ifdef TARGET_ARCH_x86
# include "vm_version_x86.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "vm_version_sparc.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "vm_version_zero.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "vm_version_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "vm_version_ppc.hpp"
#endif
#ifdef COMPILER2
#include "opto/runtime.hpp"
#endif
class UnlockFlagSaver {
private:
bool _do_not_unlock;
public:
_thread = t;
t->set_do_not_unlock_if_synchronized(false);
}
~UnlockFlagSaver() {
}
};
//------------------------------------------------------------------------------------------------------------------------
// State accessors
if (ProfileInterpreter) {
// ProfileTraps uses MDOs independently of ProfileInterpreter.
// That is why we must check both ProfileInterpreter and mdo != NULL.
last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
}
}
}
//------------------------------------------------------------------------------------------------------------------------
// Constants
// access constant pool
} else {
#ifdef ASSERT
// If we entered this runtime routine, we believed the tag contained
// an unresolved string, an unresolved class or a resolved class.
// However, another thread could have resolved the unresolved string
// or class by the time we go there.
#endif
}
#ifdef ASSERT
{
// The bytecode wrappers aren't GC-safe so construct a new one
}
#endif
}
//------------------------------------------------------------------------------------------------------------------------
// Allocation
// Make sure we are not instantiating an abstract klass
// Make sure klass is initialized
// At this point the class may not be fully initialized
// because of recursive initialization. If it is fully
// initialized & has_finalized is not set, we rewrite
// it into its fast version (Note: no locking is needed
// here since this is an atomic byte write and can be
// done more than once).
//
// Note: In case of classes with has_finalized we don't
// rewrite since that saves us an extra check in
// the fast version which then would call the
// slow version anyway (and do a call back into
// Java).
// If we have a breakpoint, then we don't rewrite
// because the _breakpoint bytecode would be lost.
IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, constantPoolOopDesc* pool, int index, jint size))
// Note: no oopHandle for pool & klass needed since they are not used
// anymore after new_objArray() and no GC can happen before.
// (This may have to change if this code changes!)
// We may want to pass in more arguments - could make this slightly faster
// We must create an array of jints to pass to multi_allocate.
if (nof_dims > small_dims) {
}
// offset from first_size_address is addressed as local[index]
}
// Quicken instance-of and check-cast bytecodes
// Force resolving; quicken the bytecode
// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
// program we might have seen an unquick'd bytecode in the interpreter but have another
// thread quicken the bytecode before we get here.
// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
//------------------------------------------------------------------------------------------------------------------------
// Exceptions
// Assume the compiler is (or will be) interested in this event.
// If necessary, create an MDO to hold the information, and record it.
if (trap_method.not_null()) {
if (HAS_PENDING_EXCEPTION) {
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
}
// and fall through...
}
// Update per-method count of trap events. The interpreter
// is updating the MDO to simulate the effect of compiler traps.
}
}
}
// get klass
"this klass should have been initialized during VM initialization");
// create instance - do not call constructor since we may have no
// (java) stack space left (should assert constructor is empty)
if (StackTraceInThrowable) {
}
return exception;
}
// Special handling for stack overflow: since we don't have any (java) stack
// space left we use the pre-allocated & pre-initialized StackOverflowError
// klass to create an stack overflow error instance. We do not call its
// constructor for the same reason (it is empty, anyway).
CHECK);
IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
// lookup exception klass
if (ProfileTraps) {
if (s == vmSymbols::java_lang_ArithmeticException()) {
} else if (s == vmSymbols::java_lang_NullPointerException()) {
}
}
// create exception
IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
// lookup exception klass
if (ProfileTraps) {
}
// create exception, with klass name as detail message
IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
// lookup exception klass
if (ProfileTraps) {
}
// create exception
if (ProfileTraps) {
}
// create exception
// exception_handler_for_exception(...) returns the continuation address,
// The exception oop is returned to make sure it is preserved over GC (it
// is only on the stack if the exception was thrown explicitly via athrow).
// During this operation, the expression stack contains the values for the
// bci where the exception happened. If the exception was propagated back
// from a call, the expression stack contains the values for the bci at the
// invoke w/o arguments (i.e., as if one were inside the call).
IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
bool should_repeat;
int handler_bci;
// Need to do this check first since when _do_not_unlock_if_synchronized
// is set, we don't want to trigger any classloading which may make calls
// into java, or surprisingly find a matching exception handler for bci 0
// since at this moment the method hasn't been "officially" entered yet.
if (thread->do_not_unlock_if_synchronized()) {
#ifdef CC_INTERP
return (address) -1;
#else
return Interpreter::remove_activation_entry();
#endif
}
do {
should_repeat = false;
// assertions
#ifdef ASSERT
// Check that exception is a subclass of Throwable, otherwise we have a VerifyError
}
#endif
// tracing
if (TraceExceptions) {
tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
}
// Don't go paging in something which won't be used.
// else if (h_extable->length() == 0) {
// // disabled for now - interpreter is not using shortcut yet
// // (shortcut is not to call runtime if we have no exception handlers)
// // warning("performance bug: should not call runtime if method has no exception handlers");
// }
// for AbortVMOnException flag
// exception handler lookup
handler_bci = methodOopDesc::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);
if (HAS_PENDING_EXCEPTION) {
// We threw an exception while trying to find the exception handler.
// Transfer the new exception to the exception handle which will
// be set into thread local storage, and do another lookup for an
// exception handler for this exception, this time starting at the
// BCI of the exception handler which caused the exception to be
// thrown (bug 4307310).
if (handler_bci >= 0) {
should_repeat = true;
}
}
} while (should_repeat == true);
// notify JVMTI of an exception throw; JVMTI will detect if this is a first
// time throw or a stack unwinding throw and accordingly notify the debugger
if (JvmtiExport::can_post_on_exceptions()) {
}
#ifdef CC_INTERP
#else
#endif
// handler in this method, or (b) after a stack overflow there is not yet
// enough stack space available to reprotect the stack.
#ifndef CC_INTERP
#endif
// Count this for compilation purposes
} else {
#ifndef CC_INTERP
#endif
}
// notify debugger of an exception catch
// (this is good for exceptions caught in native methods as well)
if (JvmtiExport::can_post_on_exceptions()) {
JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
}
return continuation;
// nothing to do - eventually we should remove this code entirely (see comments @ call sites)
//------------------------------------------------------------------------------------------------------------------------
// Fields
//
// resolve field
{
} // end JvmtiHideSingleStepping
// check if link resolution caused cpCache to be updated
if (already_resolved(thread)) return;
// compute auxiliary field attributes
// We need to delay resolving put instructions on final fields
// until we actually invoke one. This is required so we throw
// exceptions at the correct place. If we do not resolve completely
// in the current pass, leaving the put_code set to zero will
// cause the next put instruction to reresolve.
// We also need to delay resolving getstatic instructions until the
// class is intitialized. This is required so that access to the static
// field will call the initialization function every time until the class
// is completely initialized ala. in 2.17.5 in JVM Specification.
bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
!klass->is_initialized());
if (!uninitialized_static) {
}
}
info.field_index(),
info.field_offset(),
);
//------------------------------------------------------------------------------------------------------------------------
// Synchronization
//
// The interpreter's synchronization code is factored out so that it can
// be shared by method invocation and synchronized blocks.
//%note synchronization_3
}
//%note monitor_1
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
#ifdef ASSERT
#endif
if (PrintBiasedLockingStatistics) {
}
"must be NULL or an object");
if (UseBiasedLocking) {
// Retry fast entry if bias is revoked to avoid unnecessary inflation
} else {
}
"must be NULL or an object");
#ifdef ASSERT
#endif
//%note monitor_1
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
#ifdef ASSERT
#endif
"must be NULL or an object");
}
// Free entry. This must be done here, since a pending exception might be installed on
// exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
#ifdef ASSERT
#endif
// Returns an illegal exception to install into the current thread. The
// pending_exception flag is cleared so normal exception handling does not
// trigger. Any current installed exception will be overwritten. This
// method will be called during an exception unwind.
thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
CATCH);
}
//------------------------------------------------------------------------------------------------------------------------
// Invokes
IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp))
IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code))
IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp))
// extract receiver from the outgoing argument list if necessary
"sanity check");
"sanity check");
}
// resolve method
{
if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
int retry_count = 0;
// It is very unlikely that method is redefined more than 100 times
// in the middle of resolve. If it is looping here more than 100 times
// means then there could be a bug here.
"Could not resolve to latest version of redefined method");
// method is redefined in the middle of resolve so re-try.
}
}
} // end JvmtiHideSingleStepping
// check if link resolution caused cpCache to be updated
if (already_resolved(thread)) return;
if (TraceItables && Verbose) {
tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
}
SystemDictionary::Object_klass()) {
// NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
// (see also cpCacheOop.cpp for details)
"should have been set already");
} else {
// Setup itable entry
}
} else {
info.vtable_index());
}
}
// First time execution: Resolve symbols, create a permanent MethodType object.
// resolve method
{
} // end JvmtiHideSingleStepping
pool,
}
// First time execution: Resolve symbols, create a permanent CallSite object.
//TO DO: consider passing BCI to Java.
// int caller_bci = method(thread)->bci_from(bcp(thread));
// resolve method
{
} // end JvmtiHideSingleStepping
pool,
}
//------------------------------------------------------------------------------------------------------------------------
// Miscellaneous
// This was a successful request for an OSR nmethod. Because
// frequency_counter_overflow_inner ends with a safepoint check,
// nm could have been unloaded so look it up again. It's unsafe
// to examine nm directly since it might have been freed and used
// for something else.
}
#ifndef PRODUCT
if (TraceOnStackReplacement) {
}
}
#endif
return nm;
}
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
// flag, in case this method triggers classloading which will call into Java.
const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
// We may need to do on-stack replacement which requires that no
// monitors in the activation are biased because their
// BasicObjectLocks will need to migrate during OSR. Force
// unbiasing of all monitors in the activation now (even though
// the OSR nmethod might be invalidated) because we don't have a
// safepoint opportunity later once the migration begins.
if (UseBiasedLocking) {
}
}
}
}
return osr_nm;
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
// flag, in case this method triggers classloading which will call into Java.
if (HAS_PENDING_EXCEPTION) {
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
// and fall through...
}
#ifdef ASSERT
if (current_di >= 0) {
}
method->print_codes();
}
#endif // ASSERT
// Grab a lock to ensure atomic access to setting the return bci and
// the displacement. This can block and GC, invalidating all naked oops.
// ProfileData is essentially a wrapper around a derived oop, so we
// need to take the lock before making any ProfileData structures.
// We used to need an explict preserve_arguments here for invoke bytecodes. However,
// stack traversal automatically takes care of preserving arguments for invoke, so
// this is no longer needed.
// IRT_END does an implicit safepoint check, hence we are guaranteed to block
// if this is called during a safepoint
if (JvmtiExport::should_post_single_step()) {
// We are called during regular safepoints and when the VM is
// single stepping. If any thread is marked for single stepping,
// then we may have JVMTI work to do.
}
// check the access_flags for the field in the klass
instanceKlass* ik = instanceKlass::cast(java_lang_Class::as_klassOop(cp_entry->f1_as_klass_mirror()));
switch(cp_entry->flag_state()) {
case btos: // fall through
case ctos: // fall through
case stos: // fall through
case itos: // fall through
case ftos: // fall through
case ltos: // fall through
case dtos: // fall through
case atos: break;
default: ShouldNotReachHere(); return;
}
if (!is_static) {
// non-static field accessors have an object, but we need a handle
}
instanceKlassHandle h_cp_entry_f1(thread, java_lang_Class::as_klassOop(cp_entry->f1_as_klass_mirror()));
// check the access_flags for the field in the klass
// bail out if field modifications are not watched
switch(cp_entry->flag_state()) {
default: ShouldNotReachHere(); return;
}
#ifdef _LP64
#else
// tagged stacks. We can't just do a simple assignment even in the non-
// J/D cases because a C++ compiler is allowed to assume that a jvalue is
// 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
// stack slots in platform-endian order.
fvalue.j = u.long_value;
#endif // _LP64
if (!is_static) {
// non-static field accessors have an object, but we need a handle
}
JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
{
}
// Implementation of SignatureHandlerLibrary
if (handler_blob == NULL) {
return NULL;
}
return handler;
}
if (_fingerprints != NULL) {
return;
}
if (set_handler_blob() == NULL) {
}
}
// get a new handler blob
handler = set_handler_blob();
}
}
return handler;
}
// use slow signature handler if we can't do better
// check if we can use customized (fast) signature handler
if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
// use customized signature handler
// make sure data structure is initialized
initialize();
// lookup method signature's fingerprint
// create handler if necessary
if (handler_index < 0) {
// copy into code heap
// use slow signature handler
} else {
// debugging suppport
if (PrintSignatureHandlers) {
tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
buffer.insts_size());
#ifndef PRODUCT
while (*(int*)rh_end != 0) {
rh_end += sizeof(int);
}
#endif
}
// add handler to library
// set handler index
}
}
// Set handler under SignatureHandlerLibrary_lock
if (handler_index < 0) {
// use generic signature handler
} else {
// set handler
}
} else {
// use generic signature handler
}
}
#ifdef ASSERT
{
// '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
// in any way if accessed from multiple threads. To avoid races with another
// thread which may change the arrays in the above, mutex protected block, we
// have to protect this read access here with the same mutex as well!
}
}
#endif // ASSERT
}
// lookup native function entry point if it doesn't exist
bool in_base_library;
if (!m->has_native_function()) {
}
// make sure signature handler is installed
// The interpreter entry point checks the signature handler first,
// before trying to fetch the native entry point and klass mirror.
// We must set the signature handler last, so that multiple processors
// preparing the same method will be sure to see non-null entry & mirror.
IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
if (src_address == dest_address) {
return;
}
#endif