126 result = NSK_FALSE;
127 }
128 }
129 } else {
130
131 if (currentCounts[i] > 0) {
132 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
133 TranslateEvent(curr),
134 currentCounts[i]);
135 result = NSK_FALSE;
136 }
137 }
138 }
139
140 return result;
141 }
142
143 static void
144 changeCount(jvmtiEvent event, int *currentCounts) {
145
146 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
147 nsk_jvmti_setFailStatus();
148
149 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
150
151 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
152 nsk_jvmti_setFailStatus();
153
154 }
155
156 /* ============================================================================= */
157
158 /* callbacks */
159 JNIEXPORT void JNICALL
160 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
161 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
162 }
163
164 JNIEXPORT void JNICALL
165 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
166 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
167 showEventStatistics(STEP_NUMBER);
168 if (!checkEvents(STEP_NUMBER))
169 nsk_jvmti_setFailStatus();
170
171 if (!NSK_JVMTI_VERIFY(
172 NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
173 nsk_jvmti_setFailStatus();
174
175 }
176
177 void JNICALL
178 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
179 jmethodID method, jlocation location, jobject exception,
180 jmethodID catch_method, jlocation catch_location) {
181
182 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
183 }
184
185 void JNICALL
186 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
187 jmethodID method, jlocation location, jobject exception) {
188
189 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
190 }
191
192 void JNICALL
212 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
213 jmethodID method, jlocation location, jclass field_klass,
214 jobject object, jfieldID field) {
215 changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]);
216 }
217
218 void JNICALL
219 cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
220 jmethodID method, jlocation location, jclass field_klass,
221 jobject object, jfieldID field, char signature_type,
222 jvalue new_value) {
223 changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]);
224 }
225
226 void handler1(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) {
227
228 char *name;
229 char *sign;
230 char *genc;
231
232 if (!NSK_JVMTI_VERIFY(
233 NSK_CPP_STUB5(
234 GetMethodName, jvmti_env, method, &name, &sign, &genc))) {
235 nsk_jvmti_setFailStatus();
236 return;
237 }
238
239 if (!strncmp(name,"javaMethod", 8)) {
240 changeCount(event, &eventCount[0]);
241 }
242
243 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
244 jvmti_env, (unsigned char*)name))) {
245 nsk_jvmti_setFailStatus();
246 }
247 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
248 jvmti_env, (unsigned char*)sign))) {
249 nsk_jvmti_setFailStatus();
250 }
251 if (genc != NULL)
252 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
253 jvmti_env, (unsigned char*)genc))) {
254 nsk_jvmti_setFailStatus();
255 }
256 }
257
258 void JNICALL
259 cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
260 jmethodID method) {
261
262 handler1(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method);
263 }
264
265 void JNICALL
266 cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
267 jmethodID method, jboolean was_popped_by_exception,
268 jvalue return_value) {
269
270 handler1(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method);
271 }
272
273 void handler2(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) {
274
275 char *name;
276 char *sign;
277 char *genc;
278
279 if (!NSK_JVMTI_VERIFY(
280 NSK_CPP_STUB5(
281 GetMethodName, jvmti_env, method, &name, &sign, &genc))) {
282 nsk_jvmti_setFailStatus();
283 return;
284 }
285
286 if (!strncmp(name,"javaMethod", 8)) {
287 changeCount(event, &newEventCount[0]);
288 }
289
290 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
291 jvmti_env, (unsigned char*)name))) {
292 nsk_jvmti_setFailStatus();
293 }
294 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
295 jvmti_env, (unsigned char*)sign))) {
296 nsk_jvmti_setFailStatus();
297 }
298 if (genc != NULL)
299 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate,
300 jvmti_env, (unsigned char*)genc))) {
301 nsk_jvmti_setFailStatus();
302 }
303 }
304
305 void JNICALL
306 cbNewMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
307 jmethodID method) {
308
309 handler2(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method);
310 }
311
312 void JNICALL
313 cbNewMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
314 jmethodID method, jboolean was_popped_by_exception,
315 jvalue return_value) {
316
317 handler2(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method);
318 }
319
320 void JNICALL
378 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
379
380 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
381 }
382
383 void JNICALL
384 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
385 jobject object, jclass object_klass, jlong size) {
386
387 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
388 }
389
390 /* ============================================================================= */
391
392 static int enableEvent(jvmtiEvent event) {
393
394 if (nsk_jvmti_isOptionalEvent(event)
395 && (event != JVMTI_EVENT_METHOD_ENTRY)
396 && (event != JVMTI_EVENT_METHOD_EXIT)) {
397 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
398 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
399 JVMTI_ENABLE, event, NULL))) {
400 NSK_COMPLAIN1("Unexpected error enabling %s\n",
401 TranslateEvent(event));
402 return NSK_FALSE;
403 }
404 } else {
405 if (!NSK_JVMTI_VERIFY(
406 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
407 JVMTI_ENABLE, event, NULL))) {
408 NSK_COMPLAIN1("Unexpected error enabling %s\n",
409 TranslateEvent(event));
410 return NSK_FALSE;
411 }
412 }
413
414 return NSK_TRUE;
415 }
416
417 /**
418 * Enable or disable tested events.
419 */
420 static int enableEventList() {
421
422 int i, result;
423
424 result = enableEvent(JVMTI_EVENT_VM_INIT);
425
426 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
427
481 break;
482
483 case 2:
484 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
485 newEventCount[i] = 0;
486 }
487
488 eventCallbacks.MethodEntry = cbNewMethodEntry;
489 eventCallbacks.MethodExit = cbNewMethodExit;
490 break;
491
492 case 3:
493 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
494 newEventCount[i] = 0;
495 }
496
497 eventCallbacks.VMDeath = cbVMDeath;
498 break;
499
500 }
501 if (!NSK_JVMTI_VERIFY(
502 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
503 &eventCallbacks,
504 sizeof(eventCallbacks))))
505 return NSK_FALSE;
506
507 return NSK_TRUE;
508 }
509
510 /* ============================================================================= */
511
512 /** Agent algorithm. */
513 static void JNICALL
514 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
515
516 int i;
517
518 for (i = 1; i <= STEP_NUMBER; i++) {
519
520 if (!nsk_jvmti_waitForSync(timeout))
521 return;
522
523 if (i < STEP_NUMBER) {
524 showEventStatistics(i);
543 JNIEXPORT jint JNICALL Agent_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) {
544 return Agent_Initialize(jvm, options, reserved);
545 }
546 JNIEXPORT jint JNICALL Agent_OnAttach_em02t009(JavaVM *jvm, char *options, void *reserved) {
547 return Agent_Initialize(jvm, options, reserved);
548 }
549 JNIEXPORT jint JNI_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) {
550 return JNI_VERSION_1_8;
551 }
552 #endif
553 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
554
555 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
556 return JNI_ERR;
557
558 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
559
560 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
561 return JNI_ERR;
562
563 if (!NSK_JVMTI_VERIFY(
564 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
565 nsk_jvmti_setFailStatus();
566 return JNI_ERR;
567 }
568
569 {
570 jvmtiCapabilities caps;
571 memset(&caps, 0, sizeof(caps));
572
573 caps.can_generate_method_entry_events = 1;
574 caps.can_generate_method_exit_events = 1;
575 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
576 return JNI_ERR;
577 }
578
579 if (!setCallBacks(1)) {
580 return JNI_ERR;
581 }
582
583 if (!enableEventList()) {
584 return JNI_ERR;
585 }
586
587 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
588 return JNI_ERR;
589
590 return JNI_OK;
591 }
592
593 /* ============================================================================= */
594
595
|
126 result = NSK_FALSE;
127 }
128 }
129 } else {
130
131 if (currentCounts[i] > 0) {
132 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
133 TranslateEvent(curr),
134 currentCounts[i]);
135 result = NSK_FALSE;
136 }
137 }
138 }
139
140 return result;
141 }
142
143 static void
144 changeCount(jvmtiEvent event, int *currentCounts) {
145
146 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
147 nsk_jvmti_setFailStatus();
148
149 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
150
151 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
152 nsk_jvmti_setFailStatus();
153
154 }
155
156 /* ============================================================================= */
157
158 /* callbacks */
159 JNIEXPORT void JNICALL
160 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
161 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
162 }
163
164 JNIEXPORT void JNICALL
165 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
166 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
167 showEventStatistics(STEP_NUMBER);
168 if (!checkEvents(STEP_NUMBER))
169 nsk_jvmti_setFailStatus();
170
171 if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
172 nsk_jvmti_setFailStatus();
173
174 }
175
176 void JNICALL
177 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
178 jmethodID method, jlocation location, jobject exception,
179 jmethodID catch_method, jlocation catch_location) {
180
181 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
182 }
183
184 void JNICALL
185 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
186 jmethodID method, jlocation location, jobject exception) {
187
188 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
189 }
190
191 void JNICALL
211 cbFieldAccess(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
212 jmethodID method, jlocation location, jclass field_klass,
213 jobject object, jfieldID field) {
214 changeCount(JVMTI_EVENT_FIELD_ACCESS, &eventCount[0]);
215 }
216
217 void JNICALL
218 cbFieldModification(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
219 jmethodID method, jlocation location, jclass field_klass,
220 jobject object, jfieldID field, char signature_type,
221 jvalue new_value) {
222 changeCount(JVMTI_EVENT_FIELD_MODIFICATION, &eventCount[0]);
223 }
224
225 void handler1(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) {
226
227 char *name;
228 char *sign;
229 char *genc;
230
231 if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sign, &genc))) {
232 nsk_jvmti_setFailStatus();
233 return;
234 }
235
236 if (!strncmp(name,"javaMethod", 8)) {
237 changeCount(event, &eventCount[0]);
238 }
239
240 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)name))) {
241 nsk_jvmti_setFailStatus();
242 }
243 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign))) {
244 nsk_jvmti_setFailStatus();
245 }
246 if (genc != NULL)
247 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)genc))) {
248 nsk_jvmti_setFailStatus();
249 }
250 }
251
252 void JNICALL
253 cbMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
254 jmethodID method) {
255
256 handler1(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method);
257 }
258
259 void JNICALL
260 cbMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
261 jmethodID method, jboolean was_popped_by_exception,
262 jvalue return_value) {
263
264 handler1(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method);
265 }
266
267 void handler2(jvmtiEnv *jvmti_env, jvmtiEvent event, jmethodID method) {
268
269 char *name;
270 char *sign;
271 char *genc;
272
273 if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sign, &genc))) {
274 nsk_jvmti_setFailStatus();
275 return;
276 }
277
278 if (!strncmp(name,"javaMethod", 8)) {
279 changeCount(event, &newEventCount[0]);
280 }
281
282 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)name))) {
283 nsk_jvmti_setFailStatus();
284 }
285 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)sign))) {
286 nsk_jvmti_setFailStatus();
287 }
288 if (genc != NULL)
289 if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)genc))) {
290 nsk_jvmti_setFailStatus();
291 }
292 }
293
294 void JNICALL
295 cbNewMethodEntry(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
296 jmethodID method) {
297
298 handler2(jvmti_env, JVMTI_EVENT_METHOD_ENTRY, method);
299 }
300
301 void JNICALL
302 cbNewMethodExit(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
303 jmethodID method, jboolean was_popped_by_exception,
304 jvalue return_value) {
305
306 handler2(jvmti_env, JVMTI_EVENT_METHOD_EXIT, method);
307 }
308
309 void JNICALL
367 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
368
369 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
370 }
371
372 void JNICALL
373 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
374 jobject object, jclass object_klass, jlong size) {
375
376 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
377 }
378
379 /* ============================================================================= */
380
381 static int enableEvent(jvmtiEvent event) {
382
383 if (nsk_jvmti_isOptionalEvent(event)
384 && (event != JVMTI_EVENT_METHOD_ENTRY)
385 && (event != JVMTI_EVENT_METHOD_EXIT)) {
386 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
387 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
388 NSK_COMPLAIN1("Unexpected error enabling %s\n",
389 TranslateEvent(event));
390 return NSK_FALSE;
391 }
392 } else {
393 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
394 NSK_COMPLAIN1("Unexpected error enabling %s\n",
395 TranslateEvent(event));
396 return NSK_FALSE;
397 }
398 }
399
400 return NSK_TRUE;
401 }
402
403 /**
404 * Enable or disable tested events.
405 */
406 static int enableEventList() {
407
408 int i, result;
409
410 result = enableEvent(JVMTI_EVENT_VM_INIT);
411
412 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
413
467 break;
468
469 case 2:
470 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
471 newEventCount[i] = 0;
472 }
473
474 eventCallbacks.MethodEntry = cbNewMethodEntry;
475 eventCallbacks.MethodExit = cbNewMethodExit;
476 break;
477
478 case 3:
479 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
480 newEventCount[i] = 0;
481 }
482
483 eventCallbacks.VMDeath = cbVMDeath;
484 break;
485
486 }
487 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
488 return NSK_FALSE;
489
490 return NSK_TRUE;
491 }
492
493 /* ============================================================================= */
494
495 /** Agent algorithm. */
496 static void JNICALL
497 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
498
499 int i;
500
501 for (i = 1; i <= STEP_NUMBER; i++) {
502
503 if (!nsk_jvmti_waitForSync(timeout))
504 return;
505
506 if (i < STEP_NUMBER) {
507 showEventStatistics(i);
526 JNIEXPORT jint JNICALL Agent_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) {
527 return Agent_Initialize(jvm, options, reserved);
528 }
529 JNIEXPORT jint JNICALL Agent_OnAttach_em02t009(JavaVM *jvm, char *options, void *reserved) {
530 return Agent_Initialize(jvm, options, reserved);
531 }
532 JNIEXPORT jint JNI_OnLoad_em02t009(JavaVM *jvm, char *options, void *reserved) {
533 return JNI_VERSION_1_8;
534 }
535 #endif
536 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
537
538 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
539 return JNI_ERR;
540
541 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
542
543 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
544 return JNI_ERR;
545
546 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
547 nsk_jvmti_setFailStatus();
548 return JNI_ERR;
549 }
550
551 {
552 jvmtiCapabilities caps;
553 memset(&caps, 0, sizeof(caps));
554
555 caps.can_generate_method_entry_events = 1;
556 caps.can_generate_method_exit_events = 1;
557 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
558 return JNI_ERR;
559 }
560
561 if (!setCallBacks(1)) {
562 return JNI_ERR;
563 }
564
565 if (!enableEventList()) {
566 return JNI_ERR;
567 }
568
569 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
570 return JNI_ERR;
571
572 return JNI_OK;
573 }
574
575 /* ============================================================================= */
576
577
|