< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI05/ji05t001/ji05t001.c

Print this page




 300 
 301     /* check that the interception has been set properly */
 302     NSK_DISPLAY0("\nagent A (first JVMTI env): checking that the interception has been set properly ...\n");
 303     provokeIntercept(env, "A");
 304     checkIntercept(0, 0, 1); /* expected interceptions: 1 */
 305     NSK_DISPLAY0("\n<<< TEST CASE #1) done\n");
 306 
 307     /* the flag set too late in order to make sure that
 308        the agent B will be started _after_ the interception */
 309     thrstarted[0] = 1;
 310 
 311     redir[0] = 1;
 312 
 313     NSK_DISPLAY0("\nagent A: waiting for the redirection in agent B ...\n");
 314     do {
 315         THREAD_sleep(1);
 316         tries++;
 317         if (tries > TRIES) {
 318             NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent B after %d attempts\n",
 319                 TRIES);



 320             exit(STATUS_FAILED);
 321         }
 322     } while(redir[1] != 1);
 323 
 324     /* check the interception set in another JVMTI env */
 325     NSK_DISPLAY0("\n>>> TEST CASE #4) First JVMTI env: checking the redirection set in second JVMTI env ...\n");
 326     for (i=0; i<AGENTS; i++) {
 327         redir_calls[i] = 0;
 328     }
 329     provokeIntercept(env, "A");
 330     /* check that the previous interception has been overwritten */
 331     checkIntercept(0, 0, 1); /* expected interceptions: 1 */
 332     /* check the current interception set in another JVMTI env */
 333     checkIntercept(1, 0, 1); /* expected interceptions: 1 */
 334     NSK_DISPLAY0("\n<<< TEST CASE #4) done\n");
 335 
 336     NSK_DISPLAY1("\nagent A: returning exit code %d\n",
 337         exitCode);



 338     return exitCode;
 339 }
 340 
 341 static int agentB(void *context) {
 342     JNIEnv *env;
 343     jint res;
 344     int tries = 0;
 345     int i;
 346     int exitCode = PASSED;
 347 
 348     NSK_DISPLAY0("\nthe agent B started\n\tattaching the thread to the VM ...\n");
 349     if ((res =
 350             JNI_ENV_PTR(vm)->AttachCurrentThread(
 351                 JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) {
 352         NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n",
 353             res);



 354         exit(STATUS_FAILED);
 355     }
 356 
 357     thrstarted[1] = 1;
 358 
 359     NSK_DISPLAY0("\nagent B: waiting for the redirection in agent A ...\n");
 360     do {
 361         THREAD_sleep(1);
 362         tries++;
 363         if (tries > TRIES) {
 364             NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent A after %d attempts\n",
 365                 TRIES);



 366             exit(STATUS_FAILED);
 367         }
 368     } while(redir[0] != 1);
 369 
 370     /* check the interception set in another JVMTI env */
 371     NSK_DISPLAY0("\n>>> TEST CASE #2) Second JVMTI env: checking the redirection set in first JVMTI env ...\n");
 372     for (i=0; i<AGENTS; i++) {
 373         redir_calls[i] = 0;
 374     }
 375     provokeIntercept(env, "B");
 376     checkIntercept(0, 1, 1); /* expected interceptions: 1 */
 377     NSK_DISPLAY0("\n<<< TEST CASE #2) done\n");
 378 
 379     /* intercept the JNI function table */
 380     NSK_DISPLAY0("\n>>> TEST CASE #3) Second JVMTI env: checking the redirection set in the same env ...\n\
 381 \nagent B (second JVMTI env): redirecting the function table ...\n");
 382     doRedirect(env, jvmti[1], 1);
 383 
 384     for (i=0; i<AGENTS; i++) {
 385         redir_calls[i] = 0;
 386     }
 387     provokeIntercept(env, "B");
 388     /* check that the previous interception has been overwritten */
 389     checkIntercept(0, 1, 1); /* expected interceptions: 1 */
 390     /* check that the current interception has been set properly */
 391     checkIntercept(1, 1, 1); /* expected interceptions: 1 */
 392     NSK_DISPLAY0("\n<<< TEST CASE #3) done\n");
 393 
 394     redir[1] = 1;
 395 
 396     NSK_DISPLAY1("\nagent B: returning exit code %d\n",
 397         exitCode);



 398     return exitCode;
 399 }
 400 /*********************/
 401 
 402 /* callback functions */
 403 void JNICALL
 404 VMInitA(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
 405     NSK_DISPLAY0("\nagent A: VMInit event\n");
 406 
 407     startAgent(0);
 408 }
 409 
 410 void JNICALL
 411 VMInitB(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
 412     NSK_DISPLAY0("\nagent B: VMInit event\n");
 413 
 414     startAgent(1);
 415 }
 416 /*********************/
 417 




 300 
 301     /* check that the interception has been set properly */
 302     NSK_DISPLAY0("\nagent A (first JVMTI env): checking that the interception has been set properly ...\n");
 303     provokeIntercept(env, "A");
 304     checkIntercept(0, 0, 1); /* expected interceptions: 1 */
 305     NSK_DISPLAY0("\n<<< TEST CASE #1) done\n");
 306 
 307     /* the flag set too late in order to make sure that
 308        the agent B will be started _after_ the interception */
 309     thrstarted[0] = 1;
 310 
 311     redir[0] = 1;
 312 
 313     NSK_DISPLAY0("\nagent A: waiting for the redirection in agent B ...\n");
 314     do {
 315         THREAD_sleep(1);
 316         tries++;
 317         if (tries > TRIES) {
 318             NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent B after %d attempts\n",
 319                 TRIES);
 320             if ((res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) {
 321                 NSK_COMPLAIN1("TEST WARNING: agent A: DetachCurrentThread() returns: %d\n", res);
 322             }
 323             exit(STATUS_FAILED);
 324         }
 325     } while(redir[1] != 1);
 326 
 327     /* check the interception set in another JVMTI env */
 328     NSK_DISPLAY0("\n>>> TEST CASE #4) First JVMTI env: checking the redirection set in second JVMTI env ...\n");
 329     for (i=0; i<AGENTS; i++) {
 330         redir_calls[i] = 0;
 331     }
 332     provokeIntercept(env, "A");
 333     /* check that the previous interception has been overwritten */
 334     checkIntercept(0, 0, 1); /* expected interceptions: 1 */
 335     /* check the current interception set in another JVMTI env */
 336     checkIntercept(1, 0, 1); /* expected interceptions: 1 */
 337     NSK_DISPLAY0("\n<<< TEST CASE #4) done\n");
 338 
 339     NSK_DISPLAY1("\nagent A: detaching and returning exit code %d\n",
 340         exitCode);
 341     if ((res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) {
 342         NSK_COMPLAIN1("TEST WARNING: agent A: DetachCurrentThread() returns: %d\n", res);
 343     }
 344     return exitCode;
 345 }
 346 
 347 static int agentB(void *context) {
 348     JNIEnv *env;
 349     jint res;
 350     int tries = 0;
 351     int i;
 352     int exitCode = PASSED;
 353 
 354     NSK_DISPLAY0("\nthe agent B started\n\tattaching the thread to the VM ...\n");
 355     if ((res =
 356             JNI_ENV_PTR(vm)->AttachCurrentThread(
 357                 JNI_ENV_ARG(vm, (void **) &env), (void *) 0)) != 0) {
 358         NSK_COMPLAIN1("TEST FAILURE: AttachCurrentThread() returns: %d\n",
 359             res);
 360         if ((res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) {
 361             NSK_COMPLAIN1("TEST WARNING: agent B: DetachCurrentThread() returns: %d\n", res);
 362         }
 363         exit(STATUS_FAILED);
 364     }
 365 
 366     thrstarted[1] = 1;
 367 
 368     NSK_DISPLAY0("\nagent B: waiting for the redirection in agent A ...\n");
 369     do {
 370         THREAD_sleep(1);
 371         tries++;
 372         if (tries > TRIES) {
 373             NSK_COMPLAIN1("TEST FAILURE: failed to wait for the redirection in agent A after %d attempts\n",
 374                 TRIES);
 375             if ((res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) {
 376                 NSK_COMPLAIN1("TEST WARNING: agent B: DetachCurrentThread() returns: %d\n", res);
 377             }
 378             exit(STATUS_FAILED);
 379         }
 380     } while(redir[0] != 1);
 381 
 382     /* check the interception set in another JVMTI env */
 383     NSK_DISPLAY0("\n>>> TEST CASE #2) Second JVMTI env: checking the redirection set in first JVMTI env ...\n");
 384     for (i=0; i<AGENTS; i++) {
 385         redir_calls[i] = 0;
 386     }
 387     provokeIntercept(env, "B");
 388     checkIntercept(0, 1, 1); /* expected interceptions: 1 */
 389     NSK_DISPLAY0("\n<<< TEST CASE #2) done\n");
 390 
 391     /* intercept the JNI function table */
 392     NSK_DISPLAY0("\n>>> TEST CASE #3) Second JVMTI env: checking the redirection set in the same env ...\n\
 393 \nagent B (second JVMTI env): redirecting the function table ...\n");
 394     doRedirect(env, jvmti[1], 1);
 395 
 396     for (i=0; i<AGENTS; i++) {
 397         redir_calls[i] = 0;
 398     }
 399     provokeIntercept(env, "B");
 400     /* check that the previous interception has been overwritten */
 401     checkIntercept(0, 1, 1); /* expected interceptions: 1 */
 402     /* check that the current interception has been set properly */
 403     checkIntercept(1, 1, 1); /* expected interceptions: 1 */
 404     NSK_DISPLAY0("\n<<< TEST CASE #3) done\n");
 405 
 406     redir[1] = 1;
 407 
 408     NSK_DISPLAY1("\nagent B: detaching and returning exit code %d\n",
 409         exitCode);
 410     if ((res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm))) != 0) {
 411         NSK_COMPLAIN1("TEST WARNING: agent B: DetachCurrentThread() returns: %d\n", res);
 412     }
 413     return exitCode;
 414 }
 415 /*********************/
 416 
 417 /* callback functions */
 418 void JNICALL
 419 VMInitA(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
 420     NSK_DISPLAY0("\nagent A: VMInit event\n");
 421 
 422     startAgent(0);
 423 }
 424 
 425 void JNICALL
 426 VMInitB(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread) {
 427     NSK_DISPLAY0("\nagent B: VMInit event\n");
 428 
 429     startAgent(1);
 430 }
 431 /*********************/
 432 


< prev index next >