< prev index next >

test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c

Print this page




 344 
 345     jfieldID string_id = (*env)->GetFieldID(env, frame_class, "method", "Ljava/lang/String;");
 346     jstring string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 347     const char* method = (*env)->GetStringUTFChars(env, string_object, 0);
 348 
 349     string_id = (*env)->GetFieldID(env, frame_class, "fileName", "Ljava/lang/String;");
 350     string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 351     const char* file_name = (*env)->GetStringUTFChars(env, string_object, 0);
 352 
 353     string_id = (*env)->GetFieldID(env, frame_class, "signature", "Ljava/lang/String;");
 354     string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 355     const char* signature= (*env)->GetStringUTFChars(env, string_object, 0);
 356 
 357     native_frames[i].name = method;
 358     native_frames[i].file_name = file_name;
 359     native_frames[i].signature = signature;
 360     native_frames[i].line_number = line_number;
 361   }
 362 }
 363 
 364 static jint checkAnd(JNIEnv *env, jobjectArray frames, int live, int recent,
 365                      int frequent) {
 366   jobject loader = NULL;
 367 
 368   if (frames == NULL) {
 369     return 0;
 370   }
 371 
 372   // Start by transforming the frames into a C-friendly structure.
 373   jsize size = (*env)->GetArrayLength(env, frames);
 374   ExpectedContentFrame native_frames[size];
 375   fill_native_frames(env, frames, native_frames, size);
 376 
 377   if (jvmti == NULL) {
 378     throw_exc(env, "JVMTI client was not properly loaded!\n");
 379     return 0;
 380   }
 381 
 382   int result = 1;
 383 
 384   if (live) {
 385     result = frames_exist_live(env, native_frames, size);
 386   }
 387 
 388   if (recent) {
 389     result = result &&
 390         frames_exist_recent(env, native_frames, size);
 391   }
 392 
 393   if (frequent) {
 394     result = result &&
 395         frames_exist_frequent(env, native_frames, size);
 396   }
 397 
 398   return result;
 399 }
 400 
 401 static jint checkOr(JNIEnv *env, jobjectArray frames, int live, int recent,
 402                     int frequent) {
 403   jobject loader = NULL;
 404 
 405   if (frames == NULL) {
 406     return 0;
 407   }
 408 
 409   // Start by transforming the frames into a C-friendly structure.
 410   jsize size = (*env)->GetArrayLength(env, frames);
 411   ExpectedContentFrame native_frames[size];
 412   fill_native_frames(env, frames, native_frames, size);
 413 
 414   if (jvmti == NULL) {
 415     throw_exc(env, "JVMTI client was not properly loaded!\n");
 416     return 0;
 417   }
 418 
 419   int result = 0;
 420 
 421   if (live) {
 422     result = frames_exist_live(env, native_frames, size);
 423   }
 424 
 425   if (recent) {
 426     result = result ||
 427         frames_exist_recent(env, native_frames, size);
 428   }
 429 
 430   if (frequent) {
 431     result = result ||
 432         frames_exist_frequent(env, native_frames, size);
 433   }
 434 
 435   return result;
 436 }
 437 
 438 static jint checkAll(JNIEnv *env, jobjectArray frames) {
 439   return checkAnd(env, frames, 1, 1, 1);
 440 }
 441 
 442 static jint checkNone(JNIEnv *env, jobjectArray frames) {
 443   jobject loader = NULL;
 444 
 445   if (frames == NULL) {
 446     return 0;
 447   }
 448 
 449   // Start by transforming the frames into a C-friendly structure.
 450   jsize size = (*env)->GetArrayLength(env, frames);
 451   ExpectedContentFrame native_frames[size];
 452   fill_native_frames(env, frames, native_frames, size);
 453 
 454   if (jvmti == NULL) {
 455     throw_exc(env, "JVMTI client was not properly loaded!\n");
 456     return 0;
 457   }
 458 
 459   if ((!frames_exist_live(env, native_frames, size)) &&


 517   enable_sampling();
 518 }
 519 
 520 JNIEXPORT void JNICALL
 521 Java_MyPackage_HeapMonitorOnOffTest_disableSampling(JNIEnv *env, jclass cls) {
 522   disable_sampling();
 523 }
 524 
 525 // HeapMonitorRecentTest JNI.
 526 JNIEXPORT jint JNICALL
 527 Java_MyPackage_HeapMonitorRecentTest_checkFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 528   // We want the frames in each part.
 529   if (!checkAll(env, frames)) {
 530     return FAILED;
 531   }
 532   return PASSED;
 533 }
 534 
 535 JNIEXPORT jint JNICALL
 536 Java_MyPackage_HeapMonitorRecentTest_checkLiveOrRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 537   if (checkOr(env, frames, 1, 1, 0)) {
 538     return FAILED;
 539   }
 540   return PASSED;
 541 }
 542 
 543 JNIEXPORT jint JNICALL
 544 Java_MyPackage_HeapMonitorRecentTest_checkLiveAndRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 545   if (checkAnd(env, frames, 1, 1, 0)) {
 546     return FAILED;
 547   }
 548   return PASSED;
 549 }
 550 
 551 JNIEXPORT void JNICALL
 552 Java_MyPackage_HeapMonitorRecentTest_enableSampling(JNIEnv *env, jclass cls) {
 553   enable_sampling();
 554 }
 555 
 556 // HeapMonitorFrequentTest JNI.
 557 JNIEXPORT jint JNICALL
 558 Java_MyPackage_HeapMonitorFrequentTest_checkFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 559   // We want the frames in each part.
 560   if (!checkAll(env, frames)) {
 561     return FAILED;
 562   }
 563   return PASSED;
 564 }
 565 
 566 JNIEXPORT jint JNICALL
 567 Java_MyPackage_HeapMonitorFrequentTest_checkFrequentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 568   if (checkAnd(env, frames, 0, 0, 1)) {
 569     return PASSED;
 570   }
 571   return FAILED;
 572 }
 573 
 574 JNIEXPORT void JNICALL
 575 Java_MyPackage_HeapMonitorFrequentTest_enableSampling(JNIEnv *env, jclass cls) {
 576   enable_sampling();
 577 }
 578 
 579 JNIEXPORT jboolean JNICALL
 580 Java_MyPackage_HeapMonitorNoCapabilityTest_allSamplingMethodsFail(JNIEnv *env, jclass cls) {
 581   jvmtiCapabilities caps;
 582   memset(&caps, 0, sizeof(caps));
 583   caps.can_sample_heap= 1;
 584   if (check_error((*jvmti)->RelinquishCapabilities(jvmti, &caps),
 585                   "Add capabilities\n")){
 586     return 0;
 587   }
 588 


 653 
 654 JNIEXPORT void JNICALL
 655 Java_MyPackage_HeapMonitorStatCorrectnessTest_enableSampling(JNIEnv *env, jclass cls, jint rate) {
 656   enable_sampling_with_rate(rate);
 657 }
 658 
 659 JNIEXPORT jint JNICALL
 660 Java_MyPackage_HeapMonitorStatCorrectnessTest_statsNull(JNIEnv *env, jclass cls) {
 661   return stats_are_zero();
 662 }
 663 
 664 JNIEXPORT jint JNICALL
 665 Java_MyPackage_HeapMonitorStatCorrectnessTest_statsHaveSamples(JNIEnv *env,
 666                                                                jclass cls,
 667                                                                int expected,
 668                                                                int percent_error) {
 669   jvmtiHeapSamplingStats stats;
 670   check_error((*jvmti)->GetHeapSamplingStats(jvmti, &stats),
 671               "Heap Sampling Statistics");
 672 
 673   fprintf(stderr, "Statistics show:\n");
 674   fprintf(stderr, "\tCollected samples: %ld\n\tGarbage collected samples: %ld\n",
 675           stats.sample_count, stats.garbage_collected_samples);
 676   fprintf(stderr, "\tSample rate accumulated: %ld\n\tSample Rate Count: %ld\n",
 677           stats.sample_rate_accumulation, stats.sample_rate_count);
 678   fprintf(stderr, "\tStack depth accumulation: %ld\n",
 679           stats.stack_depth_accumulation);
 680 
 681   fprintf(stderr, "Expected is %d\n", expected);
 682   double diff_ratio = (stats.sample_count - expected);
 683   diff_ratio = (diff_ratio < 0) ? -diff_ratio : diff_ratio;
 684   diff_ratio /= expected;
 685 
 686   fprintf(stderr, "Diff ratio is %f\n", diff_ratio);
 687 
 688   return diff_ratio * 100 > percent_error;




















 689 }
 690 
 691 #ifdef __cplusplus
 692 }
 693 #endif


 344 
 345     jfieldID string_id = (*env)->GetFieldID(env, frame_class, "method", "Ljava/lang/String;");
 346     jstring string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 347     const char* method = (*env)->GetStringUTFChars(env, string_object, 0);
 348 
 349     string_id = (*env)->GetFieldID(env, frame_class, "fileName", "Ljava/lang/String;");
 350     string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 351     const char* file_name = (*env)->GetStringUTFChars(env, string_object, 0);
 352 
 353     string_id = (*env)->GetFieldID(env, frame_class, "signature", "Ljava/lang/String;");
 354     string_object = (jstring) (*env)->GetObjectField(env, obj, string_id);
 355     const char* signature= (*env)->GetStringUTFChars(env, string_object, 0);
 356 
 357     native_frames[i].name = method;
 358     native_frames[i].file_name = file_name;
 359     native_frames[i].signature = signature;
 360     native_frames[i].line_number = line_number;
 361   }
 362 }
 363 
 364 static jint check_and(JNIEnv *env, jobjectArray frames, int live, int recent,
 365                      int frequent) {
 366   jobject loader = NULL;
 367 
 368   if (frames == NULL) {
 369     return 0;
 370   }
 371 
 372   // Start by transforming the frames into a C-friendly structure.
 373   jsize size = (*env)->GetArrayLength(env, frames);
 374   ExpectedContentFrame native_frames[size];
 375   fill_native_frames(env, frames, native_frames, size);
 376 
 377   if (jvmti == NULL) {
 378     throw_exc(env, "JVMTI client was not properly loaded!\n");
 379     return 0;
 380   }
 381 
 382   int result = 1;
 383 
 384   if (live) {
 385     result = frames_exist_live(env, native_frames, size);
 386   }
 387 
 388   if (recent) {
 389     result = result &&
 390         frames_exist_recent(env, native_frames, size);
 391   }
 392 
 393   if (frequent) {
 394     result = result &&
 395         frames_exist_frequent(env, native_frames, size);
 396   }
 397 
 398   return result;
 399 }
 400 
 401 static jint check_or(JNIEnv *env, jobjectArray frames, int live, int recent,
 402                     int frequent) {
 403   jobject loader = NULL;
 404 
 405   if (frames == NULL) {
 406     return 0;
 407   }
 408 
 409   // Start by transforming the frames into a C-friendly structure.
 410   jsize size = (*env)->GetArrayLength(env, frames);
 411   ExpectedContentFrame native_frames[size];
 412   fill_native_frames(env, frames, native_frames, size);
 413 
 414   if (jvmti == NULL) {
 415     throw_exc(env, "JVMTI client was not properly loaded!\n");
 416     return 0;
 417   }
 418 
 419   int result = 0;
 420 
 421   if (live) {
 422     result = frames_exist_live(env, native_frames, size);
 423   }
 424 
 425   if (recent) {
 426     result = result ||
 427         frames_exist_recent(env, native_frames, size);
 428   }
 429 
 430   if (frequent) {
 431     result = result ||
 432         frames_exist_frequent(env, native_frames, size);
 433   }
 434 
 435   return result;
 436 }
 437 
 438 static jint checkAll(JNIEnv *env, jobjectArray frames) {
 439   return check_and(env, frames, 1, 1, 1);
 440 }
 441 
 442 static jint checkNone(JNIEnv *env, jobjectArray frames) {
 443   jobject loader = NULL;
 444 
 445   if (frames == NULL) {
 446     return 0;
 447   }
 448 
 449   // Start by transforming the frames into a C-friendly structure.
 450   jsize size = (*env)->GetArrayLength(env, frames);
 451   ExpectedContentFrame native_frames[size];
 452   fill_native_frames(env, frames, native_frames, size);
 453 
 454   if (jvmti == NULL) {
 455     throw_exc(env, "JVMTI client was not properly loaded!\n");
 456     return 0;
 457   }
 458 
 459   if ((!frames_exist_live(env, native_frames, size)) &&


 517   enable_sampling();
 518 }
 519 
 520 JNIEXPORT void JNICALL
 521 Java_MyPackage_HeapMonitorOnOffTest_disableSampling(JNIEnv *env, jclass cls) {
 522   disable_sampling();
 523 }
 524 
 525 // HeapMonitorRecentTest JNI.
 526 JNIEXPORT jint JNICALL
 527 Java_MyPackage_HeapMonitorRecentTest_checkFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 528   // We want the frames in each part.
 529   if (!checkAll(env, frames)) {
 530     return FAILED;
 531   }
 532   return PASSED;
 533 }
 534 
 535 JNIEXPORT jint JNICALL
 536 Java_MyPackage_HeapMonitorRecentTest_checkLiveOrRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 537   if (check_or(env, frames, 1, 1, 0)) {
 538     return FAILED;
 539   }
 540   return PASSED;
 541 }
 542 
 543 JNIEXPORT jint JNICALL
 544 Java_MyPackage_HeapMonitorRecentTest_checkLiveAndRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 545   if (check_and(env, frames, 1, 1, 0)) {
 546     return FAILED;
 547   }
 548   return PASSED;
 549 }
 550 
 551 JNIEXPORT void JNICALL
 552 Java_MyPackage_HeapMonitorRecentTest_enableSampling(JNIEnv *env, jclass cls) {
 553   enable_sampling();
 554 }
 555 
 556 // HeapMonitorFrequentTest JNI.
 557 JNIEXPORT jint JNICALL
 558 Java_MyPackage_HeapMonitorFrequentTest_checkFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 559   // We want the frames in each part.
 560   if (!checkAll(env, frames)) {
 561     return FAILED;
 562   }
 563   return PASSED;
 564 }
 565 
 566 JNIEXPORT jint JNICALL
 567 Java_MyPackage_HeapMonitorFrequentTest_checkFrequentFrames(JNIEnv *env, jclass cls, jobjectArray frames) {
 568   if (check_and(env, frames, 0, 0, 1)) {
 569     return PASSED;
 570   }
 571   return FAILED;
 572 }
 573 
 574 JNIEXPORT void JNICALL
 575 Java_MyPackage_HeapMonitorFrequentTest_enableSampling(JNIEnv *env, jclass cls) {
 576   enable_sampling();
 577 }
 578 
 579 JNIEXPORT jboolean JNICALL
 580 Java_MyPackage_HeapMonitorNoCapabilityTest_allSamplingMethodsFail(JNIEnv *env, jclass cls) {
 581   jvmtiCapabilities caps;
 582   memset(&caps, 0, sizeof(caps));
 583   caps.can_sample_heap= 1;
 584   if (check_error((*jvmti)->RelinquishCapabilities(jvmti, &caps),
 585                   "Add capabilities\n")){
 586     return 0;
 587   }
 588 


 653 
 654 JNIEXPORT void JNICALL
 655 Java_MyPackage_HeapMonitorStatCorrectnessTest_enableSampling(JNIEnv *env, jclass cls, jint rate) {
 656   enable_sampling_with_rate(rate);
 657 }
 658 
 659 JNIEXPORT jint JNICALL
 660 Java_MyPackage_HeapMonitorStatCorrectnessTest_statsNull(JNIEnv *env, jclass cls) {
 661   return stats_are_zero();
 662 }
 663 
 664 JNIEXPORT jint JNICALL
 665 Java_MyPackage_HeapMonitorStatCorrectnessTest_statsHaveSamples(JNIEnv *env,
 666                                                                jclass cls,
 667                                                                int expected,
 668                                                                int percent_error) {
 669   jvmtiHeapSamplingStats stats;
 670   check_error((*jvmti)->GetHeapSamplingStats(jvmti, &stats),
 671               "Heap Sampling Statistics");
 672 









 673   double diff_ratio = (stats.sample_count - expected);
 674   diff_ratio = (diff_ratio < 0) ? -diff_ratio : diff_ratio;
 675   diff_ratio /= expected;
 676 


 677   return diff_ratio * 100 > percent_error;
 678 }
 679 
 680 JNIEXPORT void JNICALL
 681 Java_MyPackage_HeapMonitorStatRateTest_enableSampling(JNIEnv *env, jclass cls, jint rate) {
 682   enable_sampling_with_rate(rate);
 683 }
 684 
 685 JNIEXPORT void JNICALL
 686 Java_MyPackage_HeapMonitorStatRateTest_disableSampling(JNIEnv *env, jclass cls) {
 687   disable_sampling();
 688 }
 689 
 690 JNIEXPORT jdouble JNICALL
 691 Java_MyPackage_HeapMonitorStatRateTest_getAverageRate(JNIEnv *env, jclass cls) {
 692   jvmtiHeapSamplingStats stats;
 693   check_error((*jvmti)->GetHeapSamplingStats(jvmti, &stats),
 694               "Heap Sampling Statistics");
 695     (int) stats.sample_rate_accumulation, (int) stats.sample_rate_count);
 696 
 697   return ((double) stats.sample_rate_accumulation) / stats.sample_rate_count;
 698 }
 699 
 700 #ifdef __cplusplus
 701 }
 702 #endif
< prev index next >