< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP06/sp06t003/sp06t003.cpp

Print this page
rev 52100 : 8212082: Remove the NSK_CPP_STUB macros for remaining vmTestbase/jvmti/[sS]*
Summary:
Reviewed-by:


 126             return;
 127 
 128         NSK_DISPLAY0("Clean data\n");
 129         if (!clean()) {
 130             nsk_jvmti_setFailStatus();
 131             return;
 132         }
 133     }
 134 
 135     NSK_DISPLAY0("Let debuggee to finish\n");
 136     if (!nsk_jvmti_resumeSync())
 137         return;
 138 }
 139 
 140 /* ============================================================================= */
 141 
 142 /**
 143  * Generate missed events (COMPILED_METHOD_LOAD only).
 144  */
 145 static int generateEvents() {
 146     if (!NSK_JVMTI_VERIFY(
 147             NSK_CPP_STUB2(GenerateEvents, jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD))) {
 148         nsk_jvmti_setFailStatus();
 149         return NSK_FALSE;
 150     }
 151     return NSK_TRUE;
 152 }
 153 
 154 /**
 155  * Prepare data.
 156  *    - clean threads list
 157  *    - get all live threads
 158  *    - get threads name
 159  *    - find tested threads
 160  *    - make global refs
 161  *    - enable events
 162  */
 163 static int prepare() {
 164     jthread *allThreadsList = NULL;
 165     jint allThreadsCount = 0;
 166     int found = 0;
 167     int i;
 168 
 169     NSK_DISPLAY1("Find tested threads: %d\n", THREADS_COUNT);
 170 
 171     /* clean threads list */
 172     for (i = 0; i < THREADS_COUNT; i++) {
 173         threadsDesc[i].thread = (jthread)NULL;
 174         threadsDesc[i].method = (jmethodID)NULL;
 175         threadsDesc[i].location = NSK_JVMTI_INVALID_JLOCATION;
 176         threadsDesc[i].methodCompiled = NSK_FALSE;
 177     }
 178 
 179     /* get all live threads */
 180     if (!NSK_JVMTI_VERIFY(
 181             NSK_CPP_STUB3(GetAllThreads, jvmti, &allThreadsCount, &allThreadsList)))
 182         return NSK_FALSE;
 183 
 184     if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL))
 185         return NSK_FALSE;
 186 
 187     /* find tested threads */
 188     for (i = 0; i < allThreadsCount; i++) {
 189         jvmtiThreadInfo threadInfo;
 190 
 191         if (!NSK_VERIFY(allThreadsList[i] != NULL))
 192             return NSK_FALSE;
 193 
 194         if (!NSK_JVMTI_VERIFY(
 195                 NSK_CPP_STUB3(GetThreadInfo, jvmti, allThreadsList[i], &threadInfo)))
 196             return NSK_FALSE;
 197 
 198         if (threadInfo.name != NULL) {
 199             int j;
 200 
 201             for (j = 0; j < THREADS_COUNT; j++) {
 202                 if (strcmp(threadInfo.name, threadsDesc[j].threadName) == 0) {
 203                     threadsDesc[j].thread = allThreadsList[i];
 204                     NSK_DISPLAY3("    thread #%d (%s): 0x%p\n",
 205                                             j, threadInfo.name, (void*)threadsDesc[j].thread);
 206                 }
 207             }
 208         }
 209     }
 210 
 211     /* deallocate all threads list */
 212     if (!NSK_JVMTI_VERIFY(
 213             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)allThreadsList)))
 214         return NSK_FALSE;
 215 
 216     /* check if all tested threads found */
 217     found = 0;
 218     for (i = 0; i < THREADS_COUNT; i++) {
 219         if (threadsDesc[i].thread == NULL) {
 220             NSK_COMPLAIN2("Not found tested thread #%d (%s)\n", i, threadsDesc[i].threadName);
 221         } else {
 222             found++;
 223         }
 224     }
 225 
 226     if (found < THREADS_COUNT)
 227         return NSK_FALSE;
 228 
 229     /* get threads class and frame method */
 230     NSK_DISPLAY0("Find tested methods:\n");
 231     for (i = 0; i < THREADS_COUNT; i++) {
 232 
 233         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].cls =
 234                 NSK_CPP_STUB2(GetObjectClass, jni, threadsDesc[i].thread)) != NULL))
 235             return NSK_FALSE;
 236 
 237         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].method =
 238                 NSK_CPP_STUB4(GetMethodID, jni, threadsDesc[i].cls,
 239                             threadsDesc[i].methodName, threadsDesc[i].methodSig)) != NULL))
 240             return NSK_FALSE;
 241 
 242         NSK_DISPLAY4("    thread #%d (%s): 0x%p (%s)\n",
 243                                 i, threadsDesc[i].threadName,
 244                                 (void*)threadsDesc[i].method,
 245                                 threadsDesc[i].methodName);
 246     }
 247 
 248     /* make global refs */
 249     for (i = 0; i < THREADS_COUNT; i++) {
 250         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].thread = (jthread)
 251                 NSK_CPP_STUB2(NewGlobalRef, jni, threadsDesc[i].thread)) != NULL))
 252             return NSK_FALSE;
 253         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].cls = (jclass)
 254                 NSK_CPP_STUB2(NewGlobalRef, jni, threadsDesc[i].cls)) != NULL))
 255             return NSK_FALSE;
 256     }
 257 
 258     NSK_DISPLAY0("Enable tested events\n");
 259     if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL))
 260         return NSK_FALSE;
 261 
 262     return NSK_TRUE;
 263 }
 264 
 265 /**
 266  * Suspend or resume tested threads.
 267  */
 268 static int suspendThreadsIndividually(int suspend) {
 269     int i;
 270 
 271     for (i = 0; i < THREADS_COUNT; i++) {
 272         if (suspend) {
 273             NSK_DISPLAY2("    suspend thread #%d (%s)\n", i, threadsDesc[i].threadName);
 274             if (!NSK_JVMTI_VERIFY(
 275                     NSK_CPP_STUB2(SuspendThread, jvmti, threadsDesc[i].thread)))
 276                 nsk_jvmti_setFailStatus();
 277         } else {
 278             NSK_DISPLAY2("    resume thread #%d (%s)\n", i, threadsDesc[i].threadName);
 279             if (!NSK_JVMTI_VERIFY(
 280                     NSK_CPP_STUB2(ResumeThread, jvmti, threadsDesc[i].thread)))
 281                 nsk_jvmti_setFailStatus();
 282         }
 283     }
 284     return NSK_TRUE;
 285 }
 286 
 287 /**
 288  * Testcase: check tested threads.
 289  *    - call GetFrameCount() and then GetStackTrace()
 290  *    - for each stack frame of common depth GetFrameLocation()
 291  *    - compare frame ifno returned by GetFrameLocation() and GetStackTrace()
 292  *    - find expected frame for tested method
 293  *
 294  * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
 295  */
 296 static int checkThreads(int suspended, const char* kind0) {
 297     char kind[256] = "";
 298     int i;
 299 
 300     /* check each thread */
 301     for (i = 0; i < THREADS_COUNT; i++) {
 302         jint frameCount = 0;
 303         jint frameStackSize = 0;
 304         jvmtiFrameInfo frameStack[MAX_STACK_SIZE];
 305         int commonDepth = 0;
 306         int found = 0;
 307         int j;
 308 
 309         /* make proper kind */
 310         strcpy(kind, threadsDesc[i].methodCompiled ? "compiled " : "not compiled ");
 311         strcat(kind, kind0);
 312         NSK_DISPLAY2("  thread #%d (%s):\n", i, threadsDesc[i].threadName);
 313 
 314         /* get frame count */
 315         if (!NSK_JVMTI_VERIFY(
 316                 NSK_CPP_STUB3(GetFrameCount, jvmti,
 317                                     threadsDesc[i].thread, &frameCount))) {
 318             nsk_jvmti_setFailStatus();
 319             return NSK_TRUE;
 320         }
 321         NSK_DISPLAY1("    frameCount:  %d\n", (int)frameCount);
 322 
 323         /* get stack trace */
 324         if (!NSK_JVMTI_VERIFY(
 325                 NSK_CPP_STUB6(GetStackTrace, jvmti, threadsDesc[i].thread,
 326                                     0, MAX_STACK_SIZE, frameStack, &frameStackSize))) {
 327             nsk_jvmti_setFailStatus();
 328             return NSK_TRUE;
 329         }
 330         NSK_DISPLAY1("    stack depth: %d\n", (int)frameStackSize);
 331 
 332         commonDepth = (frameCount < frameStackSize ? frameCount : frameStackSize);
 333         NSK_DISPLAY1("         common: %d\n", (int)commonDepth);
 334 
 335         /* check first commonDepth frames and find expected method there */
 336         found = 0;
 337         for (j = 0; j < commonDepth; j++) {
 338             jmethodID qMethod = (jmethodID)NULL;
 339             jlocation qLocation = NSK_JVMTI_INVALID_JLOCATION;
 340 
 341             NSK_DISPLAY3("      %d frame: method: 0x%p, location: %ld\n",
 342                                         j, (void*)frameStack[j].method,
 343                                         (long)frameStack[j].location);
 344             /* query frame location */
 345             if (!NSK_JVMTI_VERIFY(
 346                     NSK_CPP_STUB5(GetFrameLocation, jvmti, threadsDesc[i].thread,
 347                                         j, &qMethod, &qLocation))) {
 348                 nsk_jvmti_setFailStatus();
 349                 continue;
 350             }
 351 
 352             NSK_DISPLAY2("      queried: method: 0x%p, location: %ld\n",
 353                                         (void*)qMethod, (long)qLocation);
 354 
 355             /* check frame equalaty */
 356             if (frameStack[j].method != qMethod) {
 357                 NSK_COMPLAIN6("Different method in stack frame #%d for %s thread #%d (%s):\n"
 358                             "#   GetStackTrace():    0x%p\n"
 359                             "#   GetFrameLocation(): 0x%p\n",
 360                             j, kind, i, threadsDesc[i].threadName,
 361                             (void*)frameStack[j].method, (void*)qMethod);
 362                 nsk_jvmti_setFailStatus();
 363             }
 364             if (frameStack[j].location != qLocation) {
 365                 NSK_COMPLAIN6("Different location in stack frame #%d for %s thread #%d (%s):\n"
 366                             "#   GetStackTrace():    %ld\n"
 367                             "#   GetFrameLocation(): %ld\n",


 387     }
 388 
 389     /* test may continue */
 390     return NSK_TRUE;
 391 }
 392 
 393 /**
 394  * Clean data.
 395  *   - disable events
 396  *   - dispose global references to tested threads
 397  */
 398 static int clean() {
 399     int i;
 400 
 401     NSK_DISPLAY0("Disable events\n");
 402     if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL))
 403         return NSK_FALSE;
 404 
 405     NSK_DISPLAY0("Dispose global references to threads\n");
 406     for (i = 0; i < THREADS_COUNT; i++) {
 407         NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsDesc[i].thread));
 408         NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsDesc[i].cls));
 409     }
 410 
 411     return NSK_TRUE;
 412 }
 413 
 414 /* ============================================================================= */
 415 
 416 /**
 417  * COMPILED_METHOD_LOAD callback.
 418  *   - turn on flag that method is compiled
 419  */
 420 JNIEXPORT void JNICALL
 421 callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method,
 422                             jint code_size, const void* code_addr,
 423                             jint map_length, const jvmtiAddrLocationMap* map,
 424                             const void* compile_info) {
 425     int i;
 426 
 427     /* check if event is for tested method and turn flag on */
 428     for (i = 0; i < THREADS_COUNT; i++) {


 521 JNIEXPORT jint JNI_OnLoad_sp06t003(JavaVM *jvm, char *options, void *reserved) {
 522     return JNI_VERSION_1_8;
 523 }
 524 #endif
 525 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 526 
 527     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 528         return JNI_ERR;
 529 
 530     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 531 
 532     if (!NSK_VERIFY((jvmti =
 533             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 534         return JNI_ERR;
 535 
 536     {
 537         jvmtiCapabilities caps;
 538         memset(&caps, 0, sizeof(caps));
 539         caps.can_suspend = 1;
 540         caps.can_generate_compiled_method_load_events = 1;
 541         if (!NSK_JVMTI_VERIFY(
 542                 NSK_CPP_STUB2(AddCapabilities, jvmti, &caps)))
 543             return JNI_ERR;
 544     }
 545 
 546     {
 547         jvmtiEventCallbacks eventCallbacks;
 548         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 549         eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad;
 550         eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload;
 551         if (!NSK_JVMTI_VERIFY(
 552                 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
 553                                     &eventCallbacks, sizeof(eventCallbacks))))
 554             return JNI_ERR;
 555     }
 556 
 557     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 558         return JNI_ERR;
 559 
 560     return JNI_OK;
 561 }
 562 
 563 /* ============================================================================= */
 564 
 565 }


 126             return;
 127 
 128         NSK_DISPLAY0("Clean data\n");
 129         if (!clean()) {
 130             nsk_jvmti_setFailStatus();
 131             return;
 132         }
 133     }
 134 
 135     NSK_DISPLAY0("Let debuggee to finish\n");
 136     if (!nsk_jvmti_resumeSync())
 137         return;
 138 }
 139 
 140 /* ============================================================================= */
 141 
 142 /**
 143  * Generate missed events (COMPILED_METHOD_LOAD only).
 144  */
 145 static int generateEvents() {
 146     if (!NSK_JVMTI_VERIFY(jvmti->GenerateEvents(JVMTI_EVENT_COMPILED_METHOD_LOAD))) {

 147         nsk_jvmti_setFailStatus();
 148         return NSK_FALSE;
 149     }
 150     return NSK_TRUE;
 151 }
 152 
 153 /**
 154  * Prepare data.
 155  *    - clean threads list
 156  *    - get all live threads
 157  *    - get threads name
 158  *    - find tested threads
 159  *    - make global refs
 160  *    - enable events
 161  */
 162 static int prepare() {
 163     jthread *allThreadsList = NULL;
 164     jint allThreadsCount = 0;
 165     int found = 0;
 166     int i;
 167 
 168     NSK_DISPLAY1("Find tested threads: %d\n", THREADS_COUNT);
 169 
 170     /* clean threads list */
 171     for (i = 0; i < THREADS_COUNT; i++) {
 172         threadsDesc[i].thread = (jthread)NULL;
 173         threadsDesc[i].method = (jmethodID)NULL;
 174         threadsDesc[i].location = NSK_JVMTI_INVALID_JLOCATION;
 175         threadsDesc[i].methodCompiled = NSK_FALSE;
 176     }
 177 
 178     /* get all live threads */
 179     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&allThreadsCount, &allThreadsList)))

 180         return NSK_FALSE;
 181 
 182     if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL))
 183         return NSK_FALSE;
 184 
 185     /* find tested threads */
 186     for (i = 0; i < allThreadsCount; i++) {
 187         jvmtiThreadInfo threadInfo;
 188 
 189         if (!NSK_VERIFY(allThreadsList[i] != NULL))
 190             return NSK_FALSE;
 191 
 192         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(allThreadsList[i], &threadInfo)))

 193             return NSK_FALSE;
 194 
 195         if (threadInfo.name != NULL) {
 196             int j;
 197 
 198             for (j = 0; j < THREADS_COUNT; j++) {
 199                 if (strcmp(threadInfo.name, threadsDesc[j].threadName) == 0) {
 200                     threadsDesc[j].thread = allThreadsList[i];
 201                     NSK_DISPLAY3("    thread #%d (%s): 0x%p\n",
 202                                             j, threadInfo.name, (void*)threadsDesc[j].thread);
 203                 }
 204             }
 205         }
 206     }
 207 
 208     /* deallocate all threads list */
 209     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)allThreadsList)))

 210         return NSK_FALSE;
 211 
 212     /* check if all tested threads found */
 213     found = 0;
 214     for (i = 0; i < THREADS_COUNT; i++) {
 215         if (threadsDesc[i].thread == NULL) {
 216             NSK_COMPLAIN2("Not found tested thread #%d (%s)\n", i, threadsDesc[i].threadName);
 217         } else {
 218             found++;
 219         }
 220     }
 221 
 222     if (found < THREADS_COUNT)
 223         return NSK_FALSE;
 224 
 225     /* get threads class and frame method */
 226     NSK_DISPLAY0("Find tested methods:\n");
 227     for (i = 0; i < THREADS_COUNT; i++) {
 228 
 229         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].cls =
 230                 jni->GetObjectClass(threadsDesc[i].thread)) != NULL))
 231             return NSK_FALSE;
 232 
 233         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].method =
 234                 jni->GetMethodID(threadsDesc[i].cls, threadsDesc[i].methodName, threadsDesc[i].methodSig)) != NULL))

 235             return NSK_FALSE;
 236 
 237         NSK_DISPLAY4("    thread #%d (%s): 0x%p (%s)\n",
 238                                 i, threadsDesc[i].threadName,
 239                                 (void*)threadsDesc[i].method,
 240                                 threadsDesc[i].methodName);
 241     }
 242 
 243     /* make global refs */
 244     for (i = 0; i < THREADS_COUNT; i++) {
 245         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].thread = (jthread)
 246                 jni->NewGlobalRef(threadsDesc[i].thread)) != NULL))
 247             return NSK_FALSE;
 248         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].cls = (jclass)
 249                 jni->NewGlobalRef(threadsDesc[i].cls)) != NULL))
 250             return NSK_FALSE;
 251     }
 252 
 253     NSK_DISPLAY0("Enable tested events\n");
 254     if (!nsk_jvmti_enableEvents(JVMTI_ENABLE, EVENTS_COUNT, eventsList, NULL))
 255         return NSK_FALSE;
 256 
 257     return NSK_TRUE;
 258 }
 259 
 260 /**
 261  * Suspend or resume tested threads.
 262  */
 263 static int suspendThreadsIndividually(int suspend) {
 264     int i;
 265 
 266     for (i = 0; i < THREADS_COUNT; i++) {
 267         if (suspend) {
 268             NSK_DISPLAY2("    suspend thread #%d (%s)\n", i, threadsDesc[i].threadName);
 269             if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(threadsDesc[i].thread)))

 270                 nsk_jvmti_setFailStatus();
 271         } else {
 272             NSK_DISPLAY2("    resume thread #%d (%s)\n", i, threadsDesc[i].threadName);
 273             if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(threadsDesc[i].thread)))

 274                 nsk_jvmti_setFailStatus();
 275         }
 276     }
 277     return NSK_TRUE;
 278 }
 279 
 280 /**
 281  * Testcase: check tested threads.
 282  *    - call GetFrameCount() and then GetStackTrace()
 283  *    - for each stack frame of common depth GetFrameLocation()
 284  *    - compare frame ifno returned by GetFrameLocation() and GetStackTrace()
 285  *    - find expected frame for tested method
 286  *
 287  * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
 288  */
 289 static int checkThreads(int suspended, const char* kind0) {
 290     char kind[256] = "";
 291     int i;
 292 
 293     /* check each thread */
 294     for (i = 0; i < THREADS_COUNT; i++) {
 295         jint frameCount = 0;
 296         jint frameStackSize = 0;
 297         jvmtiFrameInfo frameStack[MAX_STACK_SIZE];
 298         int commonDepth = 0;
 299         int found = 0;
 300         int j;
 301 
 302         /* make proper kind */
 303         strcpy(kind, threadsDesc[i].methodCompiled ? "compiled " : "not compiled ");
 304         strcat(kind, kind0);
 305         NSK_DISPLAY2("  thread #%d (%s):\n", i, threadsDesc[i].threadName);
 306 
 307         /* get frame count */
 308         if (!NSK_JVMTI_VERIFY(jvmti->GetFrameCount(threadsDesc[i].thread, &frameCount))) {


 309             nsk_jvmti_setFailStatus();
 310             return NSK_TRUE;
 311         }
 312         NSK_DISPLAY1("    frameCount:  %d\n", (int)frameCount);
 313 
 314         /* get stack trace */
 315         if (!NSK_JVMTI_VERIFY(
 316                 jvmti->GetStackTrace(threadsDesc[i].thread, 0, MAX_STACK_SIZE, frameStack, &frameStackSize))) {

 317             nsk_jvmti_setFailStatus();
 318             return NSK_TRUE;
 319         }
 320         NSK_DISPLAY1("    stack depth: %d\n", (int)frameStackSize);
 321 
 322         commonDepth = (frameCount < frameStackSize ? frameCount : frameStackSize);
 323         NSK_DISPLAY1("         common: %d\n", (int)commonDepth);
 324 
 325         /* check first commonDepth frames and find expected method there */
 326         found = 0;
 327         for (j = 0; j < commonDepth; j++) {
 328             jmethodID qMethod = (jmethodID)NULL;
 329             jlocation qLocation = NSK_JVMTI_INVALID_JLOCATION;
 330 
 331             NSK_DISPLAY3("      %d frame: method: 0x%p, location: %ld\n",
 332                                         j, (void*)frameStack[j].method,
 333                                         (long)frameStack[j].location);
 334             /* query frame location */
 335             if (!NSK_JVMTI_VERIFY(
 336                     jvmti->GetFrameLocation(threadsDesc[i].thread, j, &qMethod, &qLocation))) {

 337                 nsk_jvmti_setFailStatus();
 338                 continue;
 339             }
 340 
 341             NSK_DISPLAY2("      queried: method: 0x%p, location: %ld\n",
 342                                         (void*)qMethod, (long)qLocation);
 343 
 344             /* check frame equalaty */
 345             if (frameStack[j].method != qMethod) {
 346                 NSK_COMPLAIN6("Different method in stack frame #%d for %s thread #%d (%s):\n"
 347                             "#   GetStackTrace():    0x%p\n"
 348                             "#   GetFrameLocation(): 0x%p\n",
 349                             j, kind, i, threadsDesc[i].threadName,
 350                             (void*)frameStack[j].method, (void*)qMethod);
 351                 nsk_jvmti_setFailStatus();
 352             }
 353             if (frameStack[j].location != qLocation) {
 354                 NSK_COMPLAIN6("Different location in stack frame #%d for %s thread #%d (%s):\n"
 355                             "#   GetStackTrace():    %ld\n"
 356                             "#   GetFrameLocation(): %ld\n",


 376     }
 377 
 378     /* test may continue */
 379     return NSK_TRUE;
 380 }
 381 
 382 /**
 383  * Clean data.
 384  *   - disable events
 385  *   - dispose global references to tested threads
 386  */
 387 static int clean() {
 388     int i;
 389 
 390     NSK_DISPLAY0("Disable events\n");
 391     if (!nsk_jvmti_enableEvents(JVMTI_DISABLE, EVENTS_COUNT, eventsList, NULL))
 392         return NSK_FALSE;
 393 
 394     NSK_DISPLAY0("Dispose global references to threads\n");
 395     for (i = 0; i < THREADS_COUNT; i++) {
 396         NSK_TRACE(jni->DeleteGlobalRef(threadsDesc[i].thread));
 397         NSK_TRACE(jni->DeleteGlobalRef(threadsDesc[i].cls));
 398     }
 399 
 400     return NSK_TRUE;
 401 }
 402 
 403 /* ============================================================================= */
 404 
 405 /**
 406  * COMPILED_METHOD_LOAD callback.
 407  *   - turn on flag that method is compiled
 408  */
 409 JNIEXPORT void JNICALL
 410 callbackCompiledMethodLoad(jvmtiEnv* jvmti, jmethodID method,
 411                             jint code_size, const void* code_addr,
 412                             jint map_length, const jvmtiAddrLocationMap* map,
 413                             const void* compile_info) {
 414     int i;
 415 
 416     /* check if event is for tested method and turn flag on */
 417     for (i = 0; i < THREADS_COUNT; i++) {


 510 JNIEXPORT jint JNI_OnLoad_sp06t003(JavaVM *jvm, char *options, void *reserved) {
 511     return JNI_VERSION_1_8;
 512 }
 513 #endif
 514 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 515 
 516     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 517         return JNI_ERR;
 518 
 519     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 520 
 521     if (!NSK_VERIFY((jvmti =
 522             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 523         return JNI_ERR;
 524 
 525     {
 526         jvmtiCapabilities caps;
 527         memset(&caps, 0, sizeof(caps));
 528         caps.can_suspend = 1;
 529         caps.can_generate_compiled_method_load_events = 1;
 530         if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))

 531             return JNI_ERR;
 532     }
 533 
 534     {
 535         jvmtiEventCallbacks eventCallbacks;
 536         memset(&eventCallbacks, 0, sizeof(eventCallbacks));
 537         eventCallbacks.CompiledMethodLoad = callbackCompiledMethodLoad;
 538         eventCallbacks.CompiledMethodUnload = callbackCompiledMethodUnload;
 539         if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks))))


 540             return JNI_ERR;
 541     }
 542 
 543     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 544         return JNI_ERR;
 545 
 546     return JNI_OK;
 547 }
 548 
 549 /* ============================================================================= */
 550 
 551 }
< prev index next >