1 7 34 35 package com.sun.tools.example.debug.bdi; 36 37 import com.sun.jdi.*; 38 import java.util.List ; 39 import java.util.ArrayList ; 40 import java.util.Iterator ; 41 42 44 public class ThreadInfo { 45 46 private ThreadReference thread; 47 private int status; 48 49 private int frameCount; 50 51 Object userObject; 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 interrupted = false; 90 throw new VMNotInterruptedException(); 91 } 92 } 93 94 public Object getUserObject() { 95 return userObject; 96 } 97 98 public void setUserObject(Object obj) { 99 userObject = obj; 100 } 101 102 104 void update() throws VMNotInterruptedException { 105 if (frameCount == -1) { 106 try { 107 status = thread.status(); 108 frameCount = thread.frameCount(); 109 } catch (IncompatibleThreadStateException e) { 110 interrupted = false; 112 throw new VMNotInterruptedException(); 113 } 114 } 115 } 116 117 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 |