# HG changeset patch # User shade # Date 1525334552 -7200 # Node ID 675e7b5c537f8ce76bac1e73925c96fca7c52342 # Parent f67f588ebf157d6d3519ce2bd3dac56de1d42412 Fix gc/epsilon/TestMemoryMXBeans failures after the merge diff -r f67f588ebf15 -r 675e7b5c537f 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 + "]"); } }