|
1 /* |
|
2 * Copyright (c) 2004, 2018, 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. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 #include <string.h> |
|
25 #include "jvmti.h" |
|
26 #include "agent_common.h" |
|
27 #include "jni_tools.h" |
|
28 #include "jvmti_tools.h" |
|
29 #include "JVMTITools.h" |
|
30 |
|
31 #ifdef __cplusplus |
|
32 extern "C" { |
|
33 #endif |
|
34 |
|
35 /* ============================================================================= */ |
|
36 |
|
37 /* scaffold objects */ |
|
38 static jvmtiEnv *jvmti = NULL; |
|
39 static jlong timeout = 0; |
|
40 static jrawMonitorID syncLock = NULL; |
|
41 |
|
42 /* constant names */ |
|
43 #define STEP_AMOUNT 3 |
|
44 #define JVMTI_EVENT_COUNT (int)(JVMTI_MAX_EVENT_TYPE_VAL - JVMTI_MIN_EVENT_TYPE_VAL + 1) |
|
45 |
|
46 static int eventCount[JVMTI_EVENT_COUNT]; |
|
47 static int newEventCount[JVMTI_EVENT_COUNT]; |
|
48 static int loadEvents = 0; |
|
49 static int unloadEvents = 0; |
|
50 |
|
51 /* ============================================================================= */ |
|
52 |
|
53 static void |
|
54 showEventStatistics(int step) { |
|
55 int i; |
|
56 const char* str; |
|
57 int *currentCounts = (step == 1) ? &eventCount[0] : &newEventCount[0]; |
|
58 |
|
59 NSK_DISPLAY0("\n"); |
|
60 NSK_DISPLAY1("Event statistics for %d step:\n", step); |
|
61 NSK_DISPLAY0("-----------------------------\n"); |
|
62 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
63 if (currentCounts[i] > 0) { |
|
64 str = TranslateEvent((jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL)); |
|
65 NSK_DISPLAY2("%-40s %7d\n", str, currentCounts[i]); |
|
66 } |
|
67 } |
|
68 } |
|
69 |
|
70 /* ========================================================================== */ |
|
71 |
|
72 int checkEvents(int step) { |
|
73 int i; |
|
74 jvmtiEvent curr; |
|
75 int result = NSK_TRUE; |
|
76 int *currentCounts; |
|
77 int isExpected = 0; |
|
78 |
|
79 switch (step) { |
|
80 case 1: |
|
81 currentCounts = &eventCount[0]; |
|
82 break; |
|
83 |
|
84 case 2: |
|
85 case 3: |
|
86 currentCounts = &newEventCount[0]; |
|
87 break; |
|
88 |
|
89 default: |
|
90 NSK_COMPLAIN1("Unexpected step no: %d\n", step); |
|
91 return NSK_FALSE; |
|
92 } |
|
93 |
|
94 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
95 |
|
96 curr = i + JVMTI_MIN_EVENT_TYPE_VAL; |
|
97 |
|
98 switch (step) { |
|
99 case 1: |
|
100 isExpected = ((curr == JVMTI_EVENT_COMPILED_METHOD_LOAD) |
|
101 || (curr == JVMTI_EVENT_VM_INIT)); |
|
102 break; |
|
103 |
|
104 case 2: |
|
105 isExpected = (curr == JVMTI_EVENT_COMPILED_METHOD_LOAD); |
|
106 break; |
|
107 |
|
108 case 3: |
|
109 isExpected = (curr == JVMTI_EVENT_VM_DEATH); |
|
110 break; |
|
111 } |
|
112 |
|
113 if (isExpected) { |
|
114 if (currentCounts[i] < 0) { |
|
115 NSK_COMPLAIN2("Unexpected events number %7d for %s\n\texpected value must be greater than 1\n", |
|
116 currentCounts[i], |
|
117 TranslateEvent(curr)); |
|
118 result = NSK_FALSE; |
|
119 } |
|
120 } else { |
|
121 |
|
122 if (curr != JVMTI_EVENT_COMPILED_METHOD_UNLOAD) { |
|
123 if (currentCounts[i] > 0) { |
|
124 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n", |
|
125 TranslateEvent(curr), |
|
126 currentCounts[i]); |
|
127 result = NSK_FALSE; |
|
128 } |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 return result; |
|
134 } |
|
135 |
|
136 static void |
|
137 changeCount(jvmtiEvent event, int *currentCounts) { |
|
138 |
|
139 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock))) |
|
140 nsk_jvmti_setFailStatus(); |
|
141 |
|
142 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++; |
|
143 |
|
144 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock))) |
|
145 nsk_jvmti_setFailStatus(); |
|
146 |
|
147 } |
|
148 |
|
149 /* ============================================================================= */ |
|
150 |
|
151 /* callbacks */ |
|
152 JNIEXPORT void JNICALL |
|
153 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) { |
|
154 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]); |
|
155 } |
|
156 |
|
157 JNIEXPORT void JNICALL |
|
158 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) { |
|
159 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]); |
|
160 showEventStatistics(STEP_AMOUNT); |
|
161 if (!checkEvents(STEP_AMOUNT)) |
|
162 nsk_jvmti_setFailStatus(); |
|
163 |
|
164 if (!NSK_JVMTI_VERIFY( |
|
165 NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock))) |
|
166 nsk_jvmti_setFailStatus(); |
|
167 |
|
168 } |
|
169 |
|
170 void JNICALL |
|
171 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
172 jmethodID method, jlocation location, jobject exception, |
|
173 jmethodID catch_method, jlocation catch_location) { |
|
174 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]); |
|
175 } |
|
176 |
|
177 void JNICALL |
|
178 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
179 jmethodID method, jlocation location, jobject exception) { |
|
180 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]); |
|
181 } |
|
182 |
|
183 void JNICALL |
|
184 cbSingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
185 jmethodID method, jlocation location) { |
|
186 changeCount(JVMTI_EVENT_SINGLE_STEP, &eventCount[0]); |
|
187 } |
|
188 |
|
189 void JNICALL |
|
190 cbFramePop(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
191 jmethodID method, jboolean was_popped_by_exception) { |
|
192 changeCount(JVMTI_EVENT_FRAME_POP, &eventCount[0]); |
|
193 } |
|
194 |
|
195 void JNICALL |
|
196 cbBreakpoint(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
197 jmethodID method, jlocation location) { |
|
198 changeCount(JVMTI_EVENT_BREAKPOINT, &eventCount[0]); |
|
199 } |
|
200 |
|
201 void JNICALL |
|
202 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
203 jmethodID method, jlocation location, jclass field_klass, |
|
204 jobject object, jfieldID field) { |
|
205 changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]); |
|
206 } |
|
207 |
|
208 void JNICALL |
|
209 cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
210 jmethodID method, jlocation location, jclass field_klass, |
|
211 jobject object, jfieldID field, char signature_type, |
|
212 jvalue new_value) { |
|
213 changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]); |
|
214 } |
|
215 |
|
216 void JNICALL |
|
217 cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
218 jmethodID method) { |
|
219 changeCount(JVMTI_EVENT_METHOD_ENTRY, &eventCount[0]); |
|
220 } |
|
221 |
|
222 void JNICALL |
|
223 cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
224 jmethodID method, jboolean was_popped_by_exception, |
|
225 jvalue return_value) { |
|
226 changeCount(JVMTI_EVENT_METHOD_EXIT, &eventCount[0]); |
|
227 } |
|
228 |
|
229 void JNICALL |
|
230 cbNativeMethodBind(jvmtiEnv *jvmti_env, JNIEnv* jni_env,jthread thread, |
|
231 jmethodID method, void* address, void** new_address_ptr) { |
|
232 changeCount(JVMTI_EVENT_NATIVE_METHOD_BIND, &eventCount[0]); |
|
233 } |
|
234 |
|
235 void JNICALL |
|
236 cbMonitorWait(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
237 jobject object, jlong tout) { |
|
238 |
|
239 changeCount(JVMTI_EVENT_MONITOR_WAIT, &eventCount[0]); |
|
240 } |
|
241 |
|
242 void JNICALL |
|
243 cbMonitorWaited(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
244 jobject object, jboolean timed_out) { |
|
245 |
|
246 changeCount(JVMTI_EVENT_MONITOR_WAITED, &eventCount[0]); |
|
247 } |
|
248 |
|
249 JNIEXPORT void JNICALL |
|
250 cbMonitorContendedEnter(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread, |
|
251 jobject object) { |
|
252 |
|
253 changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTER, &eventCount[0]); |
|
254 } |
|
255 |
|
256 void JNICALL |
|
257 cbMonitorContendedEntered(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
258 jobject object) { |
|
259 |
|
260 changeCount(JVMTI_EVENT_MONITOR_CONTENDED_ENTERED, &eventCount[0]); |
|
261 } |
|
262 |
|
263 void |
|
264 handlerMC1(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { |
|
265 |
|
266 char *name; |
|
267 char *sign; |
|
268 char *genc; |
|
269 |
|
270 if (!NSK_JVMTI_VERIFY( |
|
271 NSK_CPP_STUB5( |
|
272 GetMethodName, jvmti, method, &name, &sign, &genc))) { |
|
273 nsk_jvmti_setFailStatus(); |
|
274 return; |
|
275 } |
|
276 |
|
277 if (!strncmp(name,"javaMethod", 8)) { |
|
278 NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); |
|
279 changeCount(event, &eventCount[0]); |
|
280 } |
|
281 |
|
282 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
283 jvmti, (unsigned char*)name))) { |
|
284 nsk_jvmti_setFailStatus(); |
|
285 } |
|
286 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
287 jvmti, (unsigned char*)sign))) { |
|
288 nsk_jvmti_setFailStatus(); |
|
289 } |
|
290 if (genc != NULL) |
|
291 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
292 jvmti, (unsigned char*)genc))) { |
|
293 nsk_jvmti_setFailStatus(); |
|
294 } |
|
295 } |
|
296 |
|
297 void JNICALL |
|
298 cbCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, |
|
299 const void* code_addr, jint map_length, |
|
300 const jvmtiAddrLocationMap* map, const void* compile_info) { |
|
301 |
|
302 loadEvents++; |
|
303 handlerMC1(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); |
|
304 } |
|
305 |
|
306 void JNICALL |
|
307 cbCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, |
|
308 const void* code_addr) { |
|
309 unloadEvents++; |
|
310 NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); |
|
311 changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &eventCount[0]); |
|
312 } |
|
313 |
|
314 void JNICALL |
|
315 cbGarbageCollectionStart(jvmtiEnv *jvmti_env) { |
|
316 changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_START, &eventCount[0]); |
|
317 } |
|
318 |
|
319 void JNICALL |
|
320 cbGarbageCollectionFinish(jvmtiEnv *jvmti_env) { |
|
321 changeCount(JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, &eventCount[0]); |
|
322 } |
|
323 |
|
324 void JNICALL |
|
325 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) { |
|
326 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]); |
|
327 } |
|
328 |
|
329 void JNICALL |
|
330 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread, |
|
331 jobject object, jclass object_klass, jlong size) { |
|
332 |
|
333 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]); |
|
334 } |
|
335 |
|
336 void |
|
337 handlerMC2(jvmtiEvent event, jvmtiEnv* jvmti, jmethodID method) { |
|
338 |
|
339 char *name; |
|
340 char *sign; |
|
341 char *genc; |
|
342 |
|
343 if (!NSK_JVMTI_VERIFY( |
|
344 NSK_CPP_STUB5( |
|
345 GetMethodName, jvmti, method, &name, &sign, &genc))) { |
|
346 nsk_jvmti_setFailStatus(); |
|
347 return; |
|
348 } |
|
349 |
|
350 NSK_DISPLAY2("\tMethod: %s, signature: %s\n", name, sign); |
|
351 changeCount(event, &newEventCount[0]); |
|
352 |
|
353 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
354 jvmti, (unsigned char*)name))) { |
|
355 nsk_jvmti_setFailStatus(); |
|
356 } |
|
357 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
358 jvmti, (unsigned char*)sign))) { |
|
359 nsk_jvmti_setFailStatus(); |
|
360 } |
|
361 if (genc != NULL) |
|
362 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, |
|
363 jvmti, (unsigned char*)genc))) { |
|
364 nsk_jvmti_setFailStatus(); |
|
365 } |
|
366 } |
|
367 |
|
368 void JNICALL |
|
369 cbNewCompiledMethodLoad(jvmtiEnv *jvmti_env, jmethodID method, jint code_size, |
|
370 const void* code_addr, jint map_length, |
|
371 const jvmtiAddrLocationMap* map, const void* compile_info) { |
|
372 |
|
373 loadEvents++; |
|
374 handlerMC2(JVMTI_EVENT_COMPILED_METHOD_LOAD, jvmti_env, method); |
|
375 } |
|
376 |
|
377 void JNICALL |
|
378 cbNewCompiledMethodUnload(jvmtiEnv *jvmti_env, jmethodID method, |
|
379 const void* code_addr) { |
|
380 |
|
381 unloadEvents++; |
|
382 NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n"); |
|
383 changeCount(JVMTI_EVENT_COMPILED_METHOD_UNLOAD, &newEventCount[0]); |
|
384 } |
|
385 |
|
386 /* ============================================================================= */ |
|
387 |
|
388 static int enableEvent(jvmtiEvent event) { |
|
389 |
|
390 if (nsk_jvmti_isOptionalEvent(event) |
|
391 && (event != JVMTI_EVENT_COMPILED_METHOD_LOAD) |
|
392 && (event != JVMTI_EVENT_COMPILED_METHOD_UNLOAD)) { |
|
393 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY, |
|
394 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, |
|
395 JVMTI_ENABLE, event, NULL))) { |
|
396 NSK_COMPLAIN1("Unexpected error enabling %s\n", |
|
397 TranslateEvent(event)); |
|
398 return NSK_FALSE; |
|
399 } |
|
400 } else { |
|
401 if (!NSK_JVMTI_VERIFY( |
|
402 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, |
|
403 JVMTI_ENABLE, event, NULL))) { |
|
404 NSK_COMPLAIN1("Unexpected error enabling %s\n", |
|
405 TranslateEvent(event)); |
|
406 return NSK_FALSE; |
|
407 } |
|
408 } |
|
409 |
|
410 return NSK_TRUE; |
|
411 } |
|
412 |
|
413 /** |
|
414 * Enable or disable tested events. |
|
415 */ |
|
416 static int enableEventList() { |
|
417 int i; |
|
418 int result = NSK_TRUE; |
|
419 |
|
420 NSK_DISPLAY0("Enable events\n"); |
|
421 |
|
422 result = enableEvent(JVMTI_EVENT_VM_INIT); |
|
423 |
|
424 result = result && enableEvent(JVMTI_EVENT_VM_DEATH); |
|
425 |
|
426 /* enabling optional events */ |
|
427 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
428 jvmtiEvent event = (jvmtiEvent)(i+JVMTI_MIN_EVENT_TYPE_VAL); |
|
429 |
|
430 if (nsk_jvmti_isOptionalEvent(event)) |
|
431 result = result && enableEvent(event); |
|
432 } |
|
433 |
|
434 if (result == NSK_FALSE) { |
|
435 nsk_jvmti_setFailStatus(); |
|
436 return NSK_FALSE; |
|
437 } |
|
438 |
|
439 return NSK_TRUE; |
|
440 } |
|
441 |
|
442 /* ============================================================================= */ |
|
443 |
|
444 static int |
|
445 setCallBacks(int step) { |
|
446 |
|
447 int i; |
|
448 |
|
449 jvmtiEventCallbacks eventCallbacks; |
|
450 memset(&eventCallbacks, 0, sizeof(eventCallbacks)); |
|
451 |
|
452 NSK_DISPLAY0("\n"); |
|
453 NSK_DISPLAY1("===============step %d===============\n", step); |
|
454 NSK_DISPLAY0("\n"); |
|
455 switch (step) { |
|
456 case 1: |
|
457 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
458 eventCount[i] = 0; |
|
459 } |
|
460 |
|
461 eventCallbacks.VMInit = cbVMInit; |
|
462 eventCallbacks.Exception = cbException; |
|
463 eventCallbacks.ExceptionCatch = cbExceptionCatch; |
|
464 eventCallbacks.SingleStep = cbSingleStep; |
|
465 eventCallbacks.FramePop = cbFramePop; |
|
466 eventCallbacks.Breakpoint = cbBreakpoint; |
|
467 eventCallbacks.FieldAccess = cbFieldAccess; |
|
468 eventCallbacks.FieldModification = cbFieldModification; |
|
469 eventCallbacks.MethodEntry = cbMethodEntry; |
|
470 eventCallbacks.MethodExit = cbMethodExit; |
|
471 eventCallbacks.NativeMethodBind = cbNativeMethodBind; |
|
472 eventCallbacks.CompiledMethodLoad = cbCompiledMethodLoad; |
|
473 eventCallbacks.CompiledMethodUnload = cbCompiledMethodUnload; |
|
474 eventCallbacks.MonitorWait = cbMonitorWait; |
|
475 eventCallbacks.MonitorWaited = cbMonitorWaited; |
|
476 eventCallbacks.MonitorContendedEnter = cbMonitorContendedEnter; |
|
477 eventCallbacks.MonitorContendedEntered = cbMonitorContendedEntered; |
|
478 eventCallbacks.GarbageCollectionStart = cbGarbageCollectionStart; |
|
479 eventCallbacks.GarbageCollectionFinish = cbGarbageCollectionFinish; |
|
480 eventCallbacks.ObjectFree = cbObjectFree; |
|
481 eventCallbacks.VMObjectAlloc = cbVMObjectAlloc; |
|
482 break; |
|
483 |
|
484 case 2: |
|
485 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
486 newEventCount[i] = 0; |
|
487 } |
|
488 |
|
489 eventCallbacks.CompiledMethodLoad = cbNewCompiledMethodLoad; |
|
490 eventCallbacks.CompiledMethodUnload = cbNewCompiledMethodUnload; |
|
491 break; |
|
492 |
|
493 case 3: |
|
494 |
|
495 for (i = 0; i < JVMTI_EVENT_COUNT; i++) { |
|
496 newEventCount[i] = 0; |
|
497 } |
|
498 |
|
499 eventCallbacks.VMDeath = cbVMDeath; |
|
500 break; |
|
501 |
|
502 } |
|
503 if (!NSK_JVMTI_VERIFY( |
|
504 NSK_CPP_STUB3(SetEventCallbacks, jvmti, |
|
505 &eventCallbacks, |
|
506 sizeof(eventCallbacks)))) |
|
507 return NSK_FALSE; |
|
508 |
|
509 return NSK_TRUE; |
|
510 } |
|
511 |
|
512 /* ============================================================================= */ |
|
513 |
|
514 /** Agent algorithm. */ |
|
515 static void JNICALL |
|
516 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) { |
|
517 |
|
518 int i; |
|
519 |
|
520 for (i = 1; i <= STEP_AMOUNT; i++) { |
|
521 |
|
522 if (!nsk_jvmti_waitForSync(timeout)) |
|
523 return; |
|
524 |
|
525 NSK_DISPLAY0("Check received events\n"); |
|
526 |
|
527 if (i < STEP_AMOUNT) { |
|
528 showEventStatistics(i); |
|
529 if (!checkEvents(i)) |
|
530 nsk_jvmti_setFailStatus(); |
|
531 |
|
532 if (!setCallBacks(i + 1)) { |
|
533 return; |
|
534 } |
|
535 } |
|
536 |
|
537 if (!nsk_jvmti_resumeSync()) |
|
538 return; |
|
539 } |
|
540 |
|
541 /* checking amounts of COMPILED_METHOD_LOAD and COMPILED_METHOD_UNLOAD events */ |
|
542 if (loadEvents < unloadEvents) { |
|
543 NSK_COMPLAIN2("Number of JVMTI_EVENT_COMPILED_METHOD_LOAD events %d is less than number of JVMTI_EVENT_COMPILED_METHOD_UNLOAD %d", |
|
544 loadEvents, |
|
545 unloadEvents); |
|
546 } |
|
547 } |
|
548 |
|
549 /* ============================================================================= */ |
|
550 |
|
551 /** Agent library initialization. */ |
|
552 #ifdef STATIC_BUILD |
|
553 JNIEXPORT jint JNICALL Agent_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { |
|
554 return Agent_Initialize(jvm, options, reserved); |
|
555 } |
|
556 JNIEXPORT jint JNICALL Agent_OnAttach_em02t003(JavaVM *jvm, char *options, void *reserved) { |
|
557 return Agent_Initialize(jvm, options, reserved); |
|
558 } |
|
559 JNIEXPORT jint JNI_OnLoad_em02t003(JavaVM *jvm, char *options, void *reserved) { |
|
560 return JNI_VERSION_1_8; |
|
561 } |
|
562 #endif |
|
563 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) { |
|
564 |
|
565 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options))) |
|
566 return JNI_ERR; |
|
567 |
|
568 timeout = nsk_jvmti_getWaitTime() * 60 * 1000; |
|
569 |
|
570 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL)) |
|
571 return JNI_ERR; |
|
572 |
|
573 if (!NSK_JVMTI_VERIFY( |
|
574 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) { |
|
575 nsk_jvmti_setFailStatus(); |
|
576 return JNI_ERR; |
|
577 } |
|
578 |
|
579 { |
|
580 jvmtiCapabilities caps; |
|
581 memset(&caps, 0, sizeof(caps)); |
|
582 |
|
583 caps.can_generate_compiled_method_load_events = 1; |
|
584 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps))) |
|
585 return JNI_ERR; |
|
586 } |
|
587 |
|
588 if (!setCallBacks(1)) { |
|
589 return JNI_ERR; |
|
590 } |
|
591 |
|
592 nsk_jvmti_showPossessedCapabilities(jvmti); |
|
593 |
|
594 if (!enableEventList()) { |
|
595 return JNI_ERR; |
|
596 } |
|
597 |
|
598 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL))) |
|
599 return JNI_ERR; |
|
600 |
|
601 return JNI_OK; |
|
602 } |
|
603 |
|
604 /* ============================================================================= */ |
|
605 |
|
606 |
|
607 #ifdef __cplusplus |
|
608 } |
|
609 #endif |