src/os_cpu/solaris_sparc/vm/thread_solaris_sparc.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os_cpu/solaris_sparc/vm/thread_solaris_sparc.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,156 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "runtime/frame.inline.hpp"
    1.30 +#include "runtime/thread.inline.hpp"
    1.31 +
    1.32 +// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
    1.33 +// currently interrupted by SIGPROF
    1.34 +//
    1.35 +// NOTE: On Solaris, register windows are flushed in the signal handler
    1.36 +// except for possibly the top frame.
    1.37 +//
    1.38 +bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
    1.39 +  void* ucontext, bool isInJava) {
    1.40 +
    1.41 +  assert(Thread::current() == this, "caller must be current thread");
    1.42 +  return pd_get_top_frame(fr_addr, ucontext, isInJava, true);
    1.43 +}
    1.44 +
    1.45 +bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, bool isInJava) {
    1.46 +  // get ucontext somehow
    1.47 +  return pd_get_top_frame(fr_addr, ucontext, isInJava, false);
    1.48 +}
    1.49 +
    1.50 +bool JavaThread::pd_get_top_frame(frame* fr_addr,
    1.51 +  void* ucontext, bool isInJava, bool makeWalkable) {
    1.52 +  assert(this->is_Java_thread(), "must be JavaThread");
    1.53 +
    1.54 +  JavaThread* jt = (JavaThread *)this;
    1.55 +
    1.56 +  if (!isInJava && makeWalkable) {
    1.57 +    // make_walkable flushes register windows and grabs last_Java_pc
    1.58 +    // which can not be done if the ucontext sp matches last_Java_sp
    1.59 +    // stack walking utilities assume last_Java_pc set if marked flushed
    1.60 +    jt->frame_anchor()->make_walkable(jt);
    1.61 +  }
    1.62 +
    1.63 +  // If we have a walkable last_Java_frame, then we should use it
    1.64 +  // even if isInJava == true. It should be more reliable than
    1.65 +  // ucontext info.
    1.66 +  if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
    1.67 +    *fr_addr = jt->pd_last_frame();
    1.68 +    return true;
    1.69 +  }
    1.70 +
    1.71 +  ucontext_t* uc = (ucontext_t*) ucontext;
    1.72 +
    1.73 +  // At this point, we don't have a walkable last_Java_frame, so
    1.74 +  // we try to glean some information out of the ucontext.
    1.75 +  intptr_t* ret_sp;
    1.76 +  ExtendedPC addr = os::Solaris::fetch_frame_from_ucontext(this, uc,
    1.77 +    &ret_sp, NULL /* ret_fp only used on Solaris X86 */);
    1.78 +  if (addr.pc() == NULL || ret_sp == NULL) {
    1.79 +    // ucontext wasn't useful
    1.80 +    return false;
    1.81 +  }
    1.82 +
    1.83 +  frame ret_frame(ret_sp, frame::unpatchable, addr.pc());
    1.84 +
    1.85 +  // we were running Java code when SIGPROF came in
    1.86 +  if (isInJava) {
    1.87 +
    1.88 +
    1.89 +    // If the frame we got is safe then it is most certainly valid
    1.90 +    if (ret_frame.safe_for_sender(jt)) {
    1.91 +      *fr_addr = ret_frame;
    1.92 +      return true;
    1.93 +    }
    1.94 +
    1.95 +    // If it isn't safe then we can try several things to try and get
    1.96 +    // a good starting point.
    1.97 +    //
    1.98 +    // On sparc the frames are almost certainly walkable in the sense
    1.99 +    // of sp/fp linkages. However because of recycling of windows if
   1.100 +    // a piece of code does multiple save's where the initial save creates
   1.101 +    // a real frame with a return pc and the succeeding save's are used to
   1.102 +    // simply get free registers and have no real pc then the pc linkage on these
   1.103 +    // "inner" temporary frames will be bogus.
   1.104 +    // Since there is in general only a nesting level like
   1.105 +    // this one deep in general we'll try and unwind such an "inner" frame
   1.106 +    // here ourselves and see if it makes sense
   1.107 +
   1.108 +    frame unwind_frame(ret_frame.fp(), frame::unpatchable, addr.pc());
   1.109 +
   1.110 +    if (unwind_frame.safe_for_sender(jt)) {
   1.111 +      *fr_addr = unwind_frame;
   1.112 +      return true;
   1.113 +    }
   1.114 +
   1.115 +    // Well that didn't work. Most likely we're toast on this tick
   1.116 +    // The previous code would try this. I think it is dubious in light
   1.117 +    // of changes to safe_for_sender and the unwind trick above but
   1.118 +    // if it gets us a safe frame who wants to argue.
   1.119 +
   1.120 +    // If we have a last_Java_sp, then the SIGPROF signal caught us
   1.121 +    // right when we were transitioning from _thread_in_Java to a new
   1.122 +    // JavaThreadState. We use last_Java_sp instead of the sp from
   1.123 +    // the ucontext since it should be more reliable.
   1.124 +
   1.125 +    if (jt->has_last_Java_frame()) {
   1.126 +      ret_sp = jt->last_Java_sp();
   1.127 +      frame ret_frame2(ret_sp, frame::unpatchable, addr.pc());
   1.128 +      if (ret_frame2.safe_for_sender(jt)) {
   1.129 +        *fr_addr = ret_frame2;
   1.130 +        return true;
   1.131 +      }
   1.132 +    }
   1.133 +
   1.134 +    // This is the best we can do. We will only be able to decode the top frame
   1.135 +
   1.136 +    *fr_addr = ret_frame;
   1.137 +    return true;
   1.138 +  }
   1.139 +
   1.140 +  // At this point, we know we weren't running Java code. We might
   1.141 +  // have a last_Java_sp, but we don't have a walkable frame.
   1.142 +  // However, we might still be able to construct something useful
   1.143 +  // if the thread was running native code.
   1.144 +  if (jt->has_last_Java_frame()) {
   1.145 +    assert(!jt->frame_anchor()->walkable(), "case covered above");
   1.146 +
   1.147 +    frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc());
   1.148 +    *fr_addr = ret_frame;
   1.149 +    return true;
   1.150 +  }
   1.151 +
   1.152 +  // nothing else to try but what we found initially
   1.153 +
   1.154 +  *fr_addr = ret_frame;
   1.155 +  return true;
   1.156 +}
   1.157 +
   1.158 +void JavaThread::cache_global_variables() { }
   1.159 +

mercurial