0N/A/*
1879N/A * Copyright (c) 2003, 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 *
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 "runtime/frame.inline.hpp"
1879N/A#include "thread_solaris.inline.hpp"
0N/A
0N/A// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
0N/A// currently interrupted by SIGPROF
0N/A//
0N/A// NOTE: On Solaris, register windows are flushed in the signal handler
0N/A// except for possibly the top frame.
0N/A//
0N/Abool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
0N/A void* ucontext, bool isInJava) {
0N/A
0N/A assert(Thread::current() == this, "caller must be current thread");
4141N/A return pd_get_top_frame(fr_addr, ucontext, isInJava, true);
4141N/A}
4141N/A
4141N/Abool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, bool isInJava) {
4141N/A // get ucontext somehow
4141N/A return pd_get_top_frame(fr_addr, ucontext, isInJava, false);
4141N/A}
4141N/A
4141N/Abool JavaThread::pd_get_top_frame(frame* fr_addr,
4141N/A void* ucontext, bool isInJava, bool makeWalkable) {
0N/A assert(this->is_Java_thread(), "must be JavaThread");
0N/A
0N/A JavaThread* jt = (JavaThread *)this;
0N/A
4141N/A if (!isInJava && makeWalkable) {
0N/A // make_walkable flushes register windows and grabs last_Java_pc
0N/A // which can not be done if the ucontext sp matches last_Java_sp
0N/A // stack walking utilities assume last_Java_pc set if marked flushed
0N/A jt->frame_anchor()->make_walkable(jt);
0N/A }
0N/A
0N/A // If we have a walkable last_Java_frame, then we should use it
0N/A // even if isInJava == true. It should be more reliable than
0N/A // ucontext info.
0N/A if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
0N/A *fr_addr = jt->pd_last_frame();
0N/A return true;
0N/A }
0N/A
0N/A ucontext_t* uc = (ucontext_t*) ucontext;
0N/A
0N/A // At this point, we don't have a walkable last_Java_frame, so
0N/A // we try to glean some information out of the ucontext.
0N/A intptr_t* ret_sp;
0N/A ExtendedPC addr = os::Solaris::fetch_frame_from_ucontext(this, uc,
0N/A &ret_sp, NULL /* ret_fp only used on Solaris X86 */);
0N/A if (addr.pc() == NULL || ret_sp == NULL) {
0N/A // ucontext wasn't useful
0N/A return false;
0N/A }
0N/A
107N/A frame ret_frame(ret_sp, frame::unpatchable, addr.pc());
107N/A
0N/A // we were running Java code when SIGPROF came in
0N/A if (isInJava) {
107N/A
107N/A
107N/A // If the frame we got is safe then it is most certainly valid
107N/A if (ret_frame.safe_for_sender(jt)) {
107N/A *fr_addr = ret_frame;
107N/A return true;
107N/A }
107N/A
107N/A // If it isn't safe then we can try several things to try and get
107N/A // a good starting point.
107N/A //
107N/A // On sparc the frames are almost certainly walkable in the sense
107N/A // of sp/fp linkages. However because of recycling of windows if
107N/A // a piece of code does multiple save's where the initial save creates
107N/A // a real frame with a return pc and the succeeding save's are used to
107N/A // simply get free registers and have no real pc then the pc linkage on these
107N/A // "inner" temporary frames will be bogus.
107N/A // Since there is in general only a nesting level like
107N/A // this one deep in general we'll try and unwind such an "inner" frame
107N/A // here ourselves and see if it makes sense
107N/A
107N/A frame unwind_frame(ret_frame.fp(), frame::unpatchable, addr.pc());
107N/A
107N/A if (unwind_frame.safe_for_sender(jt)) {
107N/A *fr_addr = unwind_frame;
107N/A return true;
107N/A }
107N/A
107N/A // Well that didn't work. Most likely we're toast on this tick
107N/A // The previous code would try this. I think it is dubious in light
107N/A // of changes to safe_for_sender and the unwind trick above but
107N/A // if it gets us a safe frame who wants to argue.
107N/A
0N/A // If we have a last_Java_sp, then the SIGPROF signal caught us
0N/A // right when we were transitioning from _thread_in_Java to a new
0N/A // JavaThreadState. We use last_Java_sp instead of the sp from
0N/A // the ucontext since it should be more reliable.
107N/A
0N/A if (jt->has_last_Java_frame()) {
0N/A ret_sp = jt->last_Java_sp();
107N/A frame ret_frame2(ret_sp, frame::unpatchable, addr.pc());
107N/A if (ret_frame2.safe_for_sender(jt)) {
107N/A *fr_addr = ret_frame2;
107N/A return true;
107N/A }
0N/A }
0N/A
107N/A // This is the best we can do. We will only be able to decode the top frame
107N/A
0N/A *fr_addr = ret_frame;
0N/A return true;
0N/A }
0N/A
0N/A // At this point, we know we weren't running Java code. We might
0N/A // have a last_Java_sp, but we don't have a walkable frame.
0N/A // However, we might still be able to construct something useful
0N/A // if the thread was running native code.
0N/A if (jt->has_last_Java_frame()) {
0N/A assert(!jt->frame_anchor()->walkable(), "case covered above");
0N/A
107N/A frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc());
107N/A *fr_addr = ret_frame;
107N/A return true;
0N/A }
0N/A
107N/A // nothing else to try but what we found initially
107N/A
107N/A *fr_addr = ret_frame;
107N/A return true;
0N/A}
1601N/A
1601N/Avoid JavaThread::cache_global_variables() { }
1601N/A