# HG changeset patch # User ehelin # Date 1380533947 -7200 # Node ID 6e22e70424338cd02b6d0d857cfcb3bcc488ec2b # Parent 9ecd6d3782b18536f4dab395bd8d0ef9255a94fa 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp Reviewed-by: brutisso, mgerdin diff -r 9ecd6d3782b1 -r 6e22e7042433 test/gc/metaspace/TestPerfCountersAndMemoryPools.java --- a/test/gc/metaspace/TestPerfCountersAndMemoryPools.java Tue Oct 01 15:21:14 2013 +0200 +++ b/test/gc/metaspace/TestPerfCountersAndMemoryPools.java Mon Sep 30 11:39:07 2013 +0200 @@ -29,10 +29,11 @@ /* @test TestPerfCountersAndMemoryPools * @bug 8023476 + * @library /testlibrary * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace * report the same data. - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools - * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools */ public class TestPerfCountersAndMemoryPools { public static void main(String[] args) throws Exception { @@ -43,11 +44,11 @@ } } - private static MemoryUsage getMemoryUsage(String memoryPoolName) { + private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) { List pools = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean pool : pools) { if (pool.getName().equals(memoryPoolName)) { - return pool.getUsage(); + return pool; } } @@ -57,19 +58,18 @@ private static void checkMemoryUsage(String memoryPoolName, String perfNS) throws Exception { - // Need to do a gc before each comparison to update the perf counters + MemoryPoolMXBean pool = getMemoryPool(memoryPoolName); - System.gc(); - MemoryUsage mu = getMemoryUsage(memoryPoolName); - assertEQ(getMinCapacity(perfNS), mu.getInit()); - + // Must do a GC to update performance counters System.gc(); - mu = getMemoryUsage(memoryPoolName); - assertEQ(getUsed(perfNS), mu.getUsed()); + assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit()); + // Must do a second GC to update the perfomance counters again, since + // the call pool.getUsage().getInit() could have allocated some + // metadata. System.gc(); - mu = getMemoryUsage(memoryPoolName); - assertEQ(getCapacity(perfNS), mu.getCommitted()); + assertEQ(getUsed(perfNS), pool.getUsage().getUsed()); + assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted()); } private static long getMinCapacity(String ns) throws Exception {