Merge
authorehelin
Wed, 02 Oct 2013 18:24:58 +0200
changeset 20315 ea964395b9e9
parent 20313 27b50af2ba5a (current diff)
parent 20314 150e62794be5 (diff)
child 20316 d3ef45219aac
Merge
--- a/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java	Wed Oct 02 14:33:32 2013 +0200
+++ b/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java	Wed Oct 02 18:24:58 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<MemoryPoolMXBean> 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 {