Skip to content

Commit

Permalink
8293503: gc/metaspace/TestMetaspacePerfCounters.java#Epsilon-64 faile…
Browse files Browse the repository at this point in the history
…d assertGreaterThanOrEqual: expected MMM >= NNN

Reviewed-by: lkorinth, kbarrett
  • Loading branch information
Thomas Schatzl committed Sep 19, 2022
1 parent d77c464 commit 04d7b7d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 56 deletions.
1 change: 0 additions & 1 deletion test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ gc/stress/gclocker/TestGCLockerWithG1.java 8180622 generic-all
gc/stress/TestJNIBlockFullGC/TestJNIBlockFullGC.java 8192647 generic-all
gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java 8241293 macosx-x64
gc/stress/TestStressG1Humongous.java 8286554 windows-x64
gc/metaspace/TestMetaspacePerfCounters.java#Epsilon-64 8293503 generic-all

#############################################################################

Expand Down
118 changes: 63 additions & 55 deletions test/hotspot/jtreg/gc/metaspace/TestMetaspacePerfCounters.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package gc.metaspace;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.invoke.VarHandle;
import java.util.List;
import java.util.ArrayList;

Expand Down Expand Up @@ -183,10 +183,44 @@
* @run main/othervm -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.metaspace.TestMetaspacePerfCounters
*/

class PerfCounterSnapshot {
private static long getMinCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".minCapacity").longValue();
}

private static long getCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".capacity").longValue();
}

private static long getMaxCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".maxCapacity").longValue();
}

private static long getUsed(String ns) throws Exception {
return PerfCounters.findByName(ns + ".used").longValue();
}

public long minCapacity;
public long maxCapacity;
public long capacity;
public long used;

public void get(String ns) throws Exception {
minCapacity = getMinCapacity(ns);
maxCapacity = getMaxCapacity(ns);
used = getUsed(ns);
capacity = getCapacity(ns);
}

public boolean consistentWith(PerfCounterSnapshot other) {
return (minCapacity == other.minCapacity) && (maxCapacity == other.maxCapacity) &&
(used == other.used) && (capacity == other.capacity);
}
}

public class TestMetaspacePerfCounters {
public static Class<?> fooClass = null;
private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
private static final List<GarbageCollectorMXBean> gcBeans = ManagementFactoryHelper.getGarbageCollectorMXBeans();

public static void main(String[] args) throws Exception {
String metaspace = "sun.gc.metaspace";
Expand All @@ -204,32 +238,28 @@ public static void main(String[] args) throws Exception {
}

private static void checkPerfCounters(String ns) throws Exception {
long gcCountBefore;
long gcCountAfter;
long minCapacity;
long maxCapacity;
long capacity;
long used;

// The perf counter values are updated during GC and to be able to
// do the assertions below we need to ensure that the values are from
// the same GC cycle.
do {
gcCountBefore = currentGCCount();

minCapacity = getMinCapacity(ns);
maxCapacity = getMaxCapacity(ns);
capacity = getCapacity(ns);
used = getUsed(ns);

gcCountAfter = currentGCCount();
assertGTE(gcCountAfter, gcCountBefore);
} while(gcCountAfter > gcCountBefore);

assertGTE(minCapacity, 0L);
assertGTE(used, minCapacity);
assertGTE(capacity, used);
assertGTE(maxCapacity, capacity);
PerfCounterSnapshot snap1 = new PerfCounterSnapshot();
PerfCounterSnapshot snap2 = new PerfCounterSnapshot();

final int MaxAttempts = 10;

for (int attempts = 0; ; attempts++) {
snap1.get(ns);
VarHandle.fullFence();
snap2.get(ns);

if (snap1.consistentWith(snap2)) {
// Got a consistent snapshot for examination.
break;
} else if (attempts == MaxAttempts) {
throw new Exception("Failed to get stable reading of metaspace performance counters after " + attempts + " tries");
}
}

assertGTE(snap1.minCapacity, 0L);
assertGTE(snap1.used, snap1.minCapacity);
assertGTE(snap1.capacity, snap1.used);
assertGTE(snap1.maxCapacity, snap1.capacity);
}

private static void checkEmptyPerfCounters(String ns) throws Exception {
Expand All @@ -243,12 +273,14 @@ private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Excepti
// 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);
PerfCounterSnapshot before = new PerfCounterSnapshot();
before.get(ns);
fooClass = compileAndLoad("Foo", "public class Foo { }");
System.gc();
long after = getUsed(ns);
PerfCounterSnapshot after = new PerfCounterSnapshot();
after.get(ns);

assertGT(after, before);
assertGT(after.used, before.used);
}

private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
Expand All @@ -267,28 +299,4 @@ private static Class<?> compileAndLoad(String name, String source) throws Except
private static boolean isUsingCompressedClassPointers() {
return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
}

private static long getMinCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".minCapacity").longValue();
}

private static long getCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".capacity").longValue();
}

private static long getMaxCapacity(String ns) throws Exception {
return PerfCounters.findByName(ns + ".maxCapacity").longValue();
}

private static long getUsed(String ns) throws Exception {
return PerfCounters.findByName(ns + ".used").longValue();
}

private static long currentGCCount() {
long gcCount = 0;
for (GarbageCollectorMXBean bean : gcBeans) {
gcCount += bean.getCollectionCount();
}
return gcCount;
}
}

1 comment on commit 04d7b7d

@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.