Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java
41161 views
1
/*
2
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.tools.jdi;
27
28
import java.util.ArrayList;
29
import java.util.Collections;
30
import java.util.HashMap;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
34
35
import com.sun.jdi.Field;
36
import com.sun.jdi.Location;
37
import com.sun.jdi.NativeMethodException;
38
import com.sun.jdi.ObjectReference;
39
import com.sun.jdi.ReferenceType;
40
import com.sun.jdi.ThreadReference;
41
import com.sun.jdi.VirtualMachine;
42
import com.sun.jdi.request.AccessWatchpointRequest;
43
import com.sun.jdi.request.BreakpointRequest;
44
import com.sun.jdi.request.ClassPrepareRequest;
45
import com.sun.jdi.request.ClassUnloadRequest;
46
import com.sun.jdi.request.DuplicateRequestException;
47
import com.sun.jdi.request.EventRequest;
48
import com.sun.jdi.request.EventRequestManager;
49
import com.sun.jdi.request.ExceptionRequest;
50
import com.sun.jdi.request.InvalidRequestStateException;
51
import com.sun.jdi.request.MethodEntryRequest;
52
import com.sun.jdi.request.MethodExitRequest;
53
import com.sun.jdi.request.ModificationWatchpointRequest;
54
import com.sun.jdi.request.MonitorContendedEnterRequest;
55
import com.sun.jdi.request.MonitorContendedEnteredRequest;
56
import com.sun.jdi.request.MonitorWaitRequest;
57
import com.sun.jdi.request.MonitorWaitedRequest;
58
import com.sun.jdi.request.StepRequest;
59
import com.sun.jdi.request.ThreadDeathRequest;
60
import com.sun.jdi.request.ThreadStartRequest;
61
import com.sun.jdi.request.VMDeathRequest;
62
import com.sun.jdi.request.WatchpointRequest;
63
64
/**
65
* This interface is used to create and remove Breakpoints, Watchpoints,
66
* etc.
67
* It include implementations of all the request interfaces..
68
*/
69
// Warnings from List filters and List[] requestLists is hard to fix.
70
// Remove SuppressWarning when we fix the warnings from List filters
71
// and List[] requestLists. The generic array is not supported.
72
@SuppressWarnings({"unchecked", "rawtypes"})
73
class EventRequestManagerImpl extends MirrorImpl
74
implements EventRequestManager
75
{
76
private final List<? extends EventRequest>[] requestLists;
77
private static int methodExitEventCmd = 0;
78
79
static int JDWPtoJDISuspendPolicy(byte jdwpPolicy) {
80
switch(jdwpPolicy) {
81
case JDWP.SuspendPolicy.ALL:
82
return EventRequest.SUSPEND_ALL;
83
case JDWP.SuspendPolicy.EVENT_THREAD:
84
return EventRequest.SUSPEND_EVENT_THREAD;
85
case JDWP.SuspendPolicy.NONE:
86
return EventRequest.SUSPEND_NONE;
87
default:
88
throw new IllegalArgumentException("Illegal policy constant: " + jdwpPolicy);
89
}
90
}
91
92
static byte JDItoJDWPSuspendPolicy(int jdiPolicy) {
93
switch(jdiPolicy) {
94
case EventRequest.SUSPEND_ALL:
95
return JDWP.SuspendPolicy.ALL;
96
case EventRequest.SUSPEND_EVENT_THREAD:
97
return JDWP.SuspendPolicy.EVENT_THREAD;
98
case EventRequest.SUSPEND_NONE:
99
return JDWP.SuspendPolicy.NONE;
100
default:
101
throw new IllegalArgumentException("Illegal policy constant: " + jdiPolicy);
102
}
103
}
104
105
/*
106
* Override superclass back to default equality
107
*/
108
public boolean equals(Object obj) {
109
return this == obj;
110
}
111
112
public int hashCode() {
113
return System.identityHashCode(this);
114
}
115
116
private abstract class EventRequestImpl extends MirrorImpl implements EventRequest {
117
int id;
118
119
/*
120
* This list is not protected by a synchronized wrapper. All
121
* access/modification should be protected by synchronizing on
122
* the enclosing instance of EventRequestImpl.
123
*/
124
List<Object> filters = new ArrayList<>();
125
126
boolean isEnabled = false;
127
boolean deleted = false;
128
byte suspendPolicy = JDWP.SuspendPolicy.ALL;
129
private Map<Object, Object> clientProperties = null;
130
131
EventRequestImpl() {
132
super(EventRequestManagerImpl.this.vm);
133
}
134
135
/*
136
* Override superclass back to default equality
137
*/
138
public boolean equals(Object obj) {
139
return this == obj;
140
}
141
142
public int hashCode() {
143
return System.identityHashCode(this);
144
}
145
146
abstract int eventCmd();
147
148
InvalidRequestStateException invalidState() {
149
return new InvalidRequestStateException(toString());
150
}
151
152
String state() {
153
return deleted? " (deleted)" :
154
(isEnabled()? " (enabled)" : " (disabled)");
155
}
156
157
/**
158
* @return all the event request of this kind
159
*/
160
List requestList() {
161
return EventRequestManagerImpl.this.requestList(eventCmd());
162
}
163
164
/**
165
* delete the event request
166
*/
167
void delete() {
168
if (!deleted) {
169
requestList().remove(this);
170
disable(); /* must do BEFORE delete */
171
deleted = true;
172
}
173
}
174
175
public boolean isEnabled() {
176
return isEnabled;
177
}
178
179
public void enable() {
180
setEnabled(true);
181
}
182
183
public void disable() {
184
setEnabled(false);
185
}
186
187
public synchronized void setEnabled(boolean val) {
188
if (deleted) {
189
throw invalidState();
190
} else {
191
if (val != isEnabled) {
192
if (isEnabled) {
193
clear();
194
} else {
195
set();
196
}
197
}
198
}
199
}
200
201
public synchronized void addCountFilter(int count) {
202
if (isEnabled() || deleted) {
203
throw invalidState();
204
}
205
if (count < 1) {
206
throw new IllegalArgumentException("count is less than one");
207
}
208
filters.add(JDWP.EventRequest.Set.Modifier.Count.create(count));
209
}
210
211
public void setSuspendPolicy(int policy) {
212
if (isEnabled() || deleted) {
213
throw invalidState();
214
}
215
suspendPolicy = JDItoJDWPSuspendPolicy(policy);
216
}
217
218
public int suspendPolicy() {
219
return JDWPtoJDISuspendPolicy(suspendPolicy);
220
}
221
222
/**
223
* set (enable) the event request
224
*/
225
synchronized void set() {
226
JDWP.EventRequest.Set.Modifier[] mods =
227
filters.toArray(
228
new JDWP.EventRequest.Set.Modifier[filters.size()]);
229
try {
230
id = JDWP.EventRequest.Set.process(vm, (byte)eventCmd(),
231
suspendPolicy, mods).requestID;
232
} catch (JDWPException exc) {
233
throw exc.toJDIException();
234
}
235
isEnabled = true;
236
}
237
238
synchronized void clear() {
239
try {
240
JDWP.EventRequest.Clear.process(vm, (byte)eventCmd(), id);
241
} catch (JDWPException exc) {
242
throw exc.toJDIException();
243
}
244
isEnabled = false;
245
}
246
247
/**
248
* @return a small Map
249
* @see #putProperty
250
* @see #getProperty
251
*/
252
private Map<Object, Object> getProperties() {
253
if (clientProperties == null) {
254
clientProperties = new HashMap<>(2);
255
}
256
return clientProperties;
257
}
258
259
/**
260
* Returns the value of the property with the specified key. Only
261
* properties added with <code>putProperty</code> will return
262
* a non-null value.
263
*
264
* @return the value of this property or null
265
* @see #putProperty
266
*/
267
public final Object getProperty(Object key) {
268
if (clientProperties == null) {
269
return null;
270
} else {
271
return getProperties().get(key);
272
}
273
}
274
275
/**
276
* Add an arbitrary key/value "property" to this component.
277
*
278
* @see #getProperty
279
*/
280
public final void putProperty(Object key, Object value) {
281
if (value != null) {
282
getProperties().put(key, value);
283
} else {
284
getProperties().remove(key);
285
}
286
}
287
}
288
289
abstract class ThreadVisibleEventRequestImpl extends EventRequestImpl {
290
public synchronized void addThreadFilter(ThreadReference thread) {
291
validateMirror(thread);
292
if (isEnabled() || deleted) {
293
throw invalidState();
294
}
295
filters.add(JDWP.EventRequest.Set.Modifier.ThreadOnly
296
.create((ThreadReferenceImpl)thread));
297
}
298
}
299
300
abstract class ClassVisibleEventRequestImpl
301
extends ThreadVisibleEventRequestImpl {
302
public synchronized void addClassFilter(ReferenceType clazz) {
303
validateMirror(clazz);
304
if (isEnabled() || deleted) {
305
throw invalidState();
306
}
307
filters.add(JDWP.EventRequest.Set.Modifier.ClassOnly
308
.create((ReferenceTypeImpl)clazz));
309
}
310
311
public synchronized void addClassFilter(String classPattern) {
312
if (isEnabled() || deleted) {
313
throw invalidState();
314
}
315
if (classPattern == null) {
316
throw new NullPointerException();
317
}
318
filters.add(JDWP.EventRequest.Set.Modifier.ClassMatch
319
.create(classPattern));
320
}
321
322
public synchronized void addClassExclusionFilter(String classPattern) {
323
if (isEnabled() || deleted) {
324
throw invalidState();
325
}
326
if (classPattern == null) {
327
throw new NullPointerException();
328
}
329
filters.add(JDWP.EventRequest.Set.Modifier.ClassExclude
330
.create(classPattern));
331
}
332
333
public synchronized void addInstanceFilter(ObjectReference instance) {
334
validateMirror(instance);
335
if (isEnabled() || deleted) {
336
throw invalidState();
337
}
338
if (!vm.canUseInstanceFilters()) {
339
throw new UnsupportedOperationException(
340
"target does not support instance filters");
341
}
342
filters.add(JDWP.EventRequest.Set.Modifier.InstanceOnly
343
.create((ObjectReferenceImpl)instance));
344
}
345
}
346
347
class BreakpointRequestImpl extends ClassVisibleEventRequestImpl
348
implements BreakpointRequest {
349
private final Location location;
350
351
BreakpointRequestImpl(Location location) {
352
this.location = location;
353
filters.add(0,JDWP.EventRequest.Set.Modifier.LocationOnly
354
.create(location));
355
requestList().add(this);
356
}
357
358
public Location location() {
359
return location;
360
}
361
362
int eventCmd() {
363
return JDWP.EventKind.BREAKPOINT;
364
}
365
366
public String toString() {
367
return "breakpoint request " + location() + state();
368
}
369
}
370
371
class ClassPrepareRequestImpl extends ClassVisibleEventRequestImpl
372
implements ClassPrepareRequest {
373
ClassPrepareRequestImpl() {
374
requestList().add(this);
375
}
376
377
int eventCmd() {
378
return JDWP.EventKind.CLASS_PREPARE;
379
}
380
381
public synchronized void addSourceNameFilter(String sourceNamePattern) {
382
if (isEnabled() || deleted) {
383
throw invalidState();
384
}
385
if (!vm.canUseSourceNameFilters()) {
386
throw new UnsupportedOperationException(
387
"target does not support source name filters");
388
}
389
if (sourceNamePattern == null) {
390
throw new NullPointerException();
391
}
392
393
filters.add(JDWP.EventRequest.Set.Modifier.SourceNameMatch
394
.create(sourceNamePattern));
395
}
396
397
public String toString() {
398
return "class prepare request " + state();
399
}
400
}
401
402
class ClassUnloadRequestImpl extends ClassVisibleEventRequestImpl
403
implements ClassUnloadRequest {
404
ClassUnloadRequestImpl() {
405
requestList().add(this);
406
}
407
408
int eventCmd() {
409
return JDWP.EventKind.CLASS_UNLOAD;
410
}
411
412
public String toString() {
413
return "class unload request " + state();
414
}
415
}
416
417
class ExceptionRequestImpl extends ClassVisibleEventRequestImpl
418
implements ExceptionRequest {
419
ReferenceType exception = null;
420
boolean caught = true;
421
boolean uncaught = true;
422
423
ExceptionRequestImpl(ReferenceType refType,
424
boolean notifyCaught, boolean notifyUncaught) {
425
exception = refType;
426
caught = notifyCaught;
427
uncaught = notifyUncaught;
428
{
429
ReferenceTypeImpl exc;
430
if (exception == null) {
431
exc = new ClassTypeImpl(vm, 0);
432
} else {
433
exc = (ReferenceTypeImpl)exception;
434
}
435
filters.add(JDWP.EventRequest.Set.Modifier.ExceptionOnly.
436
create(exc, caught, uncaught));
437
}
438
requestList().add(this);
439
}
440
441
public ReferenceType exception() {
442
return exception;
443
}
444
445
public boolean notifyCaught() {
446
return caught;
447
}
448
449
public boolean notifyUncaught() {
450
return uncaught;
451
}
452
453
int eventCmd() {
454
return JDWP.EventKind.EXCEPTION;
455
}
456
457
public String toString() {
458
return "exception request " + exception() + state();
459
}
460
}
461
462
class MethodEntryRequestImpl extends ClassVisibleEventRequestImpl
463
implements MethodEntryRequest {
464
MethodEntryRequestImpl() {
465
requestList().add(this);
466
}
467
468
int eventCmd() {
469
return JDWP.EventKind.METHOD_ENTRY;
470
}
471
472
public String toString() {
473
return "method entry request " + state();
474
}
475
}
476
477
class MethodExitRequestImpl extends ClassVisibleEventRequestImpl
478
implements MethodExitRequest {
479
MethodExitRequestImpl() {
480
if (methodExitEventCmd == 0) {
481
/*
482
* If we can get return values, then we always get them.
483
* Thus, for JDI MethodExitRequests, we always use the
484
* same JDWP EventKind. Here we decide which to use and
485
* save it so that it will be used for all future
486
* MethodExitRequests.
487
*
488
* This call to canGetMethodReturnValues can't
489
* be done in the EventRequestManager ctor because that is too early.
490
*/
491
if (vm.canGetMethodReturnValues()) {
492
methodExitEventCmd = JDWP.EventKind.METHOD_EXIT_WITH_RETURN_VALUE;
493
} else {
494
methodExitEventCmd = JDWP.EventKind.METHOD_EXIT;
495
}
496
}
497
requestList().add(this);
498
}
499
500
int eventCmd() {
501
return EventRequestManagerImpl.methodExitEventCmd;
502
}
503
504
public String toString() {
505
return "method exit request " + state();
506
}
507
}
508
509
class MonitorContendedEnterRequestImpl extends ClassVisibleEventRequestImpl
510
implements MonitorContendedEnterRequest {
511
MonitorContendedEnterRequestImpl() {
512
requestList().add(this);
513
}
514
515
int eventCmd() {
516
return JDWP.EventKind.MONITOR_CONTENDED_ENTER;
517
}
518
519
public String toString() {
520
return "monitor contended enter request " + state();
521
}
522
}
523
524
class MonitorContendedEnteredRequestImpl extends ClassVisibleEventRequestImpl
525
implements MonitorContendedEnteredRequest {
526
MonitorContendedEnteredRequestImpl() {
527
requestList().add(this);
528
}
529
530
int eventCmd() {
531
return JDWP.EventKind.MONITOR_CONTENDED_ENTERED;
532
}
533
534
public String toString() {
535
return "monitor contended entered request " + state();
536
}
537
}
538
539
class MonitorWaitRequestImpl extends ClassVisibleEventRequestImpl
540
implements MonitorWaitRequest {
541
MonitorWaitRequestImpl() {
542
requestList().add(this);
543
}
544
545
int eventCmd() {
546
return JDWP.EventKind.MONITOR_WAIT;
547
}
548
549
public String toString() {
550
return "monitor wait request " + state();
551
}
552
}
553
554
class MonitorWaitedRequestImpl extends ClassVisibleEventRequestImpl
555
implements MonitorWaitedRequest {
556
MonitorWaitedRequestImpl() {
557
requestList().add(this);
558
}
559
560
int eventCmd() {
561
return JDWP.EventKind.MONITOR_WAITED;
562
}
563
564
public String toString() {
565
return "monitor waited request " + state();
566
}
567
}
568
569
class StepRequestImpl extends ClassVisibleEventRequestImpl
570
implements StepRequest {
571
ThreadReferenceImpl thread;
572
int size;
573
int depth;
574
575
StepRequestImpl(ThreadReference thread, int size, int depth) {
576
this.thread = (ThreadReferenceImpl)thread;
577
this.size = size;
578
this.depth = depth;
579
580
/*
581
* Translate size and depth to corresponding JDWP values.
582
*/
583
int jdwpSize;
584
switch (size) {
585
case STEP_MIN:
586
jdwpSize = JDWP.StepSize.MIN;
587
break;
588
case STEP_LINE:
589
jdwpSize = JDWP.StepSize.LINE;
590
break;
591
default:
592
throw new IllegalArgumentException("Invalid step size");
593
}
594
595
int jdwpDepth;
596
switch (depth) {
597
case STEP_INTO:
598
jdwpDepth = JDWP.StepDepth.INTO;
599
break;
600
case STEP_OVER:
601
jdwpDepth = JDWP.StepDepth.OVER;
602
break;
603
case STEP_OUT:
604
jdwpDepth = JDWP.StepDepth.OUT;
605
break;
606
default:
607
throw new IllegalArgumentException("Invalid step depth");
608
}
609
610
/*
611
* Make sure this isn't a duplicate
612
*/
613
List<StepRequest> requests = stepRequests();
614
Iterator<StepRequest> iter = requests.iterator();
615
while (iter.hasNext()) {
616
StepRequest request = iter.next();
617
if ((request != this) &&
618
request.isEnabled() &&
619
request.thread().equals(thread)) {
620
throw new DuplicateRequestException(
621
"Only one step request allowed per thread");
622
}
623
}
624
625
filters.add(JDWP.EventRequest.Set.Modifier.Step.
626
create(this.thread, jdwpSize, jdwpDepth));
627
requestList().add(this);
628
629
}
630
public int depth() {
631
return depth;
632
}
633
634
public int size() {
635
return size;
636
}
637
638
public ThreadReference thread() {
639
return thread;
640
}
641
642
int eventCmd() {
643
return JDWP.EventKind.SINGLE_STEP;
644
}
645
646
public String toString() {
647
return "step request " + thread() + state();
648
}
649
}
650
651
class ThreadDeathRequestImpl extends ThreadVisibleEventRequestImpl
652
implements ThreadDeathRequest {
653
ThreadDeathRequestImpl() {
654
requestList().add(this);
655
}
656
657
int eventCmd() {
658
return JDWP.EventKind.THREAD_DEATH;
659
}
660
661
public String toString() {
662
return "thread death request " + state();
663
}
664
}
665
666
class ThreadStartRequestImpl extends ThreadVisibleEventRequestImpl
667
implements ThreadStartRequest {
668
ThreadStartRequestImpl() {
669
requestList().add(this);
670
}
671
672
int eventCmd() {
673
return JDWP.EventKind.THREAD_START;
674
}
675
676
public String toString() {
677
return "thread start request " + state();
678
}
679
}
680
681
abstract class WatchpointRequestImpl extends ClassVisibleEventRequestImpl
682
implements WatchpointRequest {
683
final Field field;
684
685
WatchpointRequestImpl(Field field) {
686
this.field = field;
687
filters.add(0,
688
JDWP.EventRequest.Set.Modifier.FieldOnly.create(
689
(ReferenceTypeImpl)field.declaringType(),
690
((FieldImpl)field).ref()));
691
}
692
693
public Field field() {
694
return field;
695
}
696
}
697
698
class AccessWatchpointRequestImpl extends WatchpointRequestImpl
699
implements AccessWatchpointRequest {
700
AccessWatchpointRequestImpl(Field field) {
701
super(field);
702
requestList().add(this);
703
}
704
705
int eventCmd() {
706
return JDWP.EventKind.FIELD_ACCESS;
707
}
708
709
public String toString() {
710
return "access watchpoint request " + field + state();
711
}
712
}
713
714
class ModificationWatchpointRequestImpl extends WatchpointRequestImpl
715
implements ModificationWatchpointRequest {
716
ModificationWatchpointRequestImpl(Field field) {
717
super(field);
718
requestList().add(this);
719
}
720
721
int eventCmd() {
722
return JDWP.EventKind.FIELD_MODIFICATION;
723
}
724
725
public String toString() {
726
return "modification watchpoint request " + field + state();
727
}
728
}
729
730
class VMDeathRequestImpl extends EventRequestImpl
731
implements VMDeathRequest {
732
VMDeathRequestImpl() {
733
requestList().add(this);
734
}
735
736
int eventCmd() {
737
return JDWP.EventKind.VM_DEATH;
738
}
739
740
public String toString() {
741
return "VM death request " + state();
742
}
743
}
744
745
/**
746
* Constructor.
747
*/
748
EventRequestManagerImpl(VirtualMachine vm) {
749
super(vm);
750
java.lang.reflect.Field[] ekinds =
751
JDWP.EventKind.class.getDeclaredFields();
752
int highest = 0;
753
for (int i = 0; i < ekinds.length; ++i) {
754
int val;
755
try {
756
val = ekinds[i].getInt(null);
757
} catch (IllegalAccessException exc) {
758
throw new RuntimeException("Got: " + exc);
759
}
760
if (val > highest) {
761
highest = val;
762
}
763
}
764
requestLists = new List[highest+1];
765
for (int i=0; i <= highest; i++) {
766
requestLists[i] = Collections.synchronizedList(new ArrayList<>());
767
}
768
}
769
770
public ClassPrepareRequest createClassPrepareRequest() {
771
return new ClassPrepareRequestImpl();
772
}
773
774
public ClassUnloadRequest createClassUnloadRequest() {
775
return new ClassUnloadRequestImpl();
776
}
777
778
public ExceptionRequest createExceptionRequest(ReferenceType refType,
779
boolean notifyCaught,
780
boolean notifyUncaught) {
781
validateMirrorOrNull(refType);
782
return new ExceptionRequestImpl(refType, notifyCaught, notifyUncaught);
783
}
784
785
public StepRequest createStepRequest(ThreadReference thread,
786
int size, int depth) {
787
validateMirror(thread);
788
return new StepRequestImpl(thread, size, depth);
789
}
790
791
public ThreadDeathRequest createThreadDeathRequest() {
792
return new ThreadDeathRequestImpl();
793
}
794
795
public ThreadStartRequest createThreadStartRequest() {
796
return new ThreadStartRequestImpl();
797
}
798
799
public MethodEntryRequest createMethodEntryRequest() {
800
return new MethodEntryRequestImpl();
801
}
802
803
public MethodExitRequest createMethodExitRequest() {
804
return new MethodExitRequestImpl();
805
}
806
807
public MonitorContendedEnterRequest createMonitorContendedEnterRequest() {
808
if (!vm.canRequestMonitorEvents()) {
809
throw new UnsupportedOperationException(
810
"target VM does not support requesting Monitor events");
811
}
812
return new MonitorContendedEnterRequestImpl();
813
}
814
815
public MonitorContendedEnteredRequest createMonitorContendedEnteredRequest() {
816
if (!vm.canRequestMonitorEvents()) {
817
throw new UnsupportedOperationException(
818
"target VM does not support requesting Monitor events");
819
}
820
return new MonitorContendedEnteredRequestImpl();
821
}
822
823
public MonitorWaitRequest createMonitorWaitRequest() {
824
if (!vm.canRequestMonitorEvents()) {
825
throw new UnsupportedOperationException(
826
"target VM does not support requesting Monitor events");
827
}
828
return new MonitorWaitRequestImpl();
829
}
830
831
public MonitorWaitedRequest createMonitorWaitedRequest() {
832
if (!vm.canRequestMonitorEvents()) {
833
throw new UnsupportedOperationException(
834
"target VM does not support requesting Monitor events");
835
}
836
return new MonitorWaitedRequestImpl();
837
}
838
839
public BreakpointRequest createBreakpointRequest(Location location) {
840
validateMirror(location);
841
if (location.codeIndex() == -1) {
842
throw new NativeMethodException("Cannot set breakpoints on native methods");
843
}
844
return new BreakpointRequestImpl(location);
845
}
846
847
public AccessWatchpointRequest
848
createAccessWatchpointRequest(Field field) {
849
validateMirror(field);
850
if (!vm.canWatchFieldAccess()) {
851
throw new UnsupportedOperationException(
852
"target VM does not support access watchpoints");
853
}
854
return new AccessWatchpointRequestImpl(field);
855
}
856
857
public ModificationWatchpointRequest
858
createModificationWatchpointRequest(Field field) {
859
validateMirror(field);
860
if (!vm.canWatchFieldModification()) {
861
throw new UnsupportedOperationException(
862
"target VM does not support modification watchpoints");
863
}
864
return new ModificationWatchpointRequestImpl(field);
865
}
866
867
public VMDeathRequest createVMDeathRequest() {
868
if (!vm.canRequestVMDeathEvent()) {
869
throw new UnsupportedOperationException(
870
"target VM does not support requesting VM death events");
871
}
872
return new VMDeathRequestImpl();
873
}
874
875
public void deleteEventRequest(EventRequest eventRequest) {
876
validateMirror(eventRequest);
877
((EventRequestImpl)eventRequest).delete();
878
}
879
880
public void deleteEventRequests(List<? extends EventRequest> eventRequests) {
881
validateMirrors(eventRequests);
882
// copy the eventRequests to avoid ConcurrentModificationException
883
Iterator<? extends EventRequest> iter = (new ArrayList<>(eventRequests)).iterator();
884
while (iter.hasNext()) {
885
((EventRequestImpl)iter.next()).delete();
886
}
887
}
888
889
public void deleteAllBreakpoints() {
890
requestList(JDWP.EventKind.BREAKPOINT).clear();
891
892
try {
893
JDWP.EventRequest.ClearAllBreakpoints.process(vm);
894
} catch (JDWPException exc) {
895
throw exc.toJDIException();
896
}
897
}
898
899
public List<StepRequest> stepRequests() {
900
return (List<StepRequest>)unmodifiableRequestList(JDWP.EventKind.SINGLE_STEP);
901
}
902
903
public List<ClassPrepareRequest> classPrepareRequests() {
904
return (List<ClassPrepareRequest>)unmodifiableRequestList(JDWP.EventKind.CLASS_PREPARE);
905
}
906
907
public List<ClassUnloadRequest> classUnloadRequests() {
908
return (List<ClassUnloadRequest>)unmodifiableRequestList(JDWP.EventKind.CLASS_UNLOAD);
909
}
910
911
public List<ThreadStartRequest> threadStartRequests() {
912
return (List<ThreadStartRequest>)unmodifiableRequestList(JDWP.EventKind.THREAD_START);
913
}
914
915
public List<ThreadDeathRequest> threadDeathRequests() {
916
return (List<ThreadDeathRequest>)unmodifiableRequestList(JDWP.EventKind.THREAD_DEATH);
917
}
918
919
public List<ExceptionRequest> exceptionRequests() {
920
return (List<ExceptionRequest>)unmodifiableRequestList(JDWP.EventKind.EXCEPTION);
921
}
922
923
public List<BreakpointRequest> breakpointRequests() {
924
return (List<BreakpointRequest>)unmodifiableRequestList(JDWP.EventKind.BREAKPOINT);
925
}
926
927
public List<AccessWatchpointRequest> accessWatchpointRequests() {
928
return (List<AccessWatchpointRequest>)unmodifiableRequestList(JDWP.EventKind.FIELD_ACCESS);
929
}
930
931
public List<ModificationWatchpointRequest> modificationWatchpointRequests() {
932
return (List<ModificationWatchpointRequest>)unmodifiableRequestList(JDWP.EventKind.FIELD_MODIFICATION);
933
}
934
935
public List<MethodEntryRequest> methodEntryRequests() {
936
return (List<MethodEntryRequest>)unmodifiableRequestList(JDWP.EventKind.METHOD_ENTRY);
937
}
938
939
public List<MethodExitRequest> methodExitRequests() {
940
return (List<MethodExitRequest>)unmodifiableRequestList(EventRequestManagerImpl.methodExitEventCmd);
941
}
942
943
public List<MonitorContendedEnterRequest> monitorContendedEnterRequests() {
944
return (List<MonitorContendedEnterRequest>)unmodifiableRequestList(JDWP.EventKind.MONITOR_CONTENDED_ENTER);
945
}
946
947
public List<MonitorContendedEnteredRequest> monitorContendedEnteredRequests() {
948
return (List<MonitorContendedEnteredRequest>)unmodifiableRequestList(JDWP.EventKind.MONITOR_CONTENDED_ENTERED);
949
}
950
951
public List<MonitorWaitRequest> monitorWaitRequests() {
952
return (List<MonitorWaitRequest>)unmodifiableRequestList(JDWP.EventKind.MONITOR_WAIT);
953
}
954
955
public List<MonitorWaitedRequest> monitorWaitedRequests() {
956
return (List<MonitorWaitedRequest>)unmodifiableRequestList(JDWP.EventKind.MONITOR_WAITED);
957
}
958
959
public List<VMDeathRequest> vmDeathRequests() {
960
return (List<VMDeathRequest>)unmodifiableRequestList(JDWP.EventKind.VM_DEATH);
961
}
962
963
List<? extends EventRequest> unmodifiableRequestList(int eventCmd) {
964
// No need of explicit synchronization for requestList here.
965
// It is taken care internally by SynchronizedList class.
966
return Collections.unmodifiableList(new ArrayList<>(requestList(eventCmd)));
967
}
968
969
EventRequest request(int eventCmd, int requestId) {
970
List<? extends EventRequest> rl = requestList(eventCmd);
971
synchronized(rl) { // Refer Collections.synchronizedList javadoc.
972
Iterator<? extends EventRequest> itr = rl.iterator();
973
while (itr.hasNext()){
974
EventRequestImpl er = (EventRequestImpl)itr.next();
975
if (er.id == requestId)
976
return er;
977
}
978
}
979
return null;
980
}
981
982
private List<? extends EventRequest> requestList(int eventCmd) {
983
return requestLists[eventCmd];
984
}
985
}
986
987