hotspot/src/os_cpu/solaris_sparc/vm/thread_solaris_sparc.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 354 3b42d6fdcb82
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_thread_solaris_sparc.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// currently interrupted by SIGPROF
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// NOTE: On Solaris, register windows are flushed in the signal handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// except for possibly the top frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  void* ucontext, bool isInJava) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  assert(Thread::current() == this, "caller must be current thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(this->is_Java_thread(), "must be JavaThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  JavaThread* jt = (JavaThread *)this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  if (!isInJava) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    // make_walkable flushes register windows and grabs last_Java_pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    // which can not be done if the ucontext sp matches last_Java_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // stack walking utilities assume last_Java_pc set if marked flushed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    jt->frame_anchor()->make_walkable(jt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // If we have a walkable last_Java_frame, then we should use it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // even if isInJava == true. It should be more reliable than
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // ucontext info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    // This sanity check may not be needed with the new frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // walking code. Remove it for now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    if (!jt->frame_anchor()->post_Java_state_is_pc()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    && frame::next_younger_sp_or_null(last_Java_sp(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    jt->frame_anchor()->post_Java_sp()) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      // the anchor contains an SP, but the frame is not walkable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // because post_Java_sp isn't valid relative to last_Java_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    *fr_addr = jt->pd_last_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  ucontext_t* uc = (ucontext_t*) ucontext;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // At this point, we don't have a walkable last_Java_frame, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // we try to glean some information out of the ucontext.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  intptr_t* ret_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  ExtendedPC addr = os::Solaris::fetch_frame_from_ucontext(this, uc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    &ret_sp, NULL /* ret_fp only used on Solaris X86 */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if (addr.pc() == NULL || ret_sp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    // ucontext wasn't useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // we were running Java code when SIGPROF came in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (isInJava) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // If we have a last_Java_sp, then the SIGPROF signal caught us
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // right when we were transitioning from _thread_in_Java to a new
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // JavaThreadState. We use last_Java_sp instead of the sp from
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // the ucontext since it should be more reliable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    if (jt->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      ret_sp = jt->last_Java_sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // Implied else: we don't have a last_Java_sp so we use what we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // got from the ucontext.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    frame ret_frame(ret_sp, frame::unpatchable, addr.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if (!ret_frame.safe_for_sender(jt)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      // nothing else to try if the frame isn't good
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    *fr_addr = ret_frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // At this point, we know we weren't running Java code. We might
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // have a last_Java_sp, but we don't have a walkable frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // However, we might still be able to construct something useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // if the thread was running native code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (jt->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(!jt->frame_anchor()->walkable(), "case covered above");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (jt->thread_state() == _thread_in_native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      if (!ret_frame.safe_for_sender(jt)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        // nothing else to try if the frame isn't good
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      *fr_addr = ret_frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // nothing else to try
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}