< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t011/em02t011.cpp

Print this page
rev 52050 : [mq]: refactor


 127                 }
 128             }
 129 
 130         } else {
 131 
 132             if (currentCounts[i] > 0) {
 133                 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
 134                                     TranslateEvent(curr),
 135                                     currentCounts[i]);
 136                 result = NSK_FALSE;
 137             }
 138         }
 139     }
 140 
 141     return result;
 142 }
 143 
 144 static void
 145 changeCount(jvmtiEvent event, int *currentCounts) {
 146 
 147     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorEnter, jvmti, syncLock)))
 148         nsk_jvmti_setFailStatus();
 149 
 150     currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
 151 
 152     if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(RawMonitorExit, jvmti, syncLock)))
 153         nsk_jvmti_setFailStatus();
 154 
 155 }
 156 
 157 /* ============================================================================= */
 158 
 159 /* callbacks */
 160 JNIEXPORT void JNICALL
 161 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
 162     changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
 163 }
 164 
 165 JNIEXPORT void JNICALL
 166 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
 167     changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
 168     showEventStatistics(STEP_NUMBER);
 169     if (!checkEvents(STEP_NUMBER))
 170         nsk_jvmti_setFailStatus();
 171 
 172     if (!NSK_JVMTI_VERIFY(
 173             NSK_CPP_STUB2(DestroyRawMonitor, jvmti, syncLock)))
 174         nsk_jvmti_setFailStatus();
 175 
 176 }
 177 
 178 void JNICALL
 179 cbException(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
 180                 jmethodID method, jlocation location, jobject exception,
 181                 jmethodID catch_method, jlocation catch_location) {
 182 
 183     changeCount(JVMTI_EVENT_EXCEPTION, &eventCount[0]);
 184 }
 185 
 186 void JNICALL
 187 cbExceptionCatch(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
 188                 jmethodID method, jlocation location, jobject exception) {
 189 
 190     changeCount(JVMTI_EVENT_EXCEPTION_CATCH, &eventCount[0]);
 191 }
 192 
 193 void JNICALL


 309 void JNICALL
 310 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
 311 
 312     changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
 313 }
 314 
 315 void JNICALL
 316 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
 317                     jobject object, jclass object_klass, jlong size) {
 318 
 319     changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
 320 }
 321 
 322 /* ============================================================================= */
 323 
 324 static int enableEvent(jvmtiEvent event) {
 325 
 326     if (nsk_jvmti_isOptionalEvent(event)
 327             && (event != JVMTI_EVENT_BREAKPOINT)) {
 328         if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
 329                 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
 330                     JVMTI_ENABLE, event, NULL))) {
 331             NSK_COMPLAIN1("Unexpected error enabling %s\n",
 332                 TranslateEvent(event));
 333             return NSK_FALSE;
 334         }
 335     } else {
 336         if (!NSK_JVMTI_VERIFY(
 337                 NSK_CPP_STUB4(SetEventNotificationMode, jvmti,
 338                     JVMTI_ENABLE, event, NULL))) {
 339             NSK_COMPLAIN1("Unexpected error enabling %s\n",
 340                 TranslateEvent(event));
 341             return NSK_FALSE;
 342         }
 343     }
 344 
 345     return NSK_TRUE;
 346 }
 347 
 348 /**
 349  * Enable or disable tested events.
 350  */
 351 static int enableEventList() {
 352 
 353     int i, result;
 354 
 355     result = enableEvent(JVMTI_EVENT_VM_INIT);
 356 
 357     result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
 358 


 411             eventCallbacks.VMObjectAlloc             = cbVMObjectAlloc;
 412             break;
 413 
 414         case 2:
 415             for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
 416                 newEventCount[i] = 0;
 417             }
 418 
 419             eventCallbacks.Breakpoint                = cbNewBreakpoint;
 420             break;
 421 
 422         case 3:
 423             for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
 424                 newEventCount[i] = 0;
 425             }
 426 
 427             eventCallbacks.VMDeath                   = cbVMDeath;
 428             break;
 429 
 430     }
 431     if (!NSK_JVMTI_VERIFY(
 432             NSK_CPP_STUB3(SetEventCallbacks, jvmti,
 433                                 &eventCallbacks,
 434                                 sizeof(eventCallbacks))))
 435         return NSK_FALSE;
 436 
 437     return NSK_TRUE;
 438 }
 439 
 440 /* ============================================================================= */
 441 
 442 /** Agent algorithm. */
 443 static void JNICALL
 444 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
 445 
 446     int i;
 447     jmethodID methodID;
 448     jclass cls;
 449 
 450 
 451     if (!nsk_jvmti_waitForSync(timeout))
 452         return;
 453 
 454     if (!NSK_JNI_VERIFY(agentJNI, (cls =
 455             NSK_CPP_STUB2(FindClass, agentJNI, CLASS_NAME)) != NULL))
 456         return;
 457 
 458     if (!NSK_JNI_VERIFY(agentJNI, (methodID =
 459             NSK_CPP_STUB4(GetStaticMethodID, agentJNI, cls, METHOD_NAME,
 460                                 "()I")) != NULL))
 461         return;
 462 
 463     if (!NSK_JVMTI_VERIFY(
 464             NSK_CPP_STUB3(SetBreakpoint, jvmti, methodID, 0)))
 465         return;
 466 
 467     if (!nsk_jvmti_resumeSync())
 468         return;
 469 
 470     for (i = 1; i <= STEP_NUMBER; i++) {
 471 
 472         if (!nsk_jvmti_waitForSync(timeout))
 473             return;
 474 
 475         if (i < STEP_NUMBER) {
 476             showEventStatistics(i);
 477             if (!checkEvents(i))
 478                 nsk_jvmti_setFailStatus();
 479 
 480             if (!setCallBacks(i + 1)) {
 481                 return;
 482             }
 483         }
 484 


 495 JNIEXPORT jint JNICALL Agent_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) {
 496     return Agent_Initialize(jvm, options, reserved);
 497 }
 498 JNIEXPORT jint JNICALL Agent_OnAttach_em02t011(JavaVM *jvm, char *options, void *reserved) {
 499     return Agent_Initialize(jvm, options, reserved);
 500 }
 501 JNIEXPORT jint JNI_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) {
 502     return JNI_VERSION_1_8;
 503 }
 504 #endif
 505 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 506 
 507     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 508         return JNI_ERR;
 509 
 510     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 511 
 512     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 513         return JNI_ERR;
 514 
 515     if (!NSK_JVMTI_VERIFY(
 516             NSK_CPP_STUB3(CreateRawMonitor, jvmti, "_syncLock", &syncLock))) {
 517         nsk_jvmti_setFailStatus();
 518         return JNI_ERR;
 519     }
 520 
 521     {
 522         jvmtiCapabilities caps;
 523         memset(&caps, 0, sizeof(caps));
 524 
 525         caps.can_generate_breakpoint_events = 1;
 526         if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
 527             return JNI_ERR;
 528     }
 529 
 530     if (!setCallBacks(1)) {
 531         return JNI_ERR;
 532     }
 533 
 534     if (!enableEventList()) {
 535         return JNI_ERR;
 536     }
 537 
 538     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 539         return JNI_ERR;
 540 
 541     return JNI_OK;
 542 }
 543 
 544 /* ============================================================================= */
 545 
 546 


 127                 }
 128             }
 129 
 130         } else {
 131 
 132             if (currentCounts[i] > 0) {
 133                 NSK_COMPLAIN2("Unexpected event %s was sent %d times\n",
 134                                     TranslateEvent(curr),
 135                                     currentCounts[i]);
 136                 result = NSK_FALSE;
 137             }
 138         }
 139     }
 140 
 141     return result;
 142 }
 143 
 144 static void
 145 changeCount(jvmtiEvent event, int *currentCounts) {
 146 
 147     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
 148         nsk_jvmti_setFailStatus();
 149 
 150     currentCounts[event - JVMTI_MIN_EVENT_TYPE_VAL]++;
 151 
 152     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
 153         nsk_jvmti_setFailStatus();
 154 
 155 }
 156 
 157 /* ============================================================================= */
 158 
 159 /* callbacks */
 160 JNIEXPORT void JNICALL
 161 cbVMInit(jvmtiEnv* jvmti, JNIEnv* jni_env, jthread thread) {
 162     changeCount(JVMTI_EVENT_VM_INIT, &eventCount[0]);
 163 }
 164 
 165 JNIEXPORT void JNICALL
 166 cbVMDeath(jvmtiEnv* jvmti, JNIEnv* jni_env) {
 167     changeCount(JVMTI_EVENT_VM_DEATH, &newEventCount[0]);
 168     showEventStatistics(STEP_NUMBER);
 169     if (!checkEvents(STEP_NUMBER))
 170         nsk_jvmti_setFailStatus();
 171 
 172     if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(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


 308 void JNICALL
 309 cbObjectFree(jvmtiEnv *jvmti_env, jlong tag) {
 310 
 311     changeCount(JVMTI_EVENT_OBJECT_FREE, &eventCount[0]);
 312 }
 313 
 314 void JNICALL
 315 cbVMObjectAlloc(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
 316                     jobject object, jclass object_klass, jlong size) {
 317 
 318     changeCount(JVMTI_EVENT_VM_OBJECT_ALLOC, &eventCount[0]);
 319 }
 320 
 321 /* ============================================================================= */
 322 
 323 static int enableEvent(jvmtiEvent event) {
 324 
 325     if (nsk_jvmti_isOptionalEvent(event)
 326             && (event != JVMTI_EVENT_BREAKPOINT)) {
 327         if (!NSK_JVMTI_VERIFY_CODE(JVMTI_ERROR_MUST_POSSESS_CAPABILITY,
 328                 jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {

 329             NSK_COMPLAIN1("Unexpected error enabling %s\n",
 330                 TranslateEvent(event));
 331             return NSK_FALSE;
 332         }
 333     } else {
 334         if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, event, NULL))) {


 335             NSK_COMPLAIN1("Unexpected error enabling %s\n",
 336                 TranslateEvent(event));
 337             return NSK_FALSE;
 338         }
 339     }
 340 
 341     return NSK_TRUE;
 342 }
 343 
 344 /**
 345  * Enable or disable tested events.
 346  */
 347 static int enableEventList() {
 348 
 349     int i, result;
 350 
 351     result = enableEvent(JVMTI_EVENT_VM_INIT);
 352 
 353     result = result && enableEvent(JVMTI_EVENT_VM_DEATH);
 354 


 407             eventCallbacks.VMObjectAlloc             = cbVMObjectAlloc;
 408             break;
 409 
 410         case 2:
 411             for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
 412                 newEventCount[i] = 0;
 413             }
 414 
 415             eventCallbacks.Breakpoint                = cbNewBreakpoint;
 416             break;
 417 
 418         case 3:
 419             for (i = 0; i < JVMTI_EVENT_COUNT; i++) {
 420                 newEventCount[i] = 0;
 421             }
 422 
 423             eventCallbacks.VMDeath                   = cbVMDeath;
 424             break;
 425 
 426     }
 427     if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))



 428         return NSK_FALSE;
 429 
 430     return NSK_TRUE;
 431 }
 432 
 433 /* ============================================================================= */
 434 
 435 /** Agent algorithm. */
 436 static void JNICALL
 437 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
 438 
 439     int i;
 440     jmethodID methodID;
 441     jclass cls;
 442 
 443 
 444     if (!nsk_jvmti_waitForSync(timeout))
 445         return;
 446 
 447     if (!NSK_JNI_VERIFY(agentJNI, (cls = agentJNI->FindClass(CLASS_NAME)) != NULL))

 448         return;
 449 
 450     if (!NSK_JNI_VERIFY(agentJNI, (methodID =
 451             agentJNI->GetStaticMethodID(cls, METHOD_NAME, "()I")) != NULL))

 452         return;
 453 
 454     if (!NSK_JVMTI_VERIFY(jvmti->SetBreakpoint(methodID, 0)))

 455         return;
 456 
 457     if (!nsk_jvmti_resumeSync())
 458         return;
 459 
 460     for (i = 1; i <= STEP_NUMBER; i++) {
 461 
 462         if (!nsk_jvmti_waitForSync(timeout))
 463             return;
 464 
 465         if (i < STEP_NUMBER) {
 466             showEventStatistics(i);
 467             if (!checkEvents(i))
 468                 nsk_jvmti_setFailStatus();
 469 
 470             if (!setCallBacks(i + 1)) {
 471                 return;
 472             }
 473         }
 474 


 485 JNIEXPORT jint JNICALL Agent_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) {
 486     return Agent_Initialize(jvm, options, reserved);
 487 }
 488 JNIEXPORT jint JNICALL Agent_OnAttach_em02t011(JavaVM *jvm, char *options, void *reserved) {
 489     return Agent_Initialize(jvm, options, reserved);
 490 }
 491 JNIEXPORT jint JNI_OnLoad_em02t011(JavaVM *jvm, char *options, void *reserved) {
 492     return JNI_VERSION_1_8;
 493 }
 494 #endif
 495 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 496 
 497     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 498         return JNI_ERR;
 499 
 500     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 501 
 502     if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 503         return JNI_ERR;
 504 
 505     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {

 506         nsk_jvmti_setFailStatus();
 507         return JNI_ERR;
 508     }
 509 
 510     {
 511         jvmtiCapabilities caps;
 512         memset(&caps, 0, sizeof(caps));
 513 
 514         caps.can_generate_breakpoint_events = 1;
 515         if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
 516             return JNI_ERR;
 517     }
 518 
 519     if (!setCallBacks(1)) {
 520         return JNI_ERR;
 521     }
 522 
 523     if (!enableEventList()) {
 524         return JNI_ERR;
 525     }
 526 
 527     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 528         return JNI_ERR;
 529 
 530     return JNI_OK;
 531 }
 532 
 533 /* ============================================================================= */
 534 
 535 
< prev index next >