/*
* 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/cppInterpreter.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterGenerator.hpp"
#include "interpreter/interpreterRuntime.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/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "runtime/vframeArray.hpp"
#ifdef SHARK
#include "shark/shark_globals.hpp"
#endif
#ifdef CC_INTERP
// Routine exists to make tracebacks look decent in debugger
// while "shadow" interpreter frames are on stack. It is also
// used to distinguish interpreter frames.
}
}
Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized
// c++ interpreter entry point this holds that entry point label.
#ifdef _LP64
#else
#endif
}
// Restore any method result value
#ifdef _LP64
#else
#endif
}
// 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;
}
// tosca based result to c++ interpreter stack based result.
// Result goes to address in L1_scratch
// A result is in the native abi result register from a native method call.
// We need to return this result to the interpreter by pushing the result on the interpreter's
// stack. This is relatively simple the destination is in L1_scratch
// i.e. L1_scratch is the first free element on the stack. If we "push" a return value we must
// adjust L1_scratch
switch (type) {
case T_BOOLEAN:
// !0 => true; 0 => false
break;
// cannot use and3, 0xFFFF too big as immediate value!
case T_CHAR :
break;
case T_BYTE :
break;
case T_SHORT :
break;
case T_LONG :
#ifndef _LP64
#if defined(COMPILER2)
// 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
#else
// native result is in O0, O1
#endif /* COMPILER2 */
#else
#endif
break;
case T_INT :
break;
case T_VOID : /* nothing to do */
break;
case T_FLOAT :
break;
case T_DOUBLE :
// Every stack slot is aligned on 64 bit, However is this
// the correct stack slot on 64bit?? QQQ
break;
case T_OBJECT :
break;
default : ShouldNotReachHere();
}
return entry;
}
// A result is in the java expression stack of the interpreted method that has just
// returned. Place this result on the java expression stack of the caller.
//
// The current interpreter activation in Lstate is for the method just returning its
// result. So we know that the result of this method is on the top of the current
// execution stack (which is pre-pushed) and will be return to the top of the caller
// stack. The top of the callers stack is the bottom of the locals of the current
// activation.
// Because of the way activation are managed by the frame manager the value of esp is
// below both the stack top of the current activation and naturally the stack top
// of the calling activation. This enable this routine to leave the return address
// to the frame manager on the stack and do a vanilla return.
//
// On entry: O0 - points to source (callee stack top)
// O1 - points to destination (caller stack top [i.e. free location])
// destroys O2, O3
//
switch (type) {
case T_VOID: break;
break;
case T_FLOAT :
case T_BOOLEAN:
case T_CHAR :
case T_BYTE :
case T_SHORT :
case T_INT :
// 1 word result
break;
case T_DOUBLE :
case T_LONG :
// return top two words on current expression stack to caller's expression stack
// The caller's expression stack is adjacent to the current frame manager's intepretState
// except we allocated one extra word for this intepretState so we won't overwrite it
// when we return a two word result.
#ifdef _LP64
#else
#endif
break;
case T_OBJECT :
break;
default : ShouldNotReachHere();
}
return entry;
}
// A result is in the java expression stack of the interpreted method that has just
// returned. Place this result in the native abi that the caller expects.
// We are in a new frame registers we set must be in caller (i.e. callstub) frame.
//
// Similar to generate_stack_to_stack_converter above. Called at a similar time from the
// and so rather than return result onto caller's java expression stack we return the
// result in the expected location based on the native abi.
// On entry: O0 - source (stack top)
// On exit result in expected output register
// QQQ schedule this better
switch (type) {
case T_VOID: break;
break;
case T_FLOAT :
break;
case T_BOOLEAN:
case T_CHAR :
case T_BYTE :
case T_SHORT :
case T_INT :
// 1 word result
break;
case T_DOUBLE :
break;
case T_LONG :
// return top two words on current expression stack to caller's expression stack
// The caller's expression stack is adjacent to the current frame manager's interpretState
// except we allocated one extra word for this intepretState so we won't overwrite it
// when we return a two word result.
#ifdef _LP64
#else
#endif
// C2 expects long results in G1 we can't tell if we're returning to interpreted
// Shift bits into high (msb) of G1
// Zero extend low bits
#endif /* COMPILER2 */
break;
case T_OBJECT :
break;
default : ShouldNotReachHere();
}
return entry;
}
// make it look good in the debugger
}
if (length != 0) {
switch (state) {
case ctos:
case stos:
}
} else {
}
return ret;
}
//
// 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) {
// Update standard invocation counters
if (ProfileInterpreter) { // %%% Merge this into methodDataOop
Address interpreter_invocation_counter(G3_scratch, 0, in_bytes(methodOopDesc::interpreter_invocation_counter_offset()));
}
}
// A method that does nothing 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.
// Code: _return
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.
if ( UseFastAccessorMethods) {
// Check if we need to reach a safepoint and generate full interpreter
// frame if so.
// Check if local 0 != NULL
// 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.
__ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::indices_offset()), G1_scratch);
// Get the type and return field offset from the constant pool cache
__ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()), G1_scratch);
// 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
return entry;
}
return NULL;
}
#ifndef SERIALGC
if (UseG1GC) {
// We need to generate have a routine that generates code to:
// * load the value in the referent field
// * passes that value to the pre-barrier.
//
// In the case of G1 this will record the value of the
// referent in an SATB buffer if marking is active.
// This will cause concurrent marking to mark the referent
// field as live.
}
#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. (C++ 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
const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset()));
// 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
// NEW
// generate the code to allocate the interpreter stack frame
// NEW FRAME ALLOCATED HERE
// save callers original sp
// __ mov(SP, I5_savedSP->after_restore());
// At this point Lstate points to new interpreter state
//
// 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, so method is not locked
// if counter overflows.
if (synchronized) {
lock_method();
// Don't see how G2_thread is preserved here...
// __ verify_thread(); QQQ destroys L0,L1 can't use
} else {
#ifdef ASSERT
}
#endif // ASSERT
}
// start execution
// __ verify_thread(); kills L1,L2 can't use at the moment
// 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;
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), G5_method, false);
}
// 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 (Lstate in particular)
// Flush the state pointer to the register save area
// Which is the only register we need for a stack walk.
// 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).
// call signature handler
// get native function entry point(O0 is a good temp until the very end)
// for static methods insert the mirror argument
// where the mirror handle body is allocated:
#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 java 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
0,
// 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.
// 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.
// 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
// thread state is thread_in_native_trans. Any safepoint blocking has
// happened in the trampoline we are ready to switch to thread_in_Java.
// 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.
}
// reset handle block
// handle exceptions (exception handling will handle unlocking!)
{ Label L;
// With c++ interpreter we just leave it pending caller will do the correct thing. However...
// Like x86 we ignore the result of the native call and leave the method locked. This
// seems wrong to leave things locked.
__ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
}
if (synchronized) {
// save and restore any potential method result value around the unlocking operation
// Get the initial monitor we allocated
}
// 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 */
#ifdef ASSERT
{
}
#endif
// Calls result handler which POPS FRAME
if (TraceJumps) {
// Move target to register that is recordable
} else {
}
if (inc_counter) {
// handle invocation counter overflow
}
return entry;
}
const Register prev_state,
bool native) {
// On entry
// G5_method - caller's method
// Gargs - points to initial parameters (i.e. locals[0])
// G2_thread - valid? (C1 only??)
// "prev_state" - contains any previous frame manager state which we must save a link
//
// On return
// "state" is a pointer to the newly allocated state object. We must allocate and initialize
// a new interpretState object and the method expression stack.
const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset()));
// slop factor is two extra slots on the expression stack so that
// we always have room to store a result when returning from a call without parameters
// that returns a result.
const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor?
//6815692//methodOopDesc::extra_stack_words() + // extra push slots for MH adapters
// XXX G5_method valid
// Now compute new frame size
if (native) {
__ calc_mem_param_words(Gtmp, Gtmp); // space for native call parameters passed on the stack in words
} else {
}
// Need to do stack size check here before we fault on large frames
// compute stack bottom
// Avoid touching the guard pages
// Also a fudge for frame size of BytecodeInterpreter::run
// It varies from 1k->4k depending on build type
// throw exception return address becomes throwing pc
// New window I7 call_stub or previous activation
//
// Initialize a new Interpreter state
// orig_sp - caller's original sp
// G2_thread - thread
// Gargs - &locals[0] (unbiased?)
// G5_method - method
// SP (biased) - accounts for full size java stack, BytecodeInterpreter object, register save area, and register parameter save window
if (native) {
} else {
}
// Monitor base is just start of BytecodeInterpreter object;
// Do we need a monitor for synchonized method?
{
// lock the mirror, not the klassOop
#ifdef ASSERT
#endif // ASSERT
}
// Remember initial frame bottom
//6815692//if (EnableInvokeDynamic)
//6815692// __ inc(O3, methodOopDesc::extra_stack_entries());
// __ sub(O3, wordSize, O3); // so prepush doesn't look out of bounds
if (!native) {
//
// Code to initialize locals
//
// Now zero locals
if (true /* zerolocals */ || ClearInterpreterLocals) {
// explicitly initialize locals
init_value = G0;
} else {
#ifdef ASSERT
// initialize locals to a garbage pattern for better debugging
init_value = O3;
#endif // ASSERT
}
if (init_value != noreg) {
// NOTE: If you change the frame layout, this code will need to
// be updated!
}
}
}
// Find preallocated monitor and lock method (C++ interpreter)
//
// Lock the current method.
// Destroys registers L2_scratch, L3_scratch, O0
//
// Find everything relative to Lstate
#ifdef ASSERT
}
#endif // ASSERT
// monitor is already allocated at stack base
// and the lockee is already present
}
// Generate code for handling resuming a deopted method
// deopt needs to jump to here to enter the interpreter (return a result)
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_OBJECT), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_BOOLEAN), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_INT), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
// 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
#endif /* !_LP64 && COMPILER2 */
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_LONG), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_FLOAT), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_DOUBLE), L3_scratch); // Result stub address array index
// deopt needs to jump to here to enter the interpreter (return a result)
// Deopt return common
// an index is present that lets us move any possible result being
// return to the interpreter's stack
//
// stack is in the state that the calling convention left it.
// Copy the result from native abi result and place it on java expression stack.
// Current interpreter state is present in Lstate
// Get current pre-pushed top of interpreter stack
// Any result (if any) is in native abi
// result type index is in L3_scratch
// L1_scratch points to top of stack (prepushed)
}
// Generate the code to handle a more_monitors message from the c++ interpreter
// 1. compute new pointers // esp: old expression stack top
// 2. move expression stack
// now zero the slot so we can find it.
}
// Initial entry to C++ interpreter from the call_stub.
// This entry point is called the frame manager since it handles the generation
// of interpreter activation frames via requests directly from the vm (via call_stub)
// and via requests from the interpreter. The requests from the call_stub happen
// directly thru the entry point. Requests from the interpreter happen via returning
// from the interpreter and examining the message the interpreter has returned to
// the frame manager. The frame manager can take the following requests:
// NO_REQUEST - error, should never happen.
// MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
// allocate a new monitor.
// CALL_METHOD - setup a new activation to call a new method. Very similar to what
// happens during entry during the entry via the call stub.
// RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
//
// Arguments:
//
// ebx: methodOop
// ecx: receiver - unused (retrieved from stack as needed)
//
//
// Stack layout at entry
//
// [ return address ] <--- esp
// [ parameter n ]
// ...
// [ parameter 1 ]
// [ expression stack ]
//
//
// We are free to blow any registers we like because the call_stub which brought us here
// initially has preserved the callee save registers already.
//
//
#ifdef ASSERT
{ \
__ breakpoint_trap(); \
}
#else
#endif /* ASSERT */
//
// Adjust caller's stack so that all the locals can be contiguous with
// the parameters.
// Worries about stack overflow make this a pain.
//
// Destroys args, G3_scratch, G3_scratch
//
// assert_different_registers(state, prev_state);
const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset()));
// NEW
// determine extra space for non-argument locals & adjust caller's SP
// Gtmp1: parameter size in words
#if 1
// the call_stub will place the final interpreter argument at
// frame::memory_parameter_word_sp_offset. This is mostly not noticable for either asm
// or c++ interpreter. However with the c++ interpreter when we do a recursive call
// and try to make it look good in the debugger we will store the argument to
// RecursiveInterpreterActivation in the register argument save area. Without allocating
// extra space for the compiler this will overwrite locals in the local array of the
// interpreter.
// QQQ still needed with frameless adapters???
const int c2i_adjust_words = frame::memory_parameter_word_sp_offset - frame::callee_register_argument_save_area_sp_offset;
#endif // 1
}
// G5_method: methodOop
// G2_thread: thread (unused)
// Gargs: bottom of args (sender_sp)
// O5: sender's sp
// A single frame manager is plenty as we don't specialize for synchronized. We could and
// the code is pretty much ready. Would need to change the test below and for good measure
// modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
// routines. Not clear this is worth it yet.
if (interpreter_frame_manager) {
return interpreter_frame_manager;
}
// the following temporary registers are used during frame creation
// const Register Lmirror = L1; // native mirror (native calls only)
const Address size_of_parameters(G5_method, 0, in_bytes(methodOopDesc::size_of_parameters_offset()));
// Interpreter needs to have locals completely contiguous. In order to do that
// We must adjust the caller's stack pointer for any locals beyond just the
// parameters
// O5_savedSP still contains sender's sp
// NEW FRAME
// At this point a new interpreter frame and state object are created and initialized
// Lstate has the pointer to the new activation
// Any stack banging or limit check should already be done.
#if 1
#endif
// Call interpreter (stack bang complete) enter here if message is
// set and we know stack size is valid
#ifdef ASSERT
{
}
#endif
: BytecodeInterpreter::run),
// examine msg from interpreter to determine next action
// Allocate more monitor space, shuffle expression stack....
// new monitor slot allocated, resume the interpreter.
// uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
// QQQ what message do we send
//=============================================================================
// Returning from a compiled method into a deopted method. The bytecode at the
// bcp has completed. The result of the bytecode is in the native abi (the tosca
// for the template based interpreter). Any stack space that was used by the
// bytecode that has completed has been removed (e.g. parameters for an invoke)
// so all that we have to do is place any pending result on the expression stack
// and resume execution on the next bytecode.
// ready to resume the interpreter
// Current frame has caught an exception we need to dispatch to the
// handler. We can get here because a native interpreter frame caught
// an exception in which case there is no handler and we must rethrow
// If it is a vanilla interpreted frame the we simply drop into the
// interpreter and let it do the lookup.
// O0: exception
// O7: throwing pc
// We want exception in the thread no matter what we ultimately decide about frame type.
__ verify_thread();
// get the methodOop
// if this current frame vanilla or native?
__ br(Assembler::zero, false, Assembler::pt, return_with_exception); // vanilla interpreted frame handle directly
// We drop thru to unwind a native interpreted frame with a pending exception
// We jump here for the initial interpreter frame with exception pending
// We unwind the current acivation and forward it to our caller.
// Unwind frame and jump to forward exception. unwinding will place throwing pc in O7
// as expected by forward_exception.
__ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
// Return point from a call which returns a result in the native abi
// (c1/c2/jni-native). This result must be processed onto the java
// expression stack.
//
// A pending exception may be present in which case there is no result present
// stack is in the state that the calling convention left it.
// Copy the result from native abi result and place it on java expression stack.
// Current interpreter state is present in Lstate
// Exception pending?
// Process the native abi result to java expression stack
__ lduh(L4_scratch, in_bytes(methodOopDesc::size_of_parameters_offset()), L2_scratch); // get parameter size
__ ld(L4_scratch, in_bytes(methodOopDesc::result_index_offset()), L3_scratch); // called method result type index
// tosca is really just native abi
// L1_scratch points to top of stack (prepushed)
// An exception is being caught on return to a vanilla interpreter frame.
// Empty the stack and resume interpreter
// Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
// interpreter call, or native) and unwind this interpreter activation.
// All monitors should be unlocked.
// Interpreted result is on the top of the completed activation expression stack.
// We must return it to the top of the callers stack if caller was interpreted
// The caller's expression stack was truncated by the call however the current activation
// has enough stuff on the stack that we have usable space there no matter what. The
// other thing that makes it easy is that the top of the caller's stack is stored in STATE(_locals)
// for the current activation
// Copy result to callers java stack
// O0 - will be source, O1 - will be destination (preserved)
// O1 == &locals[0]
// Result is now on caller's stack. Just unwind current activation and resume
// O1 == &locals[0] (really callers stacktop) for activation now returning
// returning to interpreter method from "recursive" interpreter call
// result converter left O1 pointing to top of the( prepushed) java stack for method we are returning
// to. Now all we must do is unwind the state from the completed call
// Must restore stack
// Return to interpreter method after a method call (interpreted/native/c1/c2) has completed.
// Result if any is already on the caller's stack. All we must do now is remove the now dead
// frame and tell interpreter to resume.
// POP FRAME HERE ==================================
// Resume the interpreter. The current frame contains the current interpreter
// state object.
//
// O1 == new java stack pointer
// A frame we have already used before so no need to bang stack so use call_interpreter_2 entry
// Fast accessor methods share this entry point.
// This works because frame manager is in the same codelet
// we need to do a little register fixup here once we distinguish the two of them
if (UseFastAccessorMethods && !synchronized) {
// Call stub_return address still in O7
}
// convert result and unwind initial activation
// L2_scratch - scaled result type index
// we can return here with an exception that wasn't handled by interpreted code
// __ ld_ptr(STATE(_saved_sp), Gtmp1);
//
// POP FRAME HERE ==================================
// OSR request, unwind the current frame and transfer to the OSR entry
// and enter OSR nmethod
// We are going to pop this frame. Is there another interpreter frame underneath
// Frame underneath is an interpreter frame simply unwind
// POP FRAME HERE ==================================
// Since we are now calling native need to change our "return address" from the
// dummy RecursiveInterpreterActivation to a return from native
// POP FRAME HERE ==================================
// Call a new method. All we do is (temporarily) trim the expression stack
// push a return address to bring us back to here and leap to the new entry.
// At this point we have a topmost frame that was allocated by the frame manager
// which contains the current method interpreted state. We trim this frame
// of excess java expression stack entries and then recurse.
// stack points to next free location and not top element on expression stack
// method expects sp to be pointing to topmost element
// SP already takes in to account the 2 extra words we use for slop
// when we call a "static long no_params()" method. So if
// we trim back sp by the amount of unused java expression stack
// there will be automagically the 2 extra words we need.
// We also have to worry about keeping SP aligned.
// compute the unused java stack size
// Round down the unused space to that stack is always 16-byte aligned
// by making the unused space a multiple of the size of two longs.
// Now trim the stack
// Now point to the final argument (account for prepush)
#ifdef ASSERT
// Make sure we have space for the window
{
}
#endif // ASSERT
// Create a new frame where we can store values that make it look like the interpreter
// really recursed.
// prepare to recurse or call specialized entry
// First link the registers we need
// make the pc look good in debugger
// argument too
// Record our sending SP
// method uses specialized entry, push a return so we look like call stub setup
// this path will handle fact that result is returned in registers and not
// on the java stack.
//
// Bad Message from interpreter
//
// Interpreted method "returned" with an exception pass it on...
// Pass result, unwind activation and continue/return to interpreter/call_stub
// We handle result (if any) differently based on return to interpreter or call_stub
return entry_point;
}
generate_all(); // down here so it can be "virtual"
}
// 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.
//
// Ths c++ interpreter always makes sure that we have a enough extra space on the
// stack at all times to deal with the "stack long no_params()" method issue. This
// is "slop_factor" here.
}
// 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
}
bool is_top_frame
)
{
// What about any vtable?
//
// This gets filled in later but make it something recognizable for now
} else {
}
// Fill in the registers for the frame
// Need to install _sender_sp. Actually not too hard in C++!
// When the skeletal frames are layed out we fill in a value
// for _sender_sp. That value is only correct for the oldest
// skeletal frame constructed (because there is only a single
// entry for "caller_adjustment". While the skeletal frames
// exist that is good enough. We correct that calculation
// here and get all the frames correct.
// to_fill->_sender_sp = locals - (method->size_of_parameters() - 1);
// skeletal already places a useful value here and this doesn't account
// for alignment so don't bother.
// *current->register_addr(I5_savedSP) = (intptr_t) locals - (method->size_of_parameters() - 1);
if (caller->is_interpreted_frame()) {
// Make the prev callee look proper
} else {
}
}
// Need +1 here because stack_base points to the word just above the first expr stack entry
// and stack_limit is supposed to point to the word just below the last expr stack entry.
// See generate_compute_interpreter_state.
// sparc specific
#ifdef ASSERT
#endif
}
void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) {
}
int tempcount, // Number of slots on java expression stack in use
int popframe_extra_args,
int moncount, // Number of active monitors
int callee_param_size,
int callee_locals_size,
bool is_top_frame,
bool is_bottom_frame) {
// NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
// does as far as allocating an interpreter frame.
// If interpreter_frame!=NULL, set up the method, locals, and monitors.
// The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
// as determined by a previous call to this method.
// It is also guaranteed to be walkable even though it is in a skeletal state
// NOTE: return size is in words not bytes
// NOTE: tempcount is the current size of the java expression stack. For top most
// frames we will allocate a full sized expression stack and not the curback
// version that non-top frames have.
// Calculate the amount our frame will be adjust by the callee. For top frame
// this is zero.
// NOTE: ia64 seems to do this wrong (or at least backwards) in that it
// calculates the extra locals based on itself. Not what the callee does
// to it. So it ignores last_frame_adjust value. Seems suspicious as far
// as getting sender_sp correct.
int full_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size);
int short_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size);
/*
if we actually have a frame to layout we must now fill in all the pieces. This means both
the interpreterState and the registers.
*/
if (interpreter_frame != NULL) {
// MUCHO HACK
// 'interpreter_frame->sp()' is unbiased while 'frame_bottom' must be a biased value in 64bit mode.
/* Now fillin the interpreterState object */
interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
// Calculate the postion of locals[0]. This is painful because of
// stack alignment (same as ia64). The problem is that we can
// not compute the location of locals from fp(). fp() will account
// for the extra locals but it also accounts for aligning the stack
// and we can't determine if the locals[0] was misaligned but max_locals
// was enough to have the
// calculate postion of locals. fp already accounts for extra locals.
// +2 for the static long no_params() issue.
if (caller->is_interpreted_frame()) {
// locals must agree with the caller because it will be used to set the
// caller's tos when we return.
// stack() is prepushed.
} else {
// 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 {
}
}
// END MUCHO HACK
/* +1 because stack is always prepushed */
BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
}
return frame_words;
}
#endif // CC_INTERP