8151460: Metaspace counters can have inconsistent values
Reviewed-by: jmasa, pliden
--- 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 {