1:
38:
39:
40: package ;
41:
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54: import ;
55: import ;
56: import ;
57: import ;
58:
59:
64: public class ThreadReferenceCommandSet
65: extends CommandSet
66: {
67: public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
68: throws JdwpException
69: {
70: try
71: {
72: switch (command)
73: {
74: case JdwpConstants.CommandSet.ThreadReference.NAME:
75: executeName(bb, os);
76: break;
77: case JdwpConstants.CommandSet.ThreadReference.SUSPEND:
78: executeSuspend(bb, os);
79: break;
80: case JdwpConstants.CommandSet.ThreadReference.RESUME:
81: executeResume(bb, os);
82: break;
83: case JdwpConstants.CommandSet.ThreadReference.STATUS:
84: executeStatus(bb, os);
85: break;
86: case JdwpConstants.CommandSet.ThreadReference.THREAD_GROUP:
87: executeThreadGroup(bb, os);
88: break;
89: case JdwpConstants.CommandSet.ThreadReference.FRAMES:
90: executeFrames(bb, os);
91: break;
92: case JdwpConstants.CommandSet.ThreadReference.FRAME_COUNT:
93: executeFrameCount(bb, os);
94: break;
95: case JdwpConstants.CommandSet.ThreadReference.OWNED_MONITORS:
96: executeOwnedMonitors(bb, os);
97: break;
98: case JdwpConstants.CommandSet.ThreadReference.CURRENT_CONTENDED_MONITOR:
99: executeCurrentContendedMonitor(bb, os);
100: break;
101: case JdwpConstants.CommandSet.ThreadReference.STOP:
102: executeStop(bb, os);
103: break;
104: case JdwpConstants.CommandSet.ThreadReference.INTERRUPT:
105: executeInterrupt(bb, os);
106: break;
107: case JdwpConstants.CommandSet.ThreadReference.SUSPEND_COUNT:
108: executeSuspendCount(bb, os);
109: break;
110: default:
111: throw new NotImplementedException("Command " + command +
112: " not found in Thread Reference Command Set.");
113: }
114: }
115: catch (IOException ex)
116: {
117:
118:
119: throw new JdwpInternalErrorException(ex);
120: }
121:
122: return false;
123: }
124:
125: private void executeName(ByteBuffer bb, DataOutputStream os)
126: throws JdwpException, IOException
127: {
128: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
129: Thread thread = tid.getThread();
130: JdwpString.writeString(os, thread.getName());
131: }
132:
133: private void executeSuspend(ByteBuffer bb, DataOutputStream os)
134: throws JdwpException, IOException
135: {
136: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
137: Thread thread = tid.getThread();
138: VMVirtualMachine.suspendThread(thread);
139: }
140:
141: private void executeResume(ByteBuffer bb, DataOutputStream os)
142: throws JdwpException, IOException
143: {
144: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
145: Thread thread = tid.getThread();
146: VMVirtualMachine.suspendThread(thread);
147: }
148:
149: private void executeStatus(ByteBuffer bb, DataOutputStream os)
150: throws JdwpException, IOException
151: {
152: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
153: Thread thread = tid.getThread();
154: int threadStatus = VMVirtualMachine.getThreadStatus(thread);
155:
156: int suspendStatus = JdwpConstants.SuspendStatus.SUSPENDED;
157:
158: os.writeInt(threadStatus);
159: os.writeInt(suspendStatus);
160: }
161:
162: private void executeThreadGroup(ByteBuffer bb, DataOutputStream os)
163: throws JdwpException, IOException
164: {
165: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
166: Thread thread = tid.getThread();
167: ThreadGroup group = thread.getThreadGroup();
168: ObjectId groupId = idMan.getObjectId(group);
169: groupId.write(os);
170: }
171:
172: private void executeFrames(ByteBuffer bb, DataOutputStream os)
173: throws JdwpException, IOException
174: {
175: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
176: Thread thread = tid.getThread();
177: int startFrame = bb.getInt();
178: int length = bb.getInt();
179:
180: ArrayList frames = VMVirtualMachine.getFrames(thread, startFrame, length);
181: os.writeInt(frames.size());
182: for (int i = 0; i < frames.size(); i++)
183: {
184: VMFrame frame = (VMFrame) frames.get(i);
185: os.writeLong(frame.getId());
186: Location loc = frame.getLocation();
187: loc.write(os);
188: }
189: }
190:
191: private void executeFrameCount(ByteBuffer bb, DataOutputStream os)
192: throws JdwpException, IOException
193: {
194: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
195: Thread thread = tid.getThread();
196:
197: int frameCount = VMVirtualMachine.getFrameCount(thread);
198: os.writeInt(frameCount);
199: }
200:
201: private void executeOwnedMonitors(ByteBuffer bb, DataOutputStream os)
202: throws JdwpException
203: {
204:
205:
206: throw new NotImplementedException(
207: "Command OwnedMonitors not implemented.");
208: }
209:
210: private void executeCurrentContendedMonitor(ByteBuffer bb,
211: DataOutputStream os)
212: throws JdwpException
213: {
214:
215:
216: throw new NotImplementedException(
217: "Command CurrentContentedMonitors not implemented.");
218: }
219:
220: private void executeStop(ByteBuffer bb, DataOutputStream os)
221: throws JdwpException, IOException
222: {
223: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
224: Thread thread = tid.getThread();
225: ObjectId exception = idMan.readObjectId(bb);
226: Throwable throwable = (Throwable) exception.getObject();
227: thread.stop (throwable);
228: }
229:
230: private void executeInterrupt(ByteBuffer bb, DataOutputStream os)
231: throws JdwpException, IOException
232: {
233: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
234: Thread thread = tid.getThread();
235: thread.interrupt();
236: }
237:
238: private void executeSuspendCount(ByteBuffer bb, DataOutputStream os)
239: throws JdwpException, IOException
240: {
241: ThreadId tid = (ThreadId) idMan.readObjectId(bb);
242: Thread thread = tid.getThread();
243: int suspendCount = VMVirtualMachine.getSuspendCount(thread);
244: os.writeInt(suspendCount);
245: }
246: }