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