--- old/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2018-03-28 08:20:31.037177885 -0700 +++ new/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2018-03-28 08:20:30.717179056 -0700 @@ -566,6 +566,7 @@ (*jvmti)->SetHeapSamplingRate(jvmti, value); } +// TODO: should be removed, no tests using it. JNIEXPORT void JNICALL Java_MyPackage_HeapMonitor_setGarbageHistory(JNIEnv* env, jclass cls, jint value) { event_storage_set_garbage_history(&global_event_storage, value); @@ -642,6 +643,32 @@ return TRUE; } +JNIEXPORT jboolean JNICALL +Java_MyPackage_HeapMonitorIllegalArgumentTest_testIllegalArgument(JNIEnv *env, + jclass cls) { + if (check_error((*jvmti)->SetHeapSamplingRate(jvmti, 0), + "Sampling rate 0 failed\n")){ + return FALSE; + } + + if (check_error((*jvmti)->SetHeapSamplingRate(jvmti, 1024), + "Sampling rate 1024 failed\n")){ + return FALSE; + } + + if (!check_error((*jvmti)->SetHeapSamplingRate(jvmti, -1), + "Sampling rate -1 passed\n")){ + return FALSE; + } + + if (!check_error((*jvmti)->SetHeapSamplingRate(jvmti, -1024), + "Sampling rate -1024 passed\n")){ + return FALSE; + } + + return TRUE; +} + JNIEXPORT jdouble JNICALL Java_MyPackage_HeapMonitorStatRateTest_getAverageRate(JNIEnv *env, jclass cls) { return event_storage_get_average_rate(&global_event_storage); @@ -713,12 +740,12 @@ find_threads_in_array(&thread_data, global_event_storage.live_objects, global_event_storage.live_object_count); - find_threads_in_array(&thread_data, - global_event_storage.garbage_collected_objects, - global_event_storage.garbage_history_size); free(thread_data.threads); pthread_mutex_unlock(&global_event_storage.storage_mutex); + fprintf(stderr, "Obtained %d - %d\n", + thread_data.num_threads, + num_threads); return thread_data.num_threads == num_threads; }