/*
* 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 "interpreter/interpreter.hpp"
#include "memory/resourceArea.hpp"
#include "oops/markOop.hpp"
#include "oops/methodOop.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/monitorChunk.hpp"
#include "runtime/signature.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "runtime/stubRoutines.hpp"
#include "vmreg_x86.inline.hpp"
#ifdef COMPILER1
#include "c1/c1_Runtime1.hpp"
#include "runtime/vframeArray.hpp"
#endif
#ifdef ASSERT
}
#endif
// consider stack guards when trying to determine "safe" stack pointers
static size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0;
// sp must be within the usable part of the stack (not in guards)
if (!sp_safe) {
return false;
}
// unextended sp must be within the stack and above or equal sp
(unextended_sp >= sp);
if (!unextended_sp_safe) {
return false;
}
// an fp must be within the stack and above (but not equal) sp
// second evaluation on fp+ is added to handle situation where fp is -1
bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
// We know sp/unextended_sp are safe only fp is questionable here
// If the current frame is known to the code cache then we can attempt to
// to construct the sender and do some validation of it. This goes a long way
// toward eliminating issues when we get in frame construction code
// First check if frame is complete and tester is reliable
// Unfortunately we can only check frame complete for runtime stubs and nmethod
// other generic buffer blobs are more problematic so we just assume they are
// ok. adapter blobs never have a frame complete and are never ok.
// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
return false;
}
return false;
}
}
// Could just be some random pointer within the codeBlob
return false;
}
// Entry frame checks
if (is_entry_frame()) {
// an entry frame must have a valid fp.
if (!fp_safe) return false;
// Validate the JavaCallWrapper an entry frame must have
return jcw_safe;
}
if (is_interpreted_frame()) {
// fp must be safe
if (!fp_safe) {
return false;
}
} else {
// fp does not have to be safe (although it could be check for c1?)
// On Intel the return_address is always the word on the stack
}
// If the potential sender is the interpreter then we can do some more checking
// ebp is always saved in a recognizable place in any code we generate. However
// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
// is really a frame pointer.
if (!saved_fp_safe) {
return false;
}
// construct the potential sender
}
// We must always be able to find a recognizable pc
return false;
}
// Could be a zombie method
return false;
}
// Could just be some random pointer within the codeBlob
return false;
}
// We should never be able to see an adapter if the current frame is something from code cache
if (sender_blob->is_adapter_blob()) {
return false;
}
// Could be the call_stub
if (!saved_fp_safe) {
return false;
}
// construct the potential sender
// Validate the JavaCallWrapper an entry frame must have
return jcw_safe;
}
if (sender_blob->is_nmethod()) {
return false;
}
}
}
// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
// because the return address counts against the callee's frame.
if (sender_blob->frame_size() <= 0) {
return false;
}
// We should never be able to see anything here except an nmethod. If something in the
// code cache (current frame) is called by an entity within the code cache that entity
// should not be anything but the call stub (already covered), the interpreter (already covered)
// or an nmethod.
if (!sender_blob->is_nmethod()) {
return false;
}
// Could put some more validation for the potential non-interpreted sender
// frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
// One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
// We've validated the potential sender that would be created
return true;
}
// Must be native-compiled frame. Since sender will try and use fp to find
// linkages it must be safe
if (!fp_safe) {
return false;
}
// Will the pc we fetch be non-zero (which we'll find at the oldest frame)
// could try and do some more potential verification of native frame if we could think of some...
return true;
}
if (TracePcPatching) {
}
// Either the return address is the original one or we are going to
// patch in the same address that's already there.
if (original_pc != NULL) {
// leave _pc as is
} else {
}
}
}
}
// convert offset to index to deal with tsi
// Entry frame's arguments are always in relation to unextended_sp()
return &unextended_sp()[index];
}
// sender_sp
#ifdef CC_INTERP
// QQQ why does this specialize method exist if frame::sender_sp() does same thing?
// seems odd and if we always know interpreted vs. non then sender_sp() is really
// doing too much work.
return get_interpreterState()->sender_sp();
}
// monitor elements
return get_interpreterState()->monitor_base();
}
}
#else // CC_INTERP
}
}
// monitor elements
}
// make sure the pointer points inside the frame
return result;
}
}
// Used by template based interpreter deoptimization
}
#endif // CC_INTERP
// Java frame called from C; skip all C frames and return top C
// frame of that chunk as the sender
return fr;
}
return fr;
}
//------------------------------------------------------------------------------
// frame::verify_deopt_original_pc
//
// Verifies the calculated original PC of a deoptimization PC for the
// given unextended SP. The unextended SP might also be the saved SP
// for MethodHandle call sites.
#if ASSERT
void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) {
// This is ugly but it's better than to change {get,set}_original_pc
// to take an SP value as argument. And it's only a debugging
// method anyway.
}
#endif
//------------------------------------------------------------------------------
// frame::adjust_unextended_sp
// If we are returning to a compiled MethodHandle call site, the
// saved_fp will in fact be a saved value of the unextended SP. The
// simplest way to tell whether we are returning to such a call site
// is as follows:
// If the sender PC is a deoptimization point, get the original
// PC. For MethodHandle call site the unextended_sp is stored in
// saved_fp.
}
}
}
}
}
//------------------------------------------------------------------------------
// frame::update_map_with_saved_link
// location on entry. We must record where that location is
// the saved copy no matter what it called.
// code, on entry will be enough.
#ifdef AMD64
// this is weird "H" ought to be at a higher address however the
// oopMaps seems to have the "H" regs at the same address and the
// vanilla register.
// XXXX make this go away
if (true) {
}
#endif // AMD64
}
//------------------------------------------------------------------------------
// frame::sender_for_interpreter_frame
// SP is the raw SP from the sender after adapter or interpreter
// extension.
#ifdef COMPILER2
if (map->update_map()) {
}
#endif // COMPILER2
}
//------------------------------------------------------------------------------
// frame::sender_for_compiled_frame
// frame owned by optimizing compiler
// On Intel the return_address is always the word on the stack
// This is the saved value of EBP which may or may not really be an FP.
// It is only an FP if the sender is an interpreter frame (or C1?).
if (map->update_map()) {
// Tell GC to use argument oopmaps for some runtime stubs that need it.
// For C1, the runtime stub might not have oop maps, so set this flag
// outside of update_register_map.
}
// Since the prolog does the save and restore of EBP there is no oopmap
// for it so we must fill in its location as if there was an oopmap entry
// since if our caller was compiled code there could be live jvm state in it.
}
}
//------------------------------------------------------------------------------
// frame::sender
// Default is we done have to follow them. The sender_for_xxx will
// update it accordingly
map->set_include_argument_oops(false);
return sender_for_compiled_frame(map);
}
// Must be native-compiled frame, i.e. the marshaling code for native
// methods that exists in the core system.
}
// When unpacking an optimized frame the frame pointer is
// adjusted with:
}
// nothing done here now
}
// QQQ
#ifdef CC_INTERP
#else
// These are reasonable sanity checks
return false;
}
return false;
}
return false;
}
// These are hacks to keep us out of trouble.
// The problem with these is that they mask other problems
return false;
}
// do some validation of frame elements
// first the method
// validate the method we'd find in this potential sender
// stack frames shouldn't be much larger than max_stack elements
return false;
}
if (m->validate_bci_from_bcx(bcx) < 0) {
return false;
}
// validate constantPoolCacheOop
// validate locals
// We'd have to be pretty unlucky to be mislead at this point
#endif // CC_INTERP
return true;
}
#ifdef CC_INTERP
// Needed for JVMTI. The result should always be in the
// interpreterState object
#endif // CC_INTERP
// Prior to calling into the runtime to report the method_exit the possible
// QQQ seems like this code is equivalent on the two platforms
#ifdef AMD64
// This is times two because we do a push(ltos) after pushing XMM0
// and that takes two interpreter stack slots.
#else
tos_addr += 2;
#endif // AMD64
}
} else {
}
switch (type) {
case T_OBJECT :
case T_ARRAY : {
#ifdef CC_INTERP
#else
#endif // CC_INTERP
} else {
}
*oop_result = obj;
break;
}
case T_FLOAT : {
#ifdef AMD64
#else
value_result->f = (jfloat)d;
} else {
}
#endif // AMD64
break;
}
case T_VOID : /* Nothing to do */ break;
default : ShouldNotReachHere();
}
return type;
}
return &interpreter_frame_tos_address()[index];
}
#ifndef PRODUCT
if (is_interpreted_frame()) {
}
}
#endif
// used to reset the saved FP
return fp();
}
// use the frame size if valid
if (size > 0) {
return unextended_sp() + size;
}
}
// else rely on fp()
return fp();
}