/*
* 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 "asm/assembler.hpp"
#include "interpreter/bytecodeHistogram.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterGenerator.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "interpreter/templateTable.hpp"
#include "oops/arrayOop.hpp"
#include "oops/methodDataOop.hpp"
#include "oops/methodOop.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiThreadState.hpp"
#include "runtime/arguments.hpp"
#include "runtime/deoptimization.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/vframeArray.hpp"
#ifndef CC_INTERP
#ifndef FAST_DISPATCH
#endif
// Generation of Interpreter
//
// The InterpreterGenerator generates the interpreter into Interpreter::_code.
//----------------------------------------------------------------------------------------------------
// save and restore any potential method result value around the unlocking operation
#ifdef _LP64
#else
#endif
}
// Restore any method result value
#ifdef _LP64
#else
#endif
}
address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
// expression stack must be empty before entering the VM if an exception happened
// load exception object
if (pass_oop) {
__ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), G3_scratch, Otos_i);
} else {
__ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), G3_scratch, G4_scratch);
}
// throw exception
return entry;
}
// expression stack must be empty before entering the VM if an exception
// happened
// load exception object
Otos_i);
return entry;
}
// expression stack must be empty before entering the VM if an exception happened
// convention: expect aberrant index in register G3_scratch, then shuffle the
// index to G4_scratch for the VM call
__ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), G3_scratch, G4_scratch);
return entry;
}
// expression stack must be empty before entering the VM if an exception happened
return entry;
}
// All return values are where we want them, except for Longs. C2 returns
// build even if we are returning from interpreted we just do a little
// stupid shuffing.
// do this here. Unfortunately if we did a rethrow we'd see an machepilog node
if (incoming_state == ltos) {
}
#endif // !_LP64 && COMPILER2
// The callee returns with the stack possibly adjusted by adapter transition
// We remove that possible adjustment here.
// All interpreter local registers are untouched. Any result is passed back
// popped from the java expression stack; i.e., Lesp must be adjusted.
if (EnableInvokeDynamic) {
__ cmp_and_br_short(G1_scratch, Bytecodes::_invokedynamic, Assembler::equal, Assembler::pn, L_giant_index);
}
// out of the main line of code...
if (EnableInvokeDynamic) {
}
return entry;
}
{ Label L;
}
return entry;
}
// a java interpreter/compiler result. The current frame is an
// interpreter frame. The activation frame unwind code must be
// consistent with that of TemplateTable::_return(...). In the
// case of native methods, the caller's SP was not modified.
switch (type) {
case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value!
case T_LONG :
#ifndef _LP64
#endif // ifdef or no ifdef, fall through to the T_INT case
case T_VOID : /* nothing to do */ break;
case T_OBJECT :
break;
default : ShouldNotReachHere();
}
return entry;
}
address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
return entry;
}
return entry;
}
//
// Helpers for commoning out cases in the various type of method entries.
//
// increment invocation count & check for overflow
//
// Note: checking for negative value instead of overflow
// so we have a 'sticky' overflow test
//
// Lmethod: method
// ??: invocation counter
//
void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
// Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
if (TieredCompilation) {
if (ProfileInterpreter) {
// If no method data exists, go to profile_continue.
// Increment counter
}
// Increment counter in methodOop
} else {
// Update standard invocation counters
if (ProfileInterpreter) { // %%% Merge this into methodDataOop
Address interpreter_invocation_counter(Lmethod,in_bytes(methodOopDesc::interpreter_invocation_counter_offset()));
}
// Test to see if we should create a method data oop
__ cmp_and_br_short(O0, G3_scratch, Assembler::lessUnsigned, Assembler::pn, *profile_method_continue);
// if no method data exists, go to profile_method
}
}
}
// Allocate monitor and lock method (asm interpreter)
// ebx - methodOop
//
#ifdef ASSERT
}
#endif // ASSERT
// get synchronization object to O0
__ delayed()->ld_ptr(Llocals, Interpreter::local_offset_in_bytes(0), O0); // get receiver for not-static case
// lock the mirror, not the klassOop
#ifdef ASSERT
#endif // ASSERT
}
// __ untested("lock_object from method entry");
}
// get the stack base, and in debug, verify it is non-zero
#ifdef ASSERT
#endif
// get the stack size, and in debug, verify it is non-zero
#ifdef ASSERT
#endif
// compute the beginning of the protected zone minus the requested frame size
// Add in the size of the frame (which is the same as subtracting it from the
// SP, which would take another register
// the frame is greater than one page in size, so check against
// the bottom of the stack
// the stack will overflow, throw an exception
// Note that SP is restored to sender's sp (in the delay slot). This
// is necessary if the sender's frame is an extended compiled frame
// (see gen_c2i_adapter()) and safer anyway in case of JSR292
// adaptations.
// Note also that the restored frame is not necessarily interpreted.
// Use the shared runtime version of the StackOverflowError.
// if you get to here, then there is enough stack space
}
//
// Generate a fixed interpreter frame. This is identical setup for interpreted
// methods and for native methods hence the shared code.
//
//
// The entry code sets up a new interpreter frame in 4 steps:
//
// 1) Increase caller's SP by for the extra local space needed:
// (check for overflow)
// that arguments and non-argument locals are in a contigously
// addressable memory block => non-argument locals must be
// allocated in the caller's frame.
//
// 2) Create a new stack frame and register window:
// The new stack frame must provide space for the standard
// register save area, the maximum java expression stack size,
// the monitor slots (0 slots initially), and some frame local
// scratch locations.
//
// 3) The following interpreter activation registers must be setup:
// Lesp : expression stack pointer
// Lbcp : bytecode pointer
// Lmethod : method
// Llocals : locals pointer
// Lmonitors : monitor pointer
// LcpoolCache: constant pool cache
//
// 4) Initialize the non-argument locals if necessary:
// Non-argument locals may need to be initialized to NULL
// for GC to work. If the oop-map information is accurate
// (in the absence of the JSR problem), no initialization
// is necessary.
//
// (gri - 2/25/2000)
const int extra_space =
rounded_vm_local_words + // frame local scratch space
//6815692//methodOopDesc::extra_stack_words() + // extra push slots for MH adapters
// Lscratch can't be used as a temporary because the call_stub uses
// it to assert that the stack frame was setup correctly.
// Gargs points to first local + BytesPerWord
// Set the saved SP after the register window save
//
if (native_call) {
} else {
//
// Compute number of locals in method apart from incoming parameters
//
// see if the frame is greater than one page in size. If so,
// then we need to verify there is enough stack space remaining
// Frame_size = (max_stack + extra_space) * BytesPerWord;
// Add in java locals size for stack overflow check only
//
// bump SP to accomodate the extra locals
//
}
//
// now set up a stack frame with the size computed above
//
//
// now set up all the local cache registers
//
// NOTE: At this point, Lbyte_code/Lscratch has been modified. Note
// that all present references to Lbyte_code initialize the register
// immediately before use
if (native_call) {
} else {
}
#ifdef _LP64
#endif
// setup interpreter activation registers
if (ProfileInterpreter) {
#ifdef FAST_DISPATCH
// FAST_DISPATCH and ProfileInterpreter are mutually exclusive since
// they both use I2.
assert(0, "FAST_DISPATCH and +ProfileInterpreter are mutually exclusive");
#endif // FAST_DISPATCH
}
}
// Empty method, generate a very fast return.
// A method that does nother but return...
// do nothing for empty methods (do not even increment invocation counter)
if ( UseFastEmptyMethods) {
// If we need a safepoint check, generate full interpreter entry.
__ cmp_and_br_short(G3_scratch, SafepointSynchronize::_not_synchronized, Assembler::notEqual, Assembler::pn, slow_path);
// Code: _return
(void) generate_normal_entry(false);
return entry;
}
return NULL;
}
// Call an accessor method (assuming it is resolved, otherwise drop into
// vanilla (slow path) entry
// Generates code to elide accessor methods
// Uses G3_scratch and G1_scratch as scratch
// Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
// parameter size = 1
// Note: We can only use this code if the getfield has been resolved
// and if we don't have a null-pointer exception => check for
// these conditions first and use slow path if necessary.
// XXX: for compressed oops pointer loading and decoding doesn't fit in
// delay slot and damages G1
if ( UseFastAccessorMethods && !UseCompressedOops ) {
// Check if we need to reach a safepoint and generate full interpreter
// frame if so.
__ cmp_and_br_short(G3_scratch, SafepointSynchronize::_not_synchronized, Assembler::notEqual, Assembler::pn, slow_path);
// Check if local 0 != NULL
// check if local 0 == NULL and go the slow path
// read first instruction word and extract bytecode @ 1 and index @ 2
// get first 4 bytes of the bytecodes (big endian!)
// move index @ 2 far left then to the right most two bytes.
// get constant pool cache
// get specific constant pool cache entry
// Check the constant Pool cache entry to see if it has been resolved.
// If not, need the slow path.
__ cmp_and_br_short(G1_scratch, Bytecodes::_getfield, Assembler::notEqual, Assembler::pn, slow_path);
// Get the type and return field offset from the constant pool cache
// Need to differentiate between igetfield, agetfield, bgetfield etc.
// because they are different sizes.
// Get the type from the constant pool cache
// Make sure we don't need to mask G1_scratch after the above shift
#ifdef ASSERT
#endif
// _ireturn/_areturn
// Generate regular method entry
(void) generate_normal_entry(false);
return entry;
}
return NULL;
}
// Method entry for java.lang.ref.Reference.get.
#ifndef SERIALGC
// Code: _aload_0, _getfield, _areturn
// parameter size = 1
//
// The code that gets generated by this routine is split into 2 parts:
// 1. The "intrinsified" code for G1 (or any SATB based GC),
// 2. The slow path - which is an expansion of the regular method entry.
//
// Notes:-
// * In the G1 code we do not check whether we need to block for
// a safepoint. If G1 is enabled then we must execute the specialized
// code for Reference.get (except when the Reference object is null)
// so that we can log the value in the referent field with an SATB
// update buffer.
// If the code for the getfield template is modified so that the
// G1 pre-barrier code is executed when the current method is
// Reference.get() then going through the normal method entry
// will be fine.
// * The G1 code can, however, check the receiver object (the instance
// of java.lang.Reference) and jump to the slow path if null. If the
// Reference object is null then we obviously cannot fetch the referent
// and so we don't need to call the G1 pre-barrier. Thus we can use the
// regular method entry code to generate the NPE.
//
// This code is based on generate_accessor_enty.
if (UseG1GC) {
// In the G1 code we don't check if we need to reach a safepoint. We
// continue and the thread will safepoint at the next bytecode dispatch.
// Check if local 0 != NULL
// If the receiver is null then it is OK to jump to the slow path.
// check if local 0 == NULL and go the slow path
// Load the value of the referent field.
} else {
}
// Generate the G1 pre-barrier code to log the value of
// the referent field in an SATB buffer. Note with
// these parameters the pre-barrier does not generate
// the load of the previous value
Otos_i /* pre_val */,
G3_scratch /* tmp */,
true /* preserve_o_regs */);
// _areturn
// Generate regular method entry
(void) generate_normal_entry(false);
return entry;
}
#endif // SERIALGC
// If G1 is not enabled then attempt to go through the accessor entry point
// Reference.get is an accessor
return generate_accessor_entry();
}
//
// Interpreter stub for calling a native method. (asm interpreter)
// This sets up a somewhat different looking stack for calling the native method
// than the typical interpreter frame setup.
//
// the following temporary registers are used during frame creation
// make sure registers are different!
// make sure method is native & not abstract
// rethink these assertions - they can be simplified and shared (gri 2/25/2000)
#ifdef ASSERT
{
Label L;
}
{ Label L;
}
#endif // ASSERT
// generate the code to allocate the interpreter stack frame
generate_fixed_frame(true);
//
// No locals to initialize for native method
//
// this slot will be set later, we initialize it to null here just in
// case we get a GC before the actual value is stored later
// Since at this point in the method invocation the exception handler
// would try to exit the monitor of synchronized methods which hasn't
// been entered yet, we set the thread local variable
// _do_not_unlock_if_synchronized to true. If any exception was thrown by
// runtime, exception handling i.e. unlock_if_synchronized_method will
// check this thread local flag.
// This flag has two effects, one is to force an unwind in the topmost
// interpreter frame and not perform an unlock while doing so.
// increment invocation counter and check for overflow
//
// Note: checking for negative value instead of overflow
// so we have a 'sticky' overflow test (may be of
if (inc_counter) {
}
bang_stack_shadow_pages(true);
// reset the _do_not_unlock_if_synchronized flag
// check for synchronized methods
// Must happen AFTER invocation_counter check and stack overflow check,
// so method is not locked if overflows.
if (synchronized) {
lock_method();
} else {
#ifdef ASSERT
}
#endif // ASSERT
}
// start execution
__ verify_thread();
// JVMTI support
// native call
// (note that O0 is never an oop--at most it is a handle)
// It is important not to smash any handles created by this call,
// until any oop handle in O0 is dereferenced.
// (note that the space for outgoing params is preallocated)
// get signature handler
{ Label L;
}
// Push a new frame so that the args will really be stored in
// Copy a few locals across so the new frame has the variables
// we need but these values will be dead at the jni call and
// therefore not gc volatile like the values in the current
// frame (Lmethod in particular)
// Flush the method pointer to the register save area
// calculate where the mirror handle body is allocated in the interpreter frame:
// Calculate current frame size
// Note I7 has leftover trash. Slow signature handler will fill it in
// should we get there. Normal jni call will set reasonable last_Java_pc
// below (and fix I7 so the stack trace doesn't have a meaningless frame
// in it).
// Load interpreter frame's Lmethod into same register here
// ONLY Lmethod and Llocals are valid here!
// call signature handler, It will move the arg properly since Llocals in current frame
// matches that in outer frame
// Result handler is in Lscratch
// Reload interpreter frame's Lmethod since slow signature handler may block
// get native function entry point(O0 is a good temp until the very end)
// for static methods insert the mirror argument
#ifdef ASSERT
if (!PrintSignatureHandlers) // do not dirty the output with this
{ Label L;
}
#endif // ASSERT
}
// At this point, arguments have been copied off of stack into
// their JNI positions, which are O1..O5 and SP[68..].
// Oops are boxed in-place on the stack, with handles copied to arguments.
// The result handler is in Lscratch. O0 will shortly hold the JNIEnv*.
#ifdef ASSERT
{ Label L;
}
#endif // ASSERT
//
// setup the frame anchor
//
// The scavenge function only needs to know that the PC of this frame is
// in the interpreter method entry code, it doesn't need to know the exact
// PC and hence we can use O7 which points to the return address from the
// previous call in the code stream (signature handler function)
//
// The other trick is we set last_Java_sp to FP instead of the usual SP because
// we have pushed the extra frame in order to protect the volatile register(s)
// in that frame when we return from the jni call
//
// not meaningless information that'll confuse me.
// flush the windows now. We don't care about the current (protection) frame
// only the outer frames
__ flush_windows();
// mark windows as flushed
// Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.
#ifdef ASSERT
{ Label L;
}
#endif // ASSERT
// Call the jni method, using the delay slot to set the JNIEnv* argument.
// Back from jni method Lmethod in this frame is DEAD, DEAD, DEAD
// must we block?
// Block, if necessary, before resuming in _thread_in_Java state.
// In order for GC to work, don't clear the last_Java_sp until after blocking.
// Switch thread to "native transition" state before reading the synchronization state.
// This additional state is necessary because reading and testing the synchronization
// state is not atomic w.r.t. GC, as this scenario demonstrates:
// Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
// VM thread changes sync state to synchronizing and suspends threads for GC.
// Thread A is resumed to finish this native method, but doesn't block here since it
// didn't see any synchronization is progress, and escapes.
if (UseMembar) {
// Force this write out before the read below
} else {
// Write serialization page so VM thread can do a pseudo remote membar.
// We use the current thread pointer to calculate a thread specific
// offset to write to within the page. This minimizes bus traffic
// due to cache line collision.
}
}
Label L;
// Block. Save any potential method result value before the operation and
// use a leaf call to leave the last_Java_frame setup undisturbed.
// Restore any method result value
}
// Clear the frame anchor now
// Move the result handler address
// return possible result to the outer frame
#ifndef __LP64
#else
#endif /* __LP64 */
// Move result handler to expected register
// Back in normal (native) interpreter frame. State is thread_in_native_trans
// switch to thread_in_Java.
// reset handle block
// If we have an oop result store it where it will be safe for any further gc
// until we return now that we've released the handle it might be protected by
{
// Store it where gc will look for it and result handler expects it.
}
// handle exceptions (exception handling will handle unlocking!)
{ Label L;
// Note: This could be handled more efficiently since we know that the native
// method doesn't have an exception handler. We could directly return
// to the exception handler for the caller.
}
// JVMTI support (preserves thread register)
if (synchronized) {
// save and restore any potential method result value around the unlocking operation
}
// C2 expects long results in G1 we can't tell if we're returning to interpreted
// or compiled so just be safe.
#endif /* COMPILER2 && !_LP64 */
// dispose of return address and remove activation
#ifdef ASSERT
{
}
#endif
if (TraceJumps) {
// Move target to register that is recordable
} else {
}
if (inc_counter) {
// handle invocation counter overflow
}
return entry;
}
// Generic method entry to (asm) interpreter
//------------------------------------------------------------------------------------------------------------------------
//
// the following temporary registers are used during frame creation
// make sure registers are different!
// Seems like G5_method is live at the point this is used. So we could make this look consistent
// and use in the asserts.
// make sure method is not native & not abstract
// rethink these assertions - they can be simplified and shared (gri 2/25/2000)
#ifdef ASSERT
{
Label L;
}
{ Label L;
}
#endif // ASSERT
// generate the code to allocate the interpreter stack frame
generate_fixed_frame(false);
#ifdef FAST_DISPATCH
// set bytecode dispatch table base
#endif
//
// Code to initialize the extra (i.e. non-parm) locals
//
// The way the code was setup before zerolocals was always true for vanilla java entries.
// It could only be false for the specialized entries like accessor or empty which have
// no extra locals so the testing was a waste of time and the extra locals were always
// initialized. We removed this extra complication to already over complicated code.
init_value = G0;
// NOTE: If you change the frame layout, this code will need to
// be updated!
// Since at this point in the method invocation the exception handler
// would try to exit the monitor of synchronized methods which hasn't
// been entered yet, we set the thread local variable
// _do_not_unlock_if_synchronized to true. If any exception was thrown by
// runtime, exception handling i.e. unlock_if_synchronized_method will
// check this thread local flag.
// increment invocation counter and check for overflow
//
// Note: checking for negative value instead of overflow
// so we have a 'sticky' overflow test (may be of
if (inc_counter) {
if (ProfileInterpreter) {
}
}
bang_stack_shadow_pages(false);
// reset the _do_not_unlock_if_synchronized flag
// check for synchronized methods
// Must happen AFTER invocation_counter check and stack overflow check,
// so method is not locked if overflows.
if (synchronized) {
lock_method();
} else {
#ifdef ASSERT
}
#endif // ASSERT
}
// start execution
__ verify_thread();
// jvmti support
// start executing instructions
if (inc_counter) {
if (ProfileInterpreter) {
// We have decided to profile this method in the interpreter
}
// handle invocation counter overflow
}
return entry;
}
//----------------------------------------------------------------------------------------------------
// Entry points & stack frame layout
//
// Here we generate the various kind of entries into the interpreter.
// The two main entry type are generic bytecode methods and native call method.
// These both come in synchronized and non-synchronized versions but the
// frame layout they create is very similar. The other method entry
// types are really just special purpose entries that are really entry
// and interpretation all in one. These are for trivial methods like
// accessor, empty, or special math methods.
//
// When control flow reaches any of the entry types for the interpreter
// the following holds ->
//
// C2 Calling Conventions:
//
// The entry code below assumes that the following registers are set
// when coming in:
// G5_method: holds the methodOop of the method to call
// Lesp: points to the TOS of the callers expression stack
// after having pushed all the parameters
//
// The entry code does the following to setup an interpreter frame
// pop parameters from the callers stack by adjusting Lesp
// set O0 to Lesp
// compute X = (max_locals - num_parameters)
// bump SP up by X to accomadate the extra locals
// compute X = max_expression_stack
// + vm_local_words
// + 16 words of register save area
// save frame doing a save sp, -X, sp growing towards lower addresses
// set Lbcp, Lmethod, LcpoolCache
// set Llocals to i0
// set Lmonitors to FP - rounded_vm_local_words
// set Lesp to Lmonitors - 4
//
// The frame has now been setup to do the rest of the entry code
// Try this optimization: Most method entries could live in a
// "one size fits all" stack frame without all the dynamic size
// calculations. It might be profitable to do all this calculation
// statically and approximately for "small enough" methods.
//-----------------------------------------------------------------------------------------------
// C1 Calling conventions
//
// Upon method entry, the following registers are setup:
//
// g2 G2_thread: current thread
// g5 G5_method: method to activate
// g4 Gargs : pointer to last argument
//
//
// Stack:
//
// +---------------+ <--- sp
// | |
// : reg save area :
// | |
// +---------------+ <--- sp + 0x40
// | |
// : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
// | |
// +---------------+ <--- sp + 0x5c
// | |
// : free :
// | |
// +---------------+ <--- Gargs
// | |
// : arguments :
// | |
// +---------------+
// | |
//
//
//
// AFTER FRAME HAS BEEN SETUP for method interpretation the stack looks like:
//
// +---------------+ <--- sp
// | |
// : reg save area :
// | |
// +---------------+ <--- sp + 0x40
// | |
// : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
// | |
// +---------------+ <--- sp + 0x5c
// | |
// : :
// | | <--- Lesp
// +---------------+ <--- Lmonitors (fp - 0x18)
// | VM locals |
// +---------------+ <--- fp
// | |
// : reg save area :
// | |
// +---------------+ <--- fp + 0x40
// | |
// : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
// | |
// +---------------+ <--- fp + 0x5c
// | |
// : free :
// | |
// +---------------+
// | |
// : nonarg locals :
// | |
// +---------------+
// | |
// : arguments :
// | | <--- Llocals
// +---------------+ <--- Gargs
// | |
// Figure out the size of an interpreter frame (in words) given that we have a fully allocated
// expression stack, the callee will have callee_extra_locals (so we can account for
// frame extension) and monitor_size for monitors. Basically we need to calculate
// this exactly like generate_fixed_frame/generate_compute_interpreter_state.
//
//
// The big complicating thing here is that we must ensure that the stack stays properly
// aligned. This would be even uglier if monitor size wasn't modulo what the stack
// needs to be aligned for). We are given that the sp (fp) is already aligned by
// the caller so we must ensure that it is properly aligned for our callee.
//
const int rounded_vm_local_words =
// callee_locals and max_stack are counts, not the size in frame.
const int locals_size =
return (round_to((max_stack_words
//6815692//+ methodOopDesc::extra_stack_words()
// already rounded
+ locals_size + monitor_size);
}
// How much stack a method top interpreter activation needs in words.
// See call_stub code
WordsPerLong); // 7 + register save area
// Save space for one monitor to get into the interpreted method in case
// the method is synchronized
}
int tempcount,
int popframe_extra_args,
int moncount,
int callee_param_count,
int callee_local_count,
bool is_top_frame,
bool is_bottom_frame) {
// Note: This calculation must exactly parallel the frame setup
// in InterpreterGenerator::generate_fixed_frame.
// If f!=NULL, set up the following variables:
// - Lmethod
// - Llocals
// - Lmonitors (to the indicated number of monitors)
// - Lesp (to the indicated number of temps)
// The frame f (if not NULL) on entry is a description of the caller of the frame
// we are about to layout. We are guaranteed that we will be able to fill in a
// new interpreter frame as its callee (i.e. the stack space is allocated and
// the amount was determined by an earlier call to this method with f == NULL).
// On return f (if not NULL) while describe the interpreter frame we just layed out.
//
// Note: if you look closely this appears to be doing something much different
// than generate_fixed_frame. What is happening is this. On sparc we have to do
// this dance with interpreter_sp_adjustment because the window save area would
// appear just below the bottom (tos) of the caller's java expression stack. Because
// the interpreter want to have the locals completely contiguous generate_fixed_frame
// will adjust the caller's sp for the "extra locals" (max_locals - parameter_size).
// Now in generate_fixed_frame the extension of the caller's sp happens in the callee.
// In this code the opposite occurs the caller adjusts it's own stack base on the callee.
// This is mostly ok but it does cause a problem when we get to the initial frame (the oldest)
// because the oldest frame would have adjust its callers frame and yet that frame
// already exists and isn't part of this array of frames we are unpacking. So at first
// glance this would seem to mess up that frame. However Deoptimization::fetch_unroll_info_helper()
// will after it calculates all of the frame's on_stack_size()'s will then figure out the
// amount to adjust the caller of the initial (oldest) frame and the calculation will all
// add up. It does seem like it simpler to account for the adjustment here (and remove the
// callee... parameters here). However this would mean that this routine would have to take
// the caller frame as input so we could adjust its sp (and set it's interpreter_sp_adjustment)
// and run the calling loop in the reverse order. This would also would appear to mean making
// this code aware of what the interactions are when that initial caller fram was an osr or
// other adapter frame. deoptimization is complicated enough and hard enough to debug that
// there is no sense in messing working code.
//
if (interpreter_frame != NULL) {
// The skeleton frame must already look like an interpreter frame
// even if not fully filled out.
// More verification that skeleton frame is properly walkable
// preallocate monitors (cf. __ add_monitor_to_stack)
// preallocate stack space
if (caller->is_interpreted_frame()) {
// Can force the locals area to end up properly overlapping the top of the expression stack.
// Note that this computation means we replace size_of_parameters() values from the caller
// interpreter frame's expression stack with our argument locals
*interpreter_frame->register_addr(I5_savedSP) = (intptr_t) (fp + computed_sp_adjustment) - STACK_BIAS;
if (!is_bottom_frame) {
// Llast_SP is set below for the current frame to SP (with the
// extra space for the callee's locals). Here we adjust
// Llast_SP for the caller's frame, removing the extra space
// for the current method's locals.
} else {
assert(*caller->register_addr(Llast_SP) >= *interpreter_frame->register_addr(I5_savedSP), "strange Llast_SP");
}
} else {
// Don't have Lesp available; lay out locals block in the caller
// adjacent to the register window save area.
//
// Compiled frames do not allocate a varargs area which is why this if
// statement is needed.
//
if (caller->is_compiled_frame()) {
} else {
}
if (!caller->is_entry_frame()) {
// Caller wants his own SP back
*interpreter_frame->register_addr(I5_savedSP) = (intptr_t)(caller->fp() - caller_frame_size) - STACK_BIAS;
}
}
if (TraceDeoptimization) {
if (caller->is_entry_frame()) {
// make sure I5_savedSP and the entry frames notion of saved SP
// agree. This assertion duplicate a check in entry frame code
// but catches the failure earlier.
"would change callers SP");
}
if (caller->is_entry_frame()) {
}
if (caller->is_compiled_frame()) {
if (caller->is_deoptimized_frame()) {
}
}
if (caller->is_interpreted_frame()) {
}
}
if (method->max_locals() > 0) {
assert(locals < interpreter_frame->sp() || locals > (interpreter_frame->sp() + 16), "locals in save area");
assert(locals < interpreter_frame->fp() || locals >= (interpreter_frame->fp() + 16), "locals in save area");
}
#ifdef _LP64
#endif
// Llast_SP will be same as SP as there is no adapter space
#ifdef FAST_DISPATCH
#endif
#ifdef ASSERT
assert(interpreter_frame->interpreter_frame_local_at(9) == (intptr_t *)((intptr_t)locals - (9 * Interpreter::stackElementSize)), "locals match");
assert(((intptr_t *)interpreter_frame->interpreter_frame_monitor_begin()) == ((intptr_t *)mp)+monitor_size, "monitor_begin matches");
// check bounds
#endif // ASSERT
}
return raw_frame_size;
}
//----------------------------------------------------------------------------------------------------
// Exceptions
// Entry point in previous activation (i.e., if the caller was interpreted)
// O0: exception
// entry point for exceptions thrown within interpreter code
__ verify_thread();
// expression stack is undefined here
// O0: exception, i.e. Oexception
// Lbcp: exception bcx
// expression stack must be empty before entering the VM in case of an exception
// find exception handler address and preserve exception oop
// call C routine to find handler and jump to it
__ call_VM(O1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), Oexception);
// if the exception is not handled in the current frame
// the frame is removed and the exception is rethrown
// (i.e. exception continuation is _rethrow_exception)
//
// Note: At this point the bci is still the bxi for the instruction which caused
// the exception and the expression stack is empty. Thus, for any VM calls
// at this point, GC will find a legal oop map (with empty expression stack).
// in current activation
// tos: exception
// Lbcp: exception bcp
//
// JVMTI PopFrame support
//
// Set the popframe_processing bit in popframe_condition indicating that we are
// currently handling popframe, so that call_VMs that may happen later do not trigger new
// popframe handling cycles.
// Empty the expression stack, as in normal exception handling
__ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, /* install_monitor_exception */ false);
{
// Check to see whether we are returning to a deoptimized frame.
// (The PopFrame call ensures that the caller of the popped frame is
// either interpreted or compiled and deoptimizes it if compiled.)
// In this case, we can't call dispatch_next() after the frame is
// popped, but instead must save the incoming arguments and restore
// them after deoptimization has occurred.
//
// Note that we don't compare the return PC against the
// deoptimization blob's unpack entry because of the presence of
// adapter frames in C2.
__ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), I7);
// Compute size of arguments for saving when returning to deoptimized caller
// Save these arguments
__ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), G2_thread, Gtmp1, Gtmp2);
// Inform deoptimization that it is responsible for restoring these arguments
// Return from the current method
// The caller's SP was adjusted upon method entry to accomodate
// the callee's non-argument locals. Undo that adjustment.
}
// Clear the popframe condition flag
// Get out of the current method (how this is done depends on the particular compiler calling
// convention that the interpreter currently follows)
// The caller's SP was adjusted upon method entry to accomodate
// the callee's non-argument locals. Undo that adjustment.
// The method data pointer was incremented already during
// call profiling. We have to restore the mdp for the current bcp.
if (ProfileInterpreter) {
}
// Resume bytecode interpretation at the current bcp
// end of JVMTI PopFrame support
// preserve exception over this code sequence (remove activation calls the vm, but oopmaps are not correct here)
// Intel has the following comment:
//// remove the activation (without doing throws on illegalMonitorExceptions)
// They remove the activation without checking for bad monitor state.
// %%% We should make sure this is the right semantics before implementing.
// %%% changed set_vm_result_2 to set_vm_result and get_vm_result_2 to get_vm_result. Is there a bug here?
// We are done with this activation frame; find out where to go next.
// The continuation point will be an exception handler, which expects
// the following registers set up:
//
// Oexception: exception
// Oissuing_pc: the local call that threw exception
// Other On: garbage
//
// We do the required restore at the last possible moment, because we
// need to preserve some state across a runtime call.
// (Remember that the caller activation is unknown--it might not be
// interpreted, so things like Lscratch are useless in the caller.)
// Although the Intel version uses call_C, we can use the more
// compact call_VM. (The only real difference on SPARC is a
// harmlessly ignored [re]set_last_Java_frame, compared with
// the Intel code which lacks this.)
__ mov(Oexception, Oexception ->after_save()); // get exception in I0 so it will be on O0 after restore
__ add(issuing_pc_addr, Oissuing_pc->after_save()); // likewise set I1 to a value local to the caller
// The caller's SP was adjusted upon method entry to accomodate
// the callee's non-argument locals. Undo that adjustment.
// (same old exception object is already in Oexception; see above)
// Note that an "issuing PC" is actually the next PC after the call
}
//
// JVMTI ForceEarlyReturn support
//
// Clear the earlyret state
/* throw_monitor_exception */ false,
/* install_monitor_exception */ false);
// The caller's SP was adjusted upon method entry to accomodate
// the callee's non-argument locals. Undo that adjustment.
return entry;
} // end of JVMTI ForceEarlyReturn support
//------------------------------------------------------------------------------------------------------------------------
// Helper for vtos entry point generation
void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
Label L;
}
// --------------------------------------------------------------------------------
generate_all(); // down here so it can be "virtual"
}
// --------------------------------------------------------------------------------
// Non-product code
#ifndef PRODUCT
// Pass a 0 (not used in sparc) and the top of stack to the bytecode tracer
__ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), G0, Otos_l1, G3_scratch);
return entry;
}
// helpers for generate_and_dispatch
}
}
// get index, shift out old bytecode, bring in new bytecode, and store it
// _index = (_index >> log2_number_of_codes) |
// (bytecode << log2_number_of_codes);
// bump bucket contents
// _counters[_index] ++;
}
// Call a little run-time stub to avoid blow-up for each bytecode.
// The run-time runtime saves the right registers, depending on
// the tosca in-state for the given template.
}
}
#endif // not PRODUCT
#endif // !CC_INTERP