133N/A/*
1879N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
133N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
133N/A *
133N/A * This code is free software; you can redistribute it and/or modify it
133N/A * under the terms of the GNU General Public License version 2 only, as
133N/A * published by the Free Software Foundation.
133N/A *
133N/A * This code is distributed in the hope that it will be useful, but WITHOUT
133N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
133N/A * version 2 for more details (a copy is included in the LICENSE file that
133N/A * accompanied this code).
133N/A *
133N/A * You should have received a copy of the GNU General Public License version
133N/A * 2 along with this work; if not, write to the Free Software Foundation,
133N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
133N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
133N/A *
133N/A */
133N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "thread_linux.inline.hpp"
133N/A
133N/A// For Forte Analyzer AsyncGetCallTrace profiling support - thread is
133N/A// currently interrupted by SIGPROF
133N/Abool JavaThread::pd_get_top_frame_for_signal_handler(frame* fr_addr,
133N/A void* ucontext,
133N/A bool isInJava) {
133N/A assert(Thread::current() == this, "caller must be current thread");
133N/A assert(this->is_Java_thread(), "must be JavaThread");
133N/A
133N/A JavaThread* jt = (JavaThread *)this;
133N/A
133N/A if (!isInJava) {
133N/A // make_walkable flushes register windows and grabs last_Java_pc
133N/A // which can not be done if the ucontext sp matches last_Java_sp
133N/A // stack walking utilities assume last_Java_pc set if marked flushed
133N/A jt->frame_anchor()->make_walkable(jt);
133N/A }
133N/A
133N/A // If we have a walkable last_Java_frame, then we should use it
133N/A // even if isInJava == true. It should be more reliable than
133N/A // ucontext info.
133N/A if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
133N/A *fr_addr = jt->pd_last_frame();
133N/A return true;
133N/A }
133N/A
133N/A ucontext_t* uc = (ucontext_t*) ucontext;
133N/A
133N/A // At this point, we don't have a walkable last_Java_frame, so
133N/A // we try to glean some information out of the ucontext.
133N/A intptr_t* ret_sp;
133N/A ExtendedPC addr =
133N/A os::fetch_frame_from_context(uc, &ret_sp,
133N/A NULL /* ret_fp only used on X86 */);
133N/A if (addr.pc() == NULL || ret_sp == NULL) {
133N/A // ucontext wasn't useful
133N/A return false;
133N/A }
133N/A
133N/A // we were running Java code when SIGPROF came in
133N/A if (isInJava) {
133N/A // If we have a last_Java_sp, then the SIGPROF signal caught us
133N/A // right when we were transitioning from _thread_in_Java to a new
133N/A // JavaThreadState. We use last_Java_sp instead of the sp from
133N/A // the ucontext since it should be more reliable.
133N/A if (jt->has_last_Java_frame()) {
133N/A ret_sp = jt->last_Java_sp();
133N/A }
133N/A // Implied else: we don't have a last_Java_sp so we use what we
133N/A // got from the ucontext.
133N/A
133N/A frame ret_frame(ret_sp, frame::unpatchable, addr.pc());
133N/A if (!ret_frame.safe_for_sender(jt)) {
133N/A // nothing else to try if the frame isn't good
133N/A return false;
133N/A }
133N/A *fr_addr = ret_frame;
133N/A return true;
133N/A }
133N/A
133N/A // At this point, we know we weren't running Java code. We might
133N/A // have a last_Java_sp, but we don't have a walkable frame.
133N/A // However, we might still be able to construct something useful
133N/A // if the thread was running native code.
133N/A if (jt->has_last_Java_frame()) {
133N/A assert(!jt->frame_anchor()->walkable(), "case covered above");
133N/A
133N/A if (jt->thread_state() == _thread_in_native) {
133N/A frame ret_frame(jt->last_Java_sp(), frame::unpatchable, addr.pc());
133N/A if (!ret_frame.safe_for_sender(jt)) {
133N/A // nothing else to try if the frame isn't good
133N/A return false;
133N/A }
133N/A *fr_addr = ret_frame;
133N/A return true;
133N/A }
133N/A }
133N/A
133N/A // nothing else to try
133N/A return false;
133N/A}
1601N/A
1601N/Avoid JavaThread::cache_global_variables() { }
1601N/A