1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)thread_solaris_sparc.cpp 1.16 07/05/05 17:04:53 JVM" 3 #endif 4 /* 5 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 #include "incls/_precompiled.incl" 29 #include "incls/_thread_solaris_sparc.cpp.incl" 30 31 // For Forte Analyzer AsyncGetCallTrace profiling support - thread is 32 // currently interrupted by SIGPROF 33 // 34 // NOTE: On Solaris, register windows are flushed in the signal handler 35 // except for possibly the top frame. 36 // 37 bool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr, 38 void* ucontext, bool isInJava) { 39 40 assert(Thread::current() == this, "caller must be current thread"); 41 assert(this->is_Java_thread(), "must be JavaThread"); 42 43 JavaThread* jt = (JavaThread *)this; 44 45 if (!isInJava) { 46 // make_walkable flushes register windows and grabs last_Java_pc 47 // which can not be done if the ucontext sp matches last_Java_sp 48 // stack walking utilities assume last_Java_pc set if marked flushed 49 jt->frame_anchor()->make_walkable(jt); 50 } 51 52 // If we have a walkable last_Java_frame, then we should use it 53 // even if isInJava == true. It should be more reliable than 54 // ucontext info. 55 if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) { 56 *fr_addr = jt->pd_last_frame(); 57 return true; 58 } 59 60 ucontext_t* uc = (ucontext_t*) ucontext; 61 62 // At this point, we don't have a walkable last_Java_frame, so 63 // we try to glean some information out of the ucontext. 64 intptr_t* ret_sp; 65 ExtendedPC addr = os::Solaris::fetch_frame_from_ucontext(this, uc, 66 &ret_sp, NULL /* ret_fp only used on Solaris X86 */); 67 if (addr.pc() == NULL || ret_sp == NULL) { 68 // ucontext wasn't useful 69 return false; 70 } 71 72 frame ret_frame(ret_sp, frame::unpatchable, addr.pc()); 73 74 // we were running Java code when SIGPROF came in 75 if (isInJava) { 76 77 78 // If the frame we got is safe then it is most certainly valid 79 if (ret_frame.safe_for_sender(jt)) { 80 *fr_addr = ret_frame; 81 return true; 82 } 83 84 // If it isn't safe then we can try several things to try and get 85 // a good starting point. 86 // 87 // On sparc the frames are almost certainly walkable in the sense 88 // of sp/fp linkages. However because of recycling of windows if 89 // a piece of code does multiple save's where the initial save creates 90 // a real frame with a return pc and the succeeding save's are used to 91 // simply get free registers and have no real pc then the pc linkage on these 92 // "inner" temporary frames will be bogus. 93 // Since there is in general only a nesting level like 94 // this one deep in general we'll try and unwind such an "inner" frame 95 // here ourselves and see if it makes sense 96 97 frame unwind_frame(ret_frame.fp(), frame::unpatchable, addr.pc()); 98 99 if (unwind_frame.safe_for_sender(jt)) { 100 *fr_addr = unwind_frame; 101 return true; 102 } 103 104 // Well that didn't work. Most likely we're toast on this tick 105 // The previous code would try this. I think it is dubious in light 106 // of changes to safe_for_sender and the unwind trick above but 107 // if it gets us a safe frame who wants to argue. 108 109 // If we have a last_Java_sp, then the SIGPROF signal caught us 110 // right when we were transitioning from _thread_in_Java to a new 111 // JavaThreadState. We use last_Java_sp instead of the sp from 112 // the ucontext since it should be more reliable. 113 114 if (jt->has_last_Java_frame()) { 115 ret_sp = jt->last_Java_sp(); 116 frame ret_frame2(ret_sp, frame::unpatchable, addr.pc()); 117 if (ret_frame2.safe_for_sender(jt)) { 118 *fr_addr = ret_frame2; 119 return true; 120 } 121 } 122 123 // This is the best we can do. We will only be able to decode the top frame 124 125 *fr_addr = ret_frame; 126 return true; 127 } 128 129 // At this point, we know we weren't running Java code. We might 130 // have a last_Java_sp, but we don't have a walkable frame. 131 // However, we might still be able to construct something useful 132 // if the thread was running native code. 133 if (jt->has_last_Java_frame()) { 134 assert(!jt->frame_anchor()->walkable(), "case covered above"); 135 136 frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc()); 137 *fr_addr = ret_frame; 138 return true; 139 } 140 141 // nothing else to try but what we found initially 142 143 *fr_addr = ret_frame; 144 return true; 145 }