frame_sparc.cpp revision 1879
0N/A/*
0N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "interpreter/interpreter.hpp"
0N/A#include "memory/resourceArea.hpp"
0N/A#include "oops/markOop.hpp"
0N/A#include "oops/methodOop.hpp"
0N/A#include "oops/oop.inline.hpp"
0N/A#include "runtime/frame.inline.hpp"
0N/A#include "runtime/handles.inline.hpp"
0N/A#include "runtime/javaCalls.hpp"
0N/A#include "runtime/monitorChunk.hpp"
0N/A#include "runtime/signature.hpp"
0N/A#include "runtime/stubCodeGenerator.hpp"
0N/A#include "runtime/stubRoutines.hpp"
0N/A#include "vmreg_sparc.inline.hpp"
0N/A#ifdef COMPILER1
0N/A#include "c1/c1_Runtime1.hpp"
0N/A#include "runtime/vframeArray.hpp"
0N/A#endif
0N/A
0N/Avoid RegisterMap::pd_clear() {
0N/A if (_thread->has_last_Java_frame()) {
0N/A frame fr = _thread->last_frame();
0N/A _window = fr.sp();
0N/A } else {
0N/A _window = NULL;
0N/A }
0N/A _younger_window = NULL;
0N/A}
0N/A
0N/A
0N/A// Unified register numbering scheme: each 32-bits counts as a register
0N/A// number, so all the V9 registers take 2 slots.
0N/Aconst static int R_L_nums[] = {0+040,2+040,4+040,6+040,8+040,10+040,12+040,14+040};
0N/Aconst static int R_I_nums[] = {0+060,2+060,4+060,6+060,8+060,10+060,12+060,14+060};
0N/Aconst static int R_O_nums[] = {0+020,2+020,4+020,6+020,8+020,10+020,12+020,14+020};
0N/Aconst static int R_G_nums[] = {0+000,2+000,4+000,6+000,8+000,10+000,12+000,14+000};
0N/Astatic RegisterMap::LocationValidType bad_mask = 0;
0N/Astatic RegisterMap::LocationValidType R_LIO_mask = 0;
0N/Astatic bool register_map_inited = false;
0N/A
0N/Astatic void register_map_init() {
0N/A if (!register_map_inited) {
0N/A register_map_inited = true;
0N/A int i;
0N/A for (i = 0; i < 8; i++) {
0N/A assert(R_L_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
0N/A assert(R_I_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
0N/A assert(R_O_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
0N/A assert(R_G_nums[i] < RegisterMap::location_valid_type_size, "in first chunk");
0N/A }
0N/A
0N/A bad_mask |= (1LL << R_O_nums[6]); // SP
0N/A bad_mask |= (1LL << R_O_nums[7]); // cPC
0N/A bad_mask |= (1LL << R_I_nums[6]); // FP
0N/A bad_mask |= (1LL << R_I_nums[7]); // rPC
0N/A bad_mask |= (1LL << R_G_nums[2]); // TLS
0N/A bad_mask |= (1LL << R_G_nums[7]); // reserved by libthread
0N/A
0N/A for (i = 0; i < 8; i++) {
0N/A R_LIO_mask |= (1LL << R_L_nums[i]);
0N/A R_LIO_mask |= (1LL << R_I_nums[i]);
0N/A R_LIO_mask |= (1LL << R_O_nums[i]);
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Aaddress RegisterMap::pd_location(VMReg regname) const {
0N/A register_map_init();
0N/A
0N/A assert(regname->is_reg(), "sanity check");
0N/A // Only the GPRs get handled this way
0N/A if( !regname->is_Register())
0N/A return NULL;
0N/A
0N/A // don't talk about bad registers
0N/A if ((bad_mask & ((LocationValidType)1 << regname->value())) != 0) {
0N/A return NULL;
0N/A }
0N/A
0N/A // Convert to a GPR
0N/A Register reg;
0N/A int second_word = 0;
0N/A // 32-bit registers for in, out and local
0N/A if (!regname->is_concrete()) {
0N/A // HMM ought to return NULL for any non-concrete (odd) vmreg
0N/A // this all tied up in the fact we put out double oopMaps for
0N/A // register locations. When that is fixed we'd will return NULL
0N/A // (or assert here).
0N/A reg = regname->prev()->as_Register();
0N/A#ifdef _LP64
0N/A second_word = sizeof(jint);
0N/A#else
0N/A return NULL;
0N/A#endif // _LP64
0N/A } else {
0N/A reg = regname->as_Register();
0N/A }
0N/A if (reg->is_out()) {
0N/A assert(_younger_window != NULL, "Younger window should be available");
0N/A return second_word + (address)&_younger_window[reg->after_save()->sp_offset_in_saved_window()];
0N/A }
0N/A if (reg->is_local() || reg->is_in()) {
0N/A assert(_window != NULL, "Window should be available");
0N/A return second_word + (address)&_window[reg->sp_offset_in_saved_window()];
0N/A }
0N/A // Only the window'd GPRs get handled this way; not the globals.
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A#ifdef ASSERT
0N/Avoid RegisterMap::check_location_valid() {
0N/A register_map_init();
0N/A assert((_location_valid[0] & bad_mask) == 0, "cannot have special locations for SP,FP,TLS,etc.");
0N/A}
0N/A#endif
0N/A
0N/A// We are shifting windows. That means we are moving all %i to %o,
0N/A// getting rid of all current %l, and keeping all %g. This is only
0N/A// complicated if any of the location pointers for these are valid.
0N/A// The normal case is that everything is in its standard register window
0N/A// home, and _location_valid[0] is zero. In that case, this routine
0N/A// does exactly nothing.
0N/Avoid RegisterMap::shift_individual_registers() {
0N/A if (!update_map()) return; // this only applies to maps with locations
0N/A register_map_init();
0N/A check_location_valid();
0N/A
0N/A LocationValidType lv = _location_valid[0];
0N/A LocationValidType lv0 = lv;
0N/A
0N/A lv &= ~R_LIO_mask; // clear %l, %o, %i regs
0N/A
0N/A // if we cleared some non-%g locations, we may have to do some shifting
107N/A if (lv != lv0) {
0N/A // copy %i0-%i5 to %o0-%o5, if they have special locations
107N/A // This can happen in within stubs which spill argument registers
107N/A // around a dynamic link operation, such as resolve_opt_virtual_call.
107N/A for (int i = 0; i < 8; i++) {
107N/A if (lv0 & (1LL << R_I_nums[i])) {
107N/A _location[R_O_nums[i]] = _location[R_I_nums[i]];
107N/A lv |= (1LL << R_O_nums[i]);
107N/A }
107N/A }
107N/A }
107N/A
107N/A _location_valid[0] = lv;
107N/A check_location_valid();
107N/A}
107N/A
107N/Abool frame::safe_for_sender(JavaThread *thread) {
107N/A
107N/A address _SP = (address) sp();
107N/A address _FP = (address) fp();
107N/A address _UNEXTENDED_SP = (address) unextended_sp();
107N/A // sp must be within the stack
107N/A bool sp_safe = (_SP <= thread->stack_base()) &&
107N/A (_SP >= thread->stack_base() - thread->stack_size());
107N/A
107N/A if (!sp_safe) {
107N/A return false;
107N/A }
107N/A
107N/A // unextended sp must be within the stack and above or equal sp
107N/A bool unextended_sp_safe = (_UNEXTENDED_SP <= thread->stack_base()) &&
107N/A (_UNEXTENDED_SP >= _SP);
107N/A
107N/A if (!unextended_sp_safe) return false;
107N/A
107N/A // an fp must be within the stack and above (but not equal) sp
107N/A bool fp_safe = (_FP <= thread->stack_base()) &&
107N/A (_FP > _SP);
107N/A
107N/A // We know sp/unextended_sp are safe only fp is questionable here
107N/A
107N/A // If the current frame is known to the code cache then we can attempt to
107N/A // to construct the sender and do some validation of it. This goes a long way
107N/A // toward eliminating issues when we get in frame construction code
107N/A
107N/A if (_cb != NULL ) {
107N/A
107N/A // First check if frame is complete and tester is reliable
0N/A // Unfortunately we can only check frame complete for runtime stubs and nmethod
107N/A // other generic buffer blobs are more problematic so we just assume they are
107N/A // ok. adapter blobs never have a frame complete and are never ok.
107N/A
107N/A if (!_cb->is_frame_complete_at(_pc)) {
107N/A if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
107N/A return false;
107N/A }
107N/A }
107N/A
107N/A // Entry frame checks
107N/A if (is_entry_frame()) {
107N/A // an entry frame must have a valid fp.
107N/A
107N/A if (!fp_safe) {
107N/A return false;
107N/A }
107N/A
107N/A // Validate the JavaCallWrapper an entry frame must have
107N/A
107N/A address jcw = (address)entry_frame_call_wrapper();
107N/A
107N/A bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > _FP);
107N/A
107N/A return jcw_safe;
107N/A
107N/A }
107N/A
107N/A intptr_t* younger_sp = sp();
107N/A intptr_t* _SENDER_SP = sender_sp(); // sender is actually just _FP
107N/A bool adjusted_stack = is_interpreted_frame();
107N/A
107N/A address sender_pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset;
107N/A
107N/A
107N/A // We must always be able to find a recognizable pc
107N/A CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
107N/A if (sender_pc == NULL || sender_blob == NULL) {
107N/A return false;
107N/A }
107N/A
107N/A // It should be safe to construct the sender though it might not be valid
107N/A
107N/A frame sender(_SENDER_SP, younger_sp, adjusted_stack);
107N/A
107N/A // Do we have a valid fp?
107N/A address sender_fp = (address) sender.fp();
107N/A
107N/A // an fp must be within the stack and above (but not equal) current frame's _FP
107N/A
107N/A bool sender_fp_safe = (sender_fp <= thread->stack_base()) &&
107N/A (sender_fp > _FP);
107N/A
107N/A if (!sender_fp_safe) {
107N/A return false;
107N/A }
107N/A
107N/A
107N/A // If the potential sender is the interpreter then we can do some more checking
107N/A if (Interpreter::contains(sender_pc)) {
107N/A return sender.is_interpreted_frame_valid(thread);
107N/A }
107N/A
107N/A // Could just be some random pointer within the codeBlob
107N/A if (!sender.cb()->code_contains(sender_pc)) {
107N/A return false;
107N/A }
107N/A
107N/A // We should never be able to see an adapter if the current frame is something from code cache
107N/A if (sender_blob->is_adapter_blob()) {
107N/A return false;
107N/A }
107N/A
107N/A if( sender.is_entry_frame()) {
107N/A // Validate the JavaCallWrapper an entry frame must have
107N/A
107N/A address jcw = (address)sender.entry_frame_call_wrapper();
107N/A
107N/A bool jcw_safe = (jcw <= thread->stack_base()) && ( jcw > sender_fp);
107N/A
107N/A return jcw_safe;
107N/A }
107N/A
107N/A // If the frame size is 0 something is bad because every nmethod has a non-zero frame size
107N/A // because you must allocate window space
107N/A
107N/A if (sender_blob->frame_size() == 0) {
107N/A assert(!sender_blob->is_nmethod(), "should count return address at least");
107N/A return false;
107N/A }
107N/A
107N/A // The sender should positively be an nmethod or call_stub. On sparc we might in fact see something else.
107N/A // The cause of this is because at a save instruction the O7 we get is a leftover from an earlier
107N/A // window use. So if a runtime stub creates two frames (common in fastdebug/jvmg) then we see the
0N/A // stale pc. So if the sender blob is not something we'd expect we have little choice but to declare
107N/A // the stack unwalkable. pd_get_top_frame_for_signal_handler tries to recover from this by unwinding
107N/A // that initial frame and retrying.
107N/A
107N/A if (!sender_blob->is_nmethod()) {
107N/A return false;
107N/A }
107N/A
107N/A // Could put some more validation for the potential non-interpreted sender
107N/A // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
0N/A
0N/A // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
0N/A
0N/A // We've validated the potential sender that would be created
0N/A
0N/A return true;
0N/A
0N/A }
0N/A
0N/A // Must be native-compiled frame. Since sender will try and use fp to find
0N/A // linkages it must be safe
0N/A
0N/A if (!fp_safe) return false;
0N/A
0N/A // could try and do some more potential verification of native frame if we could think of some...
0N/A
0N/A return true;
0N/A}
0N/A
0N/A// constructors
0N/A
0N/A// Construct an unpatchable, deficient frame
0N/Aframe::frame(intptr_t* sp, unpatchable_t, address pc, CodeBlob* cb) {
0N/A#ifdef _LP64
0N/A assert( (((intptr_t)sp & (wordSize-1)) == 0), "frame constructor passed an invalid sp");
0N/A#endif
0N/A _sp = sp;
0N/A _younger_sp = NULL;
0N/A _pc = pc;
0N/A _cb = cb;
0N/A _sp_adjustment_by_callee = 0;
0N/A assert(pc == NULL && cb == NULL || pc != NULL, "can't have a cb and no pc!");
0N/A if (_cb == NULL && _pc != NULL ) {
0N/A _cb = CodeCache::find_blob(_pc);
0N/A }
0N/A _deopt_state = unknown;
0N/A#ifdef ASSERT
0N/A if ( _cb != NULL && _cb->is_nmethod()) {
0N/A // Without a valid unextended_sp() we can't convert the pc to "original"
0N/A assert(!((nmethod*)_cb)->is_deopt_pc(_pc), "invariant broken");
0N/A }
0N/A#endif // ASSERT
0N/A}
0N/A
0N/Aframe::frame(intptr_t* sp, intptr_t* younger_sp, bool younger_frame_is_interpreted) :
0N/A _sp(sp),
0N/A _younger_sp(younger_sp),
0N/A _deopt_state(unknown),
0N/A _sp_adjustment_by_callee(0) {
0N/A if (younger_sp == NULL) {
0N/A // make a deficient frame which doesn't know where its PC is
0N/A _pc = NULL;
0N/A _cb = NULL;
0N/A } else {
0N/A _pc = (address)younger_sp[I7->sp_offset_in_saved_window()] + pc_return_offset;
0N/A assert( (intptr_t*)younger_sp[FP->sp_offset_in_saved_window()] == (intptr_t*)((intptr_t)sp - STACK_BIAS), "younger_sp must be valid");
0N/A // Any frame we ever build should always "safe" therefore we should not have to call
0N/A // find_blob_unsafe
0N/A // In case of native stubs, the pc retrieved here might be
0N/A // wrong. (the _last_native_pc will have the right value)
0N/A // So do not put add any asserts on the _pc here.
0N/A }
0N/A
0N/A if (_pc != NULL)
0N/A _cb = CodeCache::find_blob(_pc);
0N/A
0N/A // Check for MethodHandle call sites.
0N/A if (_cb != NULL) {
0N/A nmethod* nm = _cb->as_nmethod_or_null();
0N/A if (nm != NULL) {
0N/A if (nm->is_deopt_mh_entry(_pc) || nm->is_method_handle_return(_pc)) {
0N/A _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) sp[L7_mh_SP_save->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
0N/A // The SP is already adjusted by this MH call site, don't
0N/A // overwrite this value with the wrong interpreter value.
0N/A younger_frame_is_interpreted = false;
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (younger_frame_is_interpreted) {
0N/A // compute adjustment to this frame's SP made by its interpreted callee
0N/A _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) younger_sp[I5_savedSP->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
0N/A }
0N/A
0N/A // It is important that the frame is fully constructed when we do
0N/A // this lookup as get_deopt_original_pc() needs a correct value for
0N/A // unextended_sp() which uses _sp_adjustment_by_callee.
0N/A if (_pc != NULL) {
0N/A address original_pc = nmethod::get_deopt_original_pc(this);
0N/A if (original_pc != NULL) {
0N/A _pc = original_pc;
0N/A _deopt_state = is_deoptimized;
0N/A } else {
0N/A _deopt_state = not_deoptimized;
0N/A }
0N/A }
0N/A}
0N/A
0N/Abool frame::is_interpreted_frame() const {
0N/A return Interpreter::contains(pc());
0N/A}
0N/A
0N/A// sender_sp
0N/A
0N/Aintptr_t* frame::interpreter_frame_sender_sp() const {
0N/A assert(is_interpreted_frame(), "interpreted frame expected");
0N/A return fp();
0N/A}
0N/A
0N/A#ifndef CC_INTERP
0N/Avoid frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
0N/A assert(is_interpreted_frame(), "interpreted frame expected");
0N/A Unimplemented();
0N/A}
0N/A#endif // CC_INTERP
0N/A
0N/A
0N/A#ifdef ASSERT
0N/A// Debugging aid
0N/Astatic frame nth_sender(int n) {
0N/A frame f = JavaThread::current()->last_frame();
0N/A
0N/A for(int i = 0; i < n; ++i)
0N/A f = f.sender((RegisterMap*)NULL);
0N/A
0N/A printf("first frame %d\n", f.is_first_frame() ? 1 : 0);
0N/A printf("interpreted frame %d\n", f.is_interpreted_frame() ? 1 : 0);
0N/A printf("java frame %d\n", f.is_java_frame() ? 1 : 0);
0N/A printf("entry frame %d\n", f.is_entry_frame() ? 1 : 0);
0N/A printf("native frame %d\n", f.is_native_frame() ? 1 : 0);
0N/A if (f.is_compiled_frame()) {
0N/A if (f.is_deoptimized_frame())
0N/A printf("deoptimized frame 1\n");
0N/A else
0N/A printf("compiled frame 1\n");
0N/A }
0N/A
0N/A return f;
0N/A}
0N/A#endif
0N/A
0N/A
0N/Aframe frame::sender_for_entry_frame(RegisterMap *map) const {
0N/A assert(map != NULL, "map must be set");
0N/A // Java frame called from C; skip all C frames and return top C
0N/A // frame of that chunk as the sender
0N/A JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
0N/A assert(!entry_frame_is_first(), "next Java fp must be non zero");
0N/A assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
0N/A intptr_t* last_Java_sp = jfa->last_Java_sp();
0N/A // Since we are walking the stack now this nested anchor is obviously walkable
0N/A // even if it wasn't when it was stacked.
0N/A if (!jfa->walkable()) {
0N/A // Capture _last_Java_pc (if needed) and mark anchor walkable.
0N/A jfa->capture_last_Java_pc(_sp);
0N/A }
0N/A assert(jfa->last_Java_pc() != NULL, "No captured pc!");
0N/A map->clear();
0N/A map->make_integer_regs_unsaved();
0N/A map->shift_window(last_Java_sp, NULL);
0N/A assert(map->include_argument_oops(), "should be set by clear");
0N/A return frame(last_Java_sp, frame::unpatchable, jfa->last_Java_pc());
0N/A}
0N/A
0N/Aframe frame::sender_for_interpreter_frame(RegisterMap *map) const {
0N/A ShouldNotCallThis();
0N/A return sender(map);
0N/A}
0N/A
0N/Aframe frame::sender_for_compiled_frame(RegisterMap *map) const {
0N/A ShouldNotCallThis();
0N/A return sender(map);
0N/A}
0N/A
0N/Aframe frame::sender(RegisterMap* map) const {
0N/A assert(map != NULL, "map must be set");
0N/A
0N/A assert(CodeCache::find_blob_unsafe(_pc) == _cb, "inconsistent");
0N/A
0N/A // Default is not to follow arguments; update it accordingly below
0N/A map->set_include_argument_oops(false);
0N/A
0N/A if (is_entry_frame()) return sender_for_entry_frame(map);
0N/A
0N/A intptr_t* younger_sp = sp();
0N/A intptr_t* sp = sender_sp();
0N/A
0N/A // Note: The version of this operation on any platform with callee-save
0N/A // registers must update the register map (if not null).
0N/A // In order to do this correctly, the various subtypes of
0N/A // of frame (interpreted, compiled, glue, native),
0N/A // must be distinguished. There is no need on SPARC for
0N/A // such distinctions, because all callee-save registers are
0N/A // preserved for all frames via SPARC-specific mechanisms.
0N/A //
0N/A // *** HOWEVER, *** if and when we make any floating-point
0N/A // registers callee-saved, then we will have to copy over
0N/A // the RegisterMap update logic from the Intel code.
0N/A
0N/A // The constructor of the sender must know whether this frame is interpreted so it can set the
0N/A // sender's _sp_adjustment_by_callee field. An osr adapter frame was originally
0N/A // interpreted but its pc is in the code cache (for c1 -> osr_frame_return_id stub), so it must be
0N/A // explicitly recognized.
0N/A
0N/A bool frame_is_interpreted = is_interpreted_frame();
0N/A if (frame_is_interpreted) {
0N/A map->make_integer_regs_unsaved();
0N/A map->shift_window(sp, younger_sp);
0N/A } else if (_cb != NULL) {
0N/A // Update the locations of implicitly saved registers to be their
0N/A // addresses in the register save area.
0N/A // For %o registers, the addresses of %i registers in the next younger
0N/A // frame are used.
0N/A map->shift_window(sp, younger_sp);
0N/A if (map->update_map()) {
0N/A // Tell GC to use argument oopmaps for some runtime stubs that need it.
0N/A // For C1, the runtime stub might not have oop maps, so set this flag
0N/A // outside of update_register_map.
0N/A map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
0N/A if (_cb->oop_maps() != NULL) {
0N/A OopMapSet::update_register_map(this, map);
0N/A }
0N/A }
0N/A }
0N/A return frame(sp, younger_sp, frame_is_interpreted);
0N/A}
0N/A
0N/A
0N/Avoid frame::patch_pc(Thread* thread, address pc) {
0N/A if(thread == Thread::current()) {
0N/A StubRoutines::Sparc::flush_callers_register_windows_func()();
0N/A }
0N/A if (TracePcPatching) {
0N/A // QQQ this assert is invalid (or too strong anyway) sice _pc could
0N/A // be original pc and frame could have the deopt pc.
0N/A // assert(_pc == *O7_addr() + pc_return_offset, "frame has wrong pc");
0N/A tty->print_cr("patch_pc at address 0x%x [0x%x -> 0x%x] ", O7_addr(), _pc, pc);
0N/A }
0N/A _cb = CodeCache::find_blob(pc);
0N/A *O7_addr() = pc - pc_return_offset;
0N/A _cb = CodeCache::find_blob(_pc);
0N/A address original_pc = nmethod::get_deopt_original_pc(this);
0N/A if (original_pc != NULL) {
0N/A assert(original_pc == _pc, "expected original to be stored before patching");
0N/A _deopt_state = is_deoptimized;
0N/A } else {
0N/A _deopt_state = not_deoptimized;
0N/A }
0N/A}
0N/A
0N/A
0N/Astatic bool sp_is_valid(intptr_t* old_sp, intptr_t* young_sp, intptr_t* sp) {
0N/A return (((intptr_t)sp & (2*wordSize-1)) == 0 &&
0N/A sp <= old_sp &&
0N/A sp >= young_sp);
0N/A}
0N/A
0N/A
0N/A/*
0N/A Find the (biased) sp that is just younger than old_sp starting at sp.
0N/A If not found return NULL. Register windows are assumed to be flushed.
0N/A*/
0N/Aintptr_t* frame::next_younger_sp_or_null(intptr_t* old_sp, intptr_t* sp) {
0N/A
0N/A intptr_t* previous_sp = NULL;
0N/A intptr_t* orig_sp = sp;
0N/A
0N/A int max_frames = (old_sp - sp) / 16; // Minimum frame size is 16
0N/A int max_frame2 = max_frames;
0N/A while(sp != old_sp && sp_is_valid(old_sp, orig_sp, sp)) {
0N/A if (max_frames-- <= 0)
0N/A // too many frames have gone by; invalid parameters given to this function
0N/A break;
0N/A previous_sp = sp;
0N/A sp = (intptr_t*)sp[FP->sp_offset_in_saved_window()];
0N/A sp = (intptr_t*)((intptr_t)sp + STACK_BIAS);
0N/A }
107N/A
0N/A return (sp == old_sp ? previous_sp : NULL);
0N/A}
0N/A
0N/A/*
0N/A Determine if "sp" is a valid stack pointer. "sp" is assumed to be younger than
0N/A "valid_sp". So if "sp" is valid itself then it should be possible to walk frames
0N/A from "sp" to "valid_sp". The assumption is that the registers windows for the
0N/A thread stack in question are flushed.
0N/A*/
0N/Abool frame::is_valid_stack_pointer(intptr_t* valid_sp, intptr_t* sp) {
0N/A return next_younger_sp_or_null(valid_sp, sp) != NULL;
107N/A}
0N/A
0N/A
0N/Abool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
0N/A assert(is_interpreted_frame(), "must be interpreter frame");
0N/A return this->fp() == fp;
0N/A}
0N/A
0N/A
0N/Avoid frame::pd_gc_epilog() {
107N/A if (is_interpreted_frame()) {
107N/A // set constant pool cache entry for interpreter
107N/A methodOop m = interpreter_frame_method();
107N/A
107N/A *interpreter_frame_cpoolcache_addr() = m->constants()->cache();
107N/A }
107N/A}
107N/A
107N/A
107N/Abool frame::is_interpreted_frame_valid(JavaThread* thread) const {
107N/A#ifdef CC_INTERP
107N/A // Is there anything to do?
0N/A#else
0N/A assert(is_interpreted_frame(), "Not an interpreted frame");
107N/A // These are reasonable sanity checks
107N/A if (fp() == 0 || (intptr_t(fp()) & (2*wordSize-1)) != 0) {
107N/A return false;
107N/A }
107N/A if (sp() == 0 || (intptr_t(sp()) & (2*wordSize-1)) != 0) {
107N/A return false;
107N/A }
107N/A
107N/A const intptr_t interpreter_frame_initial_sp_offset = interpreter_frame_vm_local_words;
107N/A if (fp() + interpreter_frame_initial_sp_offset < sp()) {
107N/A return false;
107N/A }
107N/A // These are hacks to keep us out of trouble.
107N/A // The problem with these is that they mask other problems
107N/A if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
107N/A return false;
107N/A }
107N/A // do some validation of frame elements
107N/A
107N/A // first the method
107N/A
107N/A methodOop m = *interpreter_frame_method_addr();
107N/A
0N/A // validate the method we'd find in this potential sender
0N/A if (!Universe::heap()->is_valid_method(m)) return false;
0N/A
0N/A // stack frames shouldn't be much larger than max_stack elements
0N/A
0N/A if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
0N/A return false;
0N/A }
0N/A
0N/A // validate bci/bcx
0N/A
0N/A intptr_t bcx = interpreter_frame_bcx();
0N/A if (m->validate_bci_from_bcx(bcx) < 0) {
0N/A return false;
0N/A }
0N/A
0N/A // validate constantPoolCacheOop
0N/A
0N/A constantPoolCacheOop cp = *interpreter_frame_cache_addr();
0N/A
0N/A if (cp == NULL ||
0N/A !Space::is_aligned(cp) ||
0N/A !Universe::heap()->is_permanent((void*)cp)) return false;
0N/A
0N/A // validate locals
0N/A
0N/A address locals = (address) *interpreter_frame_locals_addr();
0N/A
0N/A if (locals > thread->stack_base() || locals < (address) fp()) return false;
0N/A
0N/A // We'd have to be pretty unlucky to be mislead at this point
0N/A#endif /* CC_INTERP */
0N/A return true;
0N/A}
0N/A
0N/A
0N/A// Windows have been flushed on entry (but not marked). Capture the pc that
0N/A// is the return address to the frame that contains "sp" as its stack pointer.
0N/A// This pc resides in the called of the frame corresponding to "sp".
0N/A// As a side effect we mark this JavaFrameAnchor as having flushed the windows.
0N/A// This side effect lets us mark stacked JavaFrameAnchors (stacked in the
0N/A// call_helper) as flushed when we have flushed the windows for the most
0N/A// recent (i.e. current) JavaFrameAnchor. This saves useless flushing calls
0N/A// and lets us find the pc just once rather than multiple times as it did
0N/A// in the bad old _post_Java_state days.
0N/A//
0N/Avoid JavaFrameAnchor::capture_last_Java_pc(intptr_t* sp) {
0N/A if (last_Java_sp() != NULL && last_Java_pc() == NULL) {
0N/A // try and find the sp just younger than _last_Java_sp
0N/A intptr_t* _post_Java_sp = frame::next_younger_sp_or_null(last_Java_sp(), sp);
0N/A // Really this should never fail otherwise VM call must have non-standard
0N/A // frame linkage (bad) or stack is not properly flushed (worse).
0N/A guarantee(_post_Java_sp != NULL, "bad stack!");
0N/A _last_Java_pc = (address) _post_Java_sp[ I7->sp_offset_in_saved_window()] + frame::pc_return_offset;
0N/A
0N/A }
0N/A set_window_flushed();
0N/A}
0N/A
0N/Avoid JavaFrameAnchor::make_walkable(JavaThread* thread) {
0N/A if (walkable()) return;
0N/A // Eventually make an assert
0N/A guarantee(Thread::current() == (Thread*)thread, "only current thread can flush its registers");
0N/A // We always flush in case the profiler wants it but we won't mark
0N/A // the windows as flushed unless we have a last_Java_frame
0N/A intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
0N/A if (last_Java_sp() != NULL ) {
0N/A capture_last_Java_pc(sp);
0N/A }
0N/A}
0N/A
0N/Aintptr_t* frame::entry_frame_argument_at(int offset) const {
0N/A // convert offset to index to deal with tsi
0N/A int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
0N/A
0N/A intptr_t* LSP = (intptr_t*) sp()[Lentry_args->sp_offset_in_saved_window()];
0N/A return &LSP[index+1];
0N/A}
0N/A
0N/A
0N/ABasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
0N/A assert(is_interpreted_frame(), "interpreted frame expected");
0N/A methodOop method = interpreter_frame_method();
0N/A BasicType type = method->result_type();
0N/A
0N/A if (method->is_native()) {
0N/A // Prior to notifying the runtime of the method_exit the possible result
0N/A // value is saved to l_scratch and d_scratch.
0N/A
0N/A#ifdef CC_INTERP
0N/A interpreterState istate = get_interpreterState();
0N/A intptr_t* l_scratch = (intptr_t*) &istate->_native_lresult;
0N/A intptr_t* d_scratch = (intptr_t*) &istate->_native_fresult;
0N/A#else /* CC_INTERP */
0N/A intptr_t* l_scratch = fp() + interpreter_frame_l_scratch_fp_offset;
0N/A intptr_t* d_scratch = fp() + interpreter_frame_d_scratch_fp_offset;
0N/A#endif /* CC_INTERP */
0N/A
0N/A address l_addr = (address)l_scratch;
0N/A#ifdef _LP64
0N/A // On 64-bit the result for 1/8/16/32-bit result types is in the other
0N/A // word half
0N/A l_addr += wordSize/2;
0N/A#endif
0N/A
0N/A switch (type) {
0N/A case T_OBJECT:
0N/A case T_ARRAY: {
0N/A#ifdef CC_INTERP
0N/A *oop_result = istate->_oop_temp;
0N/A#else
0N/A oop obj = (oop) at(interpreter_frame_oop_temp_offset);
0N/A assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
0N/A *oop_result = obj;
0N/A#endif // CC_INTERP
0N/A break;
0N/A }
0N/A
0N/A case T_BOOLEAN : { jint* p = (jint*)l_addr; value_result->z = (jboolean)((*p) & 0x1); break; }
0N/A case T_BYTE : { jint* p = (jint*)l_addr; value_result->b = (jbyte)((*p) & 0xff); break; }
0N/A case T_CHAR : { jint* p = (jint*)l_addr; value_result->c = (jchar)((*p) & 0xffff); break; }
0N/A case T_SHORT : { jint* p = (jint*)l_addr; value_result->s = (jshort)((*p) & 0xffff); break; }
0N/A case T_INT : value_result->i = *(jint*)l_addr; break;
0N/A case T_LONG : value_result->j = *(jlong*)l_scratch; break;
0N/A case T_FLOAT : value_result->f = *(jfloat*)d_scratch; break;
0N/A case T_DOUBLE : value_result->d = *(jdouble*)d_scratch; break;
0N/A case T_VOID : /* Nothing to do */ break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A } else {
intptr_t* tos_addr = interpreter_frame_tos_address();
switch(type) {
case T_OBJECT:
case T_ARRAY: {
oop obj = (oop)*tos_addr;
assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
*oop_result = obj;
break;
}
case T_BOOLEAN : { jint* p = (jint*)tos_addr; value_result->z = (jboolean)((*p) & 0x1); break; }
case T_BYTE : { jint* p = (jint*)tos_addr; value_result->b = (jbyte)((*p) & 0xff); break; }
case T_CHAR : { jint* p = (jint*)tos_addr; value_result->c = (jchar)((*p) & 0xffff); break; }
case T_SHORT : { jint* p = (jint*)tos_addr; value_result->s = (jshort)((*p) & 0xffff); break; }
case T_INT : value_result->i = *(jint*)tos_addr; break;
case T_LONG : value_result->j = *(jlong*)tos_addr; break;
case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
case T_VOID : /* Nothing to do */ break;
default : ShouldNotReachHere();
}
};
return type;
}
// Lesp pointer is one word lower than the top item on the stack.
intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize) - 1;
return &interpreter_frame_tos_address()[index];
}