KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > VirtualMachineImpl


1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal;
12
13
14 import java.io.ByteArrayOutputStream JavaDoc;
15 import java.io.DataInputStream JavaDoc;
16 import java.io.DataOutputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.lang.reflect.Field JavaDoc;
19 import java.lang.reflect.Modifier JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.eclipse.jdi.Bootstrap;
28 import org.eclipse.jdi.internal.connect.PacketReceiveManager;
29 import org.eclipse.jdi.internal.connect.PacketSendManager;
30 import org.eclipse.jdi.internal.event.EventQueueImpl;
31 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket;
32 import org.eclipse.jdi.internal.jdwp.JdwpObjectID;
33 import org.eclipse.jdi.internal.jdwp.JdwpReferenceTypeID;
34 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket;
35 import org.eclipse.jdi.internal.request.EventRequestManagerImpl;
36
37 import com.ibm.icu.text.MessageFormat;
38 import com.sun.jdi.BooleanValue;
39 import com.sun.jdi.ByteValue;
40 import com.sun.jdi.CharValue;
41 import com.sun.jdi.DoubleValue;
42 import com.sun.jdi.FloatValue;
43 import com.sun.jdi.IntegerValue;
44 import com.sun.jdi.LongValue;
45 import com.sun.jdi.ObjectCollectedException;
46 import com.sun.jdi.ShortValue;
47 import com.sun.jdi.StringReference;
48 import com.sun.jdi.VMDisconnectedException;
49 import com.sun.jdi.VirtualMachine;
50 import com.sun.jdi.VoidValue;
51 import com.sun.jdi.connect.spi.Connection;
52 import com.sun.jdi.event.EventQueue;
53 import com.sun.jdi.request.EventRequestManager;
54
55 /**
56  * This class implements the corresponding interfaces
57  * declared by the JDI specification. See the com.sun.jdi package
58  * for more information.
59  *
60  */

