comparison test/gc/metaspace/TestPerfCountersAndMemoryPools.java @ 12348:6e22e7042433

8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp Reviewed-by: brutisso, mgerdin
author ehelin
date Mon, 30 Sep 2013 11:39:07 +0200
parents 73d0d0218068
children f967da7f0c3c
comparison
equal deleted inserted replaced
12346:9ecd6d3782b1 12348:6e22e7042433
27 import com.oracle.java.testlibrary.*; 27 import com.oracle.java.testlibrary.*;
28 import static com.oracle.java.testlibrary.Asserts.*; 28 import static com.oracle.java.testlibrary.Asserts.*;
29 29
30 /* @test TestPerfCountersAndMemoryPools 30 /* @test TestPerfCountersAndMemoryPools
31 * @bug 8023476 31 * @bug 8023476
32 * @library /testlibrary
32 * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace 33 * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace
33 * report the same data. 34 * report the same data.
34 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools 35 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
35 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools 36 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
36 */ 37 */
37 public class TestPerfCountersAndMemoryPools { 38 public class TestPerfCountersAndMemoryPools {
38 public static void main(String[] args) throws Exception { 39 public static void main(String[] args) throws Exception {
39 checkMemoryUsage("Metaspace", "sun.gc.metaspace"); 40 checkMemoryUsage("Metaspace", "sun.gc.metaspace");
40 41
41 if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) { 42 if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) {
42 checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace"); 43 checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace");
43 } 44 }
44 } 45 }
45 46
46 private static MemoryUsage getMemoryUsage(String memoryPoolName) { 47 private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) {
47 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); 48 List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
48 for (MemoryPoolMXBean pool : pools) { 49 for (MemoryPoolMXBean pool : pools) {
49 if (pool.getName().equals(memoryPoolName)) { 50 if (pool.getName().equals(memoryPoolName)) {
50 return pool.getUsage(); 51 return pool;
51 } 52 }
52 } 53 }
53 54
54 throw new RuntimeException("Excpted to find a memory pool with name " + 55 throw new RuntimeException("Excpted to find a memory pool with name " +
55 memoryPoolName); 56 memoryPoolName);
56 } 57 }
57 58
58 private static void checkMemoryUsage(String memoryPoolName, String perfNS) 59 private static void checkMemoryUsage(String memoryPoolName, String perfNS)
59 throws Exception { 60 throws Exception {
60 // Need to do a gc before each comparison to update the perf counters 61 MemoryPoolMXBean pool = getMemoryPool(memoryPoolName);
61 62
63 // Must do a GC to update performance counters
62 System.gc(); 64 System.gc();
63 MemoryUsage mu = getMemoryUsage(memoryPoolName); 65 assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
64 assertEQ(getMinCapacity(perfNS), mu.getInit());
65 66
67 // Must do a second GC to update the perfomance counters again, since
68 // the call pool.getUsage().getInit() could have allocated some
69 // metadata.
66 System.gc(); 70 System.gc();
67 mu = getMemoryUsage(memoryPoolName); 71 assertEQ(getUsed(perfNS), pool.getUsage().getUsed());
68 assertEQ(getUsed(perfNS), mu.getUsed()); 72 assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
69
70 System.gc();
71 mu = getMemoryUsage(memoryPoolName);
72 assertEQ(getCapacity(perfNS), mu.getCommitted());
73 } 73 }
74 74
75 private static long getMinCapacity(String ns) throws Exception { 75 private static long getMinCapacity(String ns) throws Exception {
76 return PerfCounters.findByName(ns + ".minCapacity").longValue(); 76 return PerfCounters.findByName(ns + ".minCapacity").longValue();
77 } 77 }