changeset 37244:9b8f2dc281ad

8151460: Metaspace counters can have inconsistent values Reviewed-by: jmasa, pliden
author sjohanss
date Thu, 24 Mar 2016 10:49:08 +0100
parents 34e1821bde93
children 55d19e96f149
files hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java	Mon Apr 04 11:32:04 2016 +0200
+++ b/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java	Thu Mar 24 10:49:08 2016 +0100
@@ -84,6 +84,9 @@
     }
 
     private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
+        // Need to ensure that used is up to date and that all unreachable
+        // classes are unloaded before doing this check.
+        System.gc();
         long before = getUsed(ns);
         fooClass = compileAndLoad("Foo", "public class Foo { }");
         System.gc();
--- a/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java	Mon Apr 04 11:32:04 2016 +0200
+++ b/hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java	Thu Mar 24 10:49:08 2016 +0100
@@ -36,14 +36,14 @@
  * @modules java.base/sun.misc
  *          java.management
  *          jdk.jvmstat/sun.jvmstat.monitor
- * @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
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
  */
 public class TestPerfCountersAndMemoryPools {
     public static void main(String[] args) throws Exception {
         checkMemoryUsage("Metaspace", "sun.gc.metaspace");
 
-        if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) {
+        if (InputArguments.contains("-XX:+UseCompressedClassPointers") && Platform.is64bit()) {
             checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace");
         }
     }
@@ -71,13 +71,17 @@
         pool.getUsage().getInit();
         pool.getUsage().getUsed();
         pool.getUsage().getCommitted();
-        assertEQ(1L, 1L);
+        assertEQ(1L, 1L, "Make assert load");
 
         // Must do a GC to update performance counters
         System.gc();
-        assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
-        assertEQ(getUsed(perfNS), pool.getUsage().getUsed());
-        assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
+        assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit(), "MinCapacity out of sync");
+
+        // Adding a second GC due to metadata allocations caused by getting the
+        // initial size from the pool. This is needed when running with -Xcomp.
+        System.gc();
+        assertEQ(getUsed(perfNS), pool.getUsage().getUsed(), "Used out of sync");
+        assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted(), "Committed out of sync");
     }
 
     private static long getMinCapacity(String ns) throws Exception {