thread_solaris_sparc.cpp revision 4802:f2110083203d
161981Sbrian/*
261981Sbrian * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
361981Sbrian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
461981Sbrian *
561981Sbrian * This code is free software; you can redistribute it and/or modify it
661981Sbrian * under the terms of the GNU General Public License version 2 only, as
761981Sbrian * published by the Free Software Foundation.
861981Sbrian *
961981Sbrian * This code is distributed in the hope that it will be useful, but WITHOUT
1061981Sbrian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1161981Sbrian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1261981Sbrian * version 2 for more details (a copy is included in the LICENSE file that
1361981Sbrian * accompanied this code).
1461981Sbrian *
1561981Sbrian * You should have received a copy of the GNU General Public License version
1661981Sbrian * 2 along with this work; if not, write to the Free Software Foundation,
1761981Sbrian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1861981Sbrian *
1961981Sbrian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2061981Sbrian * or visit www.oracle.com if you need additional information or have any
2161981Sbrian * questions.
2261981Sbrian *
2361981Sbrian */
2461981Sbrian
2565843Sbrian#include "precompiled.hpp"
2665843Sbrian#include "runtime/frame.inline.hpp"
2765843Sbrian#include "runtime/thread.inline.hpp"
2865843Sbrian
2965843Sbrian// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
3065843Sbrian// currently interrupted by SIGPROF
3165843Sbrian//
3265843Sbrian// NOTE: On Solaris, register windows are flushed in the signal handler
3365843Sbrian// except for possibly the top frame.
3465843Sbrian//
3561981Sbrianbool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
3661981Sbrian  void* ucontext, bool isInJava) {
3761981Sbrian
3861981Sbrian  assert(Thread::current() == this, "caller must be current thread");
3961981Sbrian  return pd_get_top_frame(fr_addr, ucontext, isInJava, true);
4061981Sbrian}
4161981Sbrian
4261981Sbrianbool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, bool isInJava) {
4361981Sbrian  // get ucontext somehow
4461981Sbrian  return pd_get_top_frame(fr_addr, ucontext, isInJava, false);
4561981Sbrian}
4661981Sbrian
4761981Sbrianbool JavaThread::pd_get_top_frame(frame* fr_addr,
4861981Sbrian  void* ucontext, bool isInJava, bool makeWalkable) {
4961981Sbrian  assert(this->is_Java_thread(), "must be JavaThread");
5061981Sbrian
5161981Sbrian  JavaThread* jt = (JavaThread *)this;
5261981Sbrian
5361981Sbrian  if (!isInJava && makeWalkable) {
5461981Sbrian    // make_walkable flushes register windows and grabs last_Java_pc
5561981Sbrian    // which can not be done if the ucontext sp matches last_Java_sp
5661981Sbrian    // stack walking utilities assume last_Java_pc set if marked flushed
5761981Sbrian    jt->frame_anchor()->make_walkable(jt);
5861981Sbrian  }
5961981Sbrian
6061981Sbrian  // If we have a walkable last_Java_frame, then we should use it
6161981Sbrian  // even if isInJava == true. It should be more reliable than
6261981Sbrian  // ucontext info.
63108959Swollman  if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
64108959Swollman    *fr_addr = jt->pd_last_frame();
6561981Sbrian    return true;
6661981Sbrian  }
6761981Sbrian
6861981Sbrian  ucontext_t* uc = (ucontext_t*) ucontext;
6961981Sbrian
7061981Sbrian  // At this point, we don't have a walkable last_Java_frame, so
7161981Sbrian  // we try to glean some information out of the ucontext.
7261981Sbrian  intptr_t* ret_sp;
7374314Sbrian  ExtendedPC addr = os::Solaris::fetch_frame_from_ucontext(this, uc,
7461981Sbrian    &ret_sp, NULL /* ret_fp only used on Solaris X86 */);
7561981Sbrian  if (addr.pc() == NULL || ret_sp == NULL) {
7661981Sbrian    // ucontext wasn't useful
7761981Sbrian    return false;
7861981Sbrian  }
7961981Sbrian
8062054Sbrian  frame ret_frame(ret_sp, frame::unpatchable, addr.pc());
8177496Sbrian
8277492Sbrian  // we were running Java code when SIGPROF came in
8361981Sbrian  if (isInJava) {
8461981Sbrian
8561981Sbrian
8661981Sbrian    // If the frame we got is safe then it is most certainly valid
8761981Sbrian    if (ret_frame.safe_for_sender(jt)) {
8861981Sbrian      *fr_addr = ret_frame;
8961981Sbrian      return true;
9061981Sbrian    }
9161981Sbrian
9262644Ssheldonh    // If it isn't safe then we can try several things to try and get
9361981Sbrian    // a good starting point.
9461981Sbrian    //
9561981Sbrian    // On sparc the frames are almost certainly walkable in the sense
9661981Sbrian    // of sp/fp linkages. However because of recycling of windows if
9761981Sbrian    // a piece of code does multiple save's where the initial save creates
9861981Sbrian    // a real frame with a return pc and the succeeding save's are used to
9961981Sbrian    // simply get free registers and have no real pc then the pc linkage on these
10061981Sbrian    // "inner" temporary frames will be bogus.
10161981Sbrian    // Since there is in general only a nesting level like
10261981Sbrian    // this one deep in general we'll try and unwind such an "inner" frame
10361981Sbrian    // here ourselves and see if it makes sense
10494342Sgshapiro
10561981Sbrian    frame unwind_frame(ret_frame.fp(), frame::unpatchable, addr.pc());
10661981Sbrian
10761981Sbrian    if (unwind_frame.safe_for_sender(jt)) {
10887514Scjc      *fr_addr = unwind_frame;
10961981Sbrian      return true;
11061981Sbrian    }
11161981Sbrian
11262274Sbrian    // Well that didn't work. Most likely we're toast on this tick
11361981Sbrian    // The previous code would try this. I think it is dubious in light
11475809Sdirk    // of changes to safe_for_sender and the unwind trick above but
11575809Sdirk    // if it gets us a safe frame who wants to argue.
11675809Sdirk
11775809Sdirk    // If we have a last_Java_sp, then the SIGPROF signal caught us
11872677Speter    // right when we were transitioning from _thread_in_Java to a new
11972677Speter    // JavaThreadState. We use last_Java_sp instead of the sp from
12094342Sgshapiro    // the ucontext since it should be more reliable.
12172677Speter
12261981Sbrian    if (jt->has_last_Java_frame()) {
12361981Sbrian      ret_sp = jt->last_Java_sp();
12461981Sbrian      frame ret_frame2(ret_sp, frame::unpatchable, addr.pc());
12561981Sbrian      if (ret_frame2.safe_for_sender(jt)) {
12687514Scjc        *fr_addr = ret_frame2;
12787514Scjc        return true;
128101607Sfanf      }
12987514Scjc    }
13087514Scjc
13187514Scjc    // This is the best we can do. We will only be able to decode the top frame
13287514Scjc
13387514Scjc    *fr_addr = ret_frame;
13487514Scjc    return true;
13587514Scjc  }
13687514Scjc
13787514Scjc  // At this point, we know we weren't running Java code. We might
13887514Scjc  // have a last_Java_sp, but we don't have a walkable frame.
13987514Scjc  // However, we might still be able to construct something useful
14087514Scjc  // if the thread was running native code.
14187514Scjc  if (jt->has_last_Java_frame()) {
14287514Scjc    assert(!jt->frame_anchor()->walkable(), "case covered above");
14387514Scjc
14487514Scjc    frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc());
14587514Scjc    *fr_addr = ret_frame;
14687514Scjc    return true;
14787514Scjc  }
14887514Scjc
14987514Scjc  // nothing else to try but what we found initially
15087514Scjc
15187514Scjc  *fr_addr = ret_frame;
152105937Sthomas  return true;
153105937Sthomas}
154105937Sthomas
15587514Scjcvoid JavaThread::cache_global_variables() { }
15687514Scjc
15787514Scjc