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             handledJdwpRequest();
816         }
817     }
818         
819     public List JavaDoc topLevelThreadGroups() {
820         // Note that this information should not be cached.
821
initJdwpRequest();
822         try {
823             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_TOP_LEVEL_THREAD_GROUPS);
824             defaultReplyErrorHandler(replyPacket.errorCode());
825             
826             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
827             int nrGroups = readInt("nr of groups", replyData); //$NON-NLS-1$
828
ArrayList JavaDoc result = new ArrayList JavaDoc(nrGroups);
829             for (int i = 0; i < nrGroups; i++) {
830                 ThreadGroupReferenceImpl threadGroup = ThreadGroupReferenceImpl.read(this, replyData);
831                 result.add(threadGroup);
832             }
833             return result;
834         } catch (IOException JavaDoc e) {
835             defaultIOExceptionHandler(e);
836             return null;
837         } finally {
838             handledJdwpRequest();
839         }
840     }
841
842     /**
843      * @return Returns the name of the target VM as reported by the property java.vm.name.
844      */

845     public String JavaDoc name() {
846         getVersionInfo();
847         return fVMName;
848     }
849         
850     /**
851      * @return Returns the version of the Java Runtime Environment in the target VM as reported by the property java.version.
852      */

853     public String JavaDoc version() {
854         getVersionInfo();
855         return fVMVersion;
856     }
857             
858     /**
859      * @return Returns text information on the target VM and the debugger support that mirrors it.
860      */

861     public String JavaDoc description() {
862         getVersionInfo();
863         return fVersionDescription;
864     }
865             
866     /**
867      * Reset event flags of all threads.
868      */

869     private void resetThreadEventFlags() {
870         Iterator JavaDoc iter = allThreads().iterator();
871         ThreadReferenceImpl thread;
872         while (iter.hasNext()) {
873             thread = (ThreadReferenceImpl)iter.next();
874             thread.resetEventFlags();
875         }
876     }
877
878     /**
879      * Request and fetch ID sizes of Virtual Machine.
880      */

881     private void getIDSizes() {
882         if (fGotIDSizes)
883             return;
884
885         /*
886          * fGotIDSizes must first be assigned true to prevent an invinite loop
887          * because getIDSizes() calls requestVM which calls packetSendManager.
888          */

889         fGotIDSizes = true;
890          
891         // We use a different mirror to avoid having verbose output mixed with the initiating command.
892
MirrorImpl mirror = new VoidValueImpl(this);
893         
894         mirror.initJdwpRequest();
895         try {
896             JdwpReplyPacket replyPacket = mirror.requestVM(JdwpCommandPacket.VM_ID_SIZES);
897             mirror.defaultReplyErrorHandler(replyPacket.errorCode());
898             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
899         
900             fFieldIDSize = mirror.readInt("field ID size", replyData); //$NON-NLS-1$
901
fMethodIDSize = mirror.readInt("method ID size", replyData); //$NON-NLS-1$
902
fObjectIDSize = mirror.readInt("object ID size", replyData); //$NON-NLS-1$
903
fReferenceTypeIDSize = mirror.readInt("refType ID size", replyData); //$NON-NLS-1$
904
fFrameIDSize = mirror.readInt("frame ID size", replyData); //$NON-NLS-1$
905
} catch (IOException JavaDoc e) {
906             fGotIDSizes = false;
907             mirror.defaultIOExceptionHandler(e);
908         } finally {
909             mirror.handledJdwpRequest();
910         }
911     }
912     
913     /**
914      * Retrieves version info of the VM.
915      */

