8151460: Metaspace counters can have inconsistent values

Reviewed-by: jmasa, pliden
This commit is contained in:
Stefan Johansson 2016-03-24 10:49:08 +01:00
parent 64efc0eb0f
commit d30aeec30c
2 changed files with 14 additions and 7 deletions

View File

@ -84,6 +84,9 @@ public class TestMetaspacePerfCounters {
}
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();

View File

@ -36,14 +36,14 @@ import static jdk.test.lib.Asserts.*;
* @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 @@ public class TestPerfCountersAndMemoryPools {
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 {