61 public class VirtualMachineImpl extends MirrorImpl implements VirtualMachine, org.eclipse.jdi.hcr.VirtualMachine, org.eclipse.jdi.VirtualMachine {
62     /** Result flags for Classes Have Changed command. */
63     public static final byte HCR_RELOAD_SUCCESS = 0;
64     public static final byte HCR_RELOAD_FAILURE = 1;
65     public static final byte HCR_RELOAD_IGNORED = 2;
66
67     /* Indexes in HCR capabilities list.*/
68     private static final int HCR_CAN_RELOAD_CLASSES = 0;
69     private static final int HCR_CAN_GET_CLASS_VERSION = 1;
70     private static final int HCR_CAN_DO_RETURN = 2;
71     private static final int HCR_CAN_REENTER_ON_EXIT = 3;
72     
73     protected static final String JavaDoc JAVA_STRATUM_NAME= "Java"; //$NON-NLS-1$
74

75     /** Timeout value for requests to VM if not overriden for a particular VM. */
76     private int fRequestTimeout;
77     /** Mapping of command codes to strings. */
78     
79     private static Map JavaDoc fgHCRResultMap = null;
80
81     /** EventRequestManager that creates event objects on request. */
82     private EventRequestManagerImpl fEventReqMgr;
83     /** EventQueue that returns EventSets from the Virtual Manager. */
84     private EventQueueImpl fEventQueue;
85     
86     /** If a launchingconnector is used, we store the process. */
87     private Process JavaDoc fLaunchedProcess;
88     
89     /**
90      * The following field contains cached Mirrors.
91      * Note that these are optional: their only purpose is to speed up the debugger by
92      * being able to use the stored results of JDWP calls.
93      */

94     private ValueCache fCachedReftypes = new ValueCache();
95     private ValueCache fCachedObjects = new ValueCache();
96
97     /** The following are the stored results of JDWP calls. */
98     private String JavaDoc fVersionDescription = null; // Text information on the VM version.
99
private int fJdwpMajorVersion;
100     private int fJdwpMinorVersion;
101     private String JavaDoc fVMVersion; // Target VM JRE version, as in the java.version property.
102
private String JavaDoc fVMName; // Target VM name, as in the java.vm.name property.
103
private boolean fGotIDSizes = false;
104     private int fFieldIDSize;
105     private int fMethodIDSize;
106     private int fObjectIDSize;
107     private int fReferenceTypeIDSize;
108     private int fFrameIDSize;
109        
110     private boolean fGotCapabilities = false;
111     private boolean fCanWatchFieldModification;
112     private boolean fCanWatchFieldAccess;
113     private boolean fCanGetBytecodes;
114     private boolean fCanGetSyntheticAttribute;
115     private boolean fCanGetOwnedMonitorInfo;
116     private boolean fCanGetCurrentContendedMonitor;
117     private boolean fCanGetMonitorInfo;
118     private boolean fCanRedefineClasses;
119     private boolean fCanAddMethod;
120     private boolean fCanUnrestrictedlyRedefineClasses;
121     private boolean fCanPopFrames;
122     private boolean fCanUseInstanceFilters;
123     private boolean fCanGetSourceDebugExtension;
124     private boolean fCanRequestVMDeathEvent;
125     private boolean fCanSetDefaultStratum;
126     private boolean fCanGetInstanceInfo;
127     private boolean fCanGetConstantPool;
128     private boolean fCanUseSourceNameFilters;
129     private boolean fCanForceEarlyReturn;
130     private boolean fCanRequestMonitorEvents;
131     private boolean fCanGetMonitorFrameInfo;
132     private boolean[] fHcrCapabilities = null;
133     
134     /*
135      * singletons for primitive types
136      */

137     private BooleanTypeImpl fBooleanType;
138     private ByteTypeImpl fByteType;
139     private CharTypeImpl fCharType;
140     private DoubleTypeImpl fDoubleType;
141     private FloatTypeImpl fFloatType;
142     private IntegerTypeImpl fIntegerType;
143     private LongTypeImpl fLongType;
144     private ShortTypeImpl fShortType;
145     
146     /**
147      * Disconnected flag
148      */

149     private boolean fIsDisconnected = false;
150
151     /**
152      * The name of the current default stratum.
153      */

154     private String JavaDoc fDefaultStratum;
155     private PacketReceiveManager fPacketReceiveManager;
156     private PacketSendManager fPacketSendManager;
157     
158     /**
159      * Creates a new Virtual Machine.
160      */

161     public VirtualMachineImpl(Connection connection) {
162         super("VirtualMachine"); //$NON-NLS-1$
163
fEventReqMgr = new EventRequestManagerImpl(this);
164         fEventQueue = new EventQueueImpl(this);
165         fRequestTimeout = ((VirtualMachineManagerImpl) Bootstrap.virtualMachineManager()).getGlobalRequestTimeout();
166         
167         fPacketReceiveManager = new PacketReceiveManager(connection, this);
168         Thread JavaDoc receiveThread = new Thread JavaDoc(fPacketReceiveManager, JDIMessages.VirtualMachineImpl_0);
169         receiveThread.setDaemon(true);
170         fPacketReceiveManager.setPartnerThread(receiveThread);
171         receiveThread.start();
172         
173         fPacketSendManager = new PacketSendManager(connection);
174         Thread JavaDoc sendThread = new Thread JavaDoc(fPacketSendManager, JDIMessages.VirtualMachineImpl_1);
175         sendThread.setDaemon(true);
176         fPacketReceiveManager.setPartnerThread(sendThread);
177         sendThread.start();
178     }
179
180     /**
181      * @return Returns size of JDWP ID.
182      */

183     public final int fieldIDSize() {
184         return fFieldIDSize;
185     }
186     
187     /**
188      * @return Returns size of JDWP ID.
189      */

190     public final int methodIDSize() {
191         return fMethodIDSize;
192     }
193     
194     /**
195      * @return Returns size of JDWP ID.
196      */

197     public final int objectIDSize() {
198         return fObjectIDSize;
199     }
200     
201     /**
202      * @return Returns size of JDWP ID.
203      */

204     public final int referenceTypeIDSize() {
205         return fReferenceTypeIDSize;
206     }
207     
208     /**
209      * @return Returns size of JDWP ID.
210      */

211     public final int frameIDSize() {
212         return fFrameIDSize;
213     }
214     
215     /**
216      * @return Returns cached mirror object, or null if method is not in cache.
217      */

218     public ReferenceTypeImpl getCachedMirror(JdwpReferenceTypeID ID) {
219         return (ReferenceTypeImpl)fCachedReftypes.get(ID);
220     }
221     
222     /**
223      * @return Returns cached mirror object, or null if method is not in cache.
224      */

225     public ObjectReferenceImpl getCachedMirror(JdwpObjectID ID) {
226         return (ObjectReferenceImpl)fCachedObjects.get(ID);
227     }
228     
229     /**
230      * Adds mirror object to cache.
231      */

232     public void addCachedMirror(ReferenceTypeImpl mirror) {
233         fCachedReftypes.put(mirror.getRefTypeID(), mirror);
234         // tbd: It is now yet possible to only ask for unload events for
235
// classes that we know of due to a limitation in the J9 VM.
236
// eventRequestManagerImpl().enableInternalClasUnloadEvent(mirror);
237
}
238     
239     /**
240      * Adds mirror object to cache.
241      */

242     public void addCachedMirror(ObjectReferenceImpl mirror) {
243         fCachedObjects.put(mirror.getObjectID(), mirror);
244     }
245     
246     /**
247      * Flushes all stored Jdwp results.
248      */

249     public void flushStoredJdwpResults() {
250         // All known classes also become invalid.
251
Iterator JavaDoc iter = fCachedReftypes.values().iterator();
252         while (iter.hasNext()) {
253             ReferenceTypeImpl refType = (ReferenceTypeImpl)iter.next();
254             refType.flushStoredJdwpResults();
255         }
256             
257         fVersionDescription = null;
258         fGotIDSizes = false;
259         fHcrCapabilities = null;
260     }
261
262     /*
263      * Removes a known class.
264      * A class/interface is known if we have ever received its ReferenceTypeID and we have
265      * not received an unload event for it.
266      */

267     public final void removeKnownRefType(String JavaDoc signature) {
268         List JavaDoc refTypeList = classesBySignature(signature);
269         if (refTypeList.isEmpty())
270             return;
271
272         // If we have only one known class for this signature, we known that this is the class
273
// to be removed.
274
if (refTypeList.size() == 1) {
275             ReferenceTypeImpl refType = (ReferenceTypeImpl)refTypeList.get(0);
276             refType.flushStoredJdwpResults();
277             fCachedReftypes.remove(refType.getRefTypeID());
278             return;
279         }
280         
281         // We have more than one known class for the signature, let's find the unloaded one(s).
282
Iterator JavaDoc iter = refTypeList.iterator();
283         while (iter.hasNext()) {
284             ReferenceTypeImpl refType = (ReferenceTypeImpl)iter.next();
285             boolean prepared= false;
286             try {
287                 prepared= refType.isPrepared();
288             } catch (ObjectCollectedException exception) {
289                 // The type is unloaded. Fall through
290
}
291             if (!prepared) {
292                 refType.flushStoredJdwpResults();
293                 iter.remove();
294                 fCachedReftypes.remove(refType.getRefTypeID());
295             }
296         }
297     }
298
299     /*
300      * @exception Throws UnsupportedOperationException if VM does not support J9 HCR.
301      */

302     public void checkHCRSupported() throws UnsupportedOperationException JavaDoc {
303         if (!isHCRSupported())
304             throw new UnsupportedOperationException JavaDoc(MessageFormat.format(JDIMessages.VirtualMachineImpl_Target_VM__0__does_not_support_Hot_Code_Replacement_1, new String JavaDoc[]{name()}));
305     }
306     
307     /*
308      * Returns whether J9 HCR is supported
309      */

310     public boolean isHCRSupported() throws UnsupportedOperationException JavaDoc {
311         return name().equals("j9"); //$NON-NLS-1$
312
}
313
314     /*
315      * @return Returns Manager for receiving packets from the Virtual Machine.
316      */

317     public final PacketReceiveManager packetReceiveManager() {
318         return fPacketReceiveManager;
319     }
320
321     /*
322      * @return Returns Manager for sending packets to the Virtual Machine.
323      */

324     public final PacketSendManager packetSendManager() {
325         /*
326          * Before we send out first bytes to the VM by JDI calls, we need some initial requests:
327          * - Get the sizes of the IDs (fieldID, method ID etc.) that the VM uses;
328          * - Request class prepare and unload events. We used these to cache classes/interfaces and map their signatures.
329          */

330         if (!fGotIDSizes) {
331             getIDSizes();
332             if (!fGotIDSizes) { // We can't do much without them.
333
disconnectVM();
334                 throw new VMDisconnectedException(JDIMessages.VirtualMachineImpl_Failed_to_get_ID_sizes_2);
335             }
336
337             // tbd: This call should be moved to addKnownRefType() when it can be made specific
338
// for a referencetype.
339
eventRequestManagerImpl().enableInternalClasUnloadEvent();
340         }
341
342         return fPacketSendManager;
343     }
344
345     /**
346      * Returns all loaded types (classes, interfaces, and array types).
347      * For each loaded type in the target VM a ReferenceType will be placed in the returned list.
348      */

349     public List JavaDoc allClasses() {
350         // Note that this information should not be cached.
351
initJdwpRequest();
352         try {
353             boolean withGenericSignature= virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5);
354             int jdwpCommand= withGenericSignature ? JdwpCommandPacket.VM_ALL_CLASSES_WITH_GENERIC : JdwpCommandPacket.VM_ALL_CLASSES;
355             JdwpReplyPacket replyPacket = requestVM(jdwpCommand);
356             defaultReplyErrorHandler(replyPacket.errorCode());
357             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
358             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
359
List JavaDoc elements = new ArrayList JavaDoc(nrOfElements);
360             for (int i = 0; i < nrOfElements; i++) {
361                 ReferenceTypeImpl elt = ReferenceTypeImpl.readWithTypeTagAndSignature(this, withGenericSignature, replyData);
362                 if (elt == null) {
363                     continue;
364                 }
365                 readInt("status", ReferenceTypeImpl.classStatusStrings(), replyData); //$NON-NLS-1$
366
elements.add(elt);
367             }
368             return elements;
369         } catch (IOException JavaDoc e) {
370             defaultIOExceptionHandler(e);
371             return null;
372         } finally {
373             handledJdwpRequest();
374         }
375
376     }
377
378     /**
379      * @return Returns an iterator over all loaded classes.
380      */

