39 |
|
|
40 |
package gnu.classpath.jdwp.processor; |
package gnu.classpath.jdwp.processor; |
41 |
|
|
|
import gnu.classpath.jdwp.IVirtualMachine; |
|
|
import gnu.classpath.jdwp.Jdwp; |
|
42 |
import gnu.classpath.jdwp.JdwpConstants; |
import gnu.classpath.jdwp.JdwpConstants; |
43 |
|
import gnu.classpath.jdwp.VMVirtualMachine; |
44 |
import gnu.classpath.jdwp.exception.JdwpException; |
import gnu.classpath.jdwp.exception.JdwpException; |
45 |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
import gnu.classpath.jdwp.exception.JdwpInternalErrorException; |
46 |
import gnu.classpath.jdwp.exception.NotImplementedException; |
import gnu.classpath.jdwp.exception.NotImplementedException; |
|
import gnu.classpath.jdwp.id.IdManager; |
|
47 |
import gnu.classpath.jdwp.id.ObjectId; |
import gnu.classpath.jdwp.id.ObjectId; |
48 |
import gnu.classpath.jdwp.id.ReferenceTypeId; |
import gnu.classpath.jdwp.id.ReferenceTypeId; |
49 |
import gnu.classpath.jdwp.util.JdwpString; |
import gnu.classpath.jdwp.util.JdwpString; |
61 |
* |
* |
62 |
* @author Aaron Luchko <aluchko@redhat.com> |
* @author Aaron Luchko <aluchko@redhat.com> |
63 |
*/ |
*/ |
64 |
public class VirtualMachineCommandSet implements CommandSet |
public class VirtualMachineCommandSet |
65 |
|
extends CommandSet |
66 |
{ |
{ |
|
// Our hook into the jvm |
|
|
private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); |
|
|
|
|
|
// Manages all the different ids that are assigned by jdwp |
|
|
private final IdManager idMan = Jdwp.getIdManager(); |
|
|
|
|
|
// The Jdwp object |
|
|
private final Jdwp jdwp = Jdwp.getDefault(); |
|
|
|
|
67 |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) |
68 |
throws JdwpException |
throws JdwpException |
69 |
{ |
{ |
177 |
ArrayList allMatchingClasses = new ArrayList(); |
ArrayList allMatchingClasses = new ArrayList(); |
178 |
|
|
179 |
// This will be an Iterator over all loaded Classes |
// This will be an Iterator over all loaded Classes |
180 |
Iterator iter = vm.getAllLoadedClasses(); |
Iterator iter = VMVirtualMachine.getAllLoadedClasses(); |
181 |
|
|
182 |
while (iter.hasNext()) |
while (iter.hasNext()) |
183 |
{ |
{ |
193 |
Class clazz = (Class) allMatchingClasses.get(i); |
Class clazz = (Class) allMatchingClasses.get(i); |
194 |
ReferenceTypeId id = idMan.getReferenceTypeId(clazz); |
ReferenceTypeId id = idMan.getReferenceTypeId(clazz); |
195 |
id.writeTagged(os); |
id.writeTagged(os); |
196 |
int status = vm.getStatus(clazz); |
int status = VMVirtualMachine.getClassStatus(clazz); |
197 |
os.writeInt(status); |
os.writeInt(status); |
198 |
} |
} |
199 |
} |
} |
204 |
// Disable garbage collection while we're collecting the info on loaded |
// Disable garbage collection while we're collecting the info on loaded |
205 |
// classes so we some classes don't get collected between the time we get |
// classes so we some classes don't get collected between the time we get |
206 |
// the count and the time we get the list |
// the count and the time we get the list |
207 |
vm.disableGarbageCollection(); |
//VMVirtualMachine.disableGarbageCollection(); |
208 |
|
|
209 |
int classCount = vm.getAllLoadedClassesCount(); |
int classCount = VMVirtualMachine.getAllLoadedClassesCount(); |
210 |
os.writeInt(classCount); |
os.writeInt(classCount); |
211 |
|
|
212 |
// This will be an Iterator over all loaded Classes |
// This will be an Iterator over all loaded Classes |
213 |
Iterator iter = vm.getAllLoadedClasses(); |
Iterator iter = VMVirtualMachine.getAllLoadedClasses(); |
214 |
vm.enableGarbageCollection(); |
//VMVirtualMachine.enableGarbageCollection(); |
215 |
int count = 0; |
int count = 0; |
216 |
|
|
217 |
// Note it's possible classes were created since out classCount so make |
// Note it's possible classes were created since out classCount so make |
223 |
id.writeTagged(os); |
id.writeTagged(os); |
224 |
String sig = Signature.computeClassSignature(clazz); |
String sig = Signature.computeClassSignature(clazz); |
225 |
JdwpString.writeString(os, sig); |
JdwpString.writeString(os, sig); |
226 |
int status = vm.getStatus(clazz); |
int status = VMVirtualMachine.getClassStatus(clazz); |
227 |
os.writeInt(status); |
os.writeInt(status); |
228 |
} |
} |
229 |
} |
} |
260 |
if (thread == null) |
if (thread == null) |
261 |
break; // No threads after this point |
break; // No threads after this point |
262 |
if (!thread.getThreadGroup().equals(jdwpGroup)) |
if (!thread.getThreadGroup().equals(jdwpGroup)) |
263 |
idMan.getId(thread).write(os); |
idMan.getObjectId(thread).write(os); |
264 |
} |
} |
265 |
} |
} |
266 |
|
|
267 |
private void executeTopLevelThreadGroups(ByteBuffer bb, DataOutputStream os) |
private void executeTopLevelThreadGroups(ByteBuffer bb, DataOutputStream os) |
268 |
throws JdwpException, IOException |
throws JdwpException, IOException |
269 |
{ |
{ |
270 |
ThreadGroup jdwpGroup = jdwp.getJdwpThreadGroup(); |
ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup (); |
271 |
ThreadGroup root = getRootThreadGroup(jdwpGroup); |
ThreadGroup root = getRootThreadGroup(jdwpGroup); |
272 |
|
|
273 |
os.writeInt(1); // Just one top level group allowed? |
os.writeInt(1); // Just one top level group allowed? |
274 |
idMan.getId(root); |
idMan.getObjectId(root); |
275 |
} |
} |
276 |
|
|
277 |
private void executeDispose(ByteBuffer bb, DataOutputStream os) |
private void executeDispose(ByteBuffer bb, DataOutputStream os) |
281 |
// suspended multiple times, we likely need a way to keep track of how many |
// suspended multiple times, we likely need a way to keep track of how many |
282 |
// times a thread has been suspended or else a stronger resume method for |
// times a thread has been suspended or else a stronger resume method for |
283 |
// this purpose |
// this purpose |
284 |
// vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup()); |
// VMVirtualMachine.resumeAllThreads (); |
285 |
|
|
286 |
// Simply shutting down the jdwp layer will take care of the rest of the |
// Simply shutting down the jdwp layer will take care of the rest of the |
287 |
// shutdown other than disabling debugging in the VM |
// shutdown other than disabling debugging in the VM |
288 |
// vm.disableDebugging(); |
// VMVirtualMachine.disableDebugging(); |
289 |
|
|
290 |
// Don't implement this until we're sure how to remove all the debugging |
// Don't implement this until we're sure how to remove all the debugging |
291 |
// effects from the VM. |
// effects from the VM. |
308 |
private void executeSuspend(ByteBuffer bb, DataOutputStream os) |
private void executeSuspend(ByteBuffer bb, DataOutputStream os) |
309 |
throws JdwpException |
throws JdwpException |
310 |
{ |
{ |
311 |
vm.suspendAllThreadsExcept(jdwp.getJdwpThreadGroup()); |
VMVirtualMachine.suspendAllThreads (); |
312 |
} |
} |
313 |
|
|
314 |
private void executeResume(ByteBuffer bb, DataOutputStream os) |
private void executeResume(ByteBuffer bb, DataOutputStream os) |
315 |
throws JdwpException |
throws JdwpException |
316 |
{ |
{ |
317 |
vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup()); |
VMVirtualMachine.resumeAllThreads (); |
318 |
} |
} |
319 |
|
|
320 |
private void executeExit(ByteBuffer bb, DataOutputStream os) |
private void executeExit(ByteBuffer bb, DataOutputStream os) |
321 |
throws JdwpException, IOException |
throws JdwpException, IOException |
322 |
{ |
{ |
323 |
int exitCode = bb.getInt(); |
int exitCode = bb.getInt(); |
324 |
jdwp.setExit(exitCode); |
System.exit (exitCode); |
325 |
} |
} |
326 |
|
|
327 |
private void executeCreateString(ByteBuffer bb, DataOutputStream os) |
private void executeCreateString(ByteBuffer bb, DataOutputStream os) |
328 |
throws JdwpException, IOException |
throws JdwpException, IOException |
329 |
{ |
{ |
330 |
String string = JdwpString.readString(bb); |
String string = JdwpString.readString(bb); |
331 |
ObjectId stringId = Jdwp.getIdManager().getId(string); |
ObjectId stringId = idMan.getObjectId(string); |
332 |
|
|
333 |
// Since this string isn't referenced anywhere we'll disable garbage |
// Since this string isn't referenced anywhere we'll disable garbage |
334 |
// collection on it so it's still around when the debugger gets back to it. |
// collection on it so it's still around when the debugger gets back to it. |
376 |
{ |
{ |
377 |
// Instead of going through the list of objects they give us it's probably |
// Instead of going through the list of objects they give us it's probably |
378 |
// better just to find the garbage collected objects ourselves |
// better just to find the garbage collected objects ourselves |
379 |
idMan.update(); |
//idMan.update(); |
380 |
} |
} |
381 |
|
|
382 |
private void executeHoldEvents(ByteBuffer bb, DataOutputStream os) |
private void executeHoldEvents(ByteBuffer bb, DataOutputStream os) |