< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/sampling/SP02/sp02t001/sp02t001.cpp

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


 119  * Prepare data:
 120  *    - clean threads list
 121  *    - get all live threads with names
 122  *    - find tested threads by name
 123  *    - make global refs
 124  */
 125 static int prepare() {
 126     jthread *allThreadsList = NULL;
 127     jint allThreadsCount = 0;
 128     int found = 0;
 129     int i;
 130 
 131     NSK_DISPLAY1("Find tested threads: %d\n", THREADS_COUNT);
 132 
 133     /* clean threads list */
 134     for (i = 0; i < THREADS_COUNT; i++) {
 135         threadsDesc[i].thread = (jthread)NULL;
 136     }
 137 
 138     /* get all live threads */
 139     if (!NSK_JVMTI_VERIFY(
 140             NSK_CPP_STUB3(GetAllThreads, jvmti, &allThreadsCount, &allThreadsList)))
 141         return NSK_FALSE;
 142 
 143     if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL))
 144         return NSK_FALSE;
 145 
 146     /* find tested threads */
 147     for (i = 0; i < allThreadsCount; i++) {
 148         jvmtiThreadInfo threadInfo;
 149 
 150         if (!NSK_VERIFY(allThreadsList[i] != NULL))
 151             return NSK_FALSE;
 152 
 153         /* get thread name (info) */
 154         if (!NSK_JVMTI_VERIFY(
 155                 NSK_CPP_STUB3(GetThreadInfo, jvmti, allThreadsList[i], &threadInfo)))
 156             return NSK_FALSE;
 157 
 158         /* find by name */
 159         if (threadInfo.name != NULL) {
 160             int j;
 161 
 162             for (j = 0; j < THREADS_COUNT; j++) {
 163                 if (strcmp(threadInfo.name, threadsDesc[j].threadName) == 0) {
 164                     threadsDesc[j].thread = allThreadsList[i];
 165                     NSK_DISPLAY3("    thread #%d (%s): %p\n",
 166                                             j, threadInfo.name, (void*)threadsDesc[j].thread);
 167                 }
 168             }
 169         }
 170     }
 171 
 172     /* deallocate all threads list */
 173     if (!NSK_JVMTI_VERIFY(
 174             NSK_CPP_STUB2(Deallocate, jvmti, (unsigned char*)allThreadsList)))
 175         return NSK_FALSE;
 176 
 177     /* check if all tested threads found */
 178     found = 0;
 179     for (i = 0; i < THREADS_COUNT; i++) {
 180         if (threadsDesc[i].thread == NULL) {
 181             NSK_COMPLAIN2("Not found tested thread #%d (%s)\n", i, threadsDesc[i].threadName);
 182         } else {
 183             found++;
 184         }
 185     }
 186 
 187     if (found < THREADS_COUNT)
 188         return NSK_FALSE;
 189 
 190     /* make global refs */
 191     for (i = 0; i < THREADS_COUNT; i++) {
 192         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].thread = (jthread)
 193                 NSK_CPP_STUB2(NewGlobalRef, jni, threadsDesc[i].thread)) != NULL))
 194             return NSK_FALSE;
 195     }
 196 
 197     return NSK_TRUE;
 198 }
 199 
 200 /**
 201  * Suspend or resume tested threads.
 202  */
 203 static int suspendThreadsIndividually(int suspend) {
 204     int i;
 205 
 206     for (i = 0; i < THREADS_COUNT; i++) {
 207         if (suspend) {
 208             NSK_DISPLAY2("    suspend thread #%d (%s)\n", i, threadsDesc[i].threadName);
 209             if (!NSK_JVMTI_VERIFY(
 210                     NSK_CPP_STUB2(SuspendThread, jvmti, threadsDesc[i].thread)))
 211                 nsk_jvmti_setFailStatus();
 212         } else {
 213             NSK_DISPLAY2("    resume thread #%d (%s)\n", i, threadsDesc[i].threadName);
 214             if (!NSK_JVMTI_VERIFY(
 215                     NSK_CPP_STUB2(ResumeThread, jvmti, threadsDesc[i].thread)))
 216                 nsk_jvmti_setFailStatus();
 217         }
 218     }
 219     return NSK_TRUE;
 220 }
 221 
 222 /**
 223  * Testcase: check tested threads
 224  *    - invoke getFrameCount() for each thread
 225  *    - check if frameCount is not less than minimal stack depth
 226  *    - invoke getStackTrace() for each thread
 227  *    - check if stack depth is equal to frameCount
 228  *
 229  * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
 230  */
 231 static int checkSuspendedThreads() {
 232     int i;
 233 
 234     /* check each thread */
 235     for (i = 0; i < THREADS_COUNT; i++) {
 236         jint frameCount = 0;
 237         jint frameStackSize = 0;
 238         jvmtiFrameInfo frameStack[MAX_STACK_SIZE];
 239         int found = 0;
 240 
 241         NSK_DISPLAY2("  thread #%d (%s):\n", i, threadsDesc[i].threadName);
 242 
 243         /* get frame count */
 244         if (!NSK_JVMTI_VERIFY(
 245                 NSK_CPP_STUB3(GetFrameCount, jvmti,
 246                                     threadsDesc[i].thread, &frameCount))) {
 247             nsk_jvmti_setFailStatus();
 248             return NSK_TRUE;
 249         }
 250 
 251         NSK_DISPLAY1("    frameCount:  %d\n", (int)frameCount);
 252 
 253         /* get stack trace */
 254         if (!NSK_JVMTI_VERIFY(
 255                 NSK_CPP_STUB6(GetStackTrace, jvmti, threadsDesc[i].thread,
 256                                     0, MAX_STACK_SIZE, frameStack, &frameStackSize))) {
 257             nsk_jvmti_setFailStatus();
 258             return NSK_TRUE;
 259         }
 260 
 261         NSK_DISPLAY1("    stack depth: %d\n", (int)frameStackSize);
 262 
 263         /* check frame count */
 264         if (frameCount < threadsDesc[i].minDepth) {
 265             NSK_COMPLAIN4("Too few frameCount of suspended thread #%d (%s):\n"
 266                             "#   got frameCount:   %d\n"
 267                             "#   expected minimum: %d\n",
 268                             i, threadsDesc[i].threadName,
 269                             (int)frameCount, threadsDesc[i].minDepth);
 270             nsk_jvmti_setFailStatus();
 271         }
 272 
 273         if (frameStackSize != frameCount) {
 274             NSK_COMPLAIN4("Different frames count for suspended thread #%d (%s):\n"
 275                             "#   getStackTrace(): %d\n"
 276                             "#   getFrameCount(): %d\n",
 277                             i, threadsDesc[i].threadName,
 278                             (int)frameStackSize, (int)frameCount);
 279             nsk_jvmti_setFailStatus();
 280         }
 281 
 282     }
 283 
 284     /* test may continue */
 285     return NSK_TRUE;
 286 }
 287 
 288 /**
 289  * Clean data:
 290  *   - dispose global references to tested threads
 291  */
 292 static int clean() {
 293     int i;
 294 
 295     /* dispose global references to threads */
 296     for (i = 0; i < THREADS_COUNT; i++) {
 297         NSK_TRACE(NSK_CPP_STUB2(DeleteGlobalRef, jni, threadsDesc[i].thread));
 298     }
 299 
 300     return NSK_TRUE;
 301 }
 302 
 303 /* ============================================================================= */
 304 
 305 static volatile int testedThreadRunning = NSK_FALSE;
 306 static volatile int testedThreadShouldFinish = NSK_FALSE;
 307 
 308 /** Native running method in tested thread. */
 309 JNIEXPORT void JNICALL
 310 Java_nsk_jvmti_scenarios_sampling_SP02_sp02t001ThreadRunningNative_testedMethod(JNIEnv* jni,
 311                                                                                 jobject obj) {
 312     volatile int i = 0, n = 1000;
 313 
 314     /* run in a loop */
 315     testedThreadRunning = NSK_TRUE;
 316     while (!testedThreadShouldFinish) {
 317         if (n <= 0)


 355 }
 356 #endif
 357 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 358 
 359     /* init framework and parse options */
 360     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 361         return JNI_ERR;
 362 
 363     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 364 
 365     /* create JVMTI environment */
 366     if (!NSK_VERIFY((jvmti =
 367             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 368         return JNI_ERR;
 369 
 370     /* add specific capabilities for suspending thread */
 371     {
 372         jvmtiCapabilities suspendCaps;
 373         memset(&suspendCaps, 0, sizeof(suspendCaps));
 374         suspendCaps.can_suspend = 1;
 375         if (!NSK_JVMTI_VERIFY(
 376                 NSK_CPP_STUB2(AddCapabilities, jvmti, &suspendCaps)))
 377             return JNI_ERR;
 378     }
 379 
 380     /* register agent proc and arg */
 381     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 382         return JNI_ERR;
 383 
 384     return JNI_OK;
 385 }
 386 
 387 /* ============================================================================= */
 388 
 389 }


 119  * Prepare data:
 120  *    - clean threads list
 121  *    - get all live threads with names
 122  *    - find tested threads by name
 123  *    - make global refs
 124  */
 125 static int prepare() {
 126     jthread *allThreadsList = NULL;
 127     jint allThreadsCount = 0;
 128     int found = 0;
 129     int i;
 130 
 131     NSK_DISPLAY1("Find tested threads: %d\n", THREADS_COUNT);
 132 
 133     /* clean threads list */
 134     for (i = 0; i < THREADS_COUNT; i++) {
 135         threadsDesc[i].thread = (jthread)NULL;
 136     }
 137 
 138     /* get all live threads */
 139     if (!NSK_JVMTI_VERIFY(jvmti->GetAllThreads(&allThreadsCount, &allThreadsList)))

 140         return NSK_FALSE;
 141 
 142     if (!NSK_VERIFY(allThreadsCount > 0 && allThreadsList != NULL))
 143         return NSK_FALSE;
 144 
 145     /* find tested threads */
 146     for (i = 0; i < allThreadsCount; i++) {
 147         jvmtiThreadInfo threadInfo;
 148 
 149         if (!NSK_VERIFY(allThreadsList[i] != NULL))
 150             return NSK_FALSE;
 151 
 152         /* get thread name (info) */
 153         if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(allThreadsList[i], &threadInfo)))

 154             return NSK_FALSE;
 155 
 156         /* find by name */
 157         if (threadInfo.name != NULL) {
 158             int j;
 159 
 160             for (j = 0; j < THREADS_COUNT; j++) {
 161                 if (strcmp(threadInfo.name, threadsDesc[j].threadName) == 0) {
 162                     threadsDesc[j].thread = allThreadsList[i];
 163                     NSK_DISPLAY3("    thread #%d (%s): %p\n",
 164                                             j, threadInfo.name, (void*)threadsDesc[j].thread);
 165                 }
 166             }
 167         }
 168     }
 169 
 170     /* deallocate all threads list */
 171     if (!NSK_JVMTI_VERIFY(jvmti->Deallocate((unsigned char*)allThreadsList)))

 172         return NSK_FALSE;
 173 
 174     /* check if all tested threads found */
 175     found = 0;
 176     for (i = 0; i < THREADS_COUNT; i++) {
 177         if (threadsDesc[i].thread == NULL) {
 178             NSK_COMPLAIN2("Not found tested thread #%d (%s)\n", i, threadsDesc[i].threadName);
 179         } else {
 180             found++;
 181         }
 182     }
 183 
 184     if (found < THREADS_COUNT)
 185         return NSK_FALSE;
 186 
 187     /* make global refs */
 188     for (i = 0; i < THREADS_COUNT; i++) {
 189         if (!NSK_JNI_VERIFY(jni, (threadsDesc[i].thread = (jthread)
 190                 jni->NewGlobalRef(threadsDesc[i].thread)) != NULL))
 191             return NSK_FALSE;
 192     }
 193 
 194     return NSK_TRUE;
 195 }
 196 
 197 /**
 198  * Suspend or resume tested threads.
 199  */
 200 static int suspendThreadsIndividually(int suspend) {
 201     int i;
 202 
 203     for (i = 0; i < THREADS_COUNT; i++) {
 204         if (suspend) {
 205             NSK_DISPLAY2("    suspend thread #%d (%s)\n", i, threadsDesc[i].threadName);
 206             if (!NSK_JVMTI_VERIFY(jvmti->SuspendThread(threadsDesc[i].thread)))

 207                 nsk_jvmti_setFailStatus();
 208         } else {
 209             NSK_DISPLAY2("    resume thread #%d (%s)\n", i, threadsDesc[i].threadName);
 210             if (!NSK_JVMTI_VERIFY(jvmti->ResumeThread(threadsDesc[i].thread)))

 211                 nsk_jvmti_setFailStatus();
 212         }
 213     }
 214     return NSK_TRUE;
 215 }
 216 
 217 /**
 218  * Testcase: check tested threads
 219  *    - invoke getFrameCount() for each thread
 220  *    - check if frameCount is not less than minimal stack depth
 221  *    - invoke getStackTrace() for each thread
 222  *    - check if stack depth is equal to frameCount
 223  *
 224  * Returns NSK_TRUE if test may continue; or NSK_FALSE for test break.
 225  */
 226 static int checkSuspendedThreads() {
 227     int i;
 228 
 229     /* check each thread */
 230     for (i = 0; i < THREADS_COUNT; i++) {
 231         jint frameCount = 0;
 232         jint frameStackSize = 0;
 233         jvmtiFrameInfo frameStack[MAX_STACK_SIZE];
 234         int found = 0;
 235 
 236         NSK_DISPLAY2("  thread #%d (%s):\n", i, threadsDesc[i].threadName);
 237 
 238         /* get frame count */
 239         if (!NSK_JVMTI_VERIFY(jvmti->GetFrameCount(threadsDesc[i].thread, &frameCount))) {


 240             nsk_jvmti_setFailStatus();
 241             return NSK_TRUE;
 242         }
 243 
 244         NSK_DISPLAY1("    frameCount:  %d\n", (int)frameCount);
 245 
 246         /* get stack trace */
 247         if (!NSK_JVMTI_VERIFY(
 248                 jvmti->GetStackTrace(threadsDesc[i].thread, 0, MAX_STACK_SIZE, frameStack, &frameStackSize))) {

 249             nsk_jvmti_setFailStatus();
 250             return NSK_TRUE;
 251         }
 252 
 253         NSK_DISPLAY1("    stack depth: %d\n", (int)frameStackSize);
 254 
 255         /* check frame count */
 256         if (frameCount < threadsDesc[i].minDepth) {
 257             NSK_COMPLAIN4("Too few frameCount of suspended thread #%d (%s):\n"
 258                             "#   got frameCount:   %d\n"
 259                             "#   expected minimum: %d\n",
 260                             i, threadsDesc[i].threadName,
 261                             (int)frameCount, threadsDesc[i].minDepth);
 262             nsk_jvmti_setFailStatus();
 263         }
 264 
 265         if (frameStackSize != frameCount) {
 266             NSK_COMPLAIN4("Different frames count for suspended thread #%d (%s):\n"
 267                             "#   getStackTrace(): %d\n"
 268                             "#   getFrameCount(): %d\n",
 269                             i, threadsDesc[i].threadName,
 270                             (int)frameStackSize, (int)frameCount);
 271             nsk_jvmti_setFailStatus();
 272         }
 273 
 274     }
 275 
 276     /* test may continue */
 277     return NSK_TRUE;
 278 }
 279 
 280 /**
 281  * Clean data:
 282  *   - dispose global references to tested threads
 283  */
 284 static int clean() {
 285     int i;
 286 
 287     /* dispose global references to threads */
 288     for (i = 0; i < THREADS_COUNT; i++) {
 289         NSK_TRACE(jni->DeleteGlobalRef(threadsDesc[i].thread));
 290     }
 291 
 292     return NSK_TRUE;
 293 }
 294 
 295 /* ============================================================================= */
 296 
 297 static volatile int testedThreadRunning = NSK_FALSE;
 298 static volatile int testedThreadShouldFinish = NSK_FALSE;
 299 
 300 /** Native running method in tested thread. */
 301 JNIEXPORT void JNICALL
 302 Java_nsk_jvmti_scenarios_sampling_SP02_sp02t001ThreadRunningNative_testedMethod(JNIEnv* jni,
 303                                                                                 jobject obj) {
 304     volatile int i = 0, n = 1000;
 305 
 306     /* run in a loop */
 307     testedThreadRunning = NSK_TRUE;
 308     while (!testedThreadShouldFinish) {
 309         if (n <= 0)


 347 }
 348 #endif
 349 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 350 
 351     /* init framework and parse options */
 352     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
 353         return JNI_ERR;
 354 
 355     timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
 356 
 357     /* create JVMTI environment */
 358     if (!NSK_VERIFY((jvmti =
 359             nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
 360         return JNI_ERR;
 361 
 362     /* add specific capabilities for suspending thread */
 363     {
 364         jvmtiCapabilities suspendCaps;
 365         memset(&suspendCaps, 0, sizeof(suspendCaps));
 366         suspendCaps.can_suspend = 1;
 367         if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&suspendCaps)))

 368             return JNI_ERR;
 369     }
 370 
 371     /* register agent proc and arg */
 372     if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
 373         return JNI_ERR;
 374 
 375     return JNI_OK;
 376 }
 377 
 378 /* ============================================================================= */
 379 
 380 }
< prev index next >