916     public void getVersionInfo() {
917         if (fVersionDescription != null)
918             return;
919             
920         initJdwpRequest();
921         try {
922             JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_VERSION);
923             defaultReplyErrorHandler(replyPacket.errorCode());
924             DataInputStream JavaDoc replyData = replyPacket.dataInStream();
925         
926             fVersionDescription = readString("version descr.", replyData); //$NON-NLS-1$
927
fJdwpMajorVersion = readInt("major version", replyData); //$NON-NLS-1$
928
fJdwpMinorVersion = readInt("minor version", replyData); //$NON-NLS-1$
929
fVMVersion = readString("version", replyData); //$NON-NLS-1$
930
fVMName = readString("name", replyData); //$NON-NLS-1$
931

932             if ((fVMName != null) && fVMName.equals("KVM")) { //$NON-NLS-1$
933
// KVM requires class preparation events in order
934
// to resolve things correctly
935
eventRequestManagerImpl().enableInternalClassPrepareEvent();
936             }
937
938         } catch (IOException JavaDoc e) {
939 e.printStackTrace();
940             fVersionDescription = null;
941             defaultIOExceptionHandler(e);
942         } finally {
943             handledJdwpRequest();
944         }
945     }
946         
947     /**
948      * Retrieves the HCR capabilities of the VM.
949      */

950     public void getHCRCapabilities() {
951         if (fHcrCapabilities != null)
952             return;
953         fHcrCapabilities = new boolean[HCR_CAN_REENTER_ON_EXIT + 1];
954         
955         if (isHCRSupported()) {
956             initJdwpRequest();
957             try {
958                 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.HCR_CAPABILITIES);
959                 defaultReplyErrorHandler(replyPacket.errorCode());
960                 DataInputStream JavaDoc replyData = replyPacket.dataInStream();
961             
962                 fHcrCapabilities[HCR_CAN_RELOAD_CLASSES] = readBoolean("reload classes", replyData); //$NON-NLS-1$
963
fHcrCapabilities[HCR_CAN_GET_CLASS_VERSION] = readBoolean("get class version", replyData); //$NON-NLS-1$
964
fHcrCapabilities[HCR_CAN_DO_RETURN] = readBoolean("do return", replyData); //$NON-NLS-1$
965
fHcrCapabilities[HCR_CAN_REENTER_ON_EXIT] = readBoolean("reenter on exit", replyData); //$NON-NLS-1$
966
} catch (IOException JavaDoc e) {
967                 fHcrCapabilities = null;
968                 defaultIOExceptionHandler(e);
969             } finally {
970                 handledJdwpRequest();
971             }
972         } else {
973             for (int i = 0; i < fHcrCapabilities.length; i++) {
974                 fHcrCapabilities[i] = false;
975             }
976         }
977     }
978     
979     /**
980      * @return Returns Whether VM can deal with the 'Classes have Changed' command.
981      */

982     public boolean canReloadClasses() {
983         getHCRCapabilities();
984         return fHcrCapabilities[HCR_CAN_RELOAD_CLASSES];
985     }
986     
987     /**
988      * @return Returns Whether VM can get the version of a given class file.
989      */

990     public boolean canGetClassFileVersion1() {
991         getHCRCapabilities();
992         return fHcrCapabilities[HCR_CAN_GET_CLASS_VERSION];
993     }
994     
995     /**
996      * @see com.sun.jdi.VirtualMachine#canGetClassFileVersion()
997      * @since 3.3
998      */

999     public boolean canGetClassFileVersion() {
1000        return isJdwpVersionGreaterOrEqual(1, 6);
1001    }
1002    
1003    /**
1004     * @see com.sun.jdi.VirtualMachine#canGetConstantPool()
1005     * @since 3.3
1006     */

1007    public boolean canGetConstantPool() {
1008        getCapabilities();
1009        return fCanGetConstantPool;
1010    }
1011    
1012    /**
1013     * @return Returns Whether VM can do a return in the middle of executing a method.
1014     */

1015    public boolean canDoReturn() {
1016        getHCRCapabilities();
1017        return fHcrCapabilities[HCR_CAN_DO_RETURN];
1018    }
1019    
1020    /**
1021     * @return Returns Whether VM can reenter a method on exit.
1022     */

1023    public boolean canReenterOnExit() {
1024        getHCRCapabilities();
1025        return fHcrCapabilities[HCR_CAN_REENTER_ON_EXIT];
1026    }
1027    
1028    /**
1029     * Notify the VM that classes have changed due to Hot Code Replacement.
1030     * @return Returns RELOAD_SUCCESS, RELOAD_FAILURE or RELOAD_IGNORED.
1031     */

1032    public int classesHaveChanged(String JavaDoc[] names) {
1033        checkHCRSupported();
1034        // We convert the class/interface names to signatures.
1035
String JavaDoc[] signatures = new String JavaDoc[names.length];
1036        
1037        initJdwpRequest();
1038        try {
1039            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1040            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1041            writeInt(names.length, "length", outData); //$NON-NLS-1$
1042
for (int i = 0; i < names.length; i++) {
1043                signatures[i] = TypeImpl.classNameToSignature(names[i]);
1044                writeString(signatures[i], "signature", outData); //$NON-NLS-1$
1045
}
1046        
1047            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.HCR_CLASSES_HAVE_CHANGED, outBytes);
1048            defaultReplyErrorHandler(replyPacket.errorCode());
1049            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1050        
1051            byte resultFlag = readByte("result", resultHCRMap(), replyData); //$NON-NLS-1$
1052
switch (resultFlag) {
1053                case HCR_RELOAD_SUCCESS:
1054                    return RELOAD_SUCCESS;
1055                case HCR_RELOAD_FAILURE:
1056                    return RELOAD_FAILURE;
1057                case HCR_RELOAD_IGNORED:
1058                    return RELOAD_IGNORED;
1059            }
1060            throw new InternalError JavaDoc(JDIMessages.VirtualMachineImpl_Invalid_result_flag_in_Classes_Have_Changed_response___3 + resultFlag + JDIMessages.VirtualMachineImpl__4); //
1061
} catch (IOException JavaDoc e) {
1062            defaultIOExceptionHandler(e);
1063            return 0;
1064        } finally {
1065            handledJdwpRequest();
1066        }
1067    }
1068
1069    /**
1070     * @return Returns description of Mirror object.
1071     */

1072    public String JavaDoc toString() {
1073        try {
1074            return name();
1075        } catch (Exception JavaDoc e) {
1076            return fDescription;
1077        }
1078    }
1079
1080    /**
1081     * Retrieves constant mappings.
1082     */

1083    public static void getConstantMaps() {
1084        if (fgHCRResultMap != null) {
1085            return;
1086        }
1087        
1088        Field JavaDoc[] fields = VirtualMachineImpl.class.getDeclaredFields();
1089        fgHCRResultMap = new HashMap JavaDoc();
1090        for (int i = 0; i < fields.length; i++) {
1091            Field JavaDoc field = fields[i];
1092            if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0) {
1093                continue;
1094            }
1095                
1096            try {
1097                String JavaDoc name = field.getName();
1098                if (name.startsWith("HCR_RELOAD_")) { //$NON-NLS-1$
1099
Integer JavaDoc intValue = new Integer JavaDoc(field.getInt(null));
1100                    name = name.substring(4);
1101                    fgHCRResultMap.put(intValue, name);
1102                }
1103            } catch (IllegalAccessException JavaDoc e) {
1104                // Will not occur for own class.
1105
} catch (IllegalArgumentException JavaDoc e) {
1106                // Should not occur.
1107
// We should take care that all public static final constants
1108
// in this class are numbers that are convertible to int.
1109
}
1110        }
1111    }
1112    
1113    /**
1114     * @return Returns a map with string representations of tags.
1115     */

1116     public static Map JavaDoc resultHCRMap() {
1117        getConstantMaps();
1118        return fgHCRResultMap;
1119     }
1120     
1121    /**
1122     * Sets request timeout in ms.
1123     */

1124    public void setRequestTimeout(int timeout) {
1125        fRequestTimeout = timeout;
1126    }
1127    
1128    /**
1129     * @return Returns request timeout in ms.
1130     */

1131    public int getRequestTimeout() {
1132        return fRequestTimeout;
1133    }
1134    
1135    /**
1136     * Returns whether the JDWP version is greater
1137     * than or equal to the specified major/minor
1138     * version numbers.
1139     *
1140     * @return whether the JDWP version is greater
1141     * than or equal to the specified major/minor
1142     * version numbers
1143     */

1144    public boolean isJdwpVersionGreaterOrEqual(int major, int minor) {
1145        getVersionInfo();
1146        return (fJdwpMajorVersion > major) ||
1147            (fJdwpMajorVersion == major && fJdwpMinorVersion >= minor);
1148    }
1149    
1150    public void redefineClasses(Map JavaDoc typesToBytes) {
1151        if (!canRedefineClasses()) {
1152            throw new UnsupportedOperationException JavaDoc();
1153        }
1154        
1155        initJdwpRequest();
1156        try {
1157            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1158            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1159            writeInt(typesToBytes.size(), "classes", outData); //$NON-NLS-1$
1160

1161            Set JavaDoc types = typesToBytes.keySet();
1162            Iterator JavaDoc iter = types.iterator();
1163            while (iter.hasNext()) {
1164                ReferenceTypeImpl type = (ReferenceTypeImpl) iter.next();
1165                type.write(this, outData);
1166                byte[] bytes = (byte[]) typesToBytes.get(type);
1167                writeInt(bytes.length, "classfile", outData); //$NON-NLS-1$
1168
for (int i=0; i < bytes.length; i++) {
1169                    writeByte(bytes[i], "classByte", outData); //$NON-NLS-1$
1170
}
1171                fCachedReftypes.remove(type.getRefTypeID()); // flush local cache of redefined types
1172
}
1173            
1174            JdwpReplyPacket reply = requestVM(JdwpCommandPacket.VM_REDEFINE_CLASSES, outBytes);
1175            switch (reply.errorCode()) {
1176                case JdwpReplyPacket.UNSUPPORTED_VERSION:
1177                    throw new UnsupportedClassVersionError JavaDoc();
1178                case JdwpReplyPacket.INVALID_CLASS_FORMAT:
1179                    throw new ClassFormatError JavaDoc();
1180                case JdwpReplyPacket.CIRCULAR_CLASS_DEFINITION:
1181                    throw new ClassCircularityError JavaDoc();
1182                case JdwpReplyPacket.FAILS_VERIFICATION:
1183                    throw new VerifyError JavaDoc();
1184                case JdwpReplyPacket.NAMES_DONT_MATCH:
1185                    throw new NoClassDefFoundError JavaDoc();
1186                case JdwpReplyPacket.ADD_METHOD_NOT_IMPLEMENTED:
1187                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Add_method_not_implemented_1);
1188                case JdwpReplyPacket.SCHEMA_CHANGE_NOT_IMPLEMENTED:
1189                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Scheme_change_not_implemented_2);
1190                case JdwpReplyPacket.HIERARCHY_CHANGE_NOT_IMPLEMENTED:
1191                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Hierarchy_change_not_implemented_3);
1192                case JdwpReplyPacket.DELETE_METHOD_NOT_IMPLEMENTED:
1193                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Delete_method_not_implemented_4);
1194                case JdwpReplyPacket.CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
1195                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Class_modifiers_change_not_implemented_5);
1196                case JdwpReplyPacket.METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
1197                    throw new UnsupportedOperationException JavaDoc(JDIMessages.VirtualMachineImpl_Method_modifiers_change_not_implemented_6);
1198                default:
1199                    defaultReplyErrorHandler(reply.errorCode());
1200            }
1201        } catch (IOException JavaDoc ioe) {
1202            defaultIOExceptionHandler(ioe);
1203            return;
1204        } finally {
1205            handledJdwpRequest();
1206        }
1207    }
1208
1209    /*
1210     * @see VirtualMachine#canRedefineClasses()
1211     */

1212    public boolean canRedefineClasses() {
1213        getCapabilities();
1214        return fCanRedefineClasses;
1215    }
1216
1217    /*
1218     * @see VirtualMachine#canUseInstanceFilters()
1219     */

1220    public boolean canUseInstanceFilters() {
1221        getCapabilities();
1222        return fCanUseInstanceFilters;
1223    }
1224
1225    /*
1226     * @see VirtualMachine#canAddMethod()
1227     */

1228    public boolean canAddMethod() {
1229        getCapabilities();
1230        return fCanAddMethod;
1231    }
1232
1233    /*
1234     * @see VirtualMachine#canUnrestrictedlyRedefineClasses()
1235     */

1236    public boolean canUnrestrictedlyRedefineClasses() {
1237        getCapabilities();
1238        return fCanUnrestrictedlyRedefineClasses;
1239    }
1240
1241    /**
1242     * @see com.sun.jdi.VirtualMachine#canUseSourceNameFilters()
1243     * @since 3.3
1244     */

1245    public boolean canUseSourceNameFilters() {
1246        getCapabilities();
1247        return fCanUseSourceNameFilters;
1248    }
1249    
1250    /*
1251     * @see VirtualMachine#canPopFrames()
1252     */

1253    public boolean canPopFrames() {
1254        getCapabilities();
1255        return fCanPopFrames;
1256    }
1257
1258    /*
1259     * @see VirtualMachine#canGetSourceDebugExtension()
1260     */

1261    public boolean canGetSourceDebugExtension() {
1262        getCapabilities();
1263        return fCanGetSourceDebugExtension;
1264    }
1265
1266    /*
1267     * @see VirtualMachine#canRequestVMDeathEvent()
1268     */

1269    public boolean canRequestVMDeathEvent() {
1270        getCapabilities();
1271        return fCanRequestVMDeathEvent;
1272    }
1273    
1274    public boolean canSetDefaultStratum() {
1275        getCapabilities();
1276        return fCanSetDefaultStratum;
1277    }
1278
1279    /*
1280     * @see VirtualMachine#setDefaultStratum(String)
1281     */

1282    public void setDefaultStratum(String JavaDoc stratum) {
1283        fDefaultStratum= stratum;
1284        
1285        if (!canSetDefaultStratum()) {
1286            // TODO: how to inform the user that the VM doesn't manage setDefaultStartum ?
1287
return;
1288        }
1289        if (stratum == null) {
1290            stratum= ""; //$NON-NLS-1$
1291
}
1292        initJdwpRequest();
1293        try {
1294            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1295            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1296            writeString(stratum, "stratum ID", outData); //$NON-NLS-1$
1297

1298            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_SET_DEFAULT_STRATUM, outBytes);
1299            defaultReplyErrorHandler(replyPacket.errorCode());
1300            
1301        } catch (IOException JavaDoc e) {
1302            defaultIOExceptionHandler(e);
1303        } finally {
1304            handledJdwpRequest();
1305        }
1306    }
1307    
1308    /*
1309     * @see VirtualMachine#getDefaultStratum()
1310     */

1311    public String JavaDoc getDefaultStratum() {
1312        return fDefaultStratum;
1313    }
1314    
1315    /**
1316     * @see com.sun.jdi.VirtualMachine#instanceCounts(java.util.List)
1317     * @since 3.3
1318     */

1319    public long[] instanceCounts(List JavaDoc refTypes) {
1320        if(refTypes == null) {
1321            throw new NullPointerException JavaDoc(JDIMessages.VirtualMachineImpl_2);
1322        }
1323        int size = refTypes.size();
1324        if(size == 0) {
1325            if (isJdwpVersionGreaterOrEqual(1, 6)) {
1326                return new long[0];
1327            } else {
1328                throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_27);
1329            }
1330        }
1331        try {
1332            ByteArrayOutputStream JavaDoc outBytes = new ByteArrayOutputStream JavaDoc();
1333            DataOutputStream JavaDoc outData = new DataOutputStream JavaDoc(outBytes);
1334            writeInt(size, "size", outData); //$NON-NLS-1$
1335
for(int i = 0; i < size; i++) {
1336                ((ReferenceTypeImpl)refTypes.get(i)).getRefTypeID().write(outData);
1337            }
1338            JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.VM_INSTANCE_COUNTS, outBytes);
1339            switch(replyPacket.errorCode()) {
1340                case JdwpReplyPacket.INVALID_CLASS:
1341                case JdwpReplyPacket.INVALID_OBJECT:
1342                    throw new ObjectCollectedException(JDIMessages.class_or_object_not_known);
1343                case JdwpReplyPacket.ILLEGAL_ARGUMENT:
1344                    throw new IllegalArgumentException JavaDoc(JDIMessages.VirtualMachineImpl_count_less_than_zero);
1345                case JdwpReplyPacket.NOT_IMPLEMENTED:
1346                    throw new UnsupportedOperationException JavaDoc(JDIMessages.ReferenceTypeImpl_27);
1347                case JdwpReplyPacket.VM_DEAD:
1348                    throw new VMDisconnectedException(JDIMessages.vm_dead);
1349            }
1350            defaultReplyErrorHandler(replyPacket.errorCode());
1351            
1352            DataInputStream JavaDoc replyData = replyPacket.dataInStream();
1353            int counts = readInt("counts", replyData); //$NON-NLS-1$
1354
if(counts != size) {
1355                throw new InternalError JavaDoc(JDIMessages.VirtualMachineImpl_3);
1356            }
1357            long[] ret = new long[counts];
1358            for(int i = 0; i < counts; i++) {
1359                ret[i] = readLong("ref count", replyData); //$NON-NLS-1$
1360
}
1361            return ret;
1362        }
1363        catch(IOException JavaDoc e) {
1364            defaultIOExceptionHandler(e);
1365            return null;
1366        } finally {
1367            handledJdwpRequest();
1368        }
1369    }
1370    
1371    /**
1372     * Returns whether this VM is disconnected.
1373     *
1374     * @return whether this VM is disconnected
1375     */

1376    public boolean isDisconnected() {
1377        return fIsDisconnected;
1378    }
1379
1380    /**
1381     * Sets whether this VM is disconnected.
1382     *
1383     * @param disconected whether this VM is disconnected
1384     */

1385    public synchronized void setDisconnected(boolean disconnected) {
1386        fIsDisconnected = disconnected;
1387    }
1388    
1389    /**
1390     * Return the boolean type for this VM.
1391     */

1392    protected BooleanTypeImpl getBooleanType() {
1393        if (fBooleanType == null) {
1394            fBooleanType= new BooleanTypeImpl(this);
1395        }
1396        return fBooleanType;
1397    }
1398
1399    /**
1400     * Return the byte type for this VM.
1401     */

1402    protected ByteTypeImpl getByteType() {
1403        if (fByteType == null) {
1404            fByteType= new ByteTypeImpl(this);
1405        }
1406        return fByteType;
1407    }
1408
1409    /**
1410     * Return the char type for this VM.
1411     */

1412    protected CharTypeImpl getCharType() {
1413        if (fCharType == null) {
1414            fCharType= new CharTypeImpl(this);
1415        }
1416        return fCharType;
1417    }
1418
1419    /**
1420     * Return the double type for this VM.
1421     */

1422    protected DoubleTypeImpl getDoubleType() {
1423        if (fDoubleType == null) {
1424            fDoubleType= new DoubleTypeImpl(this);
1425        }
1426        return fDoubleType;
1427    }
1428
1429    /**
1430     * Return the float type for this VM.
1431     */

1432    protected FloatTypeImpl getFloatType() {
1433        if (fFloatType == null) {
1434            fFloatType= new FloatTypeImpl(this);
1435        }
1436        return fFloatType;
1437    }
1438
1439    /**
1440     * Return the integer type for this VM.
1441     */

1442    protected IntegerTypeImpl getIntegerType() {
1443        if (fIntegerType == null) {
1444            fIntegerType= new IntegerTypeImpl(this);
1445        }
1446        return fIntegerType;
1447    }
1448
1449    /**
1450     * Return the long type for this VM.
1451     */

1452    protected LongTypeImpl getLongType() {
1453        if (fLongType == null) {
1454            fLongType= new LongTypeImpl(this);
1455        }
1456        return fLongType;
1457    }
1458
1459    /**
1460     * Return the short type for this VM.
1461     */

1462    protected ShortTypeImpl getShortType() {
1463        if (fShortType == null) {
1464            fShortType= new ShortTypeImpl(this);
1465        }
1466        return fShortType;
1467    }
1468    
1469    /*
1470     * (non-Javadoc)
1471     * @see com.sun.jdi.VirtualMachine#canBeModified()
1472     */

1473    public boolean canBeModified() {
1474        return true;
1475    }
1476
1477}
1478
Popular Tags