2
|
1 |
/*
|
715
|
2 |
* Copyright 1999-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.example.debug.bdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.request.*;
|
|
30 |
|
|
31 |
import java.util.*;
|
|
32 |
|
|
33 |
class EventRequestSpecList {
|
|
34 |
|
|
35 |
// all specs
|
|
36 |
private List<EventRequestSpec> eventRequestSpecs = Collections.synchronizedList(
|
|
37 |
new ArrayList<EventRequestSpec>());
|
|
38 |
|
|
39 |
final ExecutionManager runtime;
|
|
40 |
|
|
41 |
EventRequestSpecList(ExecutionManager runtime) {
|
|
42 |
this.runtime = runtime;
|
|
43 |
}
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Resolve all deferred eventRequests waiting for 'refType'.
|
|
47 |
*/
|
|
48 |
void resolve(ReferenceType refType) {
|
|
49 |
synchronized(eventRequestSpecs) {
|
51
|
50 |
for (EventRequestSpec spec : eventRequestSpecs) {
|
|
51 |
spec.attemptResolve(refType);
|
2
|
52 |
}
|
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
void install(EventRequestSpec ers, VirtualMachine vm) {
|
|
57 |
synchronized (eventRequestSpecs) {
|
|
58 |
eventRequestSpecs.add(ers);
|
|
59 |
}
|
|
60 |
if (vm != null) {
|
|
61 |
ers.attemptImmediateResolve(vm);
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
BreakpointSpec
|
|
66 |
createClassLineBreakpoint(String classPattern, int line) {
|
|
67 |
ReferenceTypeSpec refSpec =
|
|
68 |
new PatternReferenceTypeSpec(classPattern);
|
|
69 |
return new LineBreakpointSpec(this, refSpec, line);
|
|
70 |
}
|
|
71 |
|
|
72 |
BreakpointSpec
|
|
73 |
createSourceLineBreakpoint(String sourceName, int line) {
|
|
74 |
ReferenceTypeSpec refSpec =
|
|
75 |
new SourceNameReferenceTypeSpec(sourceName, line);
|
|
76 |
return new LineBreakpointSpec(this, refSpec, line);
|
|
77 |
}
|
|
78 |
|
|
79 |
BreakpointSpec
|
|
80 |
createMethodBreakpoint(String classPattern,
|
51
|
81 |
String methodId, List<String> methodArgs) {
|
2
|
82 |
ReferenceTypeSpec refSpec =
|
|
83 |
new PatternReferenceTypeSpec(classPattern);
|
|
84 |
return new MethodBreakpointSpec(this, refSpec,
|
|
85 |
methodId, methodArgs);
|
|
86 |
}
|
|
87 |
|
|
88 |
ExceptionSpec
|
|
89 |
createExceptionIntercept(String classPattern,
|
|
90 |
boolean notifyCaught,
|
|
91 |
boolean notifyUncaught) {
|
|
92 |
ReferenceTypeSpec refSpec =
|
|
93 |
new PatternReferenceTypeSpec(classPattern);
|
|
94 |
return new ExceptionSpec(this, refSpec,
|
|
95 |
notifyCaught, notifyUncaught);
|
|
96 |
}
|
|
97 |
|
|
98 |
AccessWatchpointSpec
|
|
99 |
createAccessWatchpoint(String classPattern, String fieldId) {
|
|
100 |
ReferenceTypeSpec refSpec =
|
|
101 |
new PatternReferenceTypeSpec(classPattern);
|
|
102 |
return new AccessWatchpointSpec(this, refSpec, fieldId);
|
|
103 |
}
|
|
104 |
|
|
105 |
ModificationWatchpointSpec
|
|
106 |
createModificationWatchpoint(String classPattern, String fieldId) {
|
|
107 |
ReferenceTypeSpec refSpec =
|
|
108 |
new PatternReferenceTypeSpec(classPattern);
|
|
109 |
return new ModificationWatchpointSpec(this, refSpec, fieldId);
|
|
110 |
}
|
|
111 |
|
|
112 |
void delete(EventRequestSpec ers) {
|
|
113 |
EventRequest request = ers.getEventRequest();
|
|
114 |
synchronized (eventRequestSpecs) {
|
|
115 |
eventRequestSpecs.remove(ers);
|
|
116 |
}
|
|
117 |
if (request != null) {
|
|
118 |
request.virtualMachine().eventRequestManager()
|
|
119 |
.deleteEventRequest(request);
|
|
120 |
}
|
|
121 |
notifyDeleted(ers);
|
|
122 |
//### notify delete - here?
|
|
123 |
}
|
|
124 |
|
|
125 |
List<EventRequestSpec> eventRequestSpecs() {
|
|
126 |
// We need to make a copy to avoid synchronization problems
|
|
127 |
synchronized (eventRequestSpecs) {
|
|
128 |
return new ArrayList<EventRequestSpec>(eventRequestSpecs);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
// -------- notify routines --------------------
|
|
133 |
|
51
|
134 |
@SuppressWarnings("unchecked")
|
|
135 |
private Vector<SpecListener> specListeners() {
|
|
136 |
return (Vector<SpecListener>)runtime.specListeners.clone();
|
2
|
137 |
}
|
|
138 |
|
|
139 |
void notifySet(EventRequestSpec spec) {
|
51
|
140 |
Vector<SpecListener> l = specListeners();
|
2
|
141 |
SpecEvent evt = new SpecEvent(spec);
|
|
142 |
for (int i = 0; i < l.size(); i++) {
|
51
|
143 |
spec.notifySet(l.elementAt(i), evt);
|
2
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
void notifyDeferred(EventRequestSpec spec) {
|
51
|
148 |
Vector<SpecListener> l = specListeners();
|
2
|
149 |
SpecEvent evt = new SpecEvent(spec);
|
|
150 |
for (int i = 0; i < l.size(); i++) {
|
51
|
151 |
spec.notifyDeferred(l.elementAt(i), evt);
|
2
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
void notifyDeleted(EventRequestSpec spec) {
|
51
|
156 |
Vector<SpecListener> l = specListeners();
|
2
|
157 |
SpecEvent evt = new SpecEvent(spec);
|
|
158 |
for (int i = 0; i < l.size(); i++) {
|
51
|
159 |
spec.notifyDeleted(l.elementAt(i), evt);
|
2
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
void notifyResolved(EventRequestSpec spec) {
|
51
|
164 |
Vector<SpecListener> l = specListeners();
|
2
|
165 |
SpecEvent evt = new SpecEvent(spec);
|
|
166 |
for (int i = 0; i < l.size(); i++) {
|
51
|
167 |
spec.notifyResolved(l.elementAt(i), evt);
|
2
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
void notifyError(EventRequestSpec spec, Exception exc) {
|
51
|
172 |
Vector<SpecListener> l = specListeners();
|
2
|
173 |
SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
|
|
174 |
for (int i = 0; i < l.size(); i++) {
|
51
|
175 |
spec.notifyError(l.elementAt(i), evt);
|
2
|
176 |
}
|
|
177 |
}
|
|
178 |
}
|