2
|
1 |
/*
|
|
2 |
* Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.jdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.connect.spi.Connection;
|
|
30 |
import com.sun.jdi.request.EventRequestManager;
|
|
31 |
import com.sun.jdi.request.EventRequest;
|
|
32 |
import com.sun.jdi.request.BreakpointRequest;
|
|
33 |
import com.sun.jdi.event.EventQueue;
|
|
34 |
|
|
35 |
import java.util.*;
|
|
36 |
import java.text.MessageFormat;
|
|
37 |
import java.lang.ref.ReferenceQueue;
|
|
38 |
import java.lang.ref.Reference;
|
|
39 |
import java.lang.ref.SoftReference;
|
|
40 |
import java.lang.ref.WeakReference;
|
|
41 |
|
|
42 |
class VirtualMachineImpl extends MirrorImpl
|
|
43 |
implements PathSearchingVirtualMachine, ThreadListener {
|
|
44 |
// VM Level exported variables, these
|
|
45 |
// are unique to a given vm
|
|
46 |
public final int sizeofFieldRef;
|
|
47 |
public final int sizeofMethodRef;
|
|
48 |
public final int sizeofObjectRef;
|
|
49 |
public final int sizeofClassRef;
|
|
50 |
public final int sizeofFrameRef;
|
|
51 |
|
|
52 |
final int sequenceNumber;
|
|
53 |
|
|
54 |
private final TargetVM target;
|
|
55 |
private final EventQueueImpl eventQueue;
|
|
56 |
private final EventRequestManagerImpl internalEventRequestManager;
|
|
57 |
private final EventRequestManagerImpl eventRequestManager;
|
|
58 |
final VirtualMachineManagerImpl vmManager;
|
|
59 |
private final ThreadGroup threadGroupForJDI;
|
|
60 |
|
|
61 |
// Allow direct access to this field so that that tracing code slows down
|
|
62 |
// JDI as little as possible when not enabled.
|
|
63 |
int traceFlags = TRACE_NONE;
|
|
64 |
|
|
65 |
static int TRACE_RAW_SENDS = 0x01000000;
|
|
66 |
static int TRACE_RAW_RECEIVES = 0x02000000;
|
|
67 |
|
|
68 |
boolean traceReceives = false; // pre-compute because of frequency
|
|
69 |
|
|
70 |
// ReferenceType access - updated with class prepare and unload events
|
|
71 |
// Protected by "synchronized(this)". "retrievedAllTypes" may be
|
|
72 |
// tested unsynchronized (since once true, it stays true), but must
|
|
73 |
// be set synchronously
|
|
74 |
private Map<Long, ReferenceType> typesByID;
|
|
75 |
private TreeSet<ReferenceType> typesBySignature;
|
|
76 |
private boolean retrievedAllTypes = false;
|
|
77 |
|
|
78 |
// For other languages support
|
|
79 |
private String defaultStratum = null;
|
|
80 |
|
|
81 |
// ObjectReference cache
|
|
82 |
// "objectsByID" protected by "synchronized(this)".
|
|
83 |
private final Map<Long, SoftObjectReference> objectsByID = new HashMap<Long, SoftObjectReference>();
|
|
84 |
private final ReferenceQueue<ObjectReferenceImpl> referenceQueue = new ReferenceQueue<ObjectReferenceImpl>();
|
|
85 |
static private final int DISPOSE_THRESHOLD = 50;
|
|
86 |
private final List<SoftObjectReference> batchedDisposeRequests =
|
|
87 |
Collections.synchronizedList(new ArrayList<SoftObjectReference>(DISPOSE_THRESHOLD + 10));
|
|
88 |
|
|
89 |
// These are cached once for the life of the VM
|
|
90 |
private JDWP.VirtualMachine.Version versionInfo;
|
|
91 |
private JDWP.VirtualMachine.ClassPaths pathInfo;
|
|
92 |
private JDWP.VirtualMachine.Capabilities capabilities = null;
|
|
93 |
private JDWP.VirtualMachine.CapabilitiesNew capabilitiesNew = null;
|
|
94 |
|
|
95 |
// Per-vm singletons for primitive types and for void.
|
|
96 |
// singleton-ness protected by "synchronized(this)".
|
|
97 |
private BooleanType theBooleanType;
|
|
98 |
private ByteType theByteType;
|
|
99 |
private CharType theCharType;
|
|
100 |
private ShortType theShortType;
|
|
101 |
private IntegerType theIntegerType;
|
|
102 |
private LongType theLongType;
|
|
103 |
private FloatType theFloatType;
|
|
104 |
private DoubleType theDoubleType;
|
|
105 |
|
|
106 |
private VoidType theVoidType;
|
|
107 |
|
|
108 |
private VoidValue voidVal;
|
|
109 |
|
|
110 |
// Launched debuggee process
|
|
111 |
private Process process;
|
|
112 |
|
|
113 |
// coordinates state changes and corresponding listener notifications
|
|
114 |
private VMState state = new VMState(this);
|
|
115 |
|
|
116 |
private Object initMonitor = new Object();
|
|
117 |
private boolean initComplete = false;
|
|
118 |
private boolean shutdown = false;
|
|
119 |
|
|
120 |
private void notifyInitCompletion() {
|
|
121 |
synchronized(initMonitor) {
|
|
122 |
initComplete = true;
|
|
123 |
initMonitor.notifyAll();
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
void waitInitCompletion() {
|
|
128 |
synchronized(initMonitor) {
|
|
129 |
while (!initComplete) {
|
|
130 |
try {
|
|
131 |
initMonitor.wait();
|
|
132 |
} catch (InterruptedException e) {
|
|
133 |
// ignore
|
|
134 |
}
|
|
135 |
}
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
VMState state() {
|
|
140 |
return state;
|
|
141 |
}
|
|
142 |
|
|
143 |
/*
|
|
144 |
* ThreadListener implementation
|
|
145 |
*/
|
|
146 |
public boolean threadResumable(ThreadAction action) {
|
|
147 |
/*
|
|
148 |
* If any thread is resumed, the VM is considered not suspended.
|
|
149 |
*/
|
|
150 |
state.thaw();
|
|
151 |
return true;
|
|
152 |
}
|
|
153 |
|
|
154 |
VirtualMachineImpl(VirtualMachineManager manager,
|
|
155 |
Connection connection, Process process,
|
|
156 |
int sequenceNumber) {
|
|
157 |
super(null); // Can't use super(this)
|
|
158 |
vm = this;
|
|
159 |
|
|
160 |
this.vmManager = (VirtualMachineManagerImpl)manager;
|
|
161 |
this.process = process;
|
|
162 |
this.sequenceNumber = sequenceNumber;
|
|
163 |
|
|
164 |
/* Create ThreadGroup to be used by all threads servicing
|
|
165 |
* this VM.
|
|
166 |
*/
|
|
167 |
threadGroupForJDI = new ThreadGroup(vmManager.mainGroupForJDI(),
|
|
168 |
"JDI [" +
|
|
169 |
this.hashCode() + "]");
|
|
170 |
|
|
171 |
/*
|
|
172 |
* Set up a thread to communicate with the target VM over
|
|
173 |
* the specified transport.
|
|
174 |
*/
|
|
175 |
target = new TargetVM(this, connection);
|
|
176 |
|
|
177 |
/*
|
|
178 |
* Set up a thread to handle events processed internally
|
|
179 |
* the JDI implementation.
|
|
180 |
*/
|
|
181 |
EventQueueImpl internalEventQueue = new EventQueueImpl(this, target);
|
|
182 |
new InternalEventHandler(this, internalEventQueue);
|
|
183 |
/*
|
|
184 |
* Initialize client access to event setting and handling
|
|
185 |
*/
|
|
186 |
eventQueue = new EventQueueImpl(this, target);
|
|
187 |
eventRequestManager = new EventRequestManagerImpl(this);
|
|
188 |
|
|
189 |
target.start();
|
|
190 |
|
|
191 |
/*
|
|
192 |
* Many ids are variably sized, depending on target VM.
|
|
193 |
* Find out the sizes right away.
|
|
194 |
*/
|
|
195 |
JDWP.VirtualMachine.IDSizes idSizes;
|
|
196 |
try {
|
|
197 |
idSizes = JDWP.VirtualMachine.IDSizes.process(vm);
|
|
198 |
} catch (JDWPException exc) {
|
|
199 |
throw exc.toJDIException();
|
|
200 |
}
|
|
201 |
sizeofFieldRef = idSizes.fieldIDSize;
|
|
202 |
sizeofMethodRef = idSizes.methodIDSize;
|
|
203 |
sizeofObjectRef = idSizes.objectIDSize;
|
|
204 |
sizeofClassRef = idSizes.referenceTypeIDSize;
|
|
205 |
sizeofFrameRef = idSizes.frameIDSize;
|
|
206 |
|
|
207 |
/**
|
|
208 |
* Set up requests needed by internal event handler.
|
|
209 |
* Make sure they are distinguished by creating them with
|
|
210 |
* an internal event request manager.
|
|
211 |
*
|
|
212 |
* Warning: create events only with SUSPEND_NONE policy.
|
|
213 |
* In the current implementation other policies will not
|
|
214 |
* be handled correctly when the event comes in. (notfiySuspend()
|
|
215 |
* will not be properly called, and if the event is combined
|
|
216 |
* with external events in the same set, suspend policy is not
|
|
217 |
* correctly determined for the internal vs. external event sets)
|
|
218 |
*/
|
|
219 |
internalEventRequestManager = new EventRequestManagerImpl(this);
|
|
220 |
EventRequest er = internalEventRequestManager.createClassPrepareRequest();
|
|
221 |
er.setSuspendPolicy(EventRequest.SUSPEND_NONE);
|
|
222 |
er.enable();
|
|
223 |
er = internalEventRequestManager.createClassUnloadRequest();
|
|
224 |
er.setSuspendPolicy(EventRequest.SUSPEND_NONE);
|
|
225 |
er.enable();
|
|
226 |
|
|
227 |
/*
|
|
228 |
* Tell other threads, notably TargetVM, that initialization
|
|
229 |
* is complete.
|
|
230 |
*/
|
|
231 |
notifyInitCompletion();
|
|
232 |
}
|
|
233 |
|
|
234 |
EventRequestManagerImpl getInternalEventRequestManager() {
|
|
235 |
return internalEventRequestManager;
|
|
236 |
}
|
|
237 |
|
|
238 |
void validateVM() {
|
|
239 |
/*
|
|
240 |
* We no longer need to do this. The spec now says
|
|
241 |
* that a VMDisconnected _may_ be thrown in these
|
|
242 |
* cases, not that it _will_ be thrown.
|
|
243 |
* So, to simplify things we will just let the
|
|
244 |
* caller's of this method proceed with their business.
|
|
245 |
* If the debuggee is disconnected, either because it
|
|
246 |
* crashed or finished or something, or because the
|
|
247 |
* debugger called exit() or dispose(), then if
|
|
248 |
* we end up trying to communicate with the debuggee,
|
|
249 |
* code in TargetVM will throw a VMDisconnectedException.
|
|
250 |
* This means that if we can satisfy a request without
|
|
251 |
* talking to the debuggee, (eg, with cached data) then
|
|
252 |
* VMDisconnectedException will _not_ be thrown.
|
|
253 |
* if (shutdown) {
|
|
254 |
* throw new VMDisconnectedException();
|
|
255 |
* }
|
|
256 |
*/
|
|
257 |
}
|
|
258 |
|
|
259 |
public boolean equals(Object obj) {
|
|
260 |
return this == obj;
|
|
261 |
}
|
|
262 |
|
|
263 |
public int hashCode() {
|
|
264 |
return System.identityHashCode(this);
|
|
265 |
}
|
|
266 |
|
|
267 |
public List<ReferenceType> classesByName(String className) {
|
|
268 |
validateVM();
|
|
269 |
String signature = JNITypeParser.typeNameToSignature(className);
|
|
270 |
List<ReferenceType> list;
|
|
271 |
if (retrievedAllTypes) {
|
|
272 |
list = findReferenceTypes(signature);
|
|
273 |
} else {
|
|
274 |
list = retrieveClassesBySignature(signature);
|
|
275 |
}
|
|
276 |
return Collections.unmodifiableList(list);
|
|
277 |
}
|
|
278 |
|
|
279 |
public List<ReferenceType> allClasses() {
|
|
280 |
validateVM();
|
|
281 |
|
|
282 |
if (!retrievedAllTypes) {
|
|
283 |
retrieveAllClasses();
|
|
284 |
}
|
|
285 |
ArrayList<ReferenceType> a;
|
|
286 |
synchronized (this) {
|
|
287 |
a = new ArrayList<ReferenceType>(typesBySignature);
|
|
288 |
}
|
|
289 |
return Collections.unmodifiableList(a);
|
|
290 |
}
|
|
291 |
|
|
292 |
public void
|
|
293 |
redefineClasses(Map<? extends ReferenceType,byte[]> classToBytes)
|
|
294 |
{
|
|
295 |
int cnt = classToBytes.size();
|
|
296 |
JDWP.VirtualMachine.RedefineClasses.ClassDef[] defs =
|
|
297 |
new JDWP.VirtualMachine.RedefineClasses.ClassDef[cnt];
|
|
298 |
validateVM();
|
|
299 |
if (!canRedefineClasses()) {
|
|
300 |
throw new UnsupportedOperationException();
|
|
301 |
}
|
|
302 |
Iterator it = classToBytes.entrySet().iterator();
|
|
303 |
for (int i = 0; it.hasNext(); i++) {
|
|
304 |
Map.Entry entry = (Map.Entry)it.next();
|
|
305 |
ReferenceTypeImpl refType = (ReferenceTypeImpl)entry.getKey();
|
|
306 |
validateMirror(refType);
|
|
307 |
defs[i] = new JDWP.VirtualMachine.RedefineClasses
|
|
308 |
.ClassDef(refType, (byte[])entry.getValue());
|
|
309 |
}
|
|
310 |
|
|
311 |
// flush caches and disable caching until the next suspend
|
|
312 |
vm.state().thaw();
|
|
313 |
|
|
314 |
try {
|
|
315 |
JDWP.VirtualMachine.RedefineClasses.
|
|
316 |
process(vm, defs);
|
|
317 |
} catch (JDWPException exc) {
|
|
318 |
switch (exc.errorCode()) {
|
|
319 |
case JDWP.Error.INVALID_CLASS_FORMAT :
|
|
320 |
throw new ClassFormatError(
|
|
321 |
"class not in class file format");
|
|
322 |
case JDWP.Error.CIRCULAR_CLASS_DEFINITION :
|
|
323 |
throw new ClassCircularityError(
|
|
324 |
"circularity has been detected while initializing a class");
|
|
325 |
case JDWP.Error.FAILS_VERIFICATION :
|
|
326 |
throw new VerifyError(
|
|
327 |
"verifier detected internal inconsistency or security problem");
|
|
328 |
case JDWP.Error.UNSUPPORTED_VERSION :
|
|
329 |
throw new UnsupportedClassVersionError(
|
|
330 |
"version numbers of class are not supported");
|
|
331 |
case JDWP.Error.ADD_METHOD_NOT_IMPLEMENTED:
|
|
332 |
throw new UnsupportedOperationException(
|
|
333 |
"add method not implemented");
|
|
334 |
case JDWP.Error.SCHEMA_CHANGE_NOT_IMPLEMENTED :
|
|
335 |
throw new UnsupportedOperationException(
|
|
336 |
"schema change not implemented");
|
|
337 |
case JDWP.Error.HIERARCHY_CHANGE_NOT_IMPLEMENTED:
|
|
338 |
throw new UnsupportedOperationException(
|
|
339 |
"hierarchy change not implemented");
|
|
340 |
case JDWP.Error.DELETE_METHOD_NOT_IMPLEMENTED :
|
|
341 |
throw new UnsupportedOperationException(
|
|
342 |
"delete method not implemented");
|
|
343 |
case JDWP.Error.CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED:
|
|
344 |
throw new UnsupportedOperationException(
|
|
345 |
"changes to class modifiers not implemented");
|
|
346 |
case JDWP.Error.METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED :
|
|
347 |
throw new UnsupportedOperationException(
|
|
348 |
"changes to method modifiers not implemented");
|
|
349 |
case JDWP.Error.NAMES_DONT_MATCH :
|
|
350 |
throw new NoClassDefFoundError(
|
|
351 |
"class names do not match");
|
|
352 |
default:
|
|
353 |
throw exc.toJDIException();
|
|
354 |
}
|
|
355 |
}
|
|
356 |
|
|
357 |
// Delete any record of the breakpoints
|
|
358 |
List<BreakpointRequest> toDelete = new ArrayList<BreakpointRequest>();
|
|
359 |
EventRequestManager erm = eventRequestManager();
|
|
360 |
it = erm.breakpointRequests().iterator();
|
|
361 |
while (it.hasNext()) {
|
|
362 |
BreakpointRequest req = (BreakpointRequest)it.next();
|
|
363 |
if (classToBytes.containsKey(req.location().declaringType())) {
|
|
364 |
toDelete.add(req);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
erm.deleteEventRequests(toDelete);
|
|
368 |
|
|
369 |
// Invalidate any information cached for the classes just redefined.
|
|
370 |
it = classToBytes.keySet().iterator();
|
|
371 |
while (it.hasNext()) {
|
|
372 |
ReferenceTypeImpl rti = (ReferenceTypeImpl)it.next();
|
|
373 |
rti.noticeRedefineClass();
|
|
374 |
}
|
|
375 |
}
|
|
376 |
|
|
377 |
public List<ThreadReference> allThreads() {
|
|
378 |
validateVM();
|
|
379 |
return state.allThreads();
|
|
380 |
}
|
|
381 |
|
|
382 |
public List<ThreadGroupReference> topLevelThreadGroups() {
|
|
383 |
validateVM();
|
|
384 |
return state.topLevelThreadGroups();
|
|
385 |
}
|
|
386 |
|
|
387 |
/*
|
|
388 |
* Sends a command to the back end which is defined to do an
|
|
389 |
* implicit vm-wide resume. The VM can no longer be considered
|
|
390 |
* suspended, so certain cached data must be invalidated.
|
|
391 |
*/
|
|
392 |
PacketStream sendResumingCommand(CommandSender sender) {
|
|
393 |
return state.thawCommand(sender);
|
|
394 |
}
|
|
395 |
|
|
396 |
/*
|
|
397 |
* The VM has been suspended. Additional caching can be done
|
|
398 |
* as long as there are no pending resumes.
|
|
399 |
*/
|
|
400 |
void notifySuspend() {
|
|
401 |
state.freeze();
|
|
402 |
}
|
|
403 |
|
|
404 |
public void suspend() {
|
|
405 |
validateVM();
|
|
406 |
try {
|
|
407 |
JDWP.VirtualMachine.Suspend.process(vm);
|
|
408 |
} catch (JDWPException exc) {
|
|
409 |
throw exc.toJDIException();
|
|
410 |
}
|
|
411 |
notifySuspend();
|
|
412 |
}
|
|
413 |
|
|
414 |
public void resume() {
|
|
415 |
validateVM();
|
|
416 |
CommandSender sender =
|
|
417 |
new CommandSender() {
|
|
418 |
public PacketStream send() {
|
|
419 |
return JDWP.VirtualMachine.Resume.enqueueCommand(vm);
|
|
420 |
}
|
|
421 |
};
|
|
422 |
try {
|
|
423 |
PacketStream stream = state.thawCommand(sender);
|
|
424 |
JDWP.VirtualMachine.Resume.waitForReply(vm, stream);
|
|
425 |
} catch (VMDisconnectedException exc) {
|
|
426 |
/*
|
|
427 |
* If the debugger makes a VMDeathRequest with SUSPEND_ALL,
|
|
428 |
* then when it does an EventSet.resume after getting the
|
|
429 |
* VMDeathEvent, the normal flow of events is that the
|
|
430 |
* BE shuts down, but the waitForReply comes back ok. In this
|
|
431 |
* case, the run loop in TargetVM that is waiting for a packet
|
|
432 |
* gets an EOF because the socket closes. It generates a
|
|
433 |
* VMDisconnectedEvent and everyone is happy.
|
|
434 |
* However, sometimes, the BE gets shutdown before this
|
|
435 |
* waitForReply completes. In this case, TargetVM.waitForReply
|
|
436 |
* gets awakened with no reply and so gens a VMDisconnectedException
|
|
437 |
* which is not what we want. It might be possible to fix this
|
|
438 |
* in the BE, but it is ok to just ignore the VMDisconnectedException
|
|
439 |
* here. This will allow the VMDisconnectedEvent to be generated
|
|
440 |
* correctly. And, if the debugger should happen to make another
|
|
441 |
* request, it will get a VMDisconnectedException at that time.
|
|
442 |
*/
|
|
443 |
} catch (JDWPException exc) {
|
|
444 |
switch (exc.errorCode()) {
|
|
445 |
case JDWP.Error.VM_DEAD:
|
|
446 |
return;
|
|
447 |
default:
|
|
448 |
throw exc.toJDIException();
|
|
449 |
}
|
|
450 |
}
|
|
451 |
}
|
|
452 |
|
|
453 |
public EventQueue eventQueue() {
|
|
454 |
/*
|
|
455 |
* No VM validation here. We allow access to the event queue
|
|
456 |
* after disconnection, so that there is access to the terminating
|
|
457 |
* events.
|
|
458 |
*/
|
|
459 |
return eventQueue;
|
|
460 |
}
|
|
461 |
|
|
462 |
public EventRequestManager eventRequestManager() {
|
|
463 |
validateVM();
|
|
464 |
return eventRequestManager;
|
|
465 |
}
|
|
466 |
|
|
467 |
EventRequestManagerImpl eventRequestManagerImpl() {
|
|
468 |
return eventRequestManager;
|
|
469 |
}
|
|
470 |
|
|
471 |
public BooleanValue mirrorOf(boolean value) {
|
|
472 |
validateVM();
|
|
473 |
return new BooleanValueImpl(this,value);
|
|
474 |
}
|
|
475 |
|
|
476 |
public ByteValue mirrorOf(byte value) {
|
|
477 |
validateVM();
|
|
478 |
return new ByteValueImpl(this,value);
|
|
479 |
}
|
|
480 |
|
|
481 |
public CharValue mirrorOf(char value) {
|
|
482 |
validateVM();
|
|
483 |
return new CharValueImpl(this,value);
|
|
484 |
}
|
|
485 |
|
|
486 |
public ShortValue mirrorOf(short value) {
|
|
487 |
validateVM();
|
|
488 |
return new ShortValueImpl(this,value);
|
|
489 |
}
|
|
490 |
|
|
491 |
public IntegerValue mirrorOf(int value) {
|
|
492 |
validateVM();
|
|
493 |
return new IntegerValueImpl(this,value);
|
|
494 |
}
|
|
495 |
|
|
496 |
public LongValue mirrorOf(long value) {
|
|
497 |
validateVM();
|
|
498 |
return new LongValueImpl(this,value);
|
|
499 |
}
|
|
500 |
|
|
501 |
public FloatValue mirrorOf(float value) {
|
|
502 |
validateVM();
|
|
503 |
return new FloatValueImpl(this,value);
|
|
504 |
}
|
|
505 |
|
|
506 |
public DoubleValue mirrorOf(double value) {
|
|
507 |
validateVM();
|
|
508 |
return new DoubleValueImpl(this,value);
|
|
509 |
}
|
|
510 |
|
|
511 |
public StringReference mirrorOf(String value) {
|
|
512 |
validateVM();
|
|
513 |
try {
|
|
514 |
return (StringReference)JDWP.VirtualMachine.CreateString.
|
|
515 |
process(vm, value).stringObject;
|
|
516 |
} catch (JDWPException exc) {
|
|
517 |
throw exc.toJDIException();
|
|
518 |
}
|
|
519 |
}
|
|
520 |
|
|
521 |
public VoidValue mirrorOfVoid() {
|
|
522 |
if (voidVal == null) {
|
|
523 |
voidVal = new VoidValueImpl(this);
|
|
524 |
}
|
|
525 |
return voidVal;
|
|
526 |
}
|
|
527 |
|
|
528 |
public long[] instanceCounts(List<? extends ReferenceType> classes) {
|
|
529 |
if (!canGetInstanceInfo()) {
|
|
530 |
throw new UnsupportedOperationException(
|
|
531 |
"target does not support getting instances");
|
|
532 |
}
|
|
533 |
long[] retValue ;
|
|
534 |
ReferenceTypeImpl[] rtArray = new ReferenceTypeImpl[classes.size()];
|
|
535 |
int ii = 0;
|
|
536 |
for (ReferenceType rti: classes) {
|
|
537 |
validateMirror(rti);
|
|
538 |
rtArray[ii++] = (ReferenceTypeImpl)rti;
|
|
539 |
}
|
|
540 |
try {
|
|
541 |
retValue = JDWP.VirtualMachine.InstanceCounts.
|
|
542 |
process(vm, rtArray).counts;
|
|
543 |
} catch (JDWPException exc) {
|
|
544 |
throw exc.toJDIException();
|
|
545 |
}
|
|
546 |
|
|
547 |
return retValue;
|
|
548 |
}
|
|
549 |
|
|
550 |
public void dispose() {
|
|
551 |
validateVM();
|
|
552 |
shutdown = true;
|
|
553 |
try {
|
|
554 |
JDWP.VirtualMachine.Dispose.process(vm);
|
|
555 |
} catch (JDWPException exc) {
|
|
556 |
throw exc.toJDIException();
|
|
557 |
}
|
|
558 |
target.stopListening();
|
|
559 |
}
|
|
560 |
|
|
561 |
public void exit(int exitCode) {
|
|
562 |
validateVM();
|
|
563 |
shutdown = true;
|
|
564 |
try {
|
|
565 |
JDWP.VirtualMachine.Exit.process(vm, exitCode);
|
|
566 |
} catch (JDWPException exc) {
|
|
567 |
throw exc.toJDIException();
|
|
568 |
}
|
|
569 |
target.stopListening();
|
|
570 |
}
|
|
571 |
|
|
572 |
public Process process() {
|
|
573 |
validateVM();
|
|
574 |
return process;
|
|
575 |
}
|
|
576 |
|
|
577 |
private JDWP.VirtualMachine.Version versionInfo() {
|
|
578 |
try {
|
|
579 |
if (versionInfo == null) {
|
|
580 |
// Need not be synchronized since it is static information
|
|
581 |
versionInfo = JDWP.VirtualMachine.Version.process(vm);
|
|
582 |
}
|
|
583 |
return versionInfo;
|
|
584 |
} catch (JDWPException exc) {
|
|
585 |
throw exc.toJDIException();
|
|
586 |
}
|
|
587 |
}
|
|
588 |
public String description() {
|
|
589 |
validateVM();
|
|
590 |
|
|
591 |
return MessageFormat.format(vmManager.getString("version_format"),
|
|
592 |
"" + vmManager.majorInterfaceVersion(),
|
|
593 |
"" + vmManager.minorInterfaceVersion(),
|
|
594 |
versionInfo().description);
|
|
595 |
}
|
|
596 |
|
|
597 |
public String version() {
|
|
598 |
validateVM();
|
|
599 |
return versionInfo().vmVersion;
|
|
600 |
}
|
|
601 |
|
|
602 |
public String name() {
|
|
603 |
validateVM();
|
|
604 |
return versionInfo().vmName;
|
|
605 |
}
|
|
606 |
|
|
607 |
public boolean canWatchFieldModification() {
|
|
608 |
validateVM();
|
|
609 |
return capabilities().canWatchFieldModification;
|
|
610 |
}
|
|
611 |
public boolean canWatchFieldAccess() {
|
|
612 |
validateVM();
|
|
613 |
return capabilities().canWatchFieldAccess;
|
|
614 |
}
|
|
615 |
public boolean canGetBytecodes() {
|
|
616 |
validateVM();
|
|
617 |
return capabilities().canGetBytecodes;
|
|
618 |
}
|
|
619 |
public boolean canGetSyntheticAttribute() {
|
|
620 |
validateVM();
|
|
621 |
return capabilities().canGetSyntheticAttribute;
|
|
622 |
}
|
|
623 |
public boolean canGetOwnedMonitorInfo() {
|
|
624 |
validateVM();
|
|
625 |
return capabilities().canGetOwnedMonitorInfo;
|
|
626 |
}
|
|
627 |
public boolean canGetCurrentContendedMonitor() {
|
|
628 |
validateVM();
|
|
629 |
return capabilities().canGetCurrentContendedMonitor;
|
|
630 |
}
|
|
631 |
public boolean canGetMonitorInfo() {
|
|
632 |
validateVM();
|
|
633 |
return capabilities().canGetMonitorInfo;
|
|
634 |
}
|
|
635 |
|
|
636 |
private boolean hasNewCapabilities() {
|
|
637 |
return versionInfo().jdwpMajor > 1 ||
|
|
638 |
versionInfo().jdwpMinor >= 4;
|
|
639 |
}
|
|
640 |
|
|
641 |
boolean canGet1_5LanguageFeatures() {
|
|
642 |
return versionInfo().jdwpMajor > 1 ||
|
|
643 |
versionInfo().jdwpMinor >= 5;
|
|
644 |
}
|
|
645 |
|
|
646 |
public boolean canUseInstanceFilters() {
|
|
647 |
validateVM();
|
|
648 |
return hasNewCapabilities() &&
|
|
649 |
capabilitiesNew().canUseInstanceFilters;
|
|
650 |
}
|
|
651 |
public boolean canRedefineClasses() {
|
|
652 |
validateVM();
|
|
653 |
return hasNewCapabilities() &&
|
|
654 |
capabilitiesNew().canRedefineClasses;
|
|
655 |
}
|
|
656 |
public boolean canAddMethod() {
|
|
657 |
validateVM();
|
|
658 |
return hasNewCapabilities() &&
|
|
659 |
capabilitiesNew().canAddMethod;
|
|
660 |
}
|
|
661 |
public boolean canUnrestrictedlyRedefineClasses() {
|
|
662 |
validateVM();
|
|
663 |
return hasNewCapabilities() &&
|
|
664 |
capabilitiesNew().canUnrestrictedlyRedefineClasses;
|
|
665 |
}
|
|
666 |
public boolean canPopFrames() {
|
|
667 |
validateVM();
|
|
668 |
return hasNewCapabilities() &&
|
|
669 |
capabilitiesNew().canPopFrames;
|
|
670 |
}
|
|
671 |
public boolean canGetMethodReturnValues() {
|
|
672 |
return versionInfo().jdwpMajor > 1 ||
|
|
673 |
versionInfo().jdwpMinor >= 6;
|
|
674 |
}
|
|
675 |
public boolean canGetInstanceInfo() {
|
|
676 |
if (versionInfo().jdwpMajor < 1 ||
|
|
677 |
versionInfo().jdwpMinor < 6) {
|
|
678 |
return false;
|
|
679 |
}
|
|
680 |
validateVM();
|
|
681 |
return hasNewCapabilities() &&
|
|
682 |
capabilitiesNew().canGetInstanceInfo;
|
|
683 |
}
|
|
684 |
public boolean canUseSourceNameFilters() {
|
|
685 |
if (versionInfo().jdwpMajor < 1 ||
|
|
686 |
versionInfo().jdwpMinor < 6) {
|
|
687 |
return false;
|
|
688 |
}
|
|
689 |
return true;
|
|
690 |
}
|
|
691 |
public boolean canForceEarlyReturn() {
|
|
692 |
validateVM();
|
|
693 |
return hasNewCapabilities() &&
|
|
694 |
capabilitiesNew().canForceEarlyReturn;
|
|
695 |
}
|
|
696 |
public boolean canBeModified() {
|
|
697 |
return true;
|
|
698 |
}
|
|
699 |
public boolean canGetSourceDebugExtension() {
|
|
700 |
validateVM();
|
|
701 |
return hasNewCapabilities() &&
|
|
702 |
capabilitiesNew().canGetSourceDebugExtension;
|
|
703 |
}
|
|
704 |
public boolean canGetClassFileVersion() {
|
|
705 |
if ( versionInfo().jdwpMajor < 1 &&
|
|
706 |
versionInfo().jdwpMinor < 6) {
|
|
707 |
return false;
|
|
708 |
} else {
|
|
709 |
return true;
|
|
710 |
}
|
|
711 |
}
|
|
712 |
public boolean canGetConstantPool() {
|
|
713 |
validateVM();
|
|
714 |
return hasNewCapabilities() &&
|
|
715 |
capabilitiesNew().canGetConstantPool;
|
|
716 |
}
|
|
717 |
public boolean canRequestVMDeathEvent() {
|
|
718 |
validateVM();
|
|
719 |
return hasNewCapabilities() &&
|
|
720 |
capabilitiesNew().canRequestVMDeathEvent;
|
|
721 |
}
|
|
722 |
public boolean canRequestMonitorEvents() {
|
|
723 |
validateVM();
|
|
724 |
return hasNewCapabilities() &&
|
|
725 |
capabilitiesNew().canRequestMonitorEvents;
|
|
726 |
}
|
|
727 |
public boolean canGetMonitorFrameInfo() {
|
|
728 |
validateVM();
|
|
729 |
return hasNewCapabilities() &&
|
|
730 |
capabilitiesNew().canGetMonitorFrameInfo;
|
|
731 |
}
|
|
732 |
|
|
733 |
public void setDebugTraceMode(int traceFlags) {
|
|
734 |
validateVM();
|
|
735 |
this.traceFlags = traceFlags;
|
|
736 |
this.traceReceives = (traceFlags & TRACE_RECEIVES) != 0;
|
|
737 |
}
|
|
738 |
|
|
739 |
void printTrace(String string) {
|
|
740 |
System.err.println("[JDI: " + string + "]");
|
|
741 |
}
|
|
742 |
|
|
743 |
void printReceiveTrace(int depth, String string) {
|
|
744 |
StringBuffer sb = new StringBuffer("Receiving:");
|
|
745 |
for (int i = depth; i > 0; --i) {
|
|
746 |
sb.append(" ");
|
|
747 |
}
|
|
748 |
sb.append(string);
|
|
749 |
printTrace(sb.toString());
|
|
750 |
}
|
|
751 |
|
|
752 |
private synchronized ReferenceTypeImpl addReferenceType(long id,
|
|
753 |
int tag,
|
|
754 |
String signature) {
|
|
755 |
if (typesByID == null) {
|
|
756 |
initReferenceTypes();
|
|
757 |
}
|
|
758 |
ReferenceTypeImpl type = null;
|
|
759 |
switch(tag) {
|
|
760 |
case JDWP.TypeTag.CLASS:
|
|
761 |
type = new ClassTypeImpl(vm, id);
|
|
762 |
break;
|
|
763 |
case JDWP.TypeTag.INTERFACE:
|
|
764 |
type = new InterfaceTypeImpl(vm, id);
|
|
765 |
break;
|
|
766 |
case JDWP.TypeTag.ARRAY:
|
|
767 |
type = new ArrayTypeImpl(vm, id);
|
|
768 |
break;
|
|
769 |
default:
|
|
770 |
throw new InternalException("Invalid reference type tag");
|
|
771 |
}
|
|
772 |
|
|
773 |
/*
|
|
774 |
* If a signature was specified, make sure to set it ASAP, to
|
|
775 |
* prevent any needless JDWP command to retrieve it. (for example,
|
|
776 |
* typesBySignature.add needs the signature, to maintain proper
|
|
777 |
* ordering.
|
|
778 |
*/
|
|
779 |
if (signature != null) {
|
|
780 |
type.setSignature(signature);
|
|
781 |
}
|
|
782 |
|
|
783 |
typesByID.put(new Long(id), type);
|
|
784 |
typesBySignature.add(type);
|
|
785 |
|
|
786 |
if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
|
|
787 |
vm.printTrace("Caching new ReferenceType, sig=" + signature +
|
|
788 |
", id=" + id);
|
|
789 |
}
|
|
790 |
|
|
791 |
return type;
|
|
792 |
}
|
|
793 |
|
|
794 |
synchronized void removeReferenceType(String signature) {
|
|
795 |
if (typesByID == null) {
|
|
796 |
return;
|
|
797 |
}
|
|
798 |
/*
|
|
799 |
* There can be multiple classes with the same name. Since
|
|
800 |
* we can't differentiate here, we first remove all
|
|
801 |
* matching classes from our cache...
|
|
802 |
*/
|
|
803 |
Iterator iter = typesBySignature.iterator();
|
|
804 |
int matches = 0;
|
|
805 |
while (iter.hasNext()) {
|
|
806 |
ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
|
|
807 |
int comp = signature.compareTo(type.signature());
|
|
808 |
if (comp == 0) {
|
|
809 |
matches++;
|
|
810 |
iter.remove();
|
|
811 |
typesByID.remove(new Long(type.ref()));
|
|
812 |
if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
|
|
813 |
vm.printTrace("Uncaching ReferenceType, sig=" + signature +
|
|
814 |
", id=" + type.ref());
|
|
815 |
}
|
|
816 |
/* fix for 4359077 , don't break out. list is no longer sorted
|
|
817 |
in the order we think
|
|
818 |
*/
|
|
819 |
}
|
|
820 |
}
|
|
821 |
|
|
822 |
/*
|
|
823 |
* ...and if there was more than one, re-retrieve the classes
|
|
824 |
* with that name
|
|
825 |
*/
|
|
826 |
if (matches > 1) {
|
|
827 |
retrieveClassesBySignature(signature);
|
|
828 |
}
|
|
829 |
}
|
|
830 |
|
|
831 |
private synchronized List<ReferenceType> findReferenceTypes(String signature) {
|
|
832 |
if (typesByID == null) {
|
|
833 |
return new ArrayList<ReferenceType>(0);
|
|
834 |
}
|
|
835 |
Iterator iter = typesBySignature.iterator();
|
|
836 |
List<ReferenceType> list = new ArrayList<ReferenceType>();
|
|
837 |
while (iter.hasNext()) {
|
|
838 |
ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
|
|
839 |
int comp = signature.compareTo(type.signature());
|
|
840 |
if (comp == 0) {
|
|
841 |
list.add(type);
|
|
842 |
/* fix for 4359077 , don't break out. list is no longer sorted
|
|
843 |
in the order we think
|
|
844 |
*/
|
|
845 |
}
|
|
846 |
}
|
|
847 |
return list;
|
|
848 |
}
|
|
849 |
|
|
850 |
private void initReferenceTypes() {
|
|
851 |
typesByID = new HashMap<Long, ReferenceType>(300);
|
|
852 |
typesBySignature = new TreeSet<ReferenceType>();
|
|
853 |
}
|
|
854 |
|
|
855 |
ReferenceTypeImpl referenceType(long ref, byte tag) {
|
|
856 |
return referenceType(ref, tag, null);
|
|
857 |
}
|
|
858 |
|
|
859 |
ClassTypeImpl classType(long ref) {
|
|
860 |
return (ClassTypeImpl)referenceType(ref, JDWP.TypeTag.CLASS, null);
|
|
861 |
}
|
|
862 |
|
|
863 |
InterfaceTypeImpl interfaceType(long ref) {
|
|
864 |
return (InterfaceTypeImpl)referenceType(ref, JDWP.TypeTag.INTERFACE, null);
|
|
865 |
}
|
|
866 |
|
|
867 |
ArrayTypeImpl arrayType(long ref) {
|
|
868 |
return (ArrayTypeImpl)referenceType(ref, JDWP.TypeTag.ARRAY, null);
|
|
869 |
}
|
|
870 |
|
|
871 |
ReferenceTypeImpl referenceType(long id, int tag,
|
|
872 |
String signature) {
|
|
873 |
if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
|
|
874 |
StringBuffer sb = new StringBuffer();
|
|
875 |
sb.append("Looking up ");
|
|
876 |
if (tag == JDWP.TypeTag.CLASS) {
|
|
877 |
sb.append("Class");
|
|
878 |
} else if (tag == JDWP.TypeTag.INTERFACE) {
|
|
879 |
sb.append("Interface");
|
|
880 |
} else if (tag == JDWP.TypeTag.ARRAY) {
|
|
881 |
sb.append("ArrayType");
|
|
882 |
} else {
|
|
883 |
sb.append("UNKNOWN TAG: " + tag);
|
|
884 |
}
|
|
885 |
if (signature != null) {
|
|
886 |
sb.append(", signature='" + signature + "'");
|
|
887 |
}
|
|
888 |
sb.append(", id=" + id);
|
|
889 |
vm.printTrace(sb.toString());
|
|
890 |
}
|
|
891 |
if (id == 0) {
|
|
892 |
return null;
|
|
893 |
} else {
|
|
894 |
ReferenceTypeImpl retType = null;
|
|
895 |
synchronized (this) {
|
|
896 |
if (typesByID != null) {
|
|
897 |
retType = (ReferenceTypeImpl)typesByID.get(new Long(id));
|
|
898 |
}
|
|
899 |
if (retType == null) {
|
|
900 |
retType = addReferenceType(id, tag, signature);
|
|
901 |
}
|
|
902 |
}
|
|
903 |
return retType;
|
|
904 |
}
|
|
905 |
}
|
|
906 |
|
|
907 |
private JDWP.VirtualMachine.Capabilities capabilities() {
|
|
908 |
if (capabilities == null) {
|
|
909 |
try {
|
|
910 |
capabilities = JDWP.VirtualMachine
|
|
911 |
.Capabilities.process(vm);
|
|
912 |
} catch (JDWPException exc) {
|
|
913 |
throw exc.toJDIException();
|
|
914 |
}
|
|
915 |
}
|
|
916 |
return capabilities;
|
|
917 |
}
|
|
918 |
|
|
919 |
private JDWP.VirtualMachine.CapabilitiesNew capabilitiesNew() {
|
|
920 |
if (capabilitiesNew == null) {
|
|
921 |
try {
|
|
922 |
capabilitiesNew = JDWP.VirtualMachine
|
|
923 |
.CapabilitiesNew.process(vm);
|
|
924 |
} catch (JDWPException exc) {
|
|
925 |
throw exc.toJDIException();
|
|
926 |
}
|
|
927 |
}
|
|
928 |
return capabilitiesNew;
|
|
929 |
}
|
|
930 |
|
|
931 |
private List<ReferenceType> retrieveClassesBySignature(String signature) {
|
|
932 |
if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
|
|
933 |
vm.printTrace("Retrieving matching ReferenceTypes, sig=" + signature);
|
|
934 |
}
|
|
935 |
JDWP.VirtualMachine.ClassesBySignature.ClassInfo[] cinfos;
|
|
936 |
try {
|
|
937 |
cinfos = JDWP.VirtualMachine.ClassesBySignature.
|
|
938 |
process(vm, signature).classes;
|
|
939 |
} catch (JDWPException exc) {
|
|
940 |
throw exc.toJDIException();
|
|
941 |
}
|
|
942 |
|
|
943 |
int count = cinfos.length;
|
|
944 |
List<ReferenceType> list = new ArrayList<ReferenceType>(count);
|
|
945 |
|
|
946 |
// Hold lock during processing to improve performance
|
|
947 |
synchronized (this) {
|
|
948 |
for (int i = 0; i < count; i++) {
|
|
949 |
JDWP.VirtualMachine.ClassesBySignature.ClassInfo ci =
|
|
950 |
cinfos[i];
|
|
951 |
ReferenceTypeImpl type = referenceType(ci.typeID,
|
|
952 |
ci.refTypeTag,
|
|
953 |
signature);
|
|
954 |
type.setStatus(ci.status);
|
|
955 |
list.add(type);
|
|
956 |
}
|
|
957 |
}
|
|
958 |
return list;
|
|
959 |
}
|
|
960 |
|
|
961 |
private void retrieveAllClasses1_4() {
|
|
962 |
JDWP.VirtualMachine.AllClasses.ClassInfo[] cinfos;
|
|
963 |
try {
|
|
964 |
cinfos = JDWP.VirtualMachine.AllClasses.process(vm).classes;
|
|
965 |
} catch (JDWPException exc) {
|
|
966 |
throw exc.toJDIException();
|
|
967 |
}
|
|
968 |
|
|
969 |
// Hold lock during processing to improve performance
|
|
970 |
// and to have safe check/set of retrievedAllTypes
|
|
971 |
synchronized (this) {
|
|
972 |
if (!retrievedAllTypes) {
|
|
973 |
// Number of classes
|
|
974 |
int count = cinfos.length;
|
|
975 |
for (int i=0; i<count; i++) {
|
|
976 |
JDWP.VirtualMachine.AllClasses.ClassInfo ci =
|
|
977 |
cinfos[i];
|
|
978 |
ReferenceTypeImpl type = referenceType(ci.typeID,
|
|
979 |
ci.refTypeTag,
|
|
980 |
ci.signature);
|
|
981 |
type.setStatus(ci.status);
|
|
982 |
}
|
|
983 |
retrievedAllTypes = true;
|
|
984 |
}
|
|
985 |
}
|
|
986 |
}
|
|
987 |
|
|
988 |
private void retrieveAllClasses() {
|
|
989 |
if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
|
|
990 |
vm.printTrace("Retrieving all ReferenceTypes");
|
|
991 |
}
|
|
992 |
|
|
993 |
if (!vm.canGet1_5LanguageFeatures()) {
|
|
994 |
retrieveAllClasses1_4();
|
|
995 |
return;
|
|
996 |
}
|
|
997 |
|
|
998 |
/*
|
|
999 |
* To save time (assuming the caller will be
|
|
1000 |
* using then) we will get the generic sigs too.
|
|
1001 |
*/
|
|
1002 |
|
|
1003 |
JDWP.VirtualMachine.AllClassesWithGeneric.ClassInfo[] cinfos;
|
|
1004 |
try {
|
|
1005 |
cinfos = JDWP.VirtualMachine.AllClassesWithGeneric.process(vm).classes;
|
|
1006 |
} catch (JDWPException exc) {
|
|
1007 |
throw exc.toJDIException();
|
|
1008 |
}
|
|
1009 |
|
|
1010 |
// Hold lock during processing to improve performance
|
|
1011 |
// and to have safe check/set of retrievedAllTypes
|
|
1012 |
synchronized (this) {
|
|
1013 |
if (!retrievedAllTypes) {
|
|
1014 |
// Number of classes
|
|
1015 |
int count = cinfos.length;
|
|
1016 |
for (int i=0; i<count; i++) {
|
|
1017 |
JDWP.VirtualMachine.AllClassesWithGeneric.ClassInfo ci =
|
|
1018 |
cinfos[i];
|
|
1019 |
ReferenceTypeImpl type = referenceType(ci.typeID,
|
|
1020 |
ci.refTypeTag,
|
|
1021 |
ci.signature);
|
|
1022 |
type.setGenericSignature(ci.genericSignature);
|
|
1023 |
type.setStatus(ci.status);
|
|
1024 |
}
|
|
1025 |
retrievedAllTypes = true;
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
void sendToTarget(Packet packet) {
|
|
1031 |
target.send(packet);
|
|
1032 |
}
|
|
1033 |
|
|
1034 |
void waitForTargetReply(Packet packet) {
|
|
1035 |
target.waitForReply(packet);
|
|
1036 |
/*
|
|
1037 |
* If any object disposes have been batched up, send them now.
|
|
1038 |
*/
|
|
1039 |
processBatchedDisposes();
|
|
1040 |
}
|
|
1041 |
|
|
1042 |
Type findBootType(String signature) throws ClassNotLoadedException {
|
|
1043 |
List types = allClasses();
|
|
1044 |
Iterator iter = types.iterator();
|
|
1045 |
while (iter.hasNext()) {
|
|
1046 |
ReferenceType type = (ReferenceType)iter.next();
|
|
1047 |
if ((type.classLoader() == null) &&
|
|
1048 |
(type.signature().equals(signature))) {
|
|
1049 |
return type;
|
|
1050 |
}
|
|
1051 |
}
|
|
1052 |
JNITypeParser parser = new JNITypeParser(signature);
|
|
1053 |
throw new ClassNotLoadedException(parser.typeName(),
|
|
1054 |
"Type " + parser.typeName() + " not loaded");
|
|
1055 |
}
|
|
1056 |
|
|
1057 |
BooleanType theBooleanType() {
|
|
1058 |
if (theBooleanType == null) {
|
|
1059 |
synchronized(this) {
|
|
1060 |
if (theBooleanType == null) {
|
|
1061 |
theBooleanType = new BooleanTypeImpl(this);
|
|
1062 |
}
|
|
1063 |
}
|
|
1064 |
}
|
|
1065 |
return theBooleanType;
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
ByteType theByteType() {
|
|
1069 |
if (theByteType == null) {
|
|
1070 |
synchronized(this) {
|
|
1071 |
if (theByteType == null) {
|
|
1072 |
theByteType = new ByteTypeImpl(this);
|
|
1073 |
}
|
|
1074 |
}
|
|
1075 |
}
|
|
1076 |
return theByteType;
|
|
1077 |
}
|
|
1078 |
|
|
1079 |
CharType theCharType() {
|
|
1080 |
if (theCharType == null) {
|
|
1081 |
synchronized(this) {
|
|
1082 |
if (theCharType == null) {
|
|
1083 |
theCharType = new CharTypeImpl(this);
|
|
1084 |
}
|
|
1085 |
}
|
|
1086 |
}
|
|
1087 |
return theCharType;
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
ShortType theShortType() {
|
|
1091 |
if (theShortType == null) {
|
|
1092 |
synchronized(this) {
|
|
1093 |
if (theShortType == null) {
|
|
1094 |
theShortType = new ShortTypeImpl(this);
|
|
1095 |
}
|
|
1096 |
}
|
|
1097 |
}
|
|
1098 |
return theShortType;
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
IntegerType theIntegerType() {
|
|
1102 |
if (theIntegerType == null) {
|
|
1103 |
synchronized(this) {
|
|
1104 |
if (theIntegerType == null) {
|
|
1105 |
theIntegerType = new IntegerTypeImpl(this);
|
|
1106 |
}
|
|
1107 |
}
|
|
1108 |
}
|
|
1109 |
return theIntegerType;
|
|
1110 |
}
|
|
1111 |
|
|
1112 |
LongType theLongType() {
|
|
1113 |
if (theLongType == null) {
|
|
1114 |
synchronized(this) {
|
|
1115 |
if (theLongType == null) {
|
|
1116 |
theLongType = new LongTypeImpl(this);
|
|
1117 |
}
|
|
1118 |
}
|
|
1119 |
}
|
|
1120 |
return theLongType;
|
|
1121 |
}
|
|
1122 |
|
|
1123 |
FloatType theFloatType() {
|
|
1124 |
if (theFloatType == null) {
|
|
1125 |
synchronized(this) {
|
|
1126 |
if (theFloatType == null) {
|
|
1127 |
theFloatType = new FloatTypeImpl(this);
|
|
1128 |
}
|
|
1129 |
}
|
|
1130 |
}
|
|
1131 |
return theFloatType;
|
|
1132 |
}
|
|
1133 |
|
|
1134 |
DoubleType theDoubleType() {
|
|
1135 |
if (theDoubleType == null) {
|
|
1136 |
synchronized(this) {
|
|
1137 |
if (theDoubleType == null) {
|
|
1138 |
theDoubleType = new DoubleTypeImpl(this);
|
|
1139 |
}
|
|
1140 |
}
|
|
1141 |
}
|
|
1142 |
return theDoubleType;
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
VoidType theVoidType() {
|
|
1146 |
if (theVoidType == null) {
|
|
1147 |
synchronized(this) {
|
|
1148 |
if (theVoidType == null) {
|
|
1149 |
theVoidType = new VoidTypeImpl(this);
|
|
1150 |
}
|
|
1151 |
}
|
|
1152 |
}
|
|
1153 |
return theVoidType;
|
|
1154 |
}
|
|
1155 |
|
|
1156 |
PrimitiveType primitiveTypeMirror(byte tag) {
|
|
1157 |
switch (tag) {
|
|
1158 |
case JDWP.Tag.BOOLEAN:
|
|
1159 |
return theBooleanType();
|
|
1160 |
case JDWP.Tag.BYTE:
|
|
1161 |
return theByteType();
|
|
1162 |
case JDWP.Tag.CHAR:
|
|
1163 |
return theCharType();
|
|
1164 |
case JDWP.Tag.SHORT:
|
|
1165 |
return theShortType();
|
|
1166 |
case JDWP.Tag.INT:
|
|
1167 |
return theIntegerType();
|
|
1168 |
case JDWP.Tag.LONG:
|
|
1169 |
return theLongType();
|
|
1170 |
case JDWP.Tag.FLOAT:
|
|
1171 |
return theFloatType();
|
|
1172 |
case JDWP.Tag.DOUBLE:
|
|
1173 |
return theDoubleType();
|
|
1174 |
default:
|
|
1175 |
throw new IllegalArgumentException("Unrecognized primitive tag " + tag);
|
|
1176 |
}
|
|
1177 |
}
|
|
1178 |
|
|
1179 |
private void processBatchedDisposes() {
|
|
1180 |
if (shutdown) {
|
|
1181 |
return;
|
|
1182 |
}
|
|
1183 |
|
|
1184 |
JDWP.VirtualMachine.DisposeObjects.Request[] requests = null;
|
|
1185 |
synchronized(batchedDisposeRequests) {
|
|
1186 |
int size = batchedDisposeRequests.size();
|
|
1187 |
if (size >= DISPOSE_THRESHOLD) {
|
|
1188 |
if ((traceFlags & TRACE_OBJREFS) != 0) {
|
|
1189 |
printTrace("Dispose threashold reached. Will dispose "
|
|
1190 |
+ size + " object references...");
|
|
1191 |
}
|
|
1192 |
requests = new JDWP.VirtualMachine.DisposeObjects.Request[size];
|
|
1193 |
for (int i = 0; i < requests.length; i++) {
|
|
1194 |
SoftObjectReference ref =
|
|
1195 |
(SoftObjectReference)batchedDisposeRequests.get(i);
|
|
1196 |
if ((traceFlags & TRACE_OBJREFS) != 0) {
|
|
1197 |
printTrace("Disposing object " + ref.key().longValue() +
|
|
1198 |
" (ref count = " + ref.count() + ")");
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
// This is kludgy. We temporarily re-create an object
|
|
1202 |
// reference so that we can correctly pass its id to the
|
|
1203 |
// JDWP command.
|
|
1204 |
requests[i] =
|
|
1205 |
new JDWP.VirtualMachine.DisposeObjects.Request(
|
|
1206 |
new ObjectReferenceImpl(this, ref.key().longValue()),
|
|
1207 |
ref.count());
|
|
1208 |
}
|
|
1209 |
batchedDisposeRequests.clear();
|
|
1210 |
}
|
|
1211 |
}
|
|
1212 |
if (requests != null) {
|
|
1213 |
try {
|
|
1214 |
JDWP.VirtualMachine.DisposeObjects.process(vm, requests);
|
|
1215 |
} catch (JDWPException exc) {
|
|
1216 |
throw exc.toJDIException();
|
|
1217 |
}
|
|
1218 |
}
|
|
1219 |
}
|
|
1220 |
|
|
1221 |
private void batchForDispose(SoftObjectReference ref) {
|
|
1222 |
if ((traceFlags & TRACE_OBJREFS) != 0) {
|
|
1223 |
printTrace("Batching object " + ref.key().longValue() +
|
|
1224 |
" for dispose (ref count = " + ref.count() + ")");
|
|
1225 |
}
|
|
1226 |
batchedDisposeRequests.add(ref);
|
|
1227 |
}
|
|
1228 |
|
|
1229 |
private void processQueue() {
|
|
1230 |
Reference ref;
|
|
1231 |
//if ((traceFlags & TRACE_OBJREFS) != 0) {
|
|
1232 |
// printTrace("Checking for softly reachable objects");
|
|
1233 |
//}
|
|
1234 |
while ((ref = referenceQueue.poll()) != null) {
|
|
1235 |
SoftObjectReference softRef = (SoftObjectReference)ref;
|
|
1236 |
removeObjectMirror(softRef);
|
|
1237 |
batchForDispose(softRef);
|
|
1238 |
}
|
|
1239 |
}
|
|
1240 |
|
|
1241 |
synchronized ObjectReferenceImpl objectMirror(long id, int tag) {
|
|
1242 |
|
|
1243 |
// Handle any queue elements that are not strongly reachable
|
|
1244 |
processQueue();
|
|
1245 |
|
|
1246 |
if (id == 0) {
|
|
1247 |
return null;
|
|
1248 |
}
|
|
1249 |
ObjectReferenceImpl object = null;
|
|
1250 |
Long key = new Long(id);
|
|
1251 |
|
|
1252 |
/*
|
|
1253 |
* Attempt to retrieve an existing object object reference
|
|
1254 |
*/
|
|
1255 |
SoftObjectReference ref = objectsByID.get(key);
|
|
1256 |
if (ref != null) {
|
|
1257 |
object = ref.object();
|
|
1258 |
}
|
|
1259 |
|
|
1260 |
/*
|
|
1261 |
* If the object wasn't in the table, or it's soft reference was
|
|
1262 |
* cleared, create a new instance.
|
|
1263 |
*/
|
|
1264 |
if (object == null) {
|
|
1265 |
switch (tag) {
|
|
1266 |
case JDWP.Tag.OBJECT:
|
|
1267 |
object = new ObjectReferenceImpl(vm, id);
|
|
1268 |
break;
|
|
1269 |
case JDWP.Tag.STRING:
|
|
1270 |
object = new StringReferenceImpl(vm, id);
|
|
1271 |
break;
|
|
1272 |
case JDWP.Tag.ARRAY:
|
|
1273 |
object = new ArrayReferenceImpl(vm, id);
|
|
1274 |
break;
|
|
1275 |
case JDWP.Tag.THREAD:
|
|
1276 |
ThreadReferenceImpl thread =
|
|
1277 |
new ThreadReferenceImpl(vm, id);
|
|
1278 |
thread.addListener(this);
|
|
1279 |
object = thread;
|
|
1280 |
break;
|
|
1281 |
case JDWP.Tag.THREAD_GROUP:
|
|
1282 |
object = new ThreadGroupReferenceImpl(vm, id);
|
|
1283 |
break;
|
|
1284 |
case JDWP.Tag.CLASS_LOADER:
|
|
1285 |
object = new ClassLoaderReferenceImpl(vm, id);
|
|
1286 |
break;
|
|
1287 |
case JDWP.Tag.CLASS_OBJECT:
|
|
1288 |
object = new ClassObjectReferenceImpl(vm, id);
|
|
1289 |
break;
|
|
1290 |
default:
|
|
1291 |
throw new IllegalArgumentException("Invalid object tag: " + tag);
|
|
1292 |
}
|
|
1293 |
ref = new SoftObjectReference(key, object, referenceQueue);
|
|
1294 |
|
|
1295 |
/*
|
|
1296 |
* If there was no previous entry in the table, we add one here
|
|
1297 |
* If the previous entry was cleared, we replace it here.
|
|
1298 |
*/
|
|
1299 |
objectsByID.put(key, ref);
|
|
1300 |
if ((traceFlags & TRACE_OBJREFS) != 0) {
|
|
1301 |
printTrace("Creating new " +
|
|
1302 |
object.getClass().getName() + " (id = " + id + ")");
|
|
1303 |
}
|
|
1304 |
} else {
|
|
1305 |
ref.incrementCount();
|
|
1306 |
}
|
|
1307 |
|
|
1308 |
return object;
|
|
1309 |
}
|
|
1310 |
|
|
1311 |
synchronized void removeObjectMirror(ObjectReferenceImpl object) {
|
|
1312 |
|
|
1313 |
// Handle any queue elements that are not strongly reachable
|
|
1314 |
processQueue();
|
|
1315 |
|
|
1316 |
SoftObjectReference ref = objectsByID.remove(new Long(object.ref()));
|
|
1317 |
if (ref != null) {
|
|
1318 |
batchForDispose(ref);
|
|
1319 |
} else {
|
|
1320 |
/*
|
|
1321 |
* If there's a live ObjectReference about, it better be part
|
|
1322 |
* of the cache.
|
|
1323 |
*/
|
|
1324 |
throw new InternalException("ObjectReference " + object.ref() +
|
|
1325 |
" not found in object cache");
|
|
1326 |
}
|
|
1327 |
}
|
|
1328 |
|
|
1329 |
synchronized void removeObjectMirror(SoftObjectReference ref) {
|
|
1330 |
/*
|
|
1331 |
* This will remove the soft reference if it has not been
|
|
1332 |
* replaced in the cache.
|
|
1333 |
*/
|
|
1334 |
objectsByID.remove(ref.key());
|
|
1335 |
}
|
|
1336 |
|
|
1337 |
ObjectReferenceImpl objectMirror(long id) {
|
|
1338 |
return objectMirror(id, JDWP.Tag.OBJECT);
|
|
1339 |
}
|
|
1340 |
|
|
1341 |
StringReferenceImpl stringMirror(long id) {
|
|
1342 |
return (StringReferenceImpl)objectMirror(id, JDWP.Tag.STRING);
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
ArrayReferenceImpl arrayMirror(long id) {
|
|
1346 |
return (ArrayReferenceImpl)objectMirror(id, JDWP.Tag.ARRAY);
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
ThreadReferenceImpl threadMirror(long id) {
|
|
1350 |
return (ThreadReferenceImpl)objectMirror(id, JDWP.Tag.THREAD);
|
|
1351 |
}
|
|
1352 |
|
|
1353 |
ThreadGroupReferenceImpl threadGroupMirror(long id) {
|
|
1354 |
return (ThreadGroupReferenceImpl)objectMirror(id,
|
|
1355 |
JDWP.Tag.THREAD_GROUP);
|
|
1356 |
}
|
|
1357 |
|
|
1358 |
ClassLoaderReferenceImpl classLoaderMirror(long id) {
|
|
1359 |
return (ClassLoaderReferenceImpl)objectMirror(id,
|
|
1360 |
JDWP.Tag.CLASS_LOADER);
|
|
1361 |
}
|
|
1362 |
|
|
1363 |
ClassObjectReferenceImpl classObjectMirror(long id) {
|
|
1364 |
return (ClassObjectReferenceImpl)objectMirror(id,
|
|
1365 |
JDWP.Tag.CLASS_OBJECT);
|
|
1366 |
}
|
|
1367 |
|
|
1368 |
/*
|
|
1369 |
* Implementation of PathSearchingVirtualMachine
|
|
1370 |
*/
|
|
1371 |
private JDWP.VirtualMachine.ClassPaths getClasspath() {
|
|
1372 |
if (pathInfo == null) {
|
|
1373 |
try {
|
|
1374 |
pathInfo = JDWP.VirtualMachine.ClassPaths.process(vm);
|
|
1375 |
} catch (JDWPException exc) {
|
|
1376 |
throw exc.toJDIException();
|
|
1377 |
}
|
|
1378 |
}
|
|
1379 |
return pathInfo;
|
|
1380 |
}
|
|
1381 |
|
|
1382 |
public List<String> classPath() {
|
|
1383 |
return Arrays.asList(getClasspath().classpaths);
|
|
1384 |
}
|
|
1385 |
|
|
1386 |
public List<String> bootClassPath() {
|
|
1387 |
return Arrays.asList(getClasspath().bootclasspaths);
|
|
1388 |
}
|
|
1389 |
|
|
1390 |
public String baseDirectory() {
|
|
1391 |
return getClasspath().baseDir;
|
|
1392 |
}
|
|
1393 |
|
|
1394 |
public void setDefaultStratum(String stratum) {
|
|
1395 |
defaultStratum = stratum;
|
|
1396 |
if (stratum == null) {
|
|
1397 |
stratum = "";
|
|
1398 |
}
|
|
1399 |
try {
|
|
1400 |
JDWP.VirtualMachine.SetDefaultStratum.process(vm,
|
|
1401 |
stratum);
|
|
1402 |
} catch (JDWPException exc) {
|
|
1403 |
throw exc.toJDIException();
|
|
1404 |
}
|
|
1405 |
}
|
|
1406 |
|
|
1407 |
public String getDefaultStratum() {
|
|
1408 |
return defaultStratum;
|
|
1409 |
}
|
|
1410 |
|
|
1411 |
ThreadGroup threadGroupForJDI() {
|
|
1412 |
return threadGroupForJDI;
|
|
1413 |
}
|
|
1414 |
|
|
1415 |
static private class SoftObjectReference extends SoftReference<ObjectReferenceImpl> {
|
|
1416 |
int count;
|
|
1417 |
Long key;
|
|
1418 |
|
|
1419 |
SoftObjectReference(Long key, ObjectReferenceImpl mirror,
|
|
1420 |
ReferenceQueue<ObjectReferenceImpl> queue) {
|
|
1421 |
super(mirror, queue);
|
|
1422 |
this.count = 1;
|
|
1423 |
this.key = key;
|
|
1424 |
}
|
|
1425 |
|
|
1426 |
int count() {
|
|
1427 |
return count;
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
void incrementCount() {
|
|
1431 |
count++;
|
|
1432 |
}
|
|
1433 |
|
|
1434 |
Long key() {
|
|
1435 |
return key;
|
|
1436 |
}
|
|
1437 |
|
|
1438 |
ObjectReferenceImpl object() {
|
|
1439 |
return (ObjectReferenceImpl)get();
|
|
1440 |
}
|
|
1441 |
}
|
|
1442 |
}
|