test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c
changeset 51138 914f305ba6fa
parent 51136 6d6611346837
child 51175 65556ae796ad
equal deleted inserted replaced
51137:e3bcc86855dd 51138:914f305ba6fa
   367   result = storage->live_object_count;
   367   result = storage->live_object_count;
   368   event_storage_unlock(storage);
   368   event_storage_unlock(storage);
   369   return result;
   369   return result;
   370 }
   370 }
   371 
   371 
   372 static double event_storage_get_average_rate(EventStorage* storage) {
   372 static double event_storage_get_average_interval(EventStorage* storage) {
   373   double accumulation = 0;
   373   double accumulation = 0;
   374   int max_size;
   374   int max_size;
   375   int i;
   375   int i;
   376 
   376 
   377   event_storage_lock(storage);
   377   event_storage_lock(storage);
   837   }
   837   }
   838   return JNI_OK;
   838   return JNI_OK;
   839 }
   839 }
   840 
   840 
   841 JNIEXPORT void JNICALL
   841 JNIEXPORT void JNICALL
   842 Java_MyPackage_HeapMonitor_setSamplingRate(JNIEnv* env, jclass cls, jint value) {
   842 Java_MyPackage_HeapMonitor_setSamplingInterval(JNIEnv* env, jclass cls, jint value) {
   843   (*jvmti)->SetHeapSamplingRate(jvmti, value);
   843   (*jvmti)->SetHeapSamplingInterval(jvmti, value);
   844 }
   844 }
   845 
   845 
   846 JNIEXPORT jboolean JNICALL
   846 JNIEXPORT jboolean JNICALL
   847 Java_MyPackage_HeapMonitor_eventStorageIsEmpty(JNIEnv* env, jclass cls) {
   847 Java_MyPackage_HeapMonitor_eventStorageIsEmpty(JNIEnv* env, jclass cls) {
   848   return event_storage_get_count(&global_event_storage) == 0;
   848   return event_storage_get_count(&global_event_storage) == 0;
   938   if (check_error((*jvmti)->RelinquishCapabilities(jvmti, &caps),
   938   if (check_error((*jvmti)->RelinquishCapabilities(jvmti, &caps),
   939                   "Add capabilities\n")){
   939                   "Add capabilities\n")){
   940     return FALSE;
   940     return FALSE;
   941   }
   941   }
   942 
   942 
   943   if (check_capability_error((*jvmti)->SetHeapSamplingRate(jvmti, 1<<19),
   943   if (check_capability_error((*jvmti)->SetHeapSamplingInterval(jvmti, 1<<19),
   944                              "Set Heap Sampling Rate")) {
   944                              "Set Heap Sampling Interval")) {
   945     return FALSE;
   945     return FALSE;
   946   }
   946   }
   947   return TRUE;
   947   return TRUE;
   948 }
   948 }
   949 
   949 
   950 JNIEXPORT jboolean JNICALL
   950 JNIEXPORT jboolean JNICALL
   951 Java_MyPackage_HeapMonitorIllegalArgumentTest_testIllegalArgument(JNIEnv *env,
   951 Java_MyPackage_HeapMonitorIllegalArgumentTest_testIllegalArgument(JNIEnv *env,
   952                                                                   jclass cls) {
   952                                                                   jclass cls) {
   953   if (check_error((*jvmti)->SetHeapSamplingRate(jvmti, 0),
   953   if (check_error((*jvmti)->SetHeapSamplingInterval(jvmti, 0),
   954                   "Sampling rate 0 failed\n")){
   954                   "Sampling interval 0 failed\n")){
   955     return FALSE;
   955     return FALSE;
   956   }
   956   }
   957 
   957 
   958   if (check_error((*jvmti)->SetHeapSamplingRate(jvmti, 1024),
   958   if (check_error((*jvmti)->SetHeapSamplingInterval(jvmti, 1024),
   959                   "Sampling rate 1024 failed\n")){
   959                   "Sampling interval 1024 failed\n")){
   960     return FALSE;
   960     return FALSE;
   961   }
   961   }
   962 
   962 
   963   if (!check_error((*jvmti)->SetHeapSamplingRate(jvmti, -1),
   963   if (!check_error((*jvmti)->SetHeapSamplingInterval(jvmti, -1),
   964                    "Sampling rate -1 passed\n")){
   964                    "Sampling interval -1 passed\n")){
   965     return FALSE;
   965     return FALSE;
   966   }
   966   }
   967 
   967 
   968   if (!check_error((*jvmti)->SetHeapSamplingRate(jvmti, -1024),
   968   if (!check_error((*jvmti)->SetHeapSamplingInterval(jvmti, -1024),
   969                    "Sampling rate -1024 passed\n")){
   969                    "Sampling interval -1024 passed\n")){
   970     return FALSE;
   970     return FALSE;
   971   }
   971   }
   972 
   972 
   973   return TRUE;
   973   return TRUE;
   974 }
   974 }
   975 
   975 
   976 JNIEXPORT jdouble JNICALL
   976 JNIEXPORT jdouble JNICALL
   977 Java_MyPackage_HeapMonitorStatRateTest_getAverageRate(JNIEnv *env, jclass cls) {
   977 Java_MyPackage_HeapMonitorStatIntervalTest_getAverageInterval(JNIEnv *env, jclass cls) {
   978   return event_storage_get_average_rate(&global_event_storage);
   978   return event_storage_get_average_interval(&global_event_storage);
   979 }
   979 }
   980 
   980 
   981 typedef struct sThreadsFound {
   981 typedef struct sThreadsFound {
   982   jthread* threads;
   982   jthread* threads;
   983   int num_threads;
   983   int num_threads;