Mercurial > hg > truffle
comparison test/gc/metaspace/TestMetaspaceMemoryPool.java @ 12248:73d0d0218068
8024718: Metaspace performance counters and memory pools should report the same data
Reviewed-by: stefank, dholmes, coleenp
author | ehelin |
---|---|
date | Tue, 17 Sep 2013 20:59:07 +0200 |
parents | 7944aba7ba41 |
children |
comparison
equal
deleted
inserted
replaced
12247:fac394091d73 | 12248:73d0d0218068 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 | 23 |
24 import java.util.List; | 24 import java.util.List; |
25 import java.lang.management.ManagementFactory; | 25 import java.lang.management.*; |
26 import java.lang.management.MemoryManagerMXBean; | 26 import com.oracle.java.testlibrary.*; |
27 import java.lang.management.MemoryPoolMXBean; | 27 import static com.oracle.java.testlibrary.Asserts.*; |
28 import java.lang.management.MemoryUsage; | |
29 | |
30 import java.lang.management.RuntimeMXBean; | |
31 import java.lang.management.ManagementFactory; | |
32 | 28 |
33 /* @test TestMetaspaceMemoryPool | 29 /* @test TestMetaspaceMemoryPool |
34 * @bug 8000754 | 30 * @bug 8000754 |
35 * @summary Tests that a MemoryPoolMXBeans is created for metaspace and that a | 31 * @summary Tests that a MemoryPoolMXBeans is created for metaspace and that a |
36 * MemoryManagerMXBean is created. | 32 * MemoryManagerMXBean is created. |
33 * @library /testlibrary | |
37 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops TestMetaspaceMemoryPool | 34 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops TestMetaspaceMemoryPool |
38 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m TestMetaspaceMemoryPool | 35 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m TestMetaspaceMemoryPool |
39 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers TestMetaspaceMemoryPool | 36 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers TestMetaspaceMemoryPool |
40 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:CompressedClassSpaceSize=60m TestMetaspaceMemoryPool | 37 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:CompressedClassSpaceSize=60m TestMetaspaceMemoryPool |
41 */ | 38 */ |
42 public class TestMetaspaceMemoryPool { | 39 public class TestMetaspaceMemoryPool { |
43 public static void main(String[] args) { | 40 public static void main(String[] args) { |
44 verifyThatMetaspaceMemoryManagerExists(); | 41 verifyThatMetaspaceMemoryManagerExists(); |
45 verifyMemoryPool(getMemoryPool("Metaspace"), isFlagDefined("MaxMetaspaceSize")); | |
46 | 42 |
47 if (runsOn64bit()) { | 43 boolean isMetaspaceMaxDefined = InputArguments.containsPrefix("-XX:MaxMetaspaceSize"); |
48 if (usesCompressedOops()) { | 44 verifyMemoryPool(getMemoryPool("Metaspace"), isMetaspaceMaxDefined); |
45 | |
46 if (Platform.is64bit()) { | |
47 if (InputArguments.contains("-XX:+UseCompressedOops")) { | |
49 MemoryPoolMXBean cksPool = getMemoryPool("Compressed Class Space"); | 48 MemoryPoolMXBean cksPool = getMemoryPool("Compressed Class Space"); |
50 verifyMemoryPool(cksPool, true); | 49 verifyMemoryPool(cksPool, true); |
51 } | 50 } |
52 } | 51 } |
53 } | |
54 | |
55 private static boolean runsOn64bit() { | |
56 return !System.getProperty("sun.arch.data.model").equals("32"); | |
57 } | |
58 | |
59 private static boolean usesCompressedOops() { | |
60 return isFlagDefined("+UseCompressedOops"); | |
61 } | |
62 | |
63 private static boolean isFlagDefined(String name) { | |
64 RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); | |
65 List<String> args = runtimeMxBean.getInputArguments(); | |
66 for (String arg : args) { | |
67 if (arg.startsWith("-XX:" + name)) { | |
68 return true; | |
69 } | |
70 } | |
71 return false; | |
72 } | 52 } |
73 | 53 |
74 private static void verifyThatMetaspaceMemoryManagerExists() { | 54 private static void verifyThatMetaspaceMemoryManagerExists() { |
75 List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans(); | 55 List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans(); |
76 for (MemoryManagerMXBean manager : managers) { | 56 for (MemoryManagerMXBean manager : managers) { |
93 throw new RuntimeException("Expected to find a memory pool with name " + name); | 73 throw new RuntimeException("Expected to find a memory pool with name " + name); |
94 } | 74 } |
95 | 75 |
96 private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) { | 76 private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) { |
97 MemoryUsage mu = pool.getUsage(); | 77 MemoryUsage mu = pool.getUsage(); |
98 assertDefined(mu.getInit(), "init"); | 78 long init = mu.getInit(); |
99 assertDefined(mu.getUsed(), "used"); | 79 long used = mu.getUsed(); |
100 assertDefined(mu.getCommitted(), "committed"); | 80 long committed = mu.getCommitted(); |
81 long max = mu.getMax(); | |
82 | |
83 assertGTE(init, 0L); | |
84 assertGTE(used, init); | |
85 assertGTE(committed, used); | |
101 | 86 |
102 if (isMaxDefined) { | 87 if (isMaxDefined) { |
103 assertDefined(mu.getMax(), "max"); | 88 assertGTE(max, committed); |
104 } else { | 89 } else { |
105 assertUndefined(mu.getMax(), "max"); | 90 assertEQ(max, -1L); |
106 } | |
107 } | |
108 | |
109 private static void assertDefined(long value, String name) { | |
110 assertTrue(value != -1, "Expected " + name + " to be defined"); | |
111 } | |
112 | |
113 private static void assertUndefined(long value, String name) { | |
114 assertEquals(value, -1, "Expected " + name + " to be undefined"); | |
115 } | |
116 | |
117 private static void assertEquals(long actual, long expected, String msg) { | |
118 assertTrue(actual == expected, msg); | |
119 } | |
120 | |
121 private static void assertTrue(boolean condition, String msg) { | |
122 if (!condition) { | |
123 throw new RuntimeException(msg); | |
124 } | 91 } |
125 } | 92 } |
126 } | 93 } |