From 826bb4f2f28538f94ec90b7e617272526865c64a Mon Sep 17 00:00:00 2001 From: jcbeyler Date: Thu, 19 Jul 2018 18:21:24 -0700 Subject: [PATCH] 8207765: HeapMonitorStatIntervalTest.java fails with ZGC Summary: Add a calculation of array sizes before test to satisfy ZGC support Reviewed-by: amenkov, sspitsyn Contributed-by: jcbeyler@google.com --- test/hotspot/jtreg/ProblemList.txt | 1 - .../HeapMonitor/MyPackage/HeapMonitor.java | 38 +++++++++++++++++-- .../HeapMonitorStatIntervalTest.java | 5 +-- .../jvmti/HeapMonitor/libHeapMonitorTest.c | 8 ++-- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 777abe22b2..92d7b4c597 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -81,7 +81,6 @@ runtime/CompressedOops/UseCompressedOops.java 8079353 generic-all serviceability/sa/TestRevPtrsForInvokeDynamic.java 8191270 generic-all serviceability/sa/sadebugd/SADebugDTest.java 8163805 generic-all -serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatRateTest.java 8207765 generic-all ############################################################################# diff --git a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java index 39860684ec..bbd9375218 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java +++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java @@ -102,13 +102,45 @@ public class HeapMonitor { return sum; } + private static double averageOneElementSize; + private static native double getAverageSize(); + + // Calculate the size of a 1-element array in order to assess average sampling interval + // via the HeapMonitorStatIntervalTest. This is needed because various GCs could add + // extra memory to arrays. + // This is done by allocating a 1-element array and then looking in the heap monitoring + // samples for the average size of objects collected. + public static void calculateAverageOneElementSize() { + enableSamplingEvents(); + // Assume a size of 24 for the average size. + averageOneElementSize = 24; + + // Call allocateSize once, this allocates the internal array for the iterations. + int totalSize = 10 * 1024 * 1024; + allocateSize(totalSize); + + // Reset the storage and now really track the size of the elements. + resetEventStorage(); + allocateSize(totalSize); + disableSamplingEvents(); + + // Get the actual average size. + averageOneElementSize = getAverageSize(); + if (averageOneElementSize == 0) { + throw new RuntimeException("Could not calculate the average size of a 1-element array."); + } + } + public static int allocateSize(int totalSize) { + if (averageOneElementSize == 0) { + throw new RuntimeException("Average size of a 1-element array was not calculated."); + } + int sum = 0; - // Let us assume that a 1-element array is 24 bytes. - int iterations = totalSize / 24; + int iterations = (int) (totalSize / averageOneElementSize); - if (arrays == null) { + if (arrays == null || arrays.length < iterations) { arrays = new int[iterations][]; } diff --git a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java index 2acd91730a..5ed4dc612c 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java +++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatIntervalTest.java @@ -33,9 +33,6 @@ package MyPackage; */ public class HeapMonitorStatIntervalTest { - - private native static double getAverageInterval(); - private static boolean testIntervalOnce(int interval, boolean throwIfFailure) { HeapMonitor.resetEventStorage(); HeapMonitor.setSamplingInterval(interval); @@ -84,6 +81,8 @@ public class HeapMonitorStatIntervalTest { public static void main(String[] args) { int[] tab = {1024, 8192}; + HeapMonitor.calculateAverageOneElementSize(); + for (int intervalIdx = 0; intervalIdx < tab.length; intervalIdx++) { testInterval(tab[intervalIdx]); } diff --git a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c index 34bda343f9..585d2c7f46 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c +++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c @@ -45,7 +45,7 @@ extern "C" { #define TRUE 1 #define FALSE 0 -#define PRINT_OUT 1 +#define PRINT_OUT 0 static jvmtiEnv *jvmti = NULL; static jvmtiEnv *second_jvmti = NULL; @@ -369,7 +369,7 @@ static int event_storage_get_count(EventStorage* storage) { return result; } -static double event_storage_get_average_interval(EventStorage* storage) { +static double event_storage_get_average_size(EventStorage* storage) { double accumulation = 0; int max_size; int i; @@ -974,8 +974,8 @@ Java_MyPackage_HeapMonitorIllegalArgumentTest_testIllegalArgument(JNIEnv *env, } JNIEXPORT jdouble JNICALL -Java_MyPackage_HeapMonitorStatIntervalTest_getAverageInterval(JNIEnv *env, jclass cls) { - return event_storage_get_average_interval(&global_event_storage); +Java_MyPackage_HeapMonitor_getAverageSize(JNIEnv *env, jclass cls) { + return event_storage_get_average_size(&global_event_storage); } typedef struct sThreadsFound { -- GitLab