Skip to content

Commit

Permalink
8151460: Metaspace counters can have inconsistent values
Browse files Browse the repository at this point in the history
Reviewed-by: phh, sgehwolf
Backport-of: d30aeec30c3832b2514a6f06451897afdaf52fb3
  • Loading branch information
tstuefe committed Apr 19, 2023
1 parent 721c0ee commit 43561ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ private static void checkEmptyPerfCounters(String ns) throws Exception {
}

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();
Expand Down
26 changes: 17 additions & 9 deletions hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
* @requires vm.gc=="Serial" | vm.gc=="null"
* @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 -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");
}
}
Expand All @@ -61,16 +61,24 @@ private static void checkMemoryUsage(String memoryPoolName, String perfNS)
throws Exception {
MemoryPoolMXBean pool = getMemoryPool(memoryPoolName);

// First, call all the methods to let them allocate their own slab of metadata
getMinCapacity(perfNS);
getCapacity(perfNS);
getUsed(perfNS);
pool.getUsage().getInit();
pool.getUsage().getUsed();
pool.getUsage().getCommitted();
assertEQ(1L, 1L, "Make assert load");

// Must do a GC to update performance counters
System.gc();
assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit(), "MinCapacity out of sync");

// Must do a second GC to update the perfomance counters again, since
// the call pool.getUsage().getInit() could have allocated some
// metadata.
// 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());
assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
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 {
Expand Down

1 comment on commit 43561ef

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.