Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/StackFrameStream.java
41161 views
/*1* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.runtime;2526import sun.jvm.hotspot.utilities.*;2728/** <P> StackFrameStream iterates through the frames of a thread29starting from top most frame. It automatically takes care of30updating the location of all (callee-saved) registers. Notice: If31a thread is stopped at a safepoint, all registers are saved, not32only the callee-saved ones. </P>3334<P> Use: </P>3536<PRE>37for(StackFrameStream fst = new StackFrameStream(thread); !fst.isDone(); fst.next()) {38...39}40</PRE>41*/4243public class StackFrameStream {44private Frame fr;45private RegisterMap regMap;46private boolean isDone;4748/** Equivalent to StackFrameStream(thread, true) */49public StackFrameStream(JavaThread thread) {50this(thread, true);51}5253public StackFrameStream(JavaThread thread, boolean update) {54if (!VM.getVM().isDebugging()) {55if (Assert.ASSERTS_ENABLED) {56Assert.that(thread.hasLastJavaFrame(), "sanity check");57}58fr = thread.getLastFrame();59regMap = thread.newRegisterMap(update);60isDone = false;61} else {62// Special case code to find the topmost Java frame63// FIXME: should check to see whether we're at safepoint, and if64// so, skip the "current frame guess" call and unnecessary65// stackwalking work66fr = thread.getCurrentFrameGuess();67regMap = thread.newRegisterMap(update);68while ((fr != null) && (!fr.isJavaFrame())) {69if (fr.isFirstFrame()) {70fr = null;71} else {72fr = fr.sender(regMap);73}74}75if (fr == null) {76isDone = true;77}78}79}8081/** Iteration */82public boolean isDone() {83if (isDone) {84return true;85} else {86if (fr == null) {87isDone = true;88return true;89}90isDone = fr.isFirstFrame();91return false;92}93}9495public void next() {96if (!isDone) {97fr = fr.sender(regMap);98}99}100101/** Query */102public Frame getCurrent() { return fr; }103public RegisterMap getRegisterMap() { return regMap; }104}105106107