KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > bdi > ThreadInfo


1 /*
2  * @(#)ThreadInfo.java 1.12 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.bdi;
36
37 import com.sun.jdi.*;
38 import java.util.List JavaDoc;
39 import java.util.ArrayList JavaDoc;
40 import java.util.Iterator JavaDoc;
41
42 //### Should handle target VM death or connection failure cleanly.
43

44 public class ThreadInfo {
45
46     private ThreadReference thread;
47     private int status;
48
49     private int frameCount;
50
51     Object JavaDoc userObject; // User-supplied annotation.
52

53     private boolean interrupted = false;
54
55     private void assureInterrupted() throws VMNotInterruptedException {
56     if (!interrupted) {
57         throw new VMNotInterruptedException();
58     }
59     }
60     
61     ThreadInfo (ThreadReference thread) {
62     this.thread = thread;
63     this.frameCount = -1;
64     }
65
66     public ThreadReference thread() {
67     return thread;
68     }
69
70     public int getStatus() throws VMNotInterruptedException {
71         assureInterrupted();
72     update();
73     return status;
74     }
75
76     public int getFrameCount() throws VMNotInterruptedException {
77         assureInterrupted();
78     update();
79     return frameCount;
80     }
81
82     public StackFrame getFrame(int index) throws VMNotInterruptedException {
83         assureInterrupted();
84     update();
85     try {
86         return thread.frame(index);
87     } catch (IncompatibleThreadStateException e) {
88         // Should not happen
89
interrupted = false;
90         throw new VMNotInterruptedException();
91     }
92     }
93
94     public Object JavaDoc getUserObject() {
95     return userObject;
96     }
97
98     public void setUserObject(Object JavaDoc obj) {
99     userObject = obj;
100     }
101
102     // Refresh upon first access after cache is cleared.
103

104     void update() throws VMNotInterruptedException {
105     if (frameCount == -1) {
106         try {
107         status = thread.status();
108         frameCount = thread.frameCount();
109         } catch (IncompatibleThreadStateException e) {
110         // Should not happen
111
interrupted = false;
112         throw new VMNotInterruptedException();
113         }
114     }
115     }
116     
117     // Called from 'ExecutionManager'.
118

119     void validate() {
120     interrupted = true;
121     }
122
123     void invalidate() {
124     interrupted = false;
125     frameCount = -1;
126     status = ThreadReference.THREAD_STATUS_UNKNOWN;
127     }
128     
129 }
130
Popular Tags