Fix gc/epsilon/TestMemoryMXBeans failures after the merge epsilon-gc-branch
authorshade
Thu, 03 May 2018 10:02:32 +0200
branchepsilon-gc-branch
changeset 56509 675e7b5c537f
parent 56508 f67f588ebf15
child 56510 54c1aa06c1d8
Fix gc/epsilon/TestMemoryMXBeans failures after the merge
test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java
--- a/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java	Thu May 03 09:43:47 2018 +0200
+++ b/test/hotspot/jtreg/gc/epsilon/TestMemoryMXBeans.java	Thu May 03 10:02:32 2018 +0200
@@ -70,13 +70,26 @@
 
     public static void testAllocs() {
         MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
+
+        // Do lazy inits first:
         long heapUsed1 = memoryMXBean.getHeapMemoryUsage().getUsed();
         sink = new int[1024*1024];
         long heapUsed2 = memoryMXBean.getHeapMemoryUsage().getUsed();
 
-        long diff = heapUsed2 - heapUsed1;
-        if (!(8 + 4*1024*1024 <= diff && diff <= 16 + 4*1024*1024)) {
-           throw new IllegalStateException("Allocation did not change used space right: " + diff);
+        // Compute how much we waste during the calls themselves:
+        heapUsed1 = memoryMXBean.getHeapMemoryUsage().getUsed();
+        heapUsed2 = memoryMXBean.getHeapMemoryUsage().getUsed();
+        long adj = heapUsed2 - heapUsed1;
+
+        heapUsed1 = memoryMXBean.getHeapMemoryUsage().getUsed();
+        sink = new int[1024*1024];
+        heapUsed2 = memoryMXBean.getHeapMemoryUsage().getUsed();
+
+        long diff = heapUsed2 - heapUsed1 - adj;
+        long min = 8 + 4*1024*1024;
+        long max = 16 + 4*1024*1024;
+        if (!(min <= diff && diff <= max)) {
+           throw new IllegalStateException("Allocation did not change used space right: " + diff + " should be in [" + min + ", " + max + "]");
         }
     }