2
|
1 |
/*
|
715
|
2 |
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
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.event.*;
|
|
30 |
import com.sun.jdi.request.*;
|
|
31 |
|
|
32 |
import java.util.*;
|
|
33 |
enum EventDestination {UNKNOWN_EVENT, INTERNAL_EVENT, CLIENT_EVENT};
|
|
34 |
|
|
35 |
/*
|
|
36 |
* An EventSet is normally created by the transport reader thread when
|
|
37 |
* it reads a JDWP Composite command. The constructor doesn't unpack
|
|
38 |
* the events contained in the Composite command and create EventImpls
|
|
39 |
* for them because that process might involve calling back into the back-end
|
|
40 |
* which should not be done by the transport reader thread. Instead,
|
|
41 |
* the raw bytes of the packet are read and stored in the EventSet.
|
|
42 |
* The EventSet is then added to each EventQueue. When an EventSet is
|
|
43 |
* removed from an EventQueue, the EventSetImpl.build() method is called.
|
|
44 |
* This method reads the packet bytes and creates the actual EventImpl objects.
|
|
45 |
* build() also filters out events for our internal handler and puts them in
|
|
46 |
* their own EventSet. This means that the EventImpls that are in the EventSet
|
|
47 |
* that is on the queues are all for client requests.
|
|
48 |
*/
|
|
49 |
public class EventSetImpl extends ArrayList<Event> implements EventSet {
|
|
50 |
|
|
51 |
private VirtualMachineImpl vm; // we implement Mirror
|
|
52 |
private Packet pkt;
|
|
53 |
private byte suspendPolicy;
|
|
54 |
private EventSetImpl internalEventSet;
|
|
55 |
|
|
56 |
public String toString() {
|
|
57 |
String string = "event set, policy:" + suspendPolicy +
|
|
58 |
", count:" + this.size() + " = {";
|
|
59 |
boolean first = true;
|
51
|
60 |
for (Event event : this) {
|
2
|
61 |
if (!first) {
|
|
62 |
string += ", ";
|
|
63 |
}
|
|
64 |
string += event.toString();
|
|
65 |
first = false;
|
|
66 |
}
|
|
67 |
string += "}";
|
|
68 |
return string;
|
|
69 |
}
|
|
70 |
|
|
71 |
abstract class EventImpl extends MirrorImpl implements Event {
|
|
72 |
|
|
73 |
private final byte eventCmd;
|
|
74 |
private final int requestID;
|
|
75 |
// This is set only for client requests, not internal requests.
|
|
76 |
private final EventRequest request;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Constructor for events.
|
|
80 |
*/
|
|
81 |
protected EventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
|
|
82 |
int requestID) {
|
|
83 |
super(EventSetImpl.this.vm);
|
|
84 |
this.eventCmd = evt.eventKind();
|
|
85 |
this.requestID = requestID;
|
|
86 |
EventRequestManagerImpl ermi = EventSetImpl.this.
|
|
87 |
vm.eventRequestManagerImpl();
|
|
88 |
this.request = ermi.request(eventCmd, requestID);
|
|
89 |
}
|
|
90 |
|
|
91 |
/*
|
|
92 |
* Override superclass back to default equality
|
|
93 |
*/
|
|
94 |
public boolean equals(Object obj) {
|
|
95 |
return this == obj;
|
|
96 |
}
|
|
97 |
|
|
98 |
public int hashCode() {
|
|
99 |
return System.identityHashCode(this);
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Constructor for VM disconnected events.
|
|
104 |
*/
|
|
105 |
protected EventImpl(byte eventCmd) {
|
|
106 |
super(EventSetImpl.this.vm);
|
|
107 |
this.eventCmd = eventCmd;
|
|
108 |
this.requestID = 0;
|
|
109 |
this.request = null;
|
|
110 |
}
|
|
111 |
|
|
112 |
public EventRequest request() {
|
|
113 |
return request;
|
|
114 |
}
|
|
115 |
|
|
116 |
int requestID() {
|
|
117 |
return requestID;
|
|
118 |
}
|
|
119 |
|
|
120 |
EventDestination destination() {
|
|
121 |
/*
|
|
122 |
* We need to decide if this event is for
|
|
123 |
* 1. an internal request
|
|
124 |
* 2. a client request that is no longer available, ie
|
|
125 |
* it has been deleted, or disabled and re-enabled
|
|
126 |
* which gives it a new ID.
|
|
127 |
* 3. a current client request that is disabled
|
|
128 |
* 4. a current enabled client request.
|
|
129 |
*
|
|
130 |
* We will filter this set into a set
|
|
131 |
* that contains only 1s for our internal queue
|
|
132 |
* and a set that contains only 4s for our client queue.
|
|
133 |
* If we get an EventSet that contains only 2 and 3
|
|
134 |
* then we have to resume it if it is not SUSPEND_NONE
|
|
135 |
* because no one else will.
|
|
136 |
*/
|
|
137 |
if (requestID == 0) {
|
|
138 |
/* An unsolicited event. These have traditionally
|
|
139 |
* been treated as client events.
|
|
140 |
*/
|
|
141 |
return EventDestination.CLIENT_EVENT;
|
|
142 |
}
|
|
143 |
|
|
144 |
// Is this an event for a current client request?
|
|
145 |
if (request == null) {
|
|
146 |
// Nope. Is it an event for an internal request?
|
|
147 |
EventRequestManagerImpl ermi = this.vm.getInternalEventRequestManager();
|
|
148 |
if (ermi.request(eventCmd, requestID) != null) {
|
|
149 |
// Yep
|
|
150 |
return EventDestination.INTERNAL_EVENT;
|
|
151 |
}
|
|
152 |
return EventDestination.UNKNOWN_EVENT;
|
|
153 |
}
|
|
154 |
|
|
155 |
// We found a client request
|
|
156 |
if (request.isEnabled()) {
|
|
157 |
return EventDestination.CLIENT_EVENT;
|
|
158 |
}
|
|
159 |
return EventDestination.UNKNOWN_EVENT;
|
|
160 |
}
|
|
161 |
|
|
162 |
abstract String eventName();
|
|
163 |
|
|
164 |
public String toString() {
|
|
165 |
return eventName();
|
|
166 |
}
|
|
167 |
|
|
168 |
}
|
|
169 |
|
|
170 |
abstract class ThreadedEventImpl extends EventImpl {
|
|
171 |
private ThreadReference thread;
|
|
172 |
|
|
173 |
ThreadedEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
|
|
174 |
int requestID, ThreadReference thread) {
|
|
175 |
super(evt, requestID);
|
|
176 |
this.thread = thread;
|
|
177 |
}
|
|
178 |
|
|
179 |
public ThreadReference thread() {
|
|
180 |
return thread;
|
|
181 |
}
|
|
182 |
|
|
183 |
public String toString() {
|
|
184 |
return eventName() + " in thread " + thread.name();
|
|
185 |
}
|
|
186 |
}
|
|
187 |
|
|
188 |
abstract class LocatableEventImpl extends ThreadedEventImpl
|
|
189 |
implements Locatable {
|
|
190 |
private Location location;
|
|
191 |
|
|
192 |
LocatableEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
|
|
193 |
int requestID,
|
|
194 |
ThreadReference thread, Location location) {
|
|
195 |
super(evt, requestID, thread);
|
|
196 |
this.location = location;
|
|
197 |
}
|
|
198 |
|
|
199 |
public Location location() {
|
|
200 |
return location;
|
|
201 |
}
|
|
202 |
|
|
203 |
/**
|
|
204 |
* For MethodEntry and MethodExit
|
|
205 |
*/
|
|
206 |
public Method method() {
|
|
207 |
return location.method();
|
|
208 |
}
|
|
209 |
|
|
210 |
public String toString() {
|
|
211 |
return eventName() + "@" + location().toString() +
|
|
212 |
" in thread " + thread().name();
|
|
213 |
}
|
|
214 |
}
|
|
215 |
|
|
216 |
class BreakpointEventImpl extends LocatableEventImpl
|
|
217 |
implements BreakpointEvent {
|
|
218 |
BreakpointEventImpl(JDWP.Event.Composite.Events.Breakpoint evt) {
|
|
219 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
220 |
}
|
|
221 |
|
|
222 |
String eventName() {
|
|
223 |
return "BreakpointEvent";
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
class StepEventImpl extends LocatableEventImpl implements StepEvent {
|
|
228 |
StepEventImpl(JDWP.Event.Composite.Events.SingleStep evt) {
|
|
229 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
230 |
}
|
|
231 |
|
|
232 |
String eventName() {
|
|
233 |
return "StepEvent";
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
class MethodEntryEventImpl extends LocatableEventImpl
|
|
238 |
implements MethodEntryEvent {
|
|
239 |
MethodEntryEventImpl(JDWP.Event.Composite.Events.MethodEntry evt) {
|
|
240 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
241 |
}
|
|
242 |
|
|
243 |
String eventName() {
|
|
244 |
return "MethodEntryEvent";
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
class MethodExitEventImpl extends LocatableEventImpl
|
|
249 |
implements MethodExitEvent {
|
|
250 |
private Value returnVal = null;
|
|
251 |
|
|
252 |
MethodExitEventImpl(JDWP.Event.Composite.Events.MethodExit evt) {
|
|
253 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
254 |
}
|
|
255 |
|
|
256 |
MethodExitEventImpl(JDWP.Event.Composite.Events.MethodExitWithReturnValue evt) {
|
|
257 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
258 |
returnVal = evt.value;
|
|
259 |
}
|
|
260 |
|
|
261 |
String eventName() {
|
|
262 |
return "MethodExitEvent";
|
|
263 |
}
|
|
264 |
|
|
265 |
public Value returnValue() {
|
|
266 |
if (!this.vm.canGetMethodReturnValues()) {
|
|
267 |
throw new UnsupportedOperationException(
|
|
268 |
"target does not support return values in MethodExit events");
|
|
269 |
}
|
|
270 |
return returnVal;
|
|
271 |
}
|
|
272 |
|
|
273 |
}
|
|
274 |
|
|
275 |
class MonitorContendedEnterEventImpl extends LocatableEventImpl
|
|
276 |
implements MonitorContendedEnterEvent {
|
|
277 |
private ObjectReference monitor = null;
|
|
278 |
|
|
279 |
MonitorContendedEnterEventImpl(JDWP.Event.Composite.Events.MonitorContendedEnter evt) {
|
|
280 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
281 |
this.monitor = evt.object;
|
|
282 |
}
|
|
283 |
|
|
284 |
String eventName() {
|
|
285 |
return "MonitorContendedEnter";
|
|
286 |
}
|
|
287 |
|
|
288 |
public ObjectReference monitor() {
|
|
289 |
return monitor;
|
|
290 |
};
|
|
291 |
|
|
292 |
}
|
|
293 |
|
|
294 |
class MonitorContendedEnteredEventImpl extends LocatableEventImpl
|
|
295 |
implements MonitorContendedEnteredEvent {
|
|
296 |
private ObjectReference monitor = null;
|
|
297 |
|
|
298 |
MonitorContendedEnteredEventImpl(JDWP.Event.Composite.Events.MonitorContendedEntered evt) {
|
|
299 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
300 |
this.monitor = evt.object;
|
|
301 |
}
|
|
302 |
|
|
303 |
String eventName() {
|
|
304 |
return "MonitorContendedEntered";
|
|
305 |
}
|
|
306 |
|
|
307 |
public ObjectReference monitor() {
|
|
308 |
return monitor;
|
|
309 |
};
|
|
310 |
|
|
311 |
}
|
|
312 |
|
|
313 |
class MonitorWaitEventImpl extends LocatableEventImpl
|
|
314 |
implements MonitorWaitEvent {
|
|
315 |
private ObjectReference monitor = null;
|
|
316 |
private long timeout;
|
|
317 |
|
|
318 |
MonitorWaitEventImpl(JDWP.Event.Composite.Events.MonitorWait evt) {
|
|
319 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
320 |
this.monitor = evt.object;
|
|
321 |
this.timeout = evt.timeout;
|
|
322 |
}
|
|
323 |
|
|
324 |
String eventName() {
|
|
325 |
return "MonitorWait";
|
|
326 |
}
|
|
327 |
|
|
328 |
public ObjectReference monitor() {
|
|
329 |
return monitor;
|
|
330 |
};
|
|
331 |
|
|
332 |
public long timeout() {
|
|
333 |
return timeout;
|
|
334 |
}
|
|
335 |
}
|
|
336 |
|
|
337 |
class MonitorWaitedEventImpl extends LocatableEventImpl
|
|
338 |
implements MonitorWaitedEvent {
|
|
339 |
private ObjectReference monitor = null;
|
|
340 |
private boolean timed_out;
|
|
341 |
|
|
342 |
MonitorWaitedEventImpl(JDWP.Event.Composite.Events.MonitorWaited evt) {
|
|
343 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
344 |
this.monitor = evt.object;
|
|
345 |
this.timed_out = evt.timed_out;
|
|
346 |
}
|
|
347 |
|
|
348 |
String eventName() {
|
|
349 |
return "MonitorWaited";
|
|
350 |
}
|
|
351 |
|
|
352 |
public ObjectReference monitor() {
|
|
353 |
return monitor;
|
|
354 |
};
|
|
355 |
|
|
356 |
public boolean timedout() {
|
|
357 |
return timed_out;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
class ClassPrepareEventImpl extends ThreadedEventImpl
|
|
362 |
implements ClassPrepareEvent {
|
|
363 |
private ReferenceType referenceType;
|
|
364 |
|
|
365 |
ClassPrepareEventImpl(JDWP.Event.Composite.Events.ClassPrepare evt) {
|
|
366 |
super(evt, evt.requestID, evt.thread);
|
|
367 |
referenceType = this.vm.referenceType(evt.typeID, evt.refTypeTag,
|
|
368 |
evt.signature);
|
|
369 |
((ReferenceTypeImpl)referenceType).setStatus(evt.status);
|
|
370 |
}
|
|
371 |
|
|
372 |
public ReferenceType referenceType() {
|
|
373 |
return referenceType;
|
|
374 |
}
|
|
375 |
|
|
376 |
String eventName() {
|
|
377 |
return "ClassPrepareEvent";
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|
|
381 |
class ClassUnloadEventImpl extends EventImpl implements ClassUnloadEvent {
|
|
382 |
private String classSignature;
|
|
383 |
|
|
384 |
ClassUnloadEventImpl(JDWP.Event.Composite.Events.ClassUnload evt) {
|
|
385 |
super(evt, evt.requestID);
|
|
386 |
this.classSignature = evt.signature;
|
|
387 |
}
|
|
388 |
|
|
389 |
public String className() {
|
|
390 |
return classSignature.substring(1, classSignature.length()-1)
|
|
391 |
.replace('/', '.');
|
|
392 |
}
|
|
393 |
|
|
394 |
public String classSignature() {
|
|
395 |
return classSignature;
|
|
396 |
}
|
|
397 |
|
|
398 |
String eventName() {
|
|
399 |
return "ClassUnloadEvent";
|
|
400 |
}
|
|
401 |
}
|
|
402 |
|
|
403 |
class ExceptionEventImpl extends LocatableEventImpl
|
|
404 |
implements ExceptionEvent {
|
|
405 |
private ObjectReference exception;
|
|
406 |
private Location catchLocation;
|
|
407 |
|
|
408 |
ExceptionEventImpl(JDWP.Event.Composite.Events.Exception evt) {
|
|
409 |
super(evt, evt.requestID, evt.thread, evt.location);
|
|
410 |
this.exception = evt.exception;
|
|
411 |
this.catchLocation = evt.catchLocation;
|
|
412 |
}
|
|
413 |
|
|
414 |
public ObjectReference exception() {
|
|
415 |
return exception;
|
|
416 |
}
|
|
417 |
|
|
418 |
public Location catchLocation() {
|
|
419 |
return catchLocation;
|
|
420 |
}
|
|
421 |
|
|
422 |
String eventName() {
|
|
423 |
return "ExceptionEvent";
|
|
424 |
}
|
|
425 |
}
|
|
426 |
|
|
427 |
class ThreadDeathEventImpl extends ThreadedEventImpl
|
|
428 |
implements ThreadDeathEvent {
|
|
429 |
ThreadDeathEventImpl(JDWP.Event.Composite.Events.ThreadDeath evt) {
|
|
430 |
super(evt, evt.requestID, evt.thread);
|
|
431 |
}
|
|
432 |
|
|
433 |
String eventName() {
|
|
434 |
return "ThreadDeathEvent";
|
|
435 |
}
|
|
436 |
}
|
|
437 |
|
|
438 |
class ThreadStartEventImpl extends ThreadedEventImpl
|
|
439 |
implements ThreadStartEvent {
|
|
440 |
ThreadStartEventImpl(JDWP.Event.Composite.Events.ThreadStart evt) {
|
|
441 |
super(evt, evt.requestID, evt.thread);
|
|
442 |
}
|
|
443 |
|
|
444 |
String eventName() {
|
|
445 |
return "ThreadStartEvent";
|
|
446 |
}
|
|
447 |
}
|
|
448 |
|
|
449 |
class VMStartEventImpl extends ThreadedEventImpl
|
|
450 |
implements VMStartEvent {
|
|
451 |
VMStartEventImpl(JDWP.Event.Composite.Events.VMStart evt) {
|
|
452 |
super(evt, evt.requestID, evt.thread);
|
|
453 |
}
|
|
454 |
|
|
455 |
String eventName() {
|
|
456 |
return "VMStartEvent";
|
|
457 |
}
|
|
458 |
}
|
|
459 |
|
|
460 |
class VMDeathEventImpl extends EventImpl implements VMDeathEvent {
|
|
461 |
|
|
462 |
VMDeathEventImpl(JDWP.Event.Composite.Events.VMDeath evt) {
|
|
463 |
super(evt, evt.requestID);
|
|
464 |
}
|
|
465 |
|
|
466 |
String eventName() {
|
|
467 |
return "VMDeathEvent";
|
|
468 |
}
|
|
469 |
}
|
|
470 |
|
|
471 |
class VMDisconnectEventImpl extends EventImpl
|
|
472 |
implements VMDisconnectEvent {
|
|
473 |
|
|
474 |
VMDisconnectEventImpl() {
|
|
475 |
super((byte)JDWP.EventKind.VM_DISCONNECTED);
|
|
476 |
}
|
|
477 |
|
|
478 |
String eventName() {
|
|
479 |
return "VMDisconnectEvent";
|
|
480 |
}
|
|
481 |
}
|
|
482 |
|
|
483 |
abstract class WatchpointEventImpl extends LocatableEventImpl
|
|
484 |
implements WatchpointEvent {
|
|
485 |
private final ReferenceTypeImpl refType;
|
|
486 |
private final long fieldID;
|
|
487 |
private final ObjectReference object;
|
|
488 |
private Field field = null;
|
|
489 |
|
|
490 |
WatchpointEventImpl(JDWP.Event.Composite.Events.EventsCommon evt,
|
|
491 |
int requestID,
|
|
492 |
ThreadReference thread, Location location,
|
|
493 |
byte refTypeTag, long typeID, long fieldID,
|
|
494 |
ObjectReference object) {
|
|
495 |
super(evt, requestID, thread, location);
|
|
496 |
this.refType = this.vm.referenceType(typeID, refTypeTag);
|
|
497 |
this.fieldID = fieldID;
|
|
498 |
this.object = object;
|
|
499 |
}
|
|
500 |
|
|
501 |
public Field field() {
|
|
502 |
if (field == null) {
|
|
503 |
field = refType.getFieldMirror(fieldID);
|
|
504 |
}
|
|
505 |
return field;
|
|
506 |
}
|
|
507 |
|
|
508 |
public ObjectReference object() {
|
|
509 |
return object;
|
|
510 |
}
|
|
511 |
|
|
512 |
public Value valueCurrent() {
|
|
513 |
if (object == null) {
|
|
514 |
return refType.getValue(field());
|
|
515 |
} else {
|
|
516 |
return object.getValue(field());
|
|
517 |
}
|
|
518 |
}
|
|
519 |
}
|
|
520 |
|
|
521 |
class AccessWatchpointEventImpl extends WatchpointEventImpl
|
|
522 |
implements AccessWatchpointEvent {
|
|
523 |
|
|
524 |
AccessWatchpointEventImpl(JDWP.Event.Composite.Events.FieldAccess evt) {
|
|
525 |
super(evt, evt.requestID, evt.thread, evt.location,
|
|
526 |
evt.refTypeTag, evt.typeID, evt.fieldID, evt.object);
|
|
527 |
}
|
|
528 |
|
|
529 |
String eventName() {
|
|
530 |
return "AccessWatchpoint";
|
|
531 |
}
|
|
532 |
}
|
|
533 |
|
|
534 |
class ModificationWatchpointEventImpl extends WatchpointEventImpl
|
|
535 |
implements ModificationWatchpointEvent {
|
|
536 |
Value newValue;
|
|
537 |
|
|
538 |
ModificationWatchpointEventImpl(
|
|
539 |
JDWP.Event.Composite.Events.FieldModification evt) {
|
|
540 |
super(evt, evt.requestID, evt.thread, evt.location,
|
|
541 |
evt.refTypeTag, evt.typeID, evt.fieldID, evt.object);
|
|
542 |
this.newValue = evt.valueToBe;
|
|
543 |
}
|
|
544 |
|
|
545 |
public Value valueToBe() {
|
|
546 |
return newValue;
|
|
547 |
}
|
|
548 |
|
|
549 |
String eventName() {
|
|
550 |
return "ModificationWatchpoint";
|
|
551 |
}
|
|
552 |
}
|
|
553 |
|
|
554 |
/**
|
|
555 |
* Events are constructed on the thread which reads all data from the
|
|
556 |
* transport. This means that the packet cannot be converted to real
|
|
557 |
* JDI objects as that may involve further communications with the
|
|
558 |
* back end which would deadlock.
|
|
559 |
*
|
|
560 |
* Hence the {@link #build()} method below called by EventQueue.
|
|
561 |
*/
|
|
562 |
EventSetImpl(VirtualMachine aVm, Packet pkt) {
|
|
563 |
super();
|
|
564 |
|
|
565 |
// From "MirrorImpl":
|
|
566 |
// Yes, its a bit of a hack. But by doing it this
|
|
567 |
// way, this is the only place we have to change
|
|
568 |
// typing to substitute a new impl.
|
|
569 |
vm = (VirtualMachineImpl)aVm;
|
|
570 |
|
|
571 |
this.pkt = pkt;
|
|
572 |
}
|
|
573 |
|
|
574 |
/**
|
|
575 |
* Constructor for special events like VM disconnected
|
|
576 |
*/
|
|
577 |
EventSetImpl(VirtualMachine aVm, byte eventCmd) {
|
|
578 |
this(aVm, null);
|
|
579 |
suspendPolicy = JDWP.SuspendPolicy.NONE;
|
|
580 |
switch (eventCmd) {
|
|
581 |
case JDWP.EventKind.VM_DISCONNECTED:
|
|
582 |
addEvent(new VMDisconnectEventImpl());
|
|
583 |
break;
|
|
584 |
|
|
585 |
default:
|
|
586 |
throw new InternalException("Bad singleton event code");
|
|
587 |
}
|
|
588 |
}
|
|
589 |
|
|
590 |
private void addEvent(EventImpl evt) {
|
|
591 |
// Note that this class has a public add method that throws
|
|
592 |
// an exception so that clients can't modify the EventSet
|
|
593 |
super.add(evt);
|
|
594 |
}
|
|
595 |
|
|
596 |
/*
|
|
597 |
* Complete the construction of an EventSet. This is called from
|
|
598 |
* an event handler thread. It upacks the JDWP events inside
|
|
599 |
* the packet and creates EventImpls for them. The EventSet is already
|
|
600 |
* on EventQueues when this is called, so it has to be synch.
|
|
601 |
*/
|
|
602 |
synchronized void build() {
|
|
603 |
if (pkt == null) {
|
|
604 |
return;
|
|
605 |
}
|
|
606 |
PacketStream ps = new PacketStream(vm, pkt);
|
|
607 |
JDWP.Event.Composite compEvt = new JDWP.Event.Composite(vm, ps);
|
|
608 |
suspendPolicy = compEvt.suspendPolicy;
|
|
609 |
if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
|
|
610 |
switch(suspendPolicy) {
|
|
611 |
case JDWP.SuspendPolicy.ALL:
|
|
612 |
vm.printTrace("EventSet: SUSPEND_ALL");
|
|
613 |
break;
|
|
614 |
|
|
615 |
case JDWP.SuspendPolicy.EVENT_THREAD:
|
|
616 |
vm.printTrace("EventSet: SUSPEND_EVENT_THREAD");
|
|
617 |
break;
|
|
618 |
|
|
619 |
case JDWP.SuspendPolicy.NONE:
|
|
620 |
vm.printTrace("EventSet: SUSPEND_NONE");
|
|
621 |
break;
|
|
622 |
}
|
|
623 |
}
|
|
624 |
|
|
625 |
ThreadReference fix6485605 = null;
|
|
626 |
for (int i = 0; i < compEvt.events.length; i++) {
|
|
627 |
EventImpl evt = createEvent(compEvt.events[i]);
|
|
628 |
if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
|
|
629 |
try {
|
|
630 |
vm.printTrace("Event: " + evt);
|
|
631 |
} catch (VMDisconnectedException ee) {
|
|
632 |
// ignore - see bug 6502716
|
|
633 |
}
|
|
634 |
}
|
|
635 |
|
|
636 |
switch (evt.destination()) {
|
|
637 |
case UNKNOWN_EVENT:
|
|
638 |
// Ignore disabled, deleted, unknown events, but
|
|
639 |
// save the thread if there is one since we might
|
|
640 |
// have to resume it. Note that events for different
|
|
641 |
// threads can't be in the same event set.
|
|
642 |
if (evt instanceof ThreadedEventImpl &&
|
|
643 |
suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
|
|
644 |
fix6485605 = ((ThreadedEventImpl)evt).thread();
|
|
645 |
}
|
|
646 |
continue;
|
|
647 |
case CLIENT_EVENT:
|
|
648 |
addEvent(evt);
|
|
649 |
break;
|
|
650 |
case INTERNAL_EVENT:
|
|
651 |
if (internalEventSet == null) {
|
|
652 |
internalEventSet = new EventSetImpl(this.vm, null);
|
|
653 |
}
|
|
654 |
internalEventSet.addEvent(evt);
|
|
655 |
break;
|
|
656 |
default:
|
|
657 |
throw new InternalException("Invalid event destination");
|
|
658 |
}
|
|
659 |
}
|
|
660 |
pkt = null; // No longer needed - free it up
|
|
661 |
|
|
662 |
// Avoid hangs described in 6296125, 6293795
|
|
663 |
if (super.size() == 0) {
|
|
664 |
// This set has no client events. If we don't do
|
|
665 |
// needed resumes, no one else is going to.
|
|
666 |
if (suspendPolicy == JDWP.SuspendPolicy.ALL) {
|
|
667 |
vm.resume();
|
|
668 |
} else if (suspendPolicy == JDWP.SuspendPolicy.EVENT_THREAD) {
|
|
669 |
// See bug 6485605.
|
|
670 |
if (fix6485605 != null) {
|
|
671 |
fix6485605.resume();
|
|
672 |
} else {
|
|
673 |
// apparently, there is nothing to resume.
|
|
674 |
}
|
|
675 |
}
|
|
676 |
suspendPolicy = JDWP.SuspendPolicy.NONE;
|
|
677 |
|
|
678 |
}
|
|
679 |
|
|
680 |
}
|
|
681 |
|
|
682 |
/**
|
|
683 |
* Filter out internal events
|
|
684 |
*/
|
|
685 |
EventSet userFilter() {
|
|
686 |
return this;
|
|
687 |
}
|
|
688 |
|
|
689 |
/**
|
|
690 |
* Filter out user events.
|
|
691 |
*/
|
|
692 |
EventSet internalFilter() {
|
|
693 |
return this.internalEventSet;
|
|
694 |
}
|
|
695 |
|
|
696 |
EventImpl createEvent(JDWP.Event.Composite.Events evt) {
|
|
697 |
JDWP.Event.Composite.Events.EventsCommon comm = evt.aEventsCommon;
|
|
698 |
switch (evt.eventKind) {
|
|
699 |
case JDWP.EventKind.THREAD_START:
|
|
700 |
return new ThreadStartEventImpl(
|
|
701 |
(JDWP.Event.Composite.Events.ThreadStart)comm);
|
|
702 |
|
|
703 |
case JDWP.EventKind.THREAD_END:
|
|
704 |
return new ThreadDeathEventImpl(
|
|
705 |
(JDWP.Event.Composite.Events.ThreadDeath)comm);
|
|
706 |
|
|
707 |
case JDWP.EventKind.EXCEPTION:
|
|
708 |
return new ExceptionEventImpl(
|
|
709 |
(JDWP.Event.Composite.Events.Exception)comm);
|
|
710 |
|
|
711 |
case JDWP.EventKind.BREAKPOINT:
|
|
712 |
return new BreakpointEventImpl(
|
|
713 |
(JDWP.Event.Composite.Events.Breakpoint)comm);
|
|
714 |
|
|
715 |
case JDWP.EventKind.METHOD_ENTRY:
|
|
716 |
return new MethodEntryEventImpl(
|
|
717 |
(JDWP.Event.Composite.Events.MethodEntry)comm);
|
|
718 |
|
|
719 |
case JDWP.EventKind.METHOD_EXIT:
|
|
720 |
return new MethodExitEventImpl(
|
|
721 |
(JDWP.Event.Composite.Events.MethodExit)comm);
|
|
722 |
|
|
723 |
case JDWP.EventKind.METHOD_EXIT_WITH_RETURN_VALUE:
|
|
724 |
return new MethodExitEventImpl(
|
|
725 |
(JDWP.Event.Composite.Events.MethodExitWithReturnValue)comm);
|
|
726 |
|
|
727 |
case JDWP.EventKind.FIELD_ACCESS:
|
|
728 |
return new AccessWatchpointEventImpl(
|
|
729 |
(JDWP.Event.Composite.Events.FieldAccess)comm);
|
|
730 |
|
|
731 |
case JDWP.EventKind.FIELD_MODIFICATION:
|
|
732 |
return new ModificationWatchpointEventImpl(
|
|
733 |
(JDWP.Event.Composite.Events.FieldModification)comm);
|
|
734 |
|
|
735 |
case JDWP.EventKind.SINGLE_STEP:
|
|
736 |
return new StepEventImpl(
|
|
737 |
(JDWP.Event.Composite.Events.SingleStep)comm);
|
|
738 |
|
|
739 |
case JDWP.EventKind.CLASS_PREPARE:
|
|
740 |
return new ClassPrepareEventImpl(
|
|
741 |
(JDWP.Event.Composite.Events.ClassPrepare)comm);
|
|
742 |
|
|
743 |
case JDWP.EventKind.CLASS_UNLOAD:
|
|
744 |
return new ClassUnloadEventImpl(
|
|
745 |
(JDWP.Event.Composite.Events.ClassUnload)comm);
|
|
746 |
|
|
747 |
case JDWP.EventKind.MONITOR_CONTENDED_ENTER:
|
|
748 |
return new MonitorContendedEnterEventImpl(
|
|
749 |
(JDWP.Event.Composite.Events.MonitorContendedEnter)comm);
|
|
750 |
|
|
751 |
case JDWP.EventKind.MONITOR_CONTENDED_ENTERED:
|
|
752 |
return new MonitorContendedEnteredEventImpl(
|
|
753 |
(JDWP.Event.Composite.Events.MonitorContendedEntered)comm);
|
|
754 |
|
|
755 |
case JDWP.EventKind.MONITOR_WAIT:
|
|
756 |
return new MonitorWaitEventImpl(
|
|
757 |
(JDWP.Event.Composite.Events.MonitorWait)comm);
|
|
758 |
|
|
759 |
case JDWP.EventKind.MONITOR_WAITED:
|
|
760 |
return new MonitorWaitedEventImpl(
|
|
761 |
(JDWP.Event.Composite.Events.MonitorWaited)comm);
|
|
762 |
|
|
763 |
case JDWP.EventKind.VM_START:
|
|
764 |
return new VMStartEventImpl(
|
|
765 |
(JDWP.Event.Composite.Events.VMStart)comm);
|
|
766 |
|
|
767 |
case JDWP.EventKind.VM_DEATH:
|
|
768 |
return new VMDeathEventImpl(
|
|
769 |
(JDWP.Event.Composite.Events.VMDeath)comm);
|
|
770 |
|
|
771 |
default:
|
|
772 |
// Ignore unknown event types
|
|
773 |
System.err.println("Ignoring event cmd " +
|
|
774 |
evt.eventKind + " from the VM");
|
|
775 |
return null;
|
|
776 |
}
|
|
777 |
}
|
|
778 |
|
|
779 |
public VirtualMachine virtualMachine() {
|
|
780 |
return vm;
|
|
781 |
}
|
|
782 |
|
|
783 |
public int suspendPolicy() {
|
|
784 |
return EventRequestManagerImpl.JDWPtoJDISuspendPolicy(suspendPolicy);
|
|
785 |
}
|
|
786 |
|
|
787 |
private ThreadReference eventThread() {
|
51
|
788 |
for (Event event : this) {
|
2
|
789 |
if (event instanceof ThreadedEventImpl) {
|
|
790 |
return ((ThreadedEventImpl)event).thread();
|
|
791 |
}
|
|
792 |
}
|
|
793 |
return null;
|
|
794 |
}
|
|
795 |
|
|
796 |
public void resume() {
|
|
797 |
switch (suspendPolicy()) {
|
|
798 |
case EventRequest.SUSPEND_ALL:
|
|
799 |
vm.resume();
|
|
800 |
break;
|
|
801 |
case EventRequest.SUSPEND_EVENT_THREAD:
|
|
802 |
ThreadReference thread = eventThread();
|
|
803 |
if (thread == null) {
|
|
804 |
throw new InternalException("Inconsistent suspend policy");
|
|
805 |
}
|
|
806 |
thread.resume();
|
|
807 |
break;
|
|
808 |
case EventRequest.SUSPEND_NONE:
|
|
809 |
// Do nothing
|
|
810 |
break;
|
|
811 |
default:
|
|
812 |
throw new InternalException("Invalid suspend policy");
|
|
813 |
}
|
|
814 |
}
|
|
815 |
|
|
816 |
public Iterator<Event> iterator() {
|
|
817 |
return new Itr();
|
|
818 |
}
|
|
819 |
|
|
820 |
public EventIterator eventIterator() {
|
|
821 |
return new Itr();
|
|
822 |
}
|
|
823 |
|
|
824 |
public class Itr implements EventIterator {
|
|
825 |
/**
|
|
826 |
* Index of element to be returned by subsequent call to next.
|
|
827 |
*/
|
|
828 |
int cursor = 0;
|
|
829 |
|
|
830 |
public boolean hasNext() {
|
|
831 |
return cursor != size();
|
|
832 |
}
|
|
833 |
|
|
834 |
public Event next() {
|
|
835 |
try {
|
|
836 |
Event nxt = get(cursor);
|
|
837 |
++cursor;
|
|
838 |
return nxt;
|
|
839 |
} catch(IndexOutOfBoundsException e) {
|
|
840 |
throw new NoSuchElementException();
|
|
841 |
}
|
|
842 |
}
|
|
843 |
|
|
844 |
public Event nextEvent() {
|
51
|
845 |
return next();
|
2
|
846 |
}
|
|
847 |
|
|
848 |
public void remove() {
|
|
849 |
throw new UnsupportedOperationException();
|
|
850 |
}
|
|
851 |
}
|
|
852 |
|
|
853 |
/* below make this unmodifiable */
|
|
854 |
|
|
855 |
public boolean add(Event o){
|
|
856 |
throw new UnsupportedOperationException();
|
|
857 |
}
|
|
858 |
public boolean remove(Object o) {
|
|
859 |
throw new UnsupportedOperationException();
|
|
860 |
}
|
|
861 |
public boolean addAll(Collection<? extends Event> coll) {
|
|
862 |
throw new UnsupportedOperationException();
|
|
863 |
}
|
|
864 |
public boolean removeAll(Collection<?> coll) {
|
|
865 |
throw new UnsupportedOperationException();
|
|
866 |
}
|
|
867 |
public boolean retainAll(Collection<?> coll) {
|
|
868 |
throw new UnsupportedOperationException();
|
|
869 |
}
|
|
870 |
public void clear() {
|
|
871 |
throw new UnsupportedOperationException();
|
|
872 |
}
|
|
873 |
}
|