comparison test/gc/metaspace/TestMetaspacePerfCounters.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
59 checkUsedIncreasesWhenLoadingClass(metaspace); 59 checkUsedIncreasesWhenLoadingClass(metaspace);
60 } 60 }
61 } 61 }
62 62
63 private static void checkPerfCounters(String ns) throws Exception { 63 private static void checkPerfCounters(String ns) throws Exception {
64 for (PerfCounter counter : countersInNamespace(ns)) { 64 long minCapacity = getMinCapacity(ns);
65 String msg = "Expected " + counter.getName() + " to be larger than 0"; 65 long maxCapacity = getMaxCapacity(ns);
66 assertGT(counter.longValue(), 0L, msg); 66 long capacity = getCapacity(ns);
67 } 67 long used = getUsed(ns);
68
69 assertGTE(minCapacity, 0L);
70 assertGTE(used, minCapacity);
71 assertGTE(capacity, used);
72 assertGTE(maxCapacity, capacity);
68 } 73 }
69 74
70 private static void checkEmptyPerfCounters(String ns) throws Exception { 75 private static void checkEmptyPerfCounters(String ns) throws Exception {
71 for (PerfCounter counter : countersInNamespace(ns)) { 76 for (PerfCounter counter : countersInNamespace(ns)) {
72 String msg = "Expected " + counter.getName() + " to equal 0"; 77 String msg = "Expected " + counter.getName() + " to equal 0";
73 assertEQ(counter.longValue(), 0L, msg); 78 assertEQ(counter.longValue(), 0L, msg);
74 } 79 }
75 } 80 }
76 81
77 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception { 82 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
78 PerfCounter used = PerfCounters.findByName(ns + ".used"); 83 long before = getUsed(ns);
79
80 long before = used.longValue();
81 fooClass = compileAndLoad("Foo", "public class Foo { }"); 84 fooClass = compileAndLoad("Foo", "public class Foo { }");
82 System.gc(); 85 System.gc();
83 long after = used.longValue(); 86 long after = getUsed(ns);
84 87
85 assertGT(after, before); 88 assertGT(after, before);
86 } 89 }
87 90
88 private static List<PerfCounter> countersInNamespace(String ns) throws Exception { 91 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
99 } 102 }
100 103
101 private static boolean isUsingCompressedClassPointers() { 104 private static boolean isUsingCompressedClassPointers() {
102 return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers"); 105 return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
103 } 106 }
107
108 private static long getMinCapacity(String ns) throws Exception {
109 return PerfCounters.findByName(ns + ".minCapacity").longValue();
110 }
111
112 private static long getCapacity(String ns) throws Exception {
113 return PerfCounters.findByName(ns + ".capacity").longValue();
114 }
115
116 private static long getMaxCapacity(String ns) throws Exception {
117 return PerfCounters.findByName(ns + ".maxCapacity").longValue();
118 }
119
120 private static long getUsed(String ns) throws Exception {
121 return PerfCounters.findByName(ns + ".used").longValue();
122 }
104 } 123 }