提交 26a90292 编写于 作者: E ehelin

Merge

......@@ -29,10 +29,11 @@ import static com.oracle.java.testlibrary.Asserts.*;
/* @test TestPerfCountersAndMemoryPools
* @bug 8023476
* @library /testlibrary
* @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 TestPerfCountersAndMemoryPools
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools
* @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
*/
public class TestPerfCountersAndMemoryPools {
public static void main(String[] args) throws Exception {
......@@ -43,11 +44,11 @@ public class TestPerfCountersAndMemoryPools {
}
}
private static MemoryUsage getMemoryUsage(String memoryPoolName) {
private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : pools) {
if (pool.getName().equals(memoryPoolName)) {
return pool.getUsage();
return pool;
}
}
......@@ -57,19 +58,18 @@ public class TestPerfCountersAndMemoryPools {
private static void checkMemoryUsage(String memoryPoolName, String perfNS)
throws Exception {
// Need to do a gc before each comparison to update the perf counters
MemoryPoolMXBean pool = getMemoryPool(memoryPoolName);
// Must do a GC to update performance counters
System.gc();
MemoryUsage mu = getMemoryUsage(memoryPoolName);
assertEQ(getMinCapacity(perfNS), mu.getInit());
assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
// Must do a second GC to update the perfomance counters again, since
// the call pool.getUsage().getInit() could have allocated some
// metadata.
System.gc();
mu = getMemoryUsage(memoryPoolName);
assertEQ(getUsed(perfNS), mu.getUsed());
System.gc();
mu = getMemoryUsage(memoryPoolName);
assertEQ(getCapacity(perfNS), mu.getCommitted());
assertEQ(getUsed(perfNS), pool.getUsage().getUsed());
assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
}
private static long getMinCapacity(String ns) throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册