jdk/src/share/classes/com/sun/tools/example/debug/tty/ThreadInfo.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.example.debug.tty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jdi.ThreadReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jdi.ThreadGroupReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jdi.IncompatibleThreadStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jdi.StackFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class ThreadInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    // This is a list of all known ThreadInfo objects. It survives
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // ThreadInfo.invalidateAll, unlike the other static fields below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static List<ThreadInfo> threads = Collections.synchronizedList(new ArrayList<ThreadInfo>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static boolean gotInitialThreads = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static ThreadInfo current = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static ThreadGroupReference group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private final ThreadReference thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int currentFrameIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private ThreadInfo(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.thread = thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (thread == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            MessageOutput.fatalError("Internal error: null ThreadInfo created");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static void initThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if (!gotInitialThreads) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    59
            for (ThreadReference thread : Env.vm().allThreads()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                threads.add(new ThreadInfo(thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            gotInitialThreads = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static void addThread(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        synchronized (threads) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            initThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            ThreadInfo ti = new ThreadInfo(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            // Guard against duplicates. Duplicates can happen during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            // initialization when a particular thread might be added both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // by a thread start event and by the initial call to threads()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            if (getThreadInfo(thread) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                threads.add(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static void removeThread(ThreadReference thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (thread.equals(ThreadInfo.current)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            // Current thread has died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // Be careful getting the thread name. If its death happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            // as part of VM termination, it may be too late to get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            // information, and an exception will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            String currentThreadName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
               currentThreadName = "\"" + thread.name() + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
               currentThreadName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            setCurrentThread(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            MessageOutput.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            MessageOutput.println("Current thread died. Execution continuing...",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                  currentThreadName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        threads.remove(getThreadInfo(thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static List<ThreadInfo> threads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        synchronized(threads) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            initThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            // Make a copy to allow iteration without synchronization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return new ArrayList<ThreadInfo>(threads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static void invalidateAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        current = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        group = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        synchronized (threads) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   114
            for (ThreadInfo ti : threads()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                ti.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static void setThreadGroup(ThreadGroupReference tg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        group = tg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static void setCurrentThread(ThreadReference tr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (tr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            setCurrentThreadInfo(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            ThreadInfo tinfo = getThreadInfo(tr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            setCurrentThreadInfo(tinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    static void setCurrentThreadInfo(ThreadInfo tinfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        current = tinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            current.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Get the current ThreadInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the ThreadInfo for the current thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static ThreadInfo getCurrentThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Get the thread from this ThreadInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the Thread wrapped by this ThreadInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    ThreadReference getThread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static ThreadGroupReference group() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (group == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Current thread group defaults to the first top level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            // thread group.
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   162
            setThreadGroup(Env.vm().topLevelThreadGroups().get(0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    static ThreadInfo getThreadInfo(long id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        ThreadInfo retInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        synchronized (threads) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   171
            for (ThreadInfo ti : threads()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                if (ti.thread.uniqueID() == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                   retInfo = ti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return retInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    static ThreadInfo getThreadInfo(ThreadReference tr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return getThreadInfo(tr.uniqueID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    static ThreadInfo getThreadInfo(String idToken) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        ThreadInfo tinfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (idToken.startsWith("t@")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            idToken = idToken.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            long threadId = Long.decode(idToken).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            tinfo = getThreadInfo(threadId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            tinfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return tinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Get the thread stack frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @return a <code>List</code> of the stack frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   204
    List<StackFrame> getStack() throws IncompatibleThreadStateException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return thread.frames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Get the current stackframe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the current stackframe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (thread.frameCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return thread.frame(currentFrameIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Invalidate the current stackframe index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        currentFrameIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /* Throw IncompatibleThreadStateException if not suspended */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private void assureSuspended() throws IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!thread.isSuspended()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new IncompatibleThreadStateException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Get the current stackframe index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return the number of the current stackframe.  Frame zero is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * closest to the current program counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    int getCurrentFrameIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return currentFrameIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Set the current stackframe to a specific frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param nFrame    the number of the desired stackframe.  Frame zero is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * closest to the current program counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @exception IllegalAccessError when the thread isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * suspended or waiting at a breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @exception ArrayIndexOutOfBoundsException when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * requested frame is beyond the stack boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    void setCurrentFrameIndex(int nFrame) throws IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        assureSuspended();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if ((nFrame < 0) || (nFrame >= thread.frameCount())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new ArrayIndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        currentFrameIndex = nFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Change the current stackframe to be one or more frames higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * (as in, away from the current program counter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param nFrames   the number of stackframes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @exception IllegalAccessError when the thread isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * suspended or waiting at a breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @exception ArrayIndexOutOfBoundsException when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * requested frame is beyond the stack boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    void up(int nFrames) throws IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        setCurrentFrameIndex(currentFrameIndex + nFrames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Change the current stackframe to be one or more frames lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * (as in, toward the current program counter).     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param nFrames   the number of stackframes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @exception IllegalAccessError when the thread isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * suspended or waiting at a breakpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @exception ArrayIndexOutOfBoundsException when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * requested frame is beyond the stack boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    void down(int nFrames) throws IncompatibleThreadStateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        setCurrentFrameIndex(currentFrameIndex - nFrames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}