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