381     protected final Iterator JavaDoc allRefTypes() {
382         return allClasses().iterator();
383     }
384
385     /**
386      * @return Returns an iterator over all cached classes.
387      */

388     protected final Iterator JavaDoc allCachedRefTypes() {
389         return fCachedReftypes.values().iterator();
390     }
391
392     /**
393      * Returns a list of the currently running threads.
394      * For each running thread in the target VM, a ThreadReference that mirrors it is placed in the list.
395      */

396     public List JavaDoc allThreads() {
397         // Note that this information should not be cached.
398
initJdwpRequest();
399         try {
400             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_ALL_THREADS);
401             defaultReplyErrorHandler(replyPacket.errorCode());
402             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
403             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
404
List JavaDoc elements = new ArrayList JavaDoc(nrOfElements);
405             for (int i = 0; i < nrOfElements; i++) {
406                 ThreadReferenceImpl elt = ThreadReferenceImpl.read(this, replyData);
407                 if (elt == null) {
408                     continue;
409                 }
410                 elements.add(elt);
411             }
412             return elements;
413         } catch (IOException JavaDoc e) {
414             defaultIOExceptionHandler(e);
415             return null;
416         } finally {
417             handledJdwpRequest();
418         }
419     }
420             
421     /**
422      * Retrieve this VM's capabilities.
423      */

424     public void getCapabilities() {
425         if (fGotCapabilities)
426             return;
427         
428         int command = JdwpCommandPacket.VM_CAPABILITIES;
429         if (isJdwpVersionGreaterOrEqual(1, 4)) {
430             command = JdwpCommandPacket.VM_CAPABILITIES_NEW;
431         }
432         
433         initJdwpRequest();
434         try {
435             JdwpReplyPacket replyPacket = requestVM(command);
436             defaultReplyErrorHandler(replyPacket.errorCode());
437             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
438         
439             fCanWatchFieldModification = readBoolean("watch field modification", replyData); //$NON-NLS-1$
440
fCanWatchFieldAccess = readBoolean("watch field access", replyData); //$NON-NLS-1$
441
fCanGetBytecodes = readBoolean("get bytecodes", replyData); //$NON-NLS-1$
442
fCanGetSyntheticAttribute = readBoolean("synth. attr", replyData); //$NON-NLS-1$
443
fCanGetOwnedMonitorInfo = readBoolean("owned monitor info", replyData); //$NON-NLS-1$
444
fCanGetCurrentContendedMonitor = readBoolean("curr. contended monitor", replyData); //$NON-NLS-1$
445
fCanGetMonitorInfo = readBoolean("monitor info", replyData); //$NON-NLS-1$
446
if (command == JdwpCommandPacket.VM_CAPABILITIES_NEW) {
447                 // extended capabilities
448
fCanRedefineClasses = readBoolean("redefine classes", replyData); //$NON-NLS-1$
449
fCanAddMethod = readBoolean("add method", replyData); //$NON-NLS-1$
450
fCanUnrestrictedlyRedefineClasses = readBoolean("unrestrictedly redefine classes", replyData); //$NON-NLS-1$
451
fCanPopFrames = readBoolean("pop frames", replyData); //$NON-NLS-1$
452
fCanUseInstanceFilters = readBoolean("use instance filters", replyData); //$NON-NLS-1$
453
fCanGetSourceDebugExtension = readBoolean("get source debug extension", replyData); //$NON-NLS-1$
454
fCanRequestVMDeathEvent = readBoolean("request vm death", replyData); //$NON-NLS-1$
455
fCanSetDefaultStratum= readBoolean("set default stratum", replyData); //$NON-NLS-1$
456
fCanGetInstanceInfo = readBoolean("instance info", replyData); //$NON-NLS-1$
457
fCanRequestMonitorEvents = readBoolean("request monitor events", replyData); //$NON-NLS-1$
458
fCanGetMonitorFrameInfo = readBoolean("monitor frame info", replyData); //$NON-NLS-1$
459
fCanUseSourceNameFilters = readBoolean("source name filters", replyData); //$NON-NLS-1$
460
fCanGetConstantPool = readBoolean("constant pool", replyData); //$NON-NLS-1$
461
fCanForceEarlyReturn = readBoolean("force early return", replyData); //$NON-NLS-1$
462
} else {
463                 fCanRedefineClasses = false;
464                 fCanAddMethod = false;
465                 fCanUnrestrictedlyRedefineClasses = false;
466                 fCanPopFrames = false;
467                 fCanUseInstanceFilters = false;
468                 fCanGetSourceDebugExtension = false;
469                 fCanRequestVMDeathEvent = false;
470                 fCanSetDefaultStratum= false;
471                 fCanGetInstanceInfo = false;
472                 fCanGetConstantPool = false;
473                 fCanUseSourceNameFilters = false;
474                 fCanForceEarlyReturn = false;
475                 fCanRequestMonitorEvents = false;
476                 fCanGetMonitorFrameInfo = false;
477             }
478             fGotCapabilities = true;
479         } catch (IOException JavaDoc e) {
480             fGotIDSizes = false;
481             defaultIOExceptionHandler(e);
482         } finally {
483             handledJdwpRequest();
484         }
485     }
486     
487     /**
488      * @see com.sun.jdi.VirtualMachine#canForceEarlyReturn()
489      * @since 3.3
490      */

491     public boolean canForceEarlyReturn() {
492         getCapabilities();
493         return fCanForceEarlyReturn;
494     }
495     
496     /**
497      * @return Returns true if this implementation supports the retrieval of a method's bytecodes.
498      */

499     public boolean canGetBytecodes() {
500         getCapabilities();
501         return fCanGetBytecodes;
502     }
503         
504     /**
505      * @return Returns true if this implementation supports the retrieval of the monitor for which a thread is currently waiting.
506      */

507     public boolean canGetCurrentContendedMonitor() {
508         getCapabilities();
509         return fCanGetCurrentContendedMonitor;
510     }
511     
512     /**
513      * @see com.sun.jdi.VirtualMachine#canGetInstanceInfo()
514      * @since 3.3
515      */

516     public boolean canGetInstanceInfo() {
517         getCapabilities();
518         return fCanGetInstanceInfo;
519     }
520     
521     /**
522      * @see com.sun.jdi.VirtualMachine#canGetMethodReturnValues()
523      * @since 3.3
524      */

525     public boolean canGetMethodReturnValues() {
526         return isJdwpVersionGreaterOrEqual(1, 6);
527     }
528     
529     /**
530      * @return Returns true if this implementation supports the retrieval of the monitor information for an object.
531      */

532     public boolean canGetMonitorInfo() {
533         getCapabilities();
534         return fCanGetMonitorInfo;
535     }
536     
537     /**
538      * @see com.sun.jdi.VirtualMachine#canGetMonitorFrameInfo()
539      * @since 3.3
540      */

541     public boolean canGetMonitorFrameInfo() {
542         getCapabilities();
543         return fCanGetMonitorFrameInfo;
544     }
545     
546     /**
547      * @return Returns true if this implementation supports the retrieval of the monitors owned by a thread.
548      */

549     public boolean canGetOwnedMonitorInfo() {
550         getCapabilities();
551         return fCanGetOwnedMonitorInfo;
552     }
553     
554     /**
555      * @return Returns true if this implementation supports the query of the synthetic attribute of a method or field.
556
557      */

558     public boolean canGetSyntheticAttribute() {
559         getCapabilities();
560         return fCanGetSyntheticAttribute;
561     }
562     
563     /**
564      * @see com.sun.jdi.VirtualMachine#canRequestMonitorEvents()
565      * @since 3.3
566      */

567     public boolean canRequestMonitorEvents() {
568         getCapabilities();
569         return fCanRequestMonitorEvents;
570     }
571     
572     /**
573      * @return Returns true if this implementation supports watchpoints for field access.
574      */

575     public boolean canWatchFieldAccess() {
576         getCapabilities();
577         return fCanWatchFieldAccess;
578     }
579     
580     /**
581      * @return Returns true if this implementation supports watchpoints for field modification.
582      */

583     public boolean canWatchFieldModification() {
584         getCapabilities();
585         return fCanWatchFieldModification;
586     }
587     
588     /**
589      * @return Returns the loaded reference types that match a given signature.
590      */

591     public List JavaDoc classesBySignature(String JavaDoc signature) {
592         // Note that this information should not be cached.
593
initJdwpRequest();
594         try {
595             ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
596             DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
597             writeString(signature, "signature", outData); //$NON-NLS-1$
598

599             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_CLASSES_BY_SIGNATURE, outBytes);
600             defaultReplyErrorHandler(replyPacket.errorCode());
601             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
602             int nrOfElements = readInt("elements", replyData); //$NON-NLS-1$
603
List JavaDoc elements = new ArrayList JavaDoc(nrOfElements);
604             for (int i = 0; i < nrOfElements; i++) {
605                 ReferenceTypeImpl elt = ReferenceTypeImpl.readWithTypeTag(this, replyData);
606                 readInt("status", ReferenceTypeImpl.classStatusStrings(), replyData); //$NON-NLS-1$
607
if (elt == null) {
608                     continue;
609                 }
610                 elements.add(elt);
611             }
612             return elements;
613         } catch (IOException JavaDoc e) {
614             defaultIOExceptionHandler(e);
615             return null;
616         } finally {
617             handledJdwpRequest();
618         }
619     }
620     
621     /**
622      * @return Returns the loaded reference types that match a given name.
623      */

624     public List JavaDoc classesByName(String JavaDoc name) {
625         String JavaDoc signature = TypeImpl.classNameToSignature(name);
626         return classesBySignature(signature);
627     }
628     
629     /**
630      * Invalidates this virtual machine mirror.
631      */

632     public void dispose() {
633         initJdwpRequest();
634         try {
635             requestVM(JdwpCommandPacket.VM_DISPOSE);
636             disconnectVM();
637         } catch (VMDisconnectedException e) {
638             // The VM can exit before we receive the reply.
639
} finally {
640             handledJdwpRequest();
641         }
642     }
643     
644     /**
645      * @return Returns EventQueue that returns EventSets from the Virtual Manager.
646      */

647     public EventQueue eventQueue() {
648         return fEventQueue;
649     }
650
651     /**
652      * @return Returns EventRequestManager that creates all event objects on request.
653      */

654     public EventRequestManager eventRequestManager() {
655         return fEventReqMgr;
656     }
657     
658     /**
659      * @return Returns EventRequestManagerImpl that creates all event objects on request.
660      */

661     public EventRequestManagerImpl eventRequestManagerImpl() {
662         return fEventReqMgr;
663     }
664
665     /**
666      * Causes the mirrored VM to terminate with the given error code.
667      */

668     public void exit(int exitCode) {
669         initJdwpRequest();
670         try {
671             ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
672             DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
673             writeInt(exitCode, "exit code", outData); //$NON-NLS-1$
674
requestVM(JdwpCommandPacket.VM_EXIT, outBytes);
675             disconnectVM();
676         } catch (VMDisconnectedException e) {
677             // The VM can exit before we receive the reply.
678
} catch (IOException JavaDoc e) {
679             defaultIOExceptionHandler(e);
680         } finally {
681             handledJdwpRequest();
682         }
683     }
684
685     /**
686      * @return Returns newly created ByteValue for the given value.
687      */

688     public ByteValue mirrorOf(byte value) {
689         return new ByteValueImpl(virtualMachineImpl(), new Byte JavaDoc(value));
690     }
691
692     /**
693      * @return Returns newly created CharValue for the given value.
694      */

695     public CharValue mirrorOf(char value) {
696         return new CharValueImpl(virtualMachineImpl(), new Character JavaDoc(value));
697     }
698
699     /**
700      * @return Returns newly created DoubleValue for the given value.
701      */

702     public DoubleValue mirrorOf(double value) {
703         return new DoubleValueImpl(virtualMachineImpl(), new Double JavaDoc(value));
704     }
705
706     /**
707      * @return Returns newly created FloatValue for the given value.
708      */

709     public FloatValue mirrorOf(float value) {
710         return new FloatValueImpl(virtualMachineImpl(), new Float JavaDoc(value));
711     }
712
713     /**
714      * @return Returns newly created IntegerValue for the given value.
715      */

716     public IntegerValue mirrorOf(int value) {
717         return new IntegerValueImpl(virtualMachineImpl(), new Integer JavaDoc(value));
718     }
719
720     /**
721      * @return Returns newly created LongValue for the given value.
722      */

723     public LongValue mirrorOf(long value) {
724         return new LongValueImpl(virtualMachineImpl(), new Long JavaDoc(value));
725     }
726
727     /**
728      * @return Returns newly created ShortValue for the given value.
729      */

730     public ShortValue mirrorOf(short value) {
731         return new ShortValueImpl(virtualMachineImpl(), new Short JavaDoc(value));
732     }
733
734     /**
735      * @return Returns newly created BooleanValue for the given value.
736      */

737     public BooleanValue mirrorOf(boolean value) {
738         return new BooleanValueImpl(virtualMachineImpl(), Boolean.valueOf(value));
739     }
740         
741     /**
742      * @return Returns newly created StringReference for the given value.
743      */

744     public StringReference mirrorOf(String JavaDoc value) {
745         initJdwpRequest();
746         try {
747             ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
748             DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
749             writeString(value, "string value", outData); //$NON-NLS-1$
750

751             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_CREATE_STRING, outBytes);
752             defaultReplyErrorHandler(replyPacket.errorCode());
753             
754             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
755             StringReference result = StringReferenceImpl.read(this, replyData);
756             return result;
757         } catch (IOException JavaDoc e) {
758             defaultIOExceptionHandler(e);
759             return null;
760         } finally {
761             handledJdwpRequest();
762         }
763     }
764     
765     /**
766      * Returns a void value from the VM.
767      *
768      * @return
769      */

770     public VoidValue mirrorOfVoid() {
771         return new VoidValueImpl(this);
772     }
773
774     /**
775      * @return Returns the Process object for this virtual machine if launched by a LaunchingConnector.
776      */

777     public Process JavaDoc process() {
778         return fLaunchedProcess;
779     }
780         
781     /**
782      * Sets Process object for this virtual machine if launched by a LaunchingConnector.
783      */

784     public void setLaunchedProcess(Process JavaDoc proc) {
785         fLaunchedProcess = proc;
786     }
787     
788     /**
789      * Continues the execution of the application running in this virtual machine.
790      */

791     public void resume() {
792         initJdwpRequest();
793         try {
794             resetThreadEventFlags();
795             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_RESUME);
796             defaultReplyErrorHandler(replyPacket.errorCode());
797         } finally {
798             handledJdwpRequest();
799         }
800     }
801         
802     public void setDebugTraceMode(int traceFlags) {
803         // We don't have trace info.
804
}
805
806     /**
807      * Suspends all threads.
808      */

809     public void suspend() {
810         initJdwpRequest();
811         try {
812             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_SUSPEND);
813             defaultReplyErrorHandler(replyPacket.errorCode());
814         } finally {
815