author | ohair |
Fri, 22 Aug 2008 12:24:27 -0700 | |
changeset 1090 | c5805b1672a6 |
parent 828 | ad3f54bd6ae8 |
child 1247 | b4c26443dee5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 2001-2005 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 |
* eventFilter |
|
27 |
* |
|
28 |
* This module handles event filteration and the enabling/disabling |
|
29 |
* of the corresponding events. Used for filters on JDI EventRequests |
|
30 |
* and also internal requests. Our data is in a private hidden section |
|
31 |
* of the HandlerNode's data. See comment for enclosing |
|
32 |
* module eventHandler. |
|
33 |
*/ |
|
34 |
||
35 |
#include "util.h" |
|
36 |
#include "eventFilter.h" |
|
37 |
#include "eventFilterRestricted.h" |
|
38 |
#include "eventHandlerRestricted.h" |
|
39 |
#include "stepControl.h" |
|
40 |
#include "threadControl.h" |
|
41 |
#include "SDE.h" |
|
42 |
||
43 |
typedef struct ClassFilter { |
|
44 |
jclass clazz; |
|
45 |
} ClassFilter; |
|
46 |
||
47 |
typedef struct LocationFilter { |
|
48 |
jclass clazz; |
|
49 |
jmethodID method; |
|
50 |
jlocation location; |
|
51 |
} LocationFilter; |
|
52 |
||
53 |
typedef struct ThreadFilter { |
|
54 |
jthread thread; |
|
55 |
} ThreadFilter; |
|
56 |
||
57 |
typedef struct CountFilter { |
|
58 |
jint count; |
|
59 |
} CountFilter; |
|
60 |
||
61 |
typedef struct ConditionalFilter { |
|
62 |
jint exprID; |
|
63 |
} ConditionalFilter; |
|
64 |
||
65 |
typedef struct FieldFilter { |
|
66 |
jclass clazz; |
|
67 |
jfieldID field; |
|
68 |
} FieldFilter; |
|
69 |
||
70 |
typedef struct ExceptionFilter { |
|
71 |
jclass exception; |
|
72 |
jboolean caught; |
|
73 |
jboolean uncaught; |
|
74 |
} ExceptionFilter; |
|
75 |
||
76 |
typedef struct InstanceFilter { |
|
77 |
jobject instance; |
|
78 |
} InstanceFilter; |
|
79 |
||
80 |
typedef struct StepFilter { |
|
81 |
jint size; |
|
82 |
jint depth; |
|
83 |
jthread thread; |
|
84 |
} StepFilter; |
|
85 |
||
86 |
typedef struct MatchFilter { |
|
87 |
char *classPattern; |
|
88 |
} MatchFilter; |
|
89 |
||
90 |
typedef struct SourceNameFilter { |
|
91 |
char *sourceNamePattern; |
|
92 |
} SourceNameFilter; |
|
93 |
||
94 |
typedef struct Filter_ { |
|
95 |
jbyte modifier; |
|
96 |
union { |
|
97 |
struct ClassFilter ClassOnly; |
|
98 |
struct LocationFilter LocationOnly; |
|
99 |
struct ThreadFilter ThreadOnly; |
|
100 |
struct CountFilter Count; |
|
101 |
struct ConditionalFilter Conditional; |
|
102 |
struct FieldFilter FieldOnly; |
|
103 |
struct ExceptionFilter ExceptionOnly; |
|
104 |
struct InstanceFilter InstanceOnly; |
|
105 |
struct StepFilter Step; |
|
106 |
struct MatchFilter ClassMatch; |
|
107 |
struct MatchFilter ClassExclude; |
|
108 |
struct SourceNameFilter SourceNameOnly; |
|
109 |
} u; |
|
110 |
} Filter; |
|
111 |
||
112 |
/* The filters array is allocated to the specified filterCount. |
|
113 |
* Theoretically, some compiler could do range checking on this |
|
114 |
* array - so, we define it to have a ludicrously large size so |
|
115 |
* that this range checking won't get upset. |
|
116 |
* |
|
117 |
* The actual allocated number of bytes is computed using the |
|
118 |
* offset of "filters" and so is not effected by this number. |
|
119 |
*/ |
|
120 |
#define MAX_FILTERS 10000 |
|
121 |
||
122 |
typedef struct EventFilters_ { |
|
123 |
jint filterCount; |
|
124 |
Filter filters[MAX_FILTERS]; |
|
125 |
} EventFilters; |
|
126 |
||
127 |
typedef struct EventFilterPrivate_HandlerNode_ { |
|
128 |
EventHandlerRestricted_HandlerNode not_for_us; |
|
129 |
EventFilters ef; |
|
130 |
} EventFilterPrivate_HandlerNode; |
|
131 |
||
132 |
/** |
|
133 |
* The following macros extract filter info (EventFilters) from private |
|
134 |
* data at the end of a HandlerNode |
|
135 |
*/ |
|
136 |
#define EVENT_FILTERS(node) (&(((EventFilterPrivate_HandlerNode*)(void*)node)->ef)) |
|
137 |
#define FILTER_COUNT(node) (EVENT_FILTERS(node)->filterCount) |
|
138 |
#define FILTERS_ARRAY(node) (EVENT_FILTERS(node)->filters) |
|
139 |
#define FILTER(node,index) ((FILTERS_ARRAY(node))[index]) |
|
140 |
#define NODE_EI(node) (node->ei) |
|
141 |
||
142 |
/***** filter set-up / destruction *****/ |
|
143 |
||
144 |
/** |
|
145 |
* Allocate a HandlerNode. |
|
146 |
* We do it because eventHandler doesn't know how big to make it. |
|
147 |
*/ |
|
148 |
HandlerNode * |
|
149 |
eventFilterRestricted_alloc(jint filterCount) |
|
150 |
{ |
|
151 |
/*LINTED*/ |
|
152 |
size_t size = offsetof(EventFilterPrivate_HandlerNode, ef) + |
|
153 |
offsetof(EventFilters, filters) + |
|
154 |
(filterCount * (int)sizeof(Filter)); |
|
155 |
HandlerNode *node = jvmtiAllocate((jint)size); |
|
156 |
||
157 |
if (node != NULL) { |
|
158 |
int i; |
|
159 |
Filter *filter; |
|
160 |
||
161 |
(void)memset(node, 0, size); |
|
162 |
||
163 |
FILTER_COUNT(node) = filterCount; |
|
164 |
||
165 |
/* Initialize all modifiers |
|
166 |
*/ |
|
167 |
for (i = 0, filter = FILTERS_ARRAY(node); |
|
168 |
i < filterCount; |
|
169 |
i++, filter++) { |
|
170 |
filter->modifier = JDWP_REQUEST_NONE; |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
return node; |
|
175 |
} |
|
176 |
||
177 |
/** |
|
178 |
* Free up global refs held by the filter. |
|
179 |
* free things up at the JNI level if needed. |
|
180 |
*/ |
|
181 |
static jvmtiError |
|
182 |
clearFilters(HandlerNode *node) |
|
183 |
{ |
|
184 |
JNIEnv *env = getEnv(); |
|
185 |
jint i; |
|
186 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
187 |
Filter *filter = FILTERS_ARRAY(node); |
|
188 |
||
189 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
190 |
switch (filter->modifier) { |
|
191 |
case JDWP_REQUEST_MODIFIER(ThreadOnly): |
|
192 |
if ( filter->u.ThreadOnly.thread != NULL ) { |
|
193 |
tossGlobalRef(env, &(filter->u.ThreadOnly.thread)); |
|
194 |
} |
|
195 |
break; |
|
196 |
case JDWP_REQUEST_MODIFIER(LocationOnly): |
|
197 |
tossGlobalRef(env, &(filter->u.LocationOnly.clazz)); |
|
198 |
break; |
|
199 |
case JDWP_REQUEST_MODIFIER(FieldOnly): |
|
200 |
tossGlobalRef(env, &(filter->u.FieldOnly.clazz)); |
|
201 |
break; |
|
202 |
case JDWP_REQUEST_MODIFIER(ExceptionOnly): |
|
203 |
if ( filter->u.ExceptionOnly.exception != NULL ) { |
|
204 |
tossGlobalRef(env, &(filter->u.ExceptionOnly.exception)); |
|
205 |
} |
|
206 |
break; |
|
207 |
case JDWP_REQUEST_MODIFIER(InstanceOnly): |
|
208 |
if ( filter->u.InstanceOnly.instance != NULL ) { |
|
209 |
tossGlobalRef(env, &(filter->u.InstanceOnly.instance)); |
|
210 |
} |
|
211 |
break; |
|
212 |
case JDWP_REQUEST_MODIFIER(ClassOnly): |
|
213 |
tossGlobalRef(env, &(filter->u.ClassOnly.clazz)); |
|
214 |
break; |
|
215 |
case JDWP_REQUEST_MODIFIER(ClassMatch): |
|
216 |
jvmtiDeallocate(filter->u.ClassMatch.classPattern); |
|
217 |
break; |
|
218 |
case JDWP_REQUEST_MODIFIER(ClassExclude): |
|
219 |
jvmtiDeallocate(filter->u.ClassExclude.classPattern); |
|
220 |
break; |
|
221 |
case JDWP_REQUEST_MODIFIER(Step): { |
|
222 |
jthread thread = filter->u.Step.thread; |
|
223 |
error = stepControl_endStep(thread); |
|
224 |
if (error == JVMTI_ERROR_NONE) { |
|
225 |
tossGlobalRef(env, &(filter->u.Step.thread)); |
|
226 |
} |
|
227 |
break; |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
if (error == JVMTI_ERROR_NONE) { |
|
232 |
FILTER_COUNT(node) = 0; /* blast so we don't clear again */ |
|
233 |
} |
|
234 |
||
235 |
return error; |
|
236 |
} |
|
237 |
||
238 |
||
239 |
/***** filtering *****/ |
|
240 |
||
241 |
/* |
|
242 |
* Match a string against a wildcard |
|
243 |
* string pattern. |
|
244 |
*/ |
|
245 |
static jboolean |
|
246 |
patternStringMatch(char *classname, const char *pattern) |
|
247 |
{ |
|
248 |
int pattLen; |
|
249 |
int compLen; |
|
250 |
char *start; |
|
251 |
int offset; |
|
252 |
||
253 |
if ( pattern==NULL || classname==NULL ) { |
|
254 |
return JNI_FALSE; |
|
255 |
} |
|
256 |
pattLen = (int)strlen(pattern); |
|
257 |
||
258 |
if ((pattern[0] != '*') && (pattern[pattLen-1] != '*')) { |
|
259 |
/* An exact match is required when there is no *: bug 4331522 */ |
|
260 |
return strcmp(pattern, classname) == 0; |
|
261 |
} else { |
|
262 |
compLen = pattLen - 1; |
|
263 |
offset = (int)strlen(classname) - compLen; |
|
264 |
if (offset < 0) { |
|
265 |
return JNI_FALSE; |
|
266 |
} else { |
|
267 |
if (pattern[0] == '*') { |
|
268 |
pattern++; |
|
269 |
start = classname + offset; |
|
270 |
} else { |
|
271 |
start = classname; |
|
272 |
} |
|
273 |
return strncmp(pattern, start, compLen) == 0; |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
/* Return the object instance in which the event occurred */ |
|
279 |
/* Return NULL if static or if an error occurs */ |
|
280 |
static jobject |
|
281 |
eventInstance(EventInfo *evinfo) |
|
282 |
{ |
|
283 |
jobject object = NULL; |
|
284 |
jthread thread ; |
|
285 |
jmethodID method ; |
|
286 |
jint modifiers = 0; |
|
287 |
jvmtiError error; |
|
288 |
||
289 |
switch (evinfo->ei) { |
|
290 |
case EI_SINGLE_STEP: |
|
291 |
case EI_BREAKPOINT: |
|
292 |
case EI_FRAME_POP: |
|
293 |
case EI_METHOD_ENTRY: |
|
294 |
case EI_METHOD_EXIT: |
|
295 |
case EI_EXCEPTION: |
|
296 |
case EI_EXCEPTION_CATCH: |
|
297 |
case EI_MONITOR_CONTENDED_ENTER: |
|
298 |
case EI_MONITOR_CONTENDED_ENTERED: |
|
299 |
case EI_MONITOR_WAIT: |
|
300 |
case EI_MONITOR_WAITED: |
|
301 |
thread = evinfo->thread; |
|
302 |
method = evinfo->method; |
|
303 |
break; |
|
304 |
case EI_FIELD_ACCESS: |
|
305 |
case EI_FIELD_MODIFICATION: |
|
306 |
object = evinfo->object; |
|
307 |
return object; |
|
308 |
default: |
|
309 |
return object; /* NULL */ |
|
310 |
} |
|
311 |
||
312 |
error = methodModifiers(method, &modifiers); |
|
313 |
||
314 |
/* fail if error or static (0x8) */ |
|
315 |
if (error == JVMTI_ERROR_NONE && thread!=NULL && (modifiers & 0x8) == 0) { |
|
316 |
FrameNumber fnum = 0; |
|
317 |
/* get slot zero object "this" */ |
|
318 |
error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject) |
|
319 |
(gdata->jvmti, thread, fnum, 0, &object); |
|
320 |
if (error != JVMTI_ERROR_NONE) |
|
321 |
object = NULL; |
|
322 |
} |
|
323 |
||
324 |
return object; |
|
325 |
} |
|
326 |
||
327 |
/* |
|
328 |
* Determine if this event is interesting to this handler. |
|
329 |
* Do so by checking each of the handler's filters. |
|
330 |
* Return false if any of the filters fail, |
|
331 |
* true if the handler wants this event. |
|
332 |
* Anyone modifying this function should check |
|
333 |
* eventFilterRestricted_passesUnloadFilter and |
|
334 |
* eventFilter_predictFiltering as well. |
|
335 |
* |
|
336 |
* If shouldDelete is returned true, a count filter has expired |
|
337 |
* and the corresponding node should be deleted. |
|
338 |
*/ |
|
339 |
jboolean |
|
340 |
eventFilterRestricted_passesFilter(JNIEnv *env, |
|
341 |
char *classname, |
|
342 |
EventInfo *evinfo, |
|
343 |
HandlerNode *node, |
|
344 |
jboolean *shouldDelete) |
|
345 |
{ |
|
346 |
jthread thread; |
|
347 |
jclass clazz; |
|
348 |
jmethodID method; |
|
349 |
Filter *filter = FILTERS_ARRAY(node); |
|
350 |
int i; |
|
351 |
||
352 |
*shouldDelete = JNI_FALSE; |
|
353 |
thread = evinfo->thread; |
|
354 |
clazz = evinfo->clazz; |
|
355 |
method = evinfo->method; |
|
356 |
||
357 |
/* |
|
358 |
* Suppress most events if they happen in debug threads |
|
359 |
*/ |
|
360 |
if ((evinfo->ei != EI_CLASS_PREPARE) && |
|
361 |
(evinfo->ei != EI_GC_FINISH) && |
|
362 |
(evinfo->ei != EI_CLASS_LOAD) && |
|
363 |
threadControl_isDebugThread(thread)) { |
|
364 |
return JNI_FALSE; |
|
365 |
} |
|
366 |
||
367 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
368 |
switch (filter->modifier) { |
|
369 |
case JDWP_REQUEST_MODIFIER(ThreadOnly): |
|
370 |
if (!isSameObject(env, thread, filter->u.ThreadOnly.thread)) { |
|
371 |
return JNI_FALSE; |
|
372 |
} |
|
373 |
break; |
|
374 |
||
375 |
case JDWP_REQUEST_MODIFIER(ClassOnly): |
|
376 |
/* Class filters catch events in the specified |
|
377 |
* class and any subclass/subinterface. |
|
378 |
*/ |
|
379 |
if (!JNI_FUNC_PTR(env,IsAssignableFrom)(env, clazz, |
|
380 |
filter->u.ClassOnly.clazz)) { |
|
381 |
return JNI_FALSE; |
|
382 |
} |
|
383 |
break; |
|
384 |
||
385 |
/* This is kinda cheating assumming the event |
|
386 |
* fields will be in the same locations, but it is |
|
387 |
* true now. |
|
388 |
*/ |
|
389 |
case JDWP_REQUEST_MODIFIER(LocationOnly): |
|
390 |
if (evinfo->method != |
|
391 |
filter->u.LocationOnly.method || |
|
392 |
evinfo->location != |
|
393 |
filter->u.LocationOnly.location || |
|
394 |
!isSameObject(env, clazz, filter->u.LocationOnly.clazz)) { |
|
395 |
return JNI_FALSE; |
|
396 |
} |
|
397 |
break; |
|
398 |
||
399 |
case JDWP_REQUEST_MODIFIER(FieldOnly): |
|
400 |
/* Field watchpoints can be triggered from the |
|
401 |
* declared class or any subclass/subinterface. |
|
402 |
*/ |
|
403 |
if ((evinfo->u.field_access.field != |
|
404 |
filter->u.FieldOnly.field) || |
|
405 |
!isSameObject(env, evinfo->u.field_access.field_clazz, |
|
406 |
filter->u.FieldOnly.clazz)) { |
|
407 |
return JNI_FALSE; |
|
408 |
} |
|
409 |
break; |
|
410 |
||
411 |
case JDWP_REQUEST_MODIFIER(ExceptionOnly): |
|
412 |
/* do we want caught/uncaught exceptions */ |
|
413 |
if (!((evinfo->u.exception.catch_clazz == NULL)? |
|
414 |
filter->u.ExceptionOnly.uncaught : |
|
415 |
filter->u.ExceptionOnly.caught)) { |
|
416 |
return JNI_FALSE; |
|
417 |
} |
|
418 |
||
419 |
/* do we care about exception class */ |
|
420 |
if (filter->u.ExceptionOnly.exception != NULL) { |
|
421 |
jclass exception = evinfo->object; |
|
422 |
||
423 |
/* do we want this exception class */ |
|
424 |
if (!JNI_FUNC_PTR(env,IsInstanceOf)(env, exception, |
|
425 |
filter->u.ExceptionOnly.exception)) { |
|
426 |
return JNI_FALSE; |
|
427 |
} |
|
428 |
} |
|
429 |
break; |
|
430 |
||
431 |
case JDWP_REQUEST_MODIFIER(InstanceOnly): { |
|
432 |
jobject eventInst = eventInstance(evinfo); |
|
433 |
jobject filterInst = filter->u.InstanceOnly.instance; |
|
434 |
/* if no error and doesn't match, don't pass |
|
435 |
* filter |
|
436 |
*/ |
|
437 |
if (eventInst != NULL && |
|
438 |
!isSameObject(env, eventInst, filterInst)) { |
|
439 |
return JNI_FALSE; |
|
440 |
} |
|
441 |
break; |
|
442 |
} |
|
443 |
case JDWP_REQUEST_MODIFIER(Count): { |
|
444 |
JDI_ASSERT(filter->u.Count.count > 0); |
|
445 |
if (--filter->u.Count.count > 0) { |
|
446 |
return JNI_FALSE; |
|
447 |
} |
|
448 |
*shouldDelete = JNI_TRUE; |
|
449 |
break; |
|
450 |
} |
|
451 |
||
452 |
case JDWP_REQUEST_MODIFIER(Conditional): |
|
453 |
/*** |
|
454 |
if (... filter->u.Conditional.exprID ...) { |
|
455 |
return JNI_FALSE; |
|
456 |
} |
|
457 |
***/ |
|
458 |
break; |
|
459 |
||
460 |
case JDWP_REQUEST_MODIFIER(ClassMatch): { |
|
461 |
if (!patternStringMatch(classname, |
|
462 |
filter->u.ClassMatch.classPattern)) { |
|
463 |
return JNI_FALSE; |
|
464 |
} |
|
465 |
break; |
|
466 |
} |
|
467 |
||
468 |
case JDWP_REQUEST_MODIFIER(ClassExclude): { |
|
469 |
if (patternStringMatch(classname, |
|
470 |
filter->u.ClassExclude.classPattern)) { |
|
471 |
return JNI_FALSE; |
|
472 |
} |
|
473 |
break; |
|
474 |
} |
|
475 |
||
476 |
case JDWP_REQUEST_MODIFIER(Step): |
|
477 |
if (!isSameObject(env, thread, filter->u.Step.thread)) { |
|
478 |
return JNI_FALSE; |
|
479 |
} |
|
480 |
if (!stepControl_handleStep(env, thread, clazz, method)) { |
|
481 |
return JNI_FALSE; |
|
482 |
} |
|
483 |
break; |
|
484 |
||
485 |
case JDWP_REQUEST_MODIFIER(SourceNameMatch): { |
|
486 |
char* desiredNamePattern = filter->u.SourceNameOnly.sourceNamePattern; |
|
487 |
if (!searchAllSourceNames(env, clazz, |
|
488 |
desiredNamePattern) == 1) { |
|
489 |
/* The name isn't in the SDE; try the sourceName in the ref |
|
490 |
* type |
|
491 |
*/ |
|
492 |
char *sourceName = 0; |
|
493 |
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName) |
|
494 |
(gdata->jvmti, clazz, &sourceName); |
|
828
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
495 |
if (error == JVMTI_ERROR_NONE && |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
496 |
sourceName != 0 && |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
497 |
patternStringMatch(sourceName, desiredNamePattern)) { |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
498 |
// got a hit - report the event |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
499 |
jvmtiDeallocate(sourceName); |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
500 |
break; |
2 | 501 |
} |
828
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
502 |
// We have no match, we have no source file name, |
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
503 |
// or we got a JVM TI error. Don't report the event. |
2 | 504 |
jvmtiDeallocate(sourceName); |
828
ad3f54bd6ae8
2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
jjh
parents:
2
diff
changeset
|
505 |
return JNI_FALSE; |
2 | 506 |
} |
507 |
break; |
|
508 |
} |
|
509 |
||
510 |
default: |
|
511 |
EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier"); |
|
512 |
return JNI_FALSE; |
|
513 |
} |
|
514 |
} |
|
515 |
return JNI_TRUE; |
|
516 |
} |
|
517 |
||
518 |
/* Determine if this event is interesting to this handler. Do so |
|
519 |
* by checking each of the handler's filters. Return false if any |
|
520 |
* of the filters fail, true if the handler wants this event. |
|
521 |
* Special version of filter for unloads since they don't have an |
|
522 |
* event structure or a jclass. |
|
523 |
* |
|
524 |
* If shouldDelete is returned true, a count filter has expired |
|
525 |
* and the corresponding node should be deleted. |
|
526 |
*/ |
|
527 |
jboolean |
|
528 |
eventFilterRestricted_passesUnloadFilter(JNIEnv *env, |
|
529 |
char *classname, |
|
530 |
HandlerNode *node, |
|
531 |
jboolean *shouldDelete) |
|
532 |
{ |
|
533 |
Filter *filter = FILTERS_ARRAY(node); |
|
534 |
int i; |
|
535 |
||
536 |
*shouldDelete = JNI_FALSE; |
|
537 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
538 |
switch (filter->modifier) { |
|
539 |
||
540 |
case JDWP_REQUEST_MODIFIER(Count): { |
|
541 |
JDI_ASSERT(filter->u.Count.count > 0); |
|
542 |
if (--filter->u.Count.count > 0) { |
|
543 |
return JNI_FALSE; |
|
544 |
} |
|
545 |
*shouldDelete = JNI_TRUE; |
|
546 |
break; |
|
547 |
} |
|
548 |
||
549 |
case JDWP_REQUEST_MODIFIER(ClassMatch): { |
|
550 |
if (!patternStringMatch(classname, |
|
551 |
filter->u.ClassMatch.classPattern)) { |
|
552 |
return JNI_FALSE; |
|
553 |
} |
|
554 |
break; |
|
555 |
} |
|
556 |
||
557 |
case JDWP_REQUEST_MODIFIER(ClassExclude): { |
|
558 |
if (patternStringMatch(classname, |
|
559 |
filter->u.ClassExclude.classPattern)) { |
|
560 |
return JNI_FALSE; |
|
561 |
} |
|
562 |
break; |
|
563 |
} |
|
564 |
||
565 |
default: |
|
566 |
EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier"); |
|
567 |
return JNI_FALSE; |
|
568 |
} |
|
569 |
} |
|
570 |
return JNI_TRUE; |
|
571 |
} |
|
572 |
||
573 |
/** |
|
574 |
* This function returns true only if it is certain that |
|
575 |
* all events for the given node in the given stack frame will |
|
576 |
* be filtered. It is used to optimize stepping. (If this |
|
577 |
* function returns true the stepping algorithm does not |
|
578 |
* have to step through every instruction in this stack frame; |
|
579 |
* instead, it can use more efficient method entry/exit |
|
580 |
* events. |
|
581 |
*/ |
|
582 |
jboolean |
|
583 |
eventFilter_predictFiltering(HandlerNode *node, jclass clazz, char *classname) |
|
584 |
{ |
|
585 |
JNIEnv *env; |
|
586 |
jboolean willBeFiltered; |
|
587 |
Filter *filter; |
|
588 |
jboolean done; |
|
589 |
int count; |
|
590 |
int i; |
|
591 |
||
592 |
willBeFiltered = JNI_FALSE; |
|
593 |
env = NULL; |
|
594 |
filter = FILTERS_ARRAY(node); |
|
595 |
count = FILTER_COUNT(node); |
|
596 |
done = JNI_FALSE; |
|
597 |
||
598 |
for (i = 0; (i < count) && (!done); ++i, ++filter) { |
|
599 |
switch (filter->modifier) { |
|
600 |
case JDWP_REQUEST_MODIFIER(ClassOnly): |
|
601 |
if ( env==NULL ) { |
|
602 |
env = getEnv(); |
|
603 |
} |
|
604 |
if (!JNI_FUNC_PTR(env,IsAssignableFrom)(env, clazz, |
|
605 |
filter->u.ClassOnly.clazz)) { |
|
606 |
willBeFiltered = JNI_TRUE; |
|
607 |
done = JNI_TRUE; |
|
608 |
} |
|
609 |
break; |
|
610 |
||
611 |
case JDWP_REQUEST_MODIFIER(Count): { |
|
612 |
/* |
|
613 |
* If preceeding filters have determined that events will |
|
614 |
* be filtered out, that is fine and we won't get here. |
|
615 |
* However, the count must be decremented - even if |
|
616 |
* subsequent filters will filter these events. We |
|
617 |
* thus must end now unable to predict |
|
618 |
*/ |
|
619 |
done = JNI_TRUE; |
|
620 |
break; |
|
621 |
} |
|
622 |
||
623 |
case JDWP_REQUEST_MODIFIER(ClassMatch): { |
|
624 |
if (!patternStringMatch(classname, |
|
625 |
filter->u.ClassMatch.classPattern)) { |
|
626 |
willBeFiltered = JNI_TRUE; |
|
627 |
done = JNI_TRUE; |
|
628 |
} |
|
629 |
break; |
|
630 |
} |
|
631 |
||
632 |
case JDWP_REQUEST_MODIFIER(ClassExclude): { |
|
633 |
if (patternStringMatch(classname, |
|
634 |
filter->u.ClassExclude.classPattern)) { |
|
635 |
willBeFiltered = JNI_TRUE; |
|
636 |
done = JNI_TRUE; |
|
637 |
} |
|
638 |
break; |
|
639 |
} |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
return willBeFiltered; |
|
644 |
} |
|
645 |
||
646 |
/** |
|
647 |
* Determine if the given breakpoint node is in the specified class. |
|
648 |
*/ |
|
649 |
jboolean |
|
650 |
eventFilterRestricted_isBreakpointInClass(JNIEnv *env, jclass clazz, |
|
651 |
HandlerNode *node) |
|
652 |
{ |
|
653 |
Filter *filter = FILTERS_ARRAY(node); |
|
654 |
int i; |
|
655 |
||
656 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
657 |
switch (filter->modifier) { |
|
658 |
case JDWP_REQUEST_MODIFIER(LocationOnly): |
|
659 |
return isSameObject(env, clazz, filter->u.LocationOnly.clazz); |
|
660 |
} |
|
661 |
} |
|
662 |
return JNI_TRUE; /* should never come here */ |
|
663 |
} |
|
664 |
||
665 |
/***** filter set-up *****/ |
|
666 |
||
667 |
jvmtiError |
|
668 |
eventFilter_setConditionalFilter(HandlerNode *node, jint index, |
|
669 |
jint exprID) |
|
670 |
{ |
|
671 |
ConditionalFilter *filter = &FILTER(node, index).u.Conditional; |
|
672 |
if (index >= FILTER_COUNT(node)) { |
|
673 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
674 |
} |
|
675 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Conditional); |
|
676 |
filter->exprID = exprID; |
|
677 |
return JVMTI_ERROR_NONE; |
|
678 |
} |
|
679 |
||
680 |
jvmtiError |
|
681 |
eventFilter_setCountFilter(HandlerNode *node, jint index, |
|
682 |
jint count) |
|
683 |
{ |
|
684 |
CountFilter *filter = &FILTER(node, index).u.Count; |
|
685 |
if (index >= FILTER_COUNT(node)) { |
|
686 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
687 |
} |
|
688 |
if (count <= 0) { |
|
689 |
return JDWP_ERROR(INVALID_COUNT); |
|
690 |
} else { |
|
691 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Count); |
|
692 |
filter->count = count; |
|
693 |
return JVMTI_ERROR_NONE; |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
jvmtiError |
|
698 |
eventFilter_setThreadOnlyFilter(HandlerNode *node, jint index, |
|
699 |
jthread thread) |
|
700 |
{ |
|
701 |
JNIEnv *env = getEnv(); |
|
702 |
ThreadFilter *filter = &FILTER(node, index).u.ThreadOnly; |
|
703 |
if (index >= FILTER_COUNT(node)) { |
|
704 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
705 |
} |
|
706 |
if (NODE_EI(node) == EI_GC_FINISH) { |
|
707 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
708 |
} |
|
709 |
||
710 |
/* Create a thread ref that will live beyond */ |
|
711 |
/* the end of this call */ |
|
712 |
saveGlobalRef(env, thread, &(filter->thread)); |
|
713 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ThreadOnly); |
|
714 |
return JVMTI_ERROR_NONE; |
|
715 |
} |
|
716 |
||
717 |
jvmtiError |
|
718 |
eventFilter_setLocationOnlyFilter(HandlerNode *node, jint index, |
|
719 |
jclass clazz, jmethodID method, |
|
720 |
jlocation location) |
|
721 |
{ |
|
722 |
JNIEnv *env = getEnv(); |
|
723 |
LocationFilter *filter = &FILTER(node, index).u.LocationOnly; |
|
724 |
if (index >= FILTER_COUNT(node)) { |
|
725 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
726 |
} |
|
727 |
if ((NODE_EI(node) != EI_BREAKPOINT) && |
|
728 |
(NODE_EI(node) != EI_FIELD_ACCESS) && |
|
729 |
(NODE_EI(node) != EI_FIELD_MODIFICATION) && |
|
730 |
(NODE_EI(node) != EI_SINGLE_STEP) && |
|
731 |
(NODE_EI(node) != EI_EXCEPTION)) { |
|
732 |
||
733 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
734 |
} |
|
735 |
||
736 |
/* Create a class ref that will live beyond */ |
|
737 |
/* the end of this call */ |
|
738 |
saveGlobalRef(env, clazz, &(filter->clazz)); |
|
739 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(LocationOnly); |
|
740 |
filter->method = method; |
|
741 |
filter->location = location; |
|
742 |
return JVMTI_ERROR_NONE; |
|
743 |
} |
|
744 |
||
745 |
jvmtiError |
|
746 |
eventFilter_setFieldOnlyFilter(HandlerNode *node, jint index, |
|
747 |
jclass clazz, jfieldID field) |
|
748 |
{ |
|
749 |
JNIEnv *env = getEnv(); |
|
750 |
FieldFilter *filter = &FILTER(node, index).u.FieldOnly; |
|
751 |
if (index >= FILTER_COUNT(node)) { |
|
752 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
753 |
} |
|
754 |
if ((NODE_EI(node) != EI_FIELD_ACCESS) && |
|
755 |
(NODE_EI(node) != EI_FIELD_MODIFICATION)) { |
|
756 |
||
757 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
758 |
} |
|
759 |
||
760 |
/* Create a class ref that will live beyond */ |
|
761 |
/* the end of this call */ |
|
762 |
saveGlobalRef(env, clazz, &(filter->clazz)); |
|
763 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(FieldOnly); |
|
764 |
filter->field = field; |
|
765 |
return JVMTI_ERROR_NONE; |
|
766 |
} |
|
767 |
||
768 |
jvmtiError |
|
769 |
eventFilter_setClassOnlyFilter(HandlerNode *node, jint index, |
|
770 |
jclass clazz) |
|
771 |
{ |
|
772 |
JNIEnv *env = getEnv(); |
|
773 |
ClassFilter *filter = &FILTER(node, index).u.ClassOnly; |
|
774 |
if (index >= FILTER_COUNT(node)) { |
|
775 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
776 |
} |
|
777 |
if ( |
|
778 |
(NODE_EI(node) == EI_GC_FINISH) || |
|
779 |
(NODE_EI(node) == EI_THREAD_START) || |
|
780 |
(NODE_EI(node) == EI_THREAD_END)) { |
|
781 |
||
782 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
783 |
} |
|
784 |
||
785 |
/* Create a class ref that will live beyond */ |
|
786 |
/* the end of this call */ |
|
787 |
saveGlobalRef(env, clazz, &(filter->clazz)); |
|
788 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ClassOnly); |
|
789 |
return JVMTI_ERROR_NONE; |
|
790 |
} |
|
791 |
||
792 |
jvmtiError |
|
793 |
eventFilter_setExceptionOnlyFilter(HandlerNode *node, jint index, |
|
794 |
jclass exceptionClass, |
|
795 |
jboolean caught, |
|
796 |
jboolean uncaught) |
|
797 |
{ |
|
798 |
JNIEnv *env = getEnv(); |
|
799 |
ExceptionFilter *filter = &FILTER(node, index).u.ExceptionOnly; |
|
800 |
if (index >= FILTER_COUNT(node)) { |
|
801 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
802 |
} |
|
803 |
if (NODE_EI(node) != EI_EXCEPTION) { |
|
804 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
805 |
} |
|
806 |
||
807 |
filter->exception = NULL; |
|
808 |
if (exceptionClass != NULL) { |
|
809 |
/* Create a class ref that will live beyond */ |
|
810 |
/* the end of this call */ |
|
811 |
saveGlobalRef(env, exceptionClass, &(filter->exception)); |
|
812 |
} |
|
813 |
FILTER(node, index).modifier = |
|
814 |
JDWP_REQUEST_MODIFIER(ExceptionOnly); |
|
815 |
filter->caught = caught; |
|
816 |
filter->uncaught = uncaught; |
|
817 |
return JVMTI_ERROR_NONE; |
|
818 |
} |
|
819 |
||
820 |
jvmtiError |
|
821 |
eventFilter_setInstanceOnlyFilter(HandlerNode *node, jint index, |
|
822 |
jobject instance) |
|
823 |
{ |
|
824 |
JNIEnv *env = getEnv(); |
|
825 |
InstanceFilter *filter = &FILTER(node, index).u.InstanceOnly; |
|
826 |
if (index >= FILTER_COUNT(node)) { |
|
827 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
828 |
} |
|
829 |
||
830 |
filter->instance = NULL; |
|
831 |
if (instance != NULL) { |
|
832 |
/* Create an object ref that will live beyond |
|
833 |
* the end of this call |
|
834 |
*/ |
|
835 |
saveGlobalRef(env, instance, &(filter->instance)); |
|
836 |
} |
|
837 |
FILTER(node, index).modifier = |
|
838 |
JDWP_REQUEST_MODIFIER(InstanceOnly); |
|
839 |
return JVMTI_ERROR_NONE; |
|
840 |
} |
|
841 |
||
842 |
jvmtiError |
|
843 |
eventFilter_setClassMatchFilter(HandlerNode *node, jint index, |
|
844 |
char *classPattern) |
|
845 |
{ |
|
846 |
MatchFilter *filter = &FILTER(node, index).u.ClassMatch; |
|
847 |
if (index >= FILTER_COUNT(node)) { |
|
848 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
849 |
} |
|
850 |
if ( |
|
851 |
(NODE_EI(node) == EI_THREAD_START) || |
|
852 |
(NODE_EI(node) == EI_THREAD_END)) { |
|
853 |
||
854 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
855 |
} |
|
856 |
||
857 |
FILTER(node, index).modifier = |
|
858 |
JDWP_REQUEST_MODIFIER(ClassMatch); |
|
859 |
filter->classPattern = classPattern; |
|
860 |
return JVMTI_ERROR_NONE; |
|
861 |
} |
|
862 |
||
863 |
jvmtiError |
|
864 |
eventFilter_setClassExcludeFilter(HandlerNode *node, jint index, |
|
865 |
char *classPattern) |
|
866 |
{ |
|
867 |
MatchFilter *filter = &FILTER(node, index).u.ClassExclude; |
|
868 |
if (index >= FILTER_COUNT(node)) { |
|
869 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
870 |
} |
|
871 |
if ( |
|
872 |
(NODE_EI(node) == EI_THREAD_START) || |
|
873 |
(NODE_EI(node) == EI_THREAD_END)) { |
|
874 |
||
875 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
876 |
} |
|
877 |
||
878 |
FILTER(node, index).modifier = |
|
879 |
JDWP_REQUEST_MODIFIER(ClassExclude); |
|
880 |
filter->classPattern = classPattern; |
|
881 |
return JVMTI_ERROR_NONE; |
|
882 |
} |
|
883 |
||
884 |
jvmtiError |
|
885 |
eventFilter_setStepFilter(HandlerNode *node, jint index, |
|
886 |
jthread thread, jint size, jint depth) |
|
887 |
{ |
|
888 |
jvmtiError error; |
|
889 |
JNIEnv *env = getEnv(); |
|
890 |
StepFilter *filter = &FILTER(node, index).u.Step; |
|
891 |
if (index >= FILTER_COUNT(node)) { |
|
892 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
893 |
} |
|
894 |
if (NODE_EI(node) != EI_SINGLE_STEP) { |
|
895 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
896 |
} |
|
897 |
||
898 |
/* Create a thread ref that will live beyond */ |
|
899 |
/* the end of this call */ |
|
900 |
saveGlobalRef(env, thread, &(filter->thread)); |
|
901 |
error = stepControl_beginStep(env, filter->thread, size, depth, node); |
|
902 |
if (error != JVMTI_ERROR_NONE) { |
|
903 |
tossGlobalRef(env, &(filter->thread)); |
|
904 |
return error; |
|
905 |
} |
|
906 |
FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Step); |
|
907 |
filter->depth = depth; |
|
908 |
filter->size = size; |
|
909 |
return JVMTI_ERROR_NONE; |
|
910 |
} |
|
911 |
||
912 |
||
913 |
jvmtiError |
|
914 |
eventFilter_setSourceNameMatchFilter(HandlerNode *node, |
|
915 |
jint index, |
|
916 |
char *sourceNamePattern) { |
|
917 |
SourceNameFilter *filter = &FILTER(node, index).u.SourceNameOnly; |
|
918 |
if (index >= FILTER_COUNT(node)) { |
|
919 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
920 |
} |
|
921 |
if (NODE_EI(node) != EI_CLASS_PREPARE) { |
|
922 |
return AGENT_ERROR_ILLEGAL_ARGUMENT; |
|
923 |
} |
|
924 |
||
925 |
FILTER(node, index).modifier = |
|
926 |
JDWP_REQUEST_MODIFIER(SourceNameMatch); |
|
927 |
filter->sourceNamePattern = sourceNamePattern; |
|
928 |
return JVMTI_ERROR_NONE; |
|
929 |
||
930 |
} |
|
931 |
||
932 |
/***** JVMTI event enabling / disabling *****/ |
|
933 |
||
934 |
/** |
|
935 |
* Return the Filter that is of the specified type (modifier). |
|
936 |
* Return NULL if not found. |
|
937 |
*/ |
|
938 |
static Filter * |
|
939 |
findFilter(HandlerNode *node, jint modifier) |
|
940 |
{ |
|
941 |
int i; |
|
942 |
Filter *filter; |
|
943 |
for (i = 0, filter = FILTERS_ARRAY(node); |
|
944 |
i <FILTER_COUNT(node); |
|
945 |
i++, filter++) { |
|
946 |
if (filter->modifier == modifier) { |
|
947 |
return filter; |
|
948 |
} |
|
949 |
} |
|
950 |
return NULL; |
|
951 |
} |
|
952 |
||
953 |
/** |
|
954 |
* Determine if the specified breakpoint node is in the |
|
955 |
* same location as the LocationFilter passed in arg. |
|
956 |
* |
|
957 |
* This is a match function called by a |
|
958 |
* eventHandlerRestricted_iterator invokation. |
|
959 |
*/ |
|
960 |
static jboolean |
|
961 |
matchBreakpoint(JNIEnv *env, HandlerNode *node, void *arg) |
|
962 |
{ |
|
963 |
LocationFilter *goal = (LocationFilter *)arg; |
|
964 |
Filter *filter = FILTERS_ARRAY(node); |
|
965 |
int i; |
|
966 |
||
967 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
968 |
switch (filter->modifier) { |
|
969 |
case JDWP_REQUEST_MODIFIER(LocationOnly): { |
|
970 |
LocationFilter *trial = &(filter->u.LocationOnly); |
|
971 |
if (trial->method == goal->method && |
|
972 |
trial->location == goal->location && |
|
973 |
isSameObject(env, trial->clazz, goal->clazz)) { |
|
974 |
return JNI_TRUE; |
|
975 |
} |
|
976 |
} |
|
977 |
} |
|
978 |
} |
|
979 |
return JNI_FALSE; |
|
980 |
} |
|
981 |
||
982 |
/** |
|
983 |
* Set a breakpoint if this is the first one at this location. |
|
984 |
*/ |
|
985 |
static jvmtiError |
|
986 |
setBreakpoint(HandlerNode *node) |
|
987 |
{ |
|
988 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
989 |
Filter *filter; |
|
990 |
||
991 |
filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly)); |
|
992 |
if (filter == NULL) { |
|
993 |
/* bp event with no location filter */ |
|
994 |
error = AGENT_ERROR_INTERNAL; |
|
995 |
} else { |
|
996 |
LocationFilter *lf = &(filter->u.LocationOnly); |
|
997 |
||
998 |
/* if this is the first handler for this |
|
999 |
* location, set bp at JVMTI level |
|
1000 |
*/ |
|
1001 |
if (!eventHandlerRestricted_iterator( |
|
1002 |
EI_BREAKPOINT, matchBreakpoint, lf)) { |
|
1003 |
LOG_LOC(("SetBreakpoint at location: method=%p,location=%d", |
|
1004 |
lf->method, (int)lf->location)); |
|
1005 |
error = JVMTI_FUNC_PTR(gdata->jvmti,SetBreakpoint) |
|
1006 |
(gdata->jvmti, lf->method, lf->location); |
|
1007 |
} |
|
1008 |
} |
|
1009 |
return error; |
|
1010 |
} |
|
1011 |
||
1012 |
/** |
|
1013 |
* Clear a breakpoint if this is the last one at this location. |
|
1014 |
*/ |
|
1015 |
static jvmtiError |
|
1016 |
clearBreakpoint(HandlerNode *node) |
|
1017 |
{ |
|
1018 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
1019 |
Filter *filter; |
|
1020 |
||
1021 |
filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly)); |
|
1022 |
if (filter == NULL) { |
|
1023 |
/* bp event with no location filter */ |
|
1024 |
error = AGENT_ERROR_INTERNAL; |
|
1025 |
} else { |
|
1026 |
LocationFilter *lf = &(filter->u.LocationOnly); |
|
1027 |
||
1028 |
/* if this is the last handler for this |
|
1029 |
* location, clear bp at JVMTI level |
|
1030 |
*/ |
|
1031 |
if (!eventHandlerRestricted_iterator( |
|
1032 |
EI_BREAKPOINT, matchBreakpoint, lf)) { |
|
1033 |
LOG_LOC(("ClearBreakpoint at location: method=%p,location=%d", |
|
1034 |
lf->method, (int)lf->location)); |
|
1035 |
error = JVMTI_FUNC_PTR(gdata->jvmti,ClearBreakpoint) |
|
1036 |
(gdata->jvmti, lf->method, lf->location); |
|
1037 |
} |
|
1038 |
} |
|
1039 |
return error; |
|
1040 |
} |
|
1041 |
||
1042 |
/** |
|
1043 |
* Return true if a breakpoint is set at the specified location. |
|
1044 |
*/ |
|
1045 |
jboolean |
|
1046 |
isBreakpointSet(jclass clazz, jmethodID method, jlocation location) |
|
1047 |
{ |
|
1048 |
LocationFilter lf; |
|
1049 |
||
1050 |
lf.clazz = clazz; |
|
1051 |
lf.method = method; |
|
1052 |
lf.location = location; |
|
1053 |
||
1054 |
return eventHandlerRestricted_iterator(EI_BREAKPOINT, |
|
1055 |
matchBreakpoint, &lf); |
|
1056 |
} |
|
1057 |
||
1058 |
/** |
|
1059 |
* Determine if the specified watchpoint node has the |
|
1060 |
* same field as the FieldFilter passed in arg. |
|
1061 |
* |
|
1062 |
* This is a match function called by a |
|
1063 |
* eventHandlerRestricted_iterator invokation. |
|
1064 |
*/ |
|
1065 |
static jboolean |
|
1066 |
matchWatchpoint(JNIEnv *env, HandlerNode *node, void *arg) |
|
1067 |
{ |
|
1068 |
FieldFilter *goal = (FieldFilter *)arg; |
|
1069 |
Filter *filter = FILTERS_ARRAY(node); |
|
1070 |
int i; |
|
1071 |
||
1072 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
1073 |
switch (filter->modifier) { |
|
1074 |
case JDWP_REQUEST_MODIFIER(FieldOnly): { |
|
1075 |
FieldFilter *trial = &(filter->u.FieldOnly); |
|
1076 |
if (trial->field == goal->field && |
|
1077 |
isSameObject(env, trial->clazz, goal->clazz)) { |
|
1078 |
return JNI_TRUE; |
|
1079 |
} |
|
1080 |
} |
|
1081 |
} |
|
1082 |
} |
|
1083 |
return JNI_FALSE; |
|
1084 |
} |
|
1085 |
||
1086 |
/** |
|
1087 |
* Set a watchpoint if this is the first one on this field. |
|
1088 |
*/ |
|
1089 |
static jvmtiError |
|
1090 |
setWatchpoint(HandlerNode *node) |
|
1091 |
{ |
|
1092 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
1093 |
Filter *filter; |
|
1094 |
||
1095 |
filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly)); |
|
1096 |
if (filter == NULL) { |
|
1097 |
/* event with no field filter */ |
|
1098 |
error = AGENT_ERROR_INTERNAL; |
|
1099 |
} else { |
|
1100 |
FieldFilter *ff = &(filter->u.FieldOnly); |
|
1101 |
||
1102 |
/* if this is the first handler for this |
|
1103 |
* field, set wp at JVMTI level |
|
1104 |
*/ |
|
1105 |
if (!eventHandlerRestricted_iterator( |
|
1106 |
NODE_EI(node), matchWatchpoint, ff)) { |
|
1107 |
error = (NODE_EI(node) == EI_FIELD_ACCESS) ? |
|
1108 |
JVMTI_FUNC_PTR(gdata->jvmti,SetFieldAccessWatch) |
|
1109 |
(gdata->jvmti, ff->clazz, ff->field) : |
|
1110 |
JVMTI_FUNC_PTR(gdata->jvmti,SetFieldModificationWatch) |
|
1111 |
(gdata->jvmti, ff->clazz, ff->field); |
|
1112 |
} |
|
1113 |
} |
|
1114 |
return error; |
|
1115 |
} |
|
1116 |
||
1117 |
/** |
|
1118 |
* Clear a watchpoint if this is the last one on this field. |
|
1119 |
*/ |
|
1120 |
static jvmtiError |
|
1121 |
clearWatchpoint(HandlerNode *node) |
|
1122 |
{ |
|
1123 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
1124 |
Filter *filter; |
|
1125 |
||
1126 |
filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly)); |
|
1127 |
if (filter == NULL) { |
|
1128 |
/* event with no field filter */ |
|
1129 |
error = AGENT_ERROR_INTERNAL; |
|
1130 |
} else { |
|
1131 |
FieldFilter *ff = &(filter->u.FieldOnly); |
|
1132 |
||
1133 |
/* if this is the last handler for this |
|
1134 |
* field, clear wp at JVMTI level |
|
1135 |
*/ |
|
1136 |
if (!eventHandlerRestricted_iterator( |
|
1137 |
NODE_EI(node), matchWatchpoint, ff)) { |
|
1138 |
error = (NODE_EI(node) == EI_FIELD_ACCESS) ? |
|
1139 |
JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldAccessWatch) |
|
1140 |
(gdata->jvmti, ff->clazz, ff->field) : |
|
1141 |
JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldModificationWatch) |
|
1142 |
(gdata->jvmti, ff->clazz, ff->field); |
|
1143 |
} |
|
1144 |
} |
|
1145 |
return error; |
|
1146 |
} |
|
1147 |
||
1148 |
/** |
|
1149 |
* Determine the thread this node is filtered on. |
|
1150 |
* NULL if not thread filtered. |
|
1151 |
*/ |
|
1152 |
static jthread |
|
1153 |
requestThread(HandlerNode *node) |
|
1154 |
{ |
|
1155 |
int i; |
|
1156 |
Filter *filter = FILTERS_ARRAY(node); |
|
1157 |
||
1158 |
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) { |
|
1159 |
switch (filter->modifier) { |
|
1160 |
case JDWP_REQUEST_MODIFIER(ThreadOnly): |
|
1161 |
return filter->u.ThreadOnly.thread; |
|
1162 |
} |
|
1163 |
} |
|
1164 |
||
1165 |
return NULL; |
|
1166 |
} |
|
1167 |
||
1168 |
/** |
|
1169 |
* Determine if the specified node has a |
|
1170 |
* thread filter with the thread passed in arg. |
|
1171 |
* |
|
1172 |
* This is a match function called by a |
|
1173 |
* eventHandlerRestricted_iterator invokation. |
|
1174 |
*/ |
|
1175 |
static jboolean |
|
1176 |
matchThread(JNIEnv *env, HandlerNode *node, void *arg) |
|
1177 |
{ |
|
1178 |
jthread goalThread = (jthread)arg; |
|
1179 |
jthread reqThread = requestThread(node); |
|
1180 |
||
1181 |
/* If the event's thread and the passed thread are the same |
|
1182 |
* (or both are NULL), we have a match. |
|
1183 |
*/ |
|
1184 |
return isSameObject(env, reqThread, goalThread); |
|
1185 |
} |
|
1186 |
||
1187 |
/** |
|
1188 |
* Do any enabling of events (including setting breakpoints etc) |
|
1189 |
* needed to get the events requested by this handler node. |
|
1190 |
*/ |
|
1191 |
static jvmtiError |
|
1192 |
enableEvents(HandlerNode *node) |
|
1193 |
{ |
|
1194 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
1195 |
||
1196 |
switch (NODE_EI(node)) { |
|
1197 |
/* The stepping code directly enables/disables stepping as |
|
1198 |
* necessary |
|
1199 |
*/ |
|
1200 |
case EI_SINGLE_STEP: |
|
1201 |
/* Internal thread event handlers are always present |
|
1202 |
* (hardwired in the event hook), so we don't change the |
|
1203 |
* notification mode here. |
|
1204 |
*/ |
|
1205 |
case EI_THREAD_START: |
|
1206 |
case EI_THREAD_END: |
|
1207 |
case EI_VM_INIT: |
|
1208 |
case EI_VM_DEATH: |
|
1209 |
case EI_CLASS_PREPARE: |
|
1210 |
case EI_GC_FINISH: |
|
1211 |
return error; |
|
1212 |
||
1213 |
case EI_FIELD_ACCESS: |
|
1214 |
case EI_FIELD_MODIFICATION: |
|
1215 |
error = setWatchpoint(node); |
|
1216 |
break; |
|
1217 |
||
1218 |
case EI_BREAKPOINT: |
|
1219 |
error = setBreakpoint(node); |
|
1220 |
break; |
|
1221 |
||
1222 |
default: |
|
1223 |
break; |
|
1224 |
} |
|
1225 |
||
1226 |
/* Don't globally enable if the above failed */ |
|
1227 |
if (error == JVMTI_ERROR_NONE) { |
|
1228 |
jthread thread = requestThread(node); |
|
1229 |
||
1230 |
/* If this is the first request of it's kind on this |
|
1231 |
* thread (or all threads (thread == NULL)) then enable |
|
1232 |
* these events on this thread. |
|
1233 |
*/ |
|
1234 |
if (!eventHandlerRestricted_iterator( |
|
1235 |
NODE_EI(node), matchThread, thread)) { |
|
1236 |
error = threadControl_setEventMode(JVMTI_ENABLE, |
|
1237 |
NODE_EI(node), thread); |
|
1238 |
} |
|
1239 |
} |
|
1240 |
return error; |
|
1241 |
} |
|
1242 |
||
1243 |
/** |
|
1244 |
* Do any disabling of events (including clearing breakpoints etc) |
|
1245 |
* needed to no longer get the events requested by this handler node. |
|
1246 |
*/ |
|
1247 |
static jvmtiError |
|
1248 |
disableEvents(HandlerNode *node) |
|
1249 |
{ |
|
1250 |
jvmtiError error = JVMTI_ERROR_NONE; |
|
1251 |
jvmtiError error2 = JVMTI_ERROR_NONE; |
|
1252 |
jthread thread; |
|
1253 |
||
1254 |
||
1255 |
switch (NODE_EI(node)) { |
|
1256 |
/* The stepping code directly enables/disables stepping as |
|
1257 |
* necessary |
|
1258 |
*/ |
|
1259 |
case EI_SINGLE_STEP: |
|
1260 |
/* Internal thread event handlers are always present |
|
1261 |
* (hardwired in the event hook), so we don't change the |
|
1262 |
* notification mode here. |
|
1263 |
*/ |
|
1264 |
case EI_THREAD_START: |
|
1265 |
case EI_THREAD_END: |
|
1266 |
case EI_VM_INIT: |
|
1267 |
case EI_VM_DEATH: |
|
1268 |
case EI_CLASS_PREPARE: |
|
1269 |
case EI_GC_FINISH: |
|
1270 |
return error; |
|
1271 |
||
1272 |
case EI_FIELD_ACCESS: |
|
1273 |
case EI_FIELD_MODIFICATION: |
|
1274 |
error = clearWatchpoint(node); |
|
1275 |
break; |
|
1276 |
||
1277 |
case EI_BREAKPOINT: |
|
1278 |
error = clearBreakpoint(node); |
|
1279 |
break; |
|
1280 |
||
1281 |
default: |
|
1282 |
break; |
|
1283 |
} |
|
1284 |
||
1285 |
thread = requestThread(node); |
|
1286 |
||
1287 |
/* If this is the last request of it's kind on this thread |
|
1288 |
* (or all threads (thread == NULL)) then disable these |
|
1289 |
* events on this thread. |
|
1290 |
* |
|
1291 |
* Disable even if the above caused an error |
|
1292 |
*/ |
|
1293 |
if (!eventHandlerRestricted_iterator(NODE_EI(node), matchThread, thread)) { |
|
1294 |
error2 = threadControl_setEventMode(JVMTI_DISABLE, |
|
1295 |
NODE_EI(node), thread); |
|
1296 |
} |
|
1297 |
return error != JVMTI_ERROR_NONE? error : error2; |
|
1298 |
} |
|
1299 |
||
1300 |
||
1301 |
/***** filter (and event) installation and deinstallation *****/ |
|
1302 |
||
1303 |
/** |
|
1304 |
* Make the set of event filters that correspond with this |
|
1305 |
* node active (including enabling the corresponding events). |
|
1306 |
*/ |
|
1307 |
jvmtiError |
|
1308 |
eventFilterRestricted_install(HandlerNode *node) |
|
1309 |
{ |
|
1310 |
return enableEvents(node); |
|
1311 |
} |
|
1312 |
||
1313 |
/** |
|
1314 |
* Make the set of event filters that correspond with this |
|
1315 |
* node inactive (including disabling the corresponding events |
|
1316 |
* and freeing resources). |
|
1317 |
*/ |
|
1318 |
jvmtiError |
|
1319 |
eventFilterRestricted_deinstall(HandlerNode *node) |
|
1320 |
{ |
|
1321 |
jvmtiError error1, error2; |
|
1322 |
||
1323 |
error1 = disableEvents(node); |
|
1324 |
error2 = clearFilters(node); |
|
1325 |
||
1326 |
return error1 != JVMTI_ERROR_NONE? error1 : error2; |
|
1327 |
} |