< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp

Print this page
rev 52432 : 8213501: Deploy ExceptionJniWrapper for a few tests
Summary:
Reviewed-by:


   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 <stdio.h>
  25 #include <string.h>
  26 #include <jvmti.h>
  27 #include "agent_common.h"
  28 
  29 #include "nsk_tools.h"
  30 #include "jni_tools.h"
  31 #include "JVMTITools.h"
  32 #include "jvmti_tools.h"
  33 
  34 extern "C" {
  35 
  36 #define OBJ_MAX_COUNT 100000
  37 
  38 static JNIEnv *jni = NULL;
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiEventCallbacks callbacks;
  41 static jvmtiCapabilities caps;
  42 
  43 static jlong timeout = 0;
  44 
  45 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;";
  46 static const char* ROOT_SIGNATURE    = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;";
  47 
  48 static jclass debugeeClass = NULL;


 288     }
 289 
 290     /* enter and notify endLock */
 291     {
 292         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
 293             nsk_jvmti_setFailStatus();
 294         }
 295         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorNotify(endLock))) {
 296             nsk_jvmti_setFailStatus();
 297         }
 298         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(endLock))) {
 299             nsk_jvmti_setFailStatus();
 300         }
 301     }
 302 
 303     NSK_DISPLAY0("Agent thread: finished.\n");
 304 }
 305 
 306 /***********************************************************************/
 307 
 308 static int startThread(JNIEnv* jni, jthread threadObj) {
 309     int success = NSK_TRUE;
 310 
 311     /* enter startLock */
 312     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(startLock))) {
 313         nsk_jvmti_setFailStatus();
 314     }
 315 
 316     /* start thread */
 317     if (!NSK_JVMTI_VERIFY(
 318             jvmti->RunAgentThread(threadObj, agent_start, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
 319         success = NSK_FALSE;
 320         nsk_jvmti_setFailStatus();
 321     } else {
 322         /* wait on startLock */
 323         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(startLock, timeout))) {
 324             nsk_jvmti_setFailStatus();
 325         }
 326     }
 327 
 328     /* exit starLock */
 329     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(startLock))) {
 330         nsk_jvmti_setFailStatus();
 331     }
 332 
 333     return success;
 334 }
 335 
 336 /** Create thread object for new agent thread. */
 337 static jthread newThreadObj(JNIEnv* jni) {

 338     jclass thrClass;
 339     jmethodID cid;
 340     jthread result = NULL;
 341 
 342     thrClass = jni->FindClass("java/lang/Thread");
 343     if (!NSK_JNI_VERIFY(jni, thrClass != NULL)) {
 344         nsk_jvmti_setFailStatus();
 345         return result;
 346     }
 347 
 348     cid = jni->GetMethodID(thrClass, "<init>", "()V");
 349     if (!NSK_JNI_VERIFY(jni, cid != NULL)) {
 350         nsk_jvmti_setFailStatus();
 351         return result;
 352     }
 353 
 354     result = jni->NewObject(thrClass, cid);
 355     if (!NSK_JNI_VERIFY(jni, result != NULL)) {
 356         nsk_jvmti_setFailStatus();
 357         return result;
 358     }
 359 
 360     return result;
 361 }
 362 
 363 /***********************************************************************/
 364 
 365 /** Clean counters and start new agent thread with agent_start() body. */
 366 static int prepareToIteration (JNIEnv* jni) {
 367     jthread threadObj = NULL;
 368 
 369     setCounter(&iterationCount, 0);
 370     setCounter(&objectCount, 0);
 371 
 372     threadObj = newThreadObj(jni);
 373     if (!NSK_VERIFY(threadObj != NULL)) {
 374         nsk_jvmti_setFailStatus();
 375         return NSK_FALSE;
 376     }
 377 
 378     /* enter endLock */
 379     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
 380         nsk_jvmti_setFailStatus();
 381     }
 382 
 383     NSK_DISPLAY0("Starting new agent thread...\n");
 384     return startThread(jni, threadObj);
 385 }
 386 
 387 /** Wait for new agent thread to complete. */
 388 static void afterIteration (JNIEnv* jni) {
 389 
 390     /* notify new agent thread (in case if not yet notified) */
 391     notifyThread();
 392 
 393     NSK_DISPLAY0("Wait for new agent thread to complete\n");
 394 
 395     /* wait on endLock */
 396     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(endLock, timeout))) {
 397         nsk_jvmti_setFailStatus();
 398     }
 399 
 400     /* exit endLock */
 401     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(endLock))) {
 402         nsk_jvmti_setFailStatus();
 403     }
 404 }
 405 
 406 /***********************************************************************/
 407 
 408 JNIEXPORT void JNICALL


 416     }
 417 }
 418 
 419 JNIEXPORT void JNICALL
 420 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverHeap(JNIEnv* jni,
 421                                                                      jclass  klass) {
 422     int modified = 0;
 423     int found = 0;
 424 
 425     if (!prepareToIteration(jni))
 426         return;
 427 
 428     NSK_DISPLAY0("Calling IterateOverHeap...\n");
 429     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_TAGGED,
 430                                                  heapObjectCallback,
 431                                                  NULL /*user_data*/))) {
 432         nsk_jvmti_setFailStatus();
 433     }
 434     NSK_DISPLAY0("IterateOverHeap finished.\n");
 435 
 436     afterIteration(jni);
 437 
 438     found = getCounter(&objectCount);
 439     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 440 
 441     modified = OBJ_MAX_COUNT - found;
 442     if (modified > 0) {
 443         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 444                                                         modified, OBJ_MAX_COUNT);
 445         nsk_jvmti_setFailStatus();
 446     }
 447 }
 448 
 449 JNIEXPORT void JNICALL
 450 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverReachableObjects(JNIEnv* jni,
 451                                                                                  jclass  klass) {
 452     int modified = 0;
 453     int found = 0;
 454 
 455     if (!prepareToIteration(jni))
 456         return;
 457 
 458     NSK_DISPLAY0("Calling IterateOverReachableObjects...\n");
 459     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
 460                                                              stackReferenceCallback,
 461                                                              objectReferenceCallback,
 462                                                              NULL /*user_data*/))) {
 463         nsk_jvmti_setFailStatus();
 464     }
 465     NSK_DISPLAY0("IterateOverReachableObjects finished.\n");
 466 
 467     afterIteration(jni);
 468 
 469     found = getCounter(&objectCount);
 470     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 471 
 472     modified = OBJ_MAX_COUNT - found;
 473     if (modified > 0) {
 474         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 475                                                         modified, OBJ_MAX_COUNT);
 476         nsk_jvmti_setFailStatus();
 477     }
 478 }
 479 
 480 JNIEXPORT void JNICALL
 481 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverInstancesOfClass(JNIEnv* jni,
 482                                                                                  jclass  klass) {
 483     int modified = 0;
 484     int found = 0;
 485 
 486     if (!prepareToIteration(jni))
 487         return;
 488 
 489     NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n");
 490     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(debugeeClass,
 491                                                              JVMTI_HEAP_OBJECT_TAGGED,
 492                                                              heapObjectCallback,
 493                                                              NULL /*user_data*/))) {
 494         nsk_jvmti_setFailStatus();
 495     }
 496     NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n");
 497 
 498     afterIteration(jni);
 499 
 500     found = getCounter(&objectCount);
 501     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 502 
 503     modified = OBJ_MAX_COUNT - found;
 504     if (modified > 0) {
 505         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 506                                                         modified, OBJ_MAX_COUNT);
 507         nsk_jvmti_setFailStatus();
 508     }
 509 }
 510 
 511 JNIEXPORT void JNICALL
 512 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni,
 513                                                                                            jclass  klass) {

 514     jobject root = NULL;
 515     int modified = 0;
 516     int found = 0;
 517 
 518     root = jni->GetStaticObjectField(debugeeClass, rootFieldID);
 519     if (!NSK_JNI_VERIFY(jni, root != NULL)) {
 520         NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n");
 521         nsk_jvmti_setFailStatus();
 522         return;
 523     }
 524 
 525     if (!prepareToIteration(jni))
 526         return;
 527 
 528     NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n");
 529     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(root,
 530                                                                        objectReferenceCallback,
 531                                                                        NULL /*user_data*/))) {
 532         nsk_jvmti_setFailStatus();
 533     }
 534     NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n");
 535 
 536     afterIteration(jni);
 537 
 538     found = getCounter(&objectCount);
 539     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 540 
 541     modified = OBJ_MAX_COUNT - found;
 542     if (modified > 0) {
 543         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 544                                                         modified, OBJ_MAX_COUNT);
 545         nsk_jvmti_setFailStatus();
 546     }
 547 }
 548 
 549 static void JNICALL
 550 agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
 551 
 552     NSK_DISPLAY0("Wait for debugee start\n\n");
 553     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 554         return;
 555 
 556     NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE);
 557     debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE);
 558     if (debugeeClass == NULL) {
 559         nsk_jvmti_setFailStatus();
 560         return;
 561     }
 562 
 563     debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass);
 564     if (!NSK_JNI_VERIFY(jni, debugeeClass != NULL))
 565         return;

 566 
 567     NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE);
 568     rootFieldID = jni->GetStaticFieldID(debugeeClass, "root", ROOT_SIGNATURE);
 569     if (!NSK_JNI_VERIFY(jni, rootFieldID != NULL)) {

 570         nsk_jvmti_setFailStatus();
 571         return;
 572     }
 573 
 574     NSK_DISPLAY0("Let debugee to run test cases\n");
 575     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 576         return;
 577 
 578     NSK_DISPLAY0("Wait for completion of test cases\n\n");
 579     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 580         return;
 581 
 582     NSK_TRACE(jni->DeleteGlobalRef(debugeeClass));
 583     NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr));
 584     NSK_TRACE(jvmti->DestroyRawMonitor(startLock));
 585     NSK_TRACE(jvmti->DestroyRawMonitor(runLock));
 586     NSK_TRACE(jvmti->DestroyRawMonitor(endLock));
 587 
 588     NSK_DISPLAY0("Let debugee to finish\n");
 589     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 590         return;
 591 }
 592 
 593 #ifdef STATIC_BUILD
 594 JNIEXPORT jint JNICALL Agent_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 595     return Agent_Initialize(jvm, options, reserved);
 596 }
 597 JNIEXPORT jint JNICALL Agent_OnAttach_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 598     return Agent_Initialize(jvm, options, reserved);
 599 }
 600 JNIEXPORT jint JNI_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 601     return JNI_VERSION_1_8;
 602 }




   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 <stdio.h>
  25 #include <string.h>
  26 #include <jvmti.h>
  27 #include "agent_common.h"
  28 #include "ExceptionCheckingJniEnv.hpp"
  29 #include "nsk_tools.h"
  30 #include "jni_tools.h"
  31 #include "JVMTITools.h"
  32 #include "jvmti_tools.h"
  33 
  34 extern "C" {
  35 
  36 #define OBJ_MAX_COUNT 100000
  37 
  38 static JNIEnv *jni = NULL;
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiEventCallbacks callbacks;
  41 static jvmtiCapabilities caps;
  42 
  43 static jlong timeout = 0;
  44 
  45 static const char* DEBUGEE_SIGNATURE = "Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;";
  46 static const char* ROOT_SIGNATURE    = "[Lnsk/jvmti/scenarios/allocation/AP04/ap04t003;";
  47 
  48 static jclass debugeeClass = NULL;


 288     }
 289 
 290     /* enter and notify endLock */
 291     {
 292         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
 293             nsk_jvmti_setFailStatus();
 294         }
 295         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorNotify(endLock))) {
 296             nsk_jvmti_setFailStatus();
 297         }
 298         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(endLock))) {
 299             nsk_jvmti_setFailStatus();
 300         }
 301     }
 302 
 303     NSK_DISPLAY0("Agent thread: finished.\n");
 304 }
 305 
 306 /***********************************************************************/
 307 
 308 static int startThread(jthread threadObj) {
 309     int success = NSK_TRUE;
 310 
 311     /* enter startLock */
 312     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(startLock))) {
 313         nsk_jvmti_setFailStatus();
 314     }
 315 
 316     /* start thread */
 317     if (!NSK_JVMTI_VERIFY(
 318             jvmti->RunAgentThread(threadObj, agent_start, NULL, JVMTI_THREAD_NORM_PRIORITY))) {
 319         success = NSK_FALSE;
 320         nsk_jvmti_setFailStatus();
 321     } else {
 322         /* wait on startLock */
 323         if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(startLock, timeout))) {
 324             nsk_jvmti_setFailStatus();
 325         }
 326     }
 327 
 328     /* exit starLock */
 329     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(startLock))) {
 330         nsk_jvmti_setFailStatus();
 331     }
 332 
 333     return success;
 334 }
 335 
 336 /** Create thread object for new agent thread. */
 337 static jthread newThreadObj(JNIEnv* jni_env) {
 338     ExceptionCheckingJniEnvPtr jni(jni_env);
 339     jclass thrClass;
 340     jmethodID cid;
 341     jthread result = NULL;
 342 
 343     thrClass = jni->FindClass("java/lang/Thread", TRACE_JNI_CALL);
 344     if (thrClass == NULL) {
 345         nsk_jvmti_setFailStatus();
 346         return result;
 347     }
 348 
 349     cid = jni->GetMethodID(thrClass, "<init>", "()V", TRACE_JNI_CALL);
 350     if (cid == NULL) {
 351         nsk_jvmti_setFailStatus();
 352         return result;
 353     }
 354 
 355     result = jni->NewObject(thrClass, cid, TRACE_JNI_CALL);
 356     if (result == NULL) {
 357         nsk_jvmti_setFailStatus();
 358         return result;
 359     }
 360 
 361     return result;
 362 }
 363 
 364 /***********************************************************************/
 365 
 366 /** Clean counters and start new agent thread with agent_start() body. */
 367 static int prepareToIteration(JNIEnv* jni) {
 368     jthread threadObj = NULL;
 369 
 370     setCounter(&iterationCount, 0);
 371     setCounter(&objectCount, 0);
 372 
 373     threadObj = newThreadObj(jni);
 374     if (!NSK_VERIFY(threadObj != NULL)) {
 375         nsk_jvmti_setFailStatus();
 376         return NSK_FALSE;
 377     }
 378 
 379     /* enter endLock */
 380     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
 381         nsk_jvmti_setFailStatus();
 382     }
 383 
 384     NSK_DISPLAY0("Starting new agent thread...\n");
 385     return startThread(threadObj);
 386 }
 387 
 388 /** Wait for new agent thread to complete. */
 389 static void afterIteration() {
 390 
 391     /* notify new agent thread (in case if not yet notified) */
 392     notifyThread();
 393 
 394     NSK_DISPLAY0("Wait for new agent thread to complete\n");
 395 
 396     /* wait on endLock */
 397     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorWait(endLock, timeout))) {
 398         nsk_jvmti_setFailStatus();
 399     }
 400 
 401     /* exit endLock */
 402     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(endLock))) {
 403         nsk_jvmti_setFailStatus();
 404     }
 405 }
 406 
 407 /***********************************************************************/
 408 
 409 JNIEXPORT void JNICALL


 417     }
 418 }
 419 
 420 JNIEXPORT void JNICALL
 421 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverHeap(JNIEnv* jni,
 422                                                                      jclass  klass) {
 423     int modified = 0;
 424     int found = 0;
 425 
 426     if (!prepareToIteration(jni))
 427         return;
 428 
 429     NSK_DISPLAY0("Calling IterateOverHeap...\n");
 430     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverHeap(JVMTI_HEAP_OBJECT_TAGGED,
 431                                                  heapObjectCallback,
 432                                                  NULL /*user_data*/))) {
 433         nsk_jvmti_setFailStatus();
 434     }
 435     NSK_DISPLAY0("IterateOverHeap finished.\n");
 436 
 437     afterIteration();
 438 
 439     found = getCounter(&objectCount);
 440     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 441 
 442     modified = OBJ_MAX_COUNT - found;
 443     if (modified > 0) {
 444         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 445                                                         modified, OBJ_MAX_COUNT);
 446         nsk_jvmti_setFailStatus();
 447     }
 448 }
 449 
 450 JNIEXPORT void JNICALL
 451 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverReachableObjects(JNIEnv* jni,
 452                                                                                  jclass  klass) {
 453     int modified = 0;
 454     int found = 0;
 455 
 456     if (!prepareToIteration(jni))
 457         return;
 458 
 459     NSK_DISPLAY0("Calling IterateOverReachableObjects...\n");
 460     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverReachableObjects(heapRootCallback,
 461                                                              stackReferenceCallback,
 462                                                              objectReferenceCallback,
 463                                                              NULL /*user_data*/))) {
 464         nsk_jvmti_setFailStatus();
 465     }
 466     NSK_DISPLAY0("IterateOverReachableObjects finished.\n");
 467 
 468     afterIteration();
 469 
 470     found = getCounter(&objectCount);
 471     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 472 
 473     modified = OBJ_MAX_COUNT - found;
 474     if (modified > 0) {
 475         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 476                                                         modified, OBJ_MAX_COUNT);
 477         nsk_jvmti_setFailStatus();
 478     }
 479 }
 480 
 481 JNIEXPORT void JNICALL
 482 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverInstancesOfClass(JNIEnv* jni,
 483                                                                                  jclass  klass) {
 484     int modified = 0;
 485     int found = 0;
 486 
 487     if (!prepareToIteration(jni))
 488         return;
 489 
 490     NSK_DISPLAY0("Calling IterateOverInstancesOfClass...\n");
 491     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverInstancesOfClass(debugeeClass,
 492                                                              JVMTI_HEAP_OBJECT_TAGGED,
 493                                                              heapObjectCallback,
 494                                                              NULL /*user_data*/))) {
 495         nsk_jvmti_setFailStatus();
 496     }
 497     NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n");
 498 
 499     afterIteration();
 500 
 501     found = getCounter(&objectCount);
 502     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 503 
 504     modified = OBJ_MAX_COUNT - found;
 505     if (modified > 0) {
 506         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 507                                                         modified, OBJ_MAX_COUNT);
 508         nsk_jvmti_setFailStatus();
 509     }
 510 }
 511 
 512 JNIEXPORT void JNICALL
 513 Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni_env,
 514                                                                                            jclass  klass) {
 515     ExceptionCheckingJniEnvPtr jni(jni_env);
 516     jobject root = NULL;
 517     int modified = 0;
 518     int found = 0;
 519 
 520     root = jni->GetStaticObjectField(debugeeClass, rootFieldID, TRACE_JNI_CALL);
 521     if (root == NULL) {
 522         NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n");
 523         nsk_jvmti_setFailStatus();
 524         return;
 525     }
 526 
 527     if (!prepareToIteration(jni_env))
 528         return;
 529 
 530     NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n");
 531     if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(root,
 532                                                                        objectReferenceCallback,
 533                                                                        NULL /*user_data*/))) {
 534         nsk_jvmti_setFailStatus();
 535     }
 536     NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n");
 537 
 538     afterIteration();
 539 
 540     found = getCounter(&objectCount);
 541     NSK_DISPLAY1("Found tagged objects: %d\n", found);
 542 
 543     modified = OBJ_MAX_COUNT - found;
 544     if (modified > 0) {
 545         NSK_COMPLAIN2("Tags were modified by other thread during heap iteration: %d of %d\n",
 546                                                         modified, OBJ_MAX_COUNT);
 547         nsk_jvmti_setFailStatus();
 548     }
 549 }
 550 
 551 static void JNICALL
 552 agentProc(jvmtiEnv* jvmti, JNIEnv* jni_env, void* arg) {
 553     ExceptionCheckingJniEnvPtr jni(jni_env);
 554     NSK_DISPLAY0("Wait for debugee start\n\n");
 555     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 556         return;
 557 
 558     NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE);
 559     debugeeClass = nsk_jvmti_classBySignature(DEBUGEE_SIGNATURE);
 560     if (debugeeClass == NULL) {
 561         nsk_jvmti_setFailStatus();
 562         return;
 563     }
 564 
 565     debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass, TRACE_JNI_CALL);
 566     if (debugeeClass == NULL) {
 567         return;
 568     }
 569 
 570     NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE);
 571     rootFieldID = jni->GetStaticFieldID(debugeeClass, "root",
 572                                         ROOT_SIGNATURE, TRACE_JNI_CALL);
 573     if (rootFieldID == NULL) {
 574         nsk_jvmti_setFailStatus();
 575         return;
 576     }
 577 
 578     NSK_DISPLAY0("Let debugee to run test cases\n");
 579     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 580         return;
 581 
 582     NSK_DISPLAY0("Wait for completion of test cases\n\n");
 583     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
 584         return;
 585 
 586     jni->DeleteGlobalRef(debugeeClass, TRACE_JNI_CALL);
 587     NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr));
 588     NSK_TRACE(jvmti->DestroyRawMonitor(startLock));
 589     NSK_TRACE(jvmti->DestroyRawMonitor(runLock));
 590     NSK_TRACE(jvmti->DestroyRawMonitor(endLock));
 591 
 592     NSK_DISPLAY0("Let debugee to finish\n");
 593     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
 594         return;
 595 }
 596 
 597 #ifdef STATIC_BUILD
 598 JNIEXPORT jint JNICALL Agent_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 599     return Agent_Initialize(jvm, options, reserved);
 600 }
 601 JNIEXPORT jint JNICALL Agent_OnAttach_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 602     return Agent_Initialize(jvm, options, reserved);
 603 }
 604 JNIEXPORT jint JNI_OnLoad_ap04t003(JavaVM *jvm, char *options, void *reserved) {
 605     return JNI_VERSION_1_8;
 606 }


< prev index next >