--- old/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2017-10-02 10:17:47.085519532 -0700 +++ new/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2017-10-02 10:17:46.717520767 -0700 @@ -361,7 +361,7 @@ } } -static jint checkAnd(JNIEnv *env, jobjectArray frames, int live, int recent, +static jint check_and(JNIEnv *env, jobjectArray frames, int live, int recent, int frequent) { jobject loader = NULL; @@ -398,7 +398,7 @@ return result; } -static jint checkOr(JNIEnv *env, jobjectArray frames, int live, int recent, +static jint check_or(JNIEnv *env, jobjectArray frames, int live, int recent, int frequent) { jobject loader = NULL; @@ -436,7 +436,7 @@ } static jint checkAll(JNIEnv *env, jobjectArray frames) { - return checkAnd(env, frames, 1, 1, 1); + return check_and(env, frames, 1, 1, 1); } static jint checkNone(JNIEnv *env, jobjectArray frames) { @@ -534,7 +534,7 @@ JNIEXPORT jint JNICALL Java_MyPackage_HeapMonitorRecentTest_checkLiveOrRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) { - if (checkOr(env, frames, 1, 1, 0)) { + if (check_or(env, frames, 1, 1, 0)) { return FAILED; } return PASSED; @@ -542,7 +542,7 @@ JNIEXPORT jint JNICALL Java_MyPackage_HeapMonitorRecentTest_checkLiveAndRecentFrames(JNIEnv *env, jclass cls, jobjectArray frames) { - if (checkAnd(env, frames, 1, 1, 0)) { + if (check_and(env, frames, 1, 1, 0)) { return FAILED; } return PASSED; @@ -565,7 +565,7 @@ JNIEXPORT jint JNICALL Java_MyPackage_HeapMonitorFrequentTest_checkFrequentFrames(JNIEnv *env, jclass cls, jobjectArray frames) { - if (checkAnd(env, frames, 0, 0, 1)) { + if (check_and(env, frames, 0, 0, 1)) { return PASSED; } return FAILED; @@ -670,24 +670,33 @@ check_error((*jvmti)->GetHeapSamplingStats(jvmti, &stats), "Heap Sampling Statistics"); - fprintf(stderr, "Statistics show:\n"); - fprintf(stderr, "\tCollected samples: %ld\n\tGarbage collected samples: %ld\n", - stats.sample_count, stats.garbage_collected_samples); - fprintf(stderr, "\tSample rate accumulated: %ld\n\tSample Rate Count: %ld\n", - stats.sample_rate_accumulation, stats.sample_rate_count); - fprintf(stderr, "\tStack depth accumulation: %ld\n", - stats.stack_depth_accumulation); - - fprintf(stderr, "Expected is %d\n", expected); double diff_ratio = (stats.sample_count - expected); diff_ratio = (diff_ratio < 0) ? -diff_ratio : diff_ratio; diff_ratio /= expected; - fprintf(stderr, "Diff ratio is %f\n", diff_ratio); - return diff_ratio * 100 > percent_error; } +JNIEXPORT void JNICALL +Java_MyPackage_HeapMonitorStatRateTest_enableSampling(JNIEnv *env, jclass cls, jint rate) { + enable_sampling_with_rate(rate); +} + +JNIEXPORT void JNICALL +Java_MyPackage_HeapMonitorStatRateTest_disableSampling(JNIEnv *env, jclass cls) { + disable_sampling(); +} + +JNIEXPORT jdouble JNICALL +Java_MyPackage_HeapMonitorStatRateTest_getAverageRate(JNIEnv *env, jclass cls) { + jvmtiHeapSamplingStats stats; + check_error((*jvmti)->GetHeapSamplingStats(jvmti, &stats), + "Heap Sampling Statistics"); + (int) stats.sample_rate_accumulation, (int) stats.sample_rate_count); + + return ((double) stats.sample_rate_accumulation) / stats.sample_rate_count; +} + #ifdef __cplusplus } #endif