131 }
132 }
133
134 } else {
135
136 if (currentCounts[i] > 0) {
137 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
138 TranslateEvent(curr),
139 currentCounts[i]);
140 result = NSK_FALSE;
141 }
142 }
143 }
144
145 return result;
146 }
147
148 static void
149 changeCount(jvmtiEvent event, int *currentCounts) {
150
151 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
152 nsk_jvmti_setFailStatus();
153
154 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
155
156 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
157 nsk_jvmti_setFailStatus();
158
159 }
160
161 /* ============================================================================= */
162
163 /* callbacks */
164 JNIEXPORT void JNICALL
165 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
166 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
167 }
168
169 JNIEXPORT void JNICALL
170 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
171 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
172 showEventStatistics(STEP_NUMBER);
173 if (!checkEvents(STEP_NUMBER))
174 nsk_jvmti_setFailStatus();
175
176 if (!NSK_JVMTI_VERIFY(
177 NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
178 nsk_jvmti_setFailStatus();
179
180 }
181
182 void JNICALL
183 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
184 jmethodID method, jlocation location, jobject exception,
185 jmethodID catch_method, jlocation catch_location) {
186
187 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
188 }
189
190 void JNICALL
191 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
192 jmethodID method, jlocation location, jobject exception) {
193
194 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
195 }
196
197 void JNICALL
323 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
324
325 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
326 }
327
328 void JNICALL
329 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
330 jobject object, jclass object_klass, jlong size) {
331
332 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
333 }
334
335 /* ============================================================================= */
336
337 static int enableEvent(jvmtiEvent event) {
338
339 if (nsk_jvmti_isOptionalEvent(event)
340 && (event != JVMTI_EVENT_FIELD_MODIFICATION)
341 && (event != JVMTI_EVENT_FIELD_ACCESS)) {
342 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
343 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
344 JVMTI_ENABLE, event, NULL))) {
345 NSK_COMPLAIN1("Unexpected error enabling %s\n",
346 TranslateEvent(event));
347 return NSK_FALSE;
348 }
349 } else {
350 if (!NSK_JVMTI_VERIFY(
351 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
352 JVMTI_ENABLE, event, NULL))) {
353 NSK_COMPLAIN1("Unexpected error enabling %s\n",
354 TranslateEvent(event));
355 return NSK_FALSE;
356 }
357 }
358
359 return NSK_TRUE;
360 }
361
362 /**
363 * Enable or disable tested events.
364 */
365 static int enableEventList() {
366
367 int i, result;
368
369 result = enableEvent(JVMTI_EVENT_VM_INIT);
370
371 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
372
426 break;
427
428 case 2:
429 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
430 newEventCount[i] = 0;
431 }
432
433 eventCallbacks.FieldAccess = cbNewFieldAccess;
434 eventCallbacks.FieldModification = cbNewFieldModification;
435 break;
436
437 case 3:
438 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
439 newEventCount[i] = 0;
440 }
441
442 eventCallbacks.VMDeath = cbVMDeath;
443 break;
444
445 }
446 if (!NSK_JVMTI_VERIFY(
447 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
448 &eventCallbacks,
449 sizeof(eventCallbacks))))
450 return NSK_FALSE;
451
452 return NSK_TRUE;
453 }
454
455 /* ============================================================================= */
456
457 /** Agent algorithm. */
458 static void JNICALL
459 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
460
461 int i;
462 jfieldID field_accID, field_modID;
463 jclass cls;
464
465
466 if (!nsk_jvmti_waitForSync(timeout))
467 return;
468
469 if (!NSK_JNI_VERIFY(agentJNI, (cls =
470 NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL))
471 return;
472
473 if (!NSK_JNI_VERIFY(agentJNI, (field_accID =
474 NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_ACC_NAME,
475 "I")) != NULL))
476 return;
477
478 if (!NSK_JNI_VERIFY(agentJNI, (field_modID =
479 NSK_CPP_STUB4(GetStaticFieldID, agentJNI, cls, FIELD_MOD_NAME,
480 "I")) != NULL))
481 return;
482
483 if (!NSK_JVMTI_VERIFY(
484 NSK_CPP_STUB3(SetFieldModificationWatch, jvmti, cls, field_modID)))
485 return;
486
487 if (!NSK_JVMTI_VERIFY(
488 NSK_CPP_STUB3(SetFieldAccessWatch, jvmti, cls, field_accID)))
489 return;
490
491 if (!nsk_jvmti_resumeSync())
492 return;
493
494 for (i = 1; i <= STEP_NUMBER; i++) {
495
496 if (!nsk_jvmti_waitForSync(timeout))
497 return;
498
499 if (i < STEP_NUMBER) {
500 showEventStatistics(i);
501 if (!checkEvents(i))
502 nsk_jvmti_setFailStatus();
503
504 if (!setCallBacks(i + 1)) {
505 return;
506 }
507 }
508
519 JNIEXPORT jint JNICALL Agent_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) {
520 return Agent_Initialize(jvm, options, reserved);
521 }
522 JNIEXPORT jint JNICALL Agent_OnAttach_em02t010(JavaVM *jvm, char *options, void *reserved) {
523 return Agent_Initialize(jvm, options, reserved);
524 }
525 JNIEXPORT jint JNI_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) {
526 return JNI_VERSION_1_8;
527 }
528 #endif
529 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
530
531 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
532 return JNI_ERR;
533
534 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
535
536 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
537 return JNI_ERR;
538
539 if (!NSK_JVMTI_VERIFY(
540 NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
541 nsk_jvmti_setFailStatus();
542 return JNI_ERR;
543 }
544
545 {
546 jvmtiCapabilities caps;
547 memset(&caps, 0, sizeof(caps));
548
549 caps.can_generate_field_modification_events = 1;
550 caps.can_generate_field_access_events = 1;
551 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
552 return JNI_ERR;
553 }
554
555 if (!setCallBacks(1)) {
556 return JNI_ERR;
557 }
558
559 if (!enableEventList()) {
560 return JNI_ERR;
561 }
562
563 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
564 return JNI_ERR;
565
566 return JNI_OK;
567 }
568
569 /* ============================================================================= */
570
571
|
131 }
132 }
133
134 } else {
135
136 if (currentCounts[i] > 0) {
137 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
138 TranslateEvent(curr),
139 currentCounts[i]);
140 result = NSK_FALSE;
141 }
142 }
143 }
144
145 return result;
146 }
147
148 static void
149 changeCount(jvmtiEvent event, int *currentCounts) {
150
151 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
152 nsk_jvmti_setFailStatus();
153
154 currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
155
156 if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
157 nsk_jvmti_setFailStatus();
158
159 }
160
161 /* ============================================================================= */
162
163 /* callbacks */
164 JNIEXPORT void JNICALL
165 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
166 changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
167 }
168
169 JNIEXPORT void JNICALL
170 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
171 changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
172 showEventStatistics(STEP_NUMBER);
173 if (!checkEvents(STEP_NUMBER))
174 nsk_jvmti_setFailStatus();
175
176 if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
177 nsk_jvmti_setFailStatus();
178
179 }
180
181 void JNICALL
182 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
183 jmethodID method, jlocation location, jobject exception,
184 jmethodID catch_method, jlocation catch_location) {
185
186 changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
187 }
188
189 void JNICALL
190 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
191 jmethodID method, jlocation location, jobject exception) {
192
193 changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
194 }
195
196 void JNICALL
322 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
323
324 changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
325 }
326
327 void JNICALL
328 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
329 jobject object, jclass object_klass, jlong size) {
330
331 changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
332 }
333
334 /* ============================================================================= */
335
336 static int enableEvent(jvmtiEvent event) {
337
338 if (nsk_jvmti_isOptionalEvent(event)
339 && (event != JVMTI_EVENT_FIELD_MODIFICATION)
340 && (event != JVMTI_EVENT_FIELD_ACCESS)) {
341 if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
342 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
343 NSK_COMPLAIN1("Unexpected error enabling %s\n",
344 TranslateEvent(event));
345 return NSK_FALSE;
346 }
347 } else {
348 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {
349 NSK_COMPLAIN1("Unexpected error enabling %s\n",
350 TranslateEvent(event));
351 return NSK_FALSE;
352 }
353 }
354
355 return NSK_TRUE;
356 }
357
358 /**
359 * Enable or disable tested events.
360 */
361 static int enableEventList() {
362
363 int i, result;
364
365 result = enableEvent(JVMTI_EVENT_VM_INIT);
366
367 result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
368
422 break;
423
424 case 2:
425 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
426 newEventCount[i] = 0;
427 }
428
429 eventCallbacks.FieldAccess = cbNewFieldAccess;
430 eventCallbacks.FieldModification = cbNewFieldModification;
431 break;
432
433 case 3:
434 for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
435 newEventCount[i] = 0;
436 }
437
438 eventCallbacks.VMDeath = cbVMDeath;
439 break;
440
441 }
442 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))
443 return NSK_FALSE;
444
445 return NSK_TRUE;
446 }
447
448 /* ============================================================================= */
449
450 /** Agent algorithm. */
451 static void JNICALL
452 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
453
454 int i;
455 jfieldID field_accID, field_modID;
456 jclass cls;
457
458
459 if (!nsk_jvmti_waitForSync(timeout))
460 return;
461
462 if (!NSK_JNI_VERIFY(agentJNI, (cls = agentJNI->FindClass(CLASS_NAME)) != NULL))
463 return;
464
465 if (!NSK_JNI_VERIFY(agentJNI, (field_accID =
466 agentJNI->GetStaticFieldID(cls, FIELD_ACC_NAME, "I")) != NULL))
467 return;
468
469 if (!NSK_JNI_VERIFY(agentJNI, (field_modID =
470 agentJNI->GetStaticFieldID(cls, FIELD_MOD_NAME, "I")) != NULL))
471 return;
472
473 if (!NSK_JVMTI_VERIFY(jvmti->SetFieldModificationWatch(cls, field_modID)))
474 return;
475
476 if (!NSK_JVMTI_VERIFY(jvmti->SetFieldAccessWatch(cls, field_accID)))
477 return;
478
479 if (!nsk_jvmti_resumeSync())
480 return;
481
482 for (i = 1; i <= STEP_NUMBER; i++) {
483
484 if (!nsk_jvmti_waitForSync(timeout))
485 return;
486
487 if (i < STEP_NUMBER) {
488 showEventStatistics(i);
489 if (!checkEvents(i))
490 nsk_jvmti_setFailStatus();
491
492 if (!setCallBacks(i + 1)) {
493 return;
494 }
495 }
496
507 JNIEXPORT jint JNICALL Agent_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) {
508 return Agent_Initialize(jvm, options, reserved);
509 }
510 JNIEXPORT jint JNICALL Agent_OnAttach_em02t010(JavaVM *jvm, char *options, void *reserved) {
511 return Agent_Initialize(jvm, options, reserved);
512 }
513 JNIEXPORT jint JNI_OnLoad_em02t010(JavaVM *jvm, char *options, void *reserved) {
514 return JNI_VERSION_1_8;
515 }
516 #endif
517 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
518
519 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
520 return JNI_ERR;
521
522 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
523
524 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
525 return JNI_ERR;
526
527 if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
528 nsk_jvmti_setFailStatus();
529 return JNI_ERR;
530 }
531
532 {
533 jvmtiCapabilities caps;
534 memset(&caps, 0, sizeof(caps));
535
536 caps.can_generate_field_modification_events = 1;
537 caps.can_generate_field_access_events = 1;
538 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
539 return JNI_ERR;
540 }
541
542 if (!setCallBacks(1)) {
543 return JNI_ERR;
544 }
545
546 if (!enableEventList()) {
547 return JNI_ERR;
548 }
549
550 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
551 return JNI_ERR;
552
553 return JNI_OK;
554 }
555
556 /* ============================================================================= */
557
558
|