runtime.cpp revision 1166
/*
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
#include "incls/_precompiled.incl"
#include "incls/_runtime.cpp.incl"
// For debugging purposes:
// To force FullGCALot inside a runtime function, add the following two lines
//
// Universe::release_fullgc_alot_dummy();
// MarkSweep::invoke(0, "Debugging");
//
// At command line specify the parameters: -XX:+FullGCALot -XX:FullGCALotStart=100000000
// Compiled code entry points
# ifdef ENABLE_ZAP_DEAD_LOCALS
# endif
// This should be called in an assertion at the start of OptoRuntime routines
// which are entered from compiled code (all of them)
#ifndef PRODUCT
#ifdef ASSERT
#endif /* ASSERT */
return true;
}
#endif
var = generate_stub(env, type_func_gen, CAST_FROM_FN_PTR(address, c_func), #var, fancy_jump, pass_tls, save_arg_regs, return_pc)
// Note: tls: Means fetching the return oop out of the thread-local storage
//
// -------------------------------------------------------------------------------------------------------------------------------
gen(env, _multianewarray2_Java , multianewarray2_Type , multianewarray2_C , 0 , true , false, false);
gen(env, _multianewarray3_Java , multianewarray3_Type , multianewarray3_C , 0 , true , false, false);
gen(env, _multianewarray4_Java , multianewarray4_Type , multianewarray4_C , 0 , true , false, false);
gen(env, _multianewarray5_Java , multianewarray5_Type , multianewarray5_C , 0 , true , false, false);
gen(env, _complete_monitor_locking_Java , complete_monitor_enter_Type , SharedRuntime::complete_monitor_locking_C , 0 , false, false, false);
gen(env, _slow_arraycopy_Java , slow_arraycopy_Type , SharedRuntime::slow_arraycopy_C , 0 , false, false, false);
gen(env, _register_finalizer_Java , register_finalizer_Type , register_finalizer , 0 , false, false, false);
# ifdef ENABLE_ZAP_DEAD_LOCALS
gen(env, _zap_dead_Java_locals_Java , zap_dead_locals_Type , zap_dead_Java_locals_C , 0 , false, true , false );
gen(env, _zap_dead_native_locals_Java , zap_dead_locals_Type , zap_dead_native_locals_C , 0 , false, true , false );
# endif
}
// Helper method to do generation of RunTimeStub's
const char *name, int is_fancy_jump,
bool pass_tls,
bool save_argument_registers,
bool return_pc ) {
Compile C( env, gen, C_function, name, is_fancy_jump, pass_tls, save_argument_registers, return_pc );
return C.stub_entry_point();
}
#ifndef PRODUCT
#else
// Fast implementation for product mode (maybe it should be inlined too)
return "runtime stub";
#endif
}
//=============================================================================
// Opto compiler runtime routines
//=============================================================================
//=============================allocation======================================
// We failed the fast-path allocation. Now we need to do a scavenge or GC
// and try allocation again.
// After any safepoint, just before going back to compiled code,
// we inform the GC that we will be doing initializing writes to
// this object in the future without emitting card-marks, so
// GC may take any compensating steps.
// NOTE: Keep this code consistent with GraphKit::store_barrier.
"compiler must check this first");
// GC may decide to give back a safer copy of new_obj.
}
// object allocation
#ifndef PRODUCT
#endif
// These checks are cheap to make and support reflective allocation.
if (!HAS_PENDING_EXCEPTION) {
}
if (!HAS_PENDING_EXCEPTION) {
} else {
}
}
// Scavenge and allocate an instance.
// Pass oops back through thread local storage. Our apparent type to Java
// is that we return an oop, but we can block on exit from this routine and
// a GC can trash the oop in C's return register. The generated stub will
// fetch the oop from TLS after any possible GC.
}
if (GraphKit::use_ReduceInitialCardMarks()) {
// inform GC that we won't do card marks for initializing writes.
}
// array allocation
JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(klassOopDesc* array_type, int len, JavaThread *thread))
#ifndef PRODUCT
#endif
// Scavenge and allocate an instance.
// The oopFactory likes to work with the element type.
// (We could bypass the oopFactory, since it doesn't add much value.)
} else {
// Although the oopFactory likes to work with the elem_type,
// the compiler prefers the array_type, since it must already have
// that latter value in hand for the fast path.
}
// Pass oops back through thread local storage. Our apparent type to Java
// is that we return an oop, but we can block on exit from this routine and
// a GC can trash the oop in C's return register. The generated stub will
// fetch the oop from TLS after any possible GC.
if (GraphKit::use_ReduceInitialCardMarks()) {
// inform GC that we won't do card marks for initializing writes.
}
// Note: multianewarray for one dimension is handled inline by GraphKit::new_array.
// multianewarray for 2 dimensions
JRT_ENTRY(void, OptoRuntime::multianewarray2_C(klassOopDesc* elem_type, int len1, int len2, JavaThread *thread))
#ifndef PRODUCT
#endif
// multianewarray for 3 dimensions
JRT_ENTRY(void, OptoRuntime::multianewarray3_C(klassOopDesc* elem_type, int len1, int len2, int len3, JavaThread *thread))
#ifndef PRODUCT
#endif
// multianewarray for 4 dimensions
JRT_ENTRY(void, OptoRuntime::multianewarray4_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, JavaThread *thread))
#ifndef PRODUCT
#endif
// multianewarray for 5 dimensions
JRT_ENTRY(void, OptoRuntime::multianewarray5_C(klassOopDesc* elem_type, int len1, int len2, int len3, int len4, int len5, JavaThread *thread))
#ifndef PRODUCT
#endif
// create input type (domain)
// create result type (range)
}
// create input type (domain)
// create result type (range)
}
// create input type (domain)
// create result type (range)
}
// create input type (domain)
for( int i = 1; i < nargs; i++ )
// create result type (range)
}
return multianewarray_Type(2);
}
return multianewarray_Type(3);
}
return multianewarray_Type(4);
}
return multianewarray_Type(5);
}
// create result type (range)
}
// create result type (range)
}
// create input type (domain)
// symbolOop name of class to be loaded
// create result type (range)
}
# ifdef ENABLE_ZAP_DEAD_LOCALS
// Type used for stub generation for zap_dead_locals.
// No inputs or outputs
// create input type (domain)
// create result type (range)
}
# endif
//-----------------------------------------------------------------------------
// Monitor Handling
// create input type (domain)
// create result type (range)
}
//-----------------------------------------------------------------------------
// create input type (domain)
// create result type (range)
}
// create input type (domain)
// create result type
}
// create input type (domain)
// create result type (range)
}
// create result type (range)
}
// create input type (domain)
// symbolOop name of class to be loaded
// create result type (range)
}
// create result type (range)
}
//-------------- currentTimeMillis
// create input type (domain)
// create result type (range)
}
// arraycopy stub variations:
enum ArrayCopyType {
ac_fast, // void(ptr, ptr, size_t)
ac_checkcast, // int(ptr, ptr, size_t, size_t, ptr)
ac_slow, // void(ptr, int, ptr, int, int)
ac_generic // int(ptr, int, ptr, int, int)
};
// create input type (domain)
if (num_size_args == 0) {
}
if (num_size_args == 0) {
}
while (num_size_args-- > 0) {
}
if (act == ac_checkcast) {
}
// create result type if needed
if (retcnt == 0)
else
}
// This signature is simple: Two base pointers and a size_t.
return make_arraycopy_Type(ac_fast);
}
// An extension of fast_arraycopy_Type which adds type checking.
return make_arraycopy_Type(ac_checkcast);
}
// This signature is exactly the same as System.arraycopy.
return make_arraycopy_Type(ac_slow);
}
// This signature is like System.arraycopy, except that it returns status.
return make_arraycopy_Type(ac_generic);
}
//------------- Interpreter state access for on stack replacement
// create input type (domain)
// create result type
// fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // locked oop
}
//-------------- methodData update helpers
// create input type (domain)
// create result type
}
// ReceiverTypeData* vc = new ReceiverTypeData(mdp);
// if (vc->receiver(row) == receiver_klass)
// vc->set_receiver_count(row, vc->receiver_count(row) + DataLayout::counter_increment);
return;
} else if (row_recv == 0) {
// else if (vc->receiver(row) == NULL)
}
}
if (empty_row != -1) {
// vc->set_receiver(empty_row, receiver_klass);
// vc->set_receiver_count(empty_row, DataLayout::counter_increment);
}
//-----------------------------------------------------------------------------
// implicit exception support.
if (n != NULL) {
if (n->is_nmethod()) {
tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string());
const char* title = "HotSpot Runtime Error";
const char* question = "Do you want to exclude compilation of this method in future runs?";
CompilerOracle::append_comment_to_file("Null exception in compiled code resulted in the following exclude");
}
}
fatal("Implicit null exception happened in compiled method");
} else {
n->print();
fatal("Implicit null exception happened in generated stub");
}
}
fatal("Implicit null exception at wrong place");
}
//-------------------------------------------------------------------------------------
// register policy
switch (register_save_policy[reg]) {
case 'C': return false; //SOC
case 'E': return true ; //SOE
case 'N': return false; //NS
case 'A': return false; //AS
}
return false;
}
//-----------------------------------------------------------------------
// Exceptions
//
static void trace_exception(oop exception_oop, address exception_pc, const char* msg) PRODUCT_RETURN;
// The method is an entry that is always called by a C++ method not
// directly from compiled code. Compiled code will call the C++ method following.
// We can't allow async exception to be installed during exception processing.
JRT_ENTRY_NO_ASYNC(address, OptoRuntime::handle_exception_C_helper(JavaThread* thread, nmethod* &nm))
// Do not confuse exception_oop with pending_exception. The exception_oop
// is only used to pass arguments into the method. Not for general
// exception handling. DO NOT CHANGE IT to use pending_exception, since
// the runtime stubs checks this on exit.
if (TraceExceptions) {
}
// for AbortVMOnException flag
#ifdef ASSERT
// should throw an exception here
}
#endif
// new exception handling: this method is entered only from adapters
// exceptions from compiled java methods are handled in compiled code
// using rethrow node
if (nm->is_native_method()) {
fatal("Native mathod should not have path to exception handling");
} else {
// we are switching to old paradigm: search for exception handler in caller_frame
// instead in exception handler of caller_frame.sender()
if (JvmtiExport::can_post_exceptions()) {
// "Full-speed catching" is not necessary here,
// since we're notifying the VM on every catch.
// Force deoptimization and the rest of the lookup
// will be fine.
deoptimize_caller_frame(thread, true);
}
// Check the stack guard pages. If enabled, look for handler in this frame;
// otherwise, forcibly unwind the frame.
//
// 4826555: use default current sp for reguard_stack instead of &nm: it's more accurate.
bool deopting = false;
deopting = true;
// Adjust the pc back to the original throwing pc
}
// If we are forcing an unwind because of stack overflow then deopt is
// irrelevant sice we are throwing the frame away anyway.
if (deopting && !force_unwind) {
} else {
if (handler_address == NULL) {
handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true);
// Update the exception cache only when the unwind was not forced.
if (!force_unwind) {
}
} else {
assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same");
}
}
// Check if the exception PC is a MethodHandle call.
}
// Restore correct return pc. Was saved above.
return handler_address;
// We are entering here from exception_blob
// If there is a compiled exception handler in this method, we will continue there;
// otherwise we will unwind the stack and continue at the caller of top frame method
// Note we enter without the usual JRT wrapper. We will call a helper routine that
// will do the normal VM entry. We do it this way so that we can see if the nmethod
// we looked up the handler for has been deoptimized in the meantime. If it has been
// we must not use the handler and instread return the deopt blob.
//
// We are in Java not VM and in debug mode we have a NoHandleMark
//
#ifndef PRODUCT
#endif
{
// Enter the VM
}
// Back in java: Use no oops, DON'T safepoint
// Now check to see if the handler we are returning is in a now
// deoptimized frame
#ifdef ASSERT
#endif // ASSERT
if (caller.is_deoptimized_frame()) {
}
}
return handler_address;
}
//------------------------------rethrow----------------------------------------
// We get here after compiled code has executed a 'RethrowNode'. The callee
// is either throwing or rethrowing an exception. The callee-save registers
// have been restored, synchronized objects have been unlocked and the callee
// stack frame has been removed. The return address was passed in.
// Exception oop is passed as the 1st argument. This routine is then called
// from the stub. On exit, we know where to jump in the caller's code.
// After this C code exits, the stub will pop his frame and end in a jump
// (instead of a return). We enter the caller's default handler.
//
// This must be JRT_LEAF:
// - caller will not change its state as we cannot block on exit,
// therefore raw_exception_handler_for_return_address is all it takes
// to handle deoptimized blobs
//
// However, there needs to be a safepoint check in the middle! So compiled
// safepoints are completely watertight.
//
// Thus, it cannot be a leaf since it contains the No_GC_Verifier.
//
// *THIS IS NOT RECOMMENDED PROGRAMMING STYLE*
//
#ifndef PRODUCT
#endif
#ifdef ASSERT
// should throw an exception here
}
#endif
// Frame not compiled (handles deoptimization blob)
}
// create input type (domain)
// create result type (range)
}
// Deoptimize frame
if (doit) {
// Called from within the owner thread, so no need for safepoint
assert(stub_frame.is_runtime_frame() || exception_blob()->contains(stub_frame.pc()), "sanity check");
}
}
// create input type (domain)
// // The JavaThread* is passed to each routine as the last argument
// fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // JavaThread *; Executing thread
// create result type (range)
}
//-----------------------------------------------------------------------------
// Dtrace support. entry and exit probes have the same signature
// create input type (domain)
// create result type (range)
}
// create input type (domain)
// create result type (range)
}
//-----------------------------------------------------------------------------
//
// dump the collected NamedCounters.
//
void OptoRuntime::print_named_counters() {
int total_lock_count = 0;
int eliminated_lock_count = 0;
NamedCounter* c = _named_counters;
while (c) {
if (count > 0) {
if (Verbose) {
}
if (eliminated) {
}
}
}
}
c = c->next();
}
if (total_lock_count > 0) {
if (eliminated_lock_count) {
}
}
}
//
// Allocate a new NamedCounter. The JVMState is used to generate the
// name which consists of method@line for the inlining tree.
//
NamedCounter* OptoRuntime::new_named_counter(JVMState* youngest_jvms, NamedCounter::CounterTag tag) {
// Visit scopes from youngest to oldest.
bool first = true;
if (!first) {
} else {
first = false;
}
// To print linenumbers instead of bci use: m->line_number_from_bci(bci)
}
NamedCounter* c;
} else {
}
// atomically add the new counter to the head of the list. We only
// add counters so this is safe.
do {
return c;
}
//-----------------------------------------------------------------------------
// Non-product code
#ifndef PRODUCT
int trace_exception_counter = 0;
if (blob->is_nmethod()) {
} else if (blob->is_runtime_stub()) {
} else {
}
}
#endif // PRODUCT
# ifdef ENABLE_ZAP_DEAD_LOCALS
// Called from call sites in compiled code with oop maps (actually safepoints)
// Zaps dead locals in first java frame.
// Is entry because may need to lock to generate oop maps
// Currently, only used for compiler frames, but someday may be used
// for interpreter frames, too.
int OptoRuntime::ZapDeadCompiledLocals_count = 0;
// avoid pointers to member funcs with these helpers
bool (*is_this_the_right_frame_to_zap)(frame*)) {
if ( !ZapDeadCompiledLocals ) return;
bool skip = false;
if ( ZapDeadCompiledLocalsFirst == 0 ) ; // nothing special
else if ( ZapDeadCompiledLocalsFirst == ZapDeadCompiledLocals_count )
warning("starting zapping after skipping");
else if ( ZapDeadCompiledLocalsLast == ZapDeadCompiledLocals_count )
warning("about to zap last zap");
++ZapDeadCompiledLocals_count; // counts skipped zaps, too
if ( skip ) return;
// find java frame and zap it
return;
}
}
warning("no frame found to zap in zap_dead_Java_locals_C");
}
// The following does not work because for one thing, the
// thread state is wrong; it expects java, but it is native.
// Also, the invariants in a native stub are different and
// I'm not sure it is safe to have a MachCalRuntimeDirectNode
// in there.
// So for now, we do not zap in native stubs.
# endif