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

Merge

...@@ -29,10 +29,11 @@ import static com.oracle.java.testlibrary.Asserts.*; ...@@ -29,10 +29,11 @@ import static com.oracle.java.testlibrary.Asserts.*;
/* @test TestPerfCountersAndMemoryPools /* @test TestPerfCountersAndMemoryPools
* @bug 8023476 * @bug 8023476
* @library /testlibrary
* @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace * @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace
* report the same data. * 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 -Xint 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
*/ */
public class TestPerfCountersAndMemoryPools { public class TestPerfCountersAndMemoryPools {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
...@@ -43,11 +44,11 @@ public class TestPerfCountersAndMemoryPools { ...@@ -43,11 +44,11 @@ public class TestPerfCountersAndMemoryPools {
} }
} }
private static MemoryUsage getMemoryUsage(String memoryPoolName) { private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : pools) { for (MemoryPoolMXBean pool : pools) {
if (pool.getName().equals(memoryPoolName)) { if (pool.getName().equals(memoryPoolName)) {
return pool.getUsage(); return pool;
} }
} }
...@@ -57,19 +58,18 @@ public class TestPerfCountersAndMemoryPools { ...@@ -57,19 +58,18 @@ public class TestPerfCountersAndMemoryPools {
private static void checkMemoryUsage(String memoryPoolName, String perfNS) private static void checkMemoryUsage(String memoryPoolName, String perfNS)
throws Exception { 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(); System.gc();
MemoryUsage mu = getMemoryUsage(memoryPoolName); assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
assertEQ(getMinCapacity(perfNS), mu.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(); System.gc();
mu = getMemoryUsage(memoryPoolName); assertEQ(getUsed(perfNS), pool.getUsage().getUsed());
assertEQ(getUsed(perfNS), mu.getUsed()); assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
System.gc();
mu = getMemoryUsage(memoryPoolName);
assertEQ(getCapacity(perfNS), mu.getCommitted());
} }
private static long getMinCapacity(String ns) throws Exception { 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.
先完成此消息的编辑!
想要评论请 注册