0N/A/*
3101N/A * Copyright (c) 1997, 2012, 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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "memory/resourceArea.hpp"
1879N/A#include "oops/markOop.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
3153N/A#include "prims/methodHandles.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "runtime/handles.inline.hpp"
1879N/A#include "runtime/javaCalls.hpp"
1879N/A#include "runtime/monitorChunk.hpp"
1879N/A#include "runtime/signature.hpp"
1879N/A#include "runtime/stubCodeGenerator.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "vmreg_sparc.inline.hpp"
1879N/A#ifdef COMPILER1
1879N/A#include "c1/c1_Runtime1.hpp"
1879N/A#include "runtime/vframeArray.hpp"
1879N/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
0N/A if (lv != lv0) {
0N/A // copy %i0-%i5 to %o0-%o5, if they have special locations
0N/A // This can happen in within stubs which spill argument registers
0N/A // around a dynamic link operation, such as resolve_opt_virtual_call.
0N/A for (int i = 0; i < 8; i++) {
0N/A if (lv0 & (1LL << R_I_nums[i])) {
0N/A _location[R_O_nums[i]] = _location[R_I_nums[i]];
0N/A lv |= (1LL << R_O_nums[i]);
0N/A }
0N/A }
0N/A }
0N/A
0N/A _location_valid[0] = lv;
0N/A check_location_valid();
0N/A}
0N/A
107N/Abool frame::safe_for_sender(JavaThread *thread) {
0N/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
107N/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
4248N/A // Could just be some random pointer within the codeBlob
4248N/A if (!_cb->code_contains(_pc)) {
4248N/A return false;
4248N/A }
4248N/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;
0N/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
4310N/A // Could be a zombie method
4310N/A if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
4310N/A return false;
4310N/A }
4310N/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
1668N/A if (!sender.cb()->code_contains(sender_pc)) {
1668N/A return false;
1668N/A }
107N/A
107N/A // We should never be able to see an adapter if the current frame is something from code cache
1668N/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
4310N/A // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
107N/A // because you must allocate window space
107N/A
4310N/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
107N/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...
107N/A
107N/A // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
107N/A
107N/A // We've validated the potential sender that would be created
107N/A
107N/A return true;
107N/A
0N/A }
107N/A
107N/A // Must be native-compiled frame. Since sender will try and use fp to find
107N/A // linkages it must be safe
107N/A
107N/A if (!fp_safe) return false;
107N/A
107N/A // could try and do some more potential verification of native frame if we could think of some...
107N/A
107N/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
1484N/Aframe::frame(intptr_t* sp, intptr_t* younger_sp, bool younger_frame_is_interpreted) :
1484N/A _sp(sp),
1484N/A _younger_sp(younger_sp),
1484N/A _deopt_state(unknown),
1484N/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 }
1484N/A
1484N/A if (_pc != NULL)
1484N/A _cb = CodeCache::find_blob(_pc);
1484N/A
1484N/A // Check for MethodHandle call sites.
1484N/A if (_cb != NULL) {
1484N/A nmethod* nm = _cb->as_nmethod_or_null();
1484N/A if (nm != NULL) {
1484N/A if (nm->is_deopt_mh_entry(_pc) || nm->is_method_handle_return(_pc)) {
1484N/A _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) sp[L7_mh_SP_save->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
1484N/A // The SP is already adjusted by this MH call site, don't
1484N/A // overwrite this value with the wrong interpreter value.
1484N/A younger_frame_is_interpreted = false;
1484N/A }
1484N/A }
0N/A }
0N/A
1484N/A if (younger_frame_is_interpreted) {
1484N/A // compute adjustment to this frame's SP made by its interpreted callee
1484N/A _sp_adjustment_by_callee = (intptr_t*) ((intptr_t) younger_sp[I5_savedSP->sp_offset_in_saved_window()] + STACK_BIAS) - sp;
1484N/A }
0N/A
1484N/A // It is important that the frame is fully constructed when we do
1484N/A // this lookup as get_deopt_original_pc() needs a correct value for
1484N/A // unextended_sp() which uses _sp_adjustment_by_callee.
0N/A if (_pc != NULL) {
1204N/A address original_pc = nmethod::get_deopt_original_pc(this);
1204N/A if (original_pc != NULL) {
1204N/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
1484N/A intptr_t* younger_sp = sp();
1484N/A intptr_t* Error!

 

There was an error!

null

java.lang.NullPointerException