67 private static void checkPerfCounters(String ns) throws Exception {
68 long minCapacity = getMinCapacity(ns);
69 long maxCapacity = getMaxCapacity(ns);
70 long capacity = getCapacity(ns);
71 long used = getUsed(ns);
72
73 assertGTE(minCapacity, 0L);
74 assertGTE(used, minCapacity);
75 assertGTE(capacity, used);
76 assertGTE(maxCapacity, capacity);
77 }
78
79 private static void checkEmptyPerfCounters(String ns) throws Exception {
80 for (PerfCounter counter : countersInNamespace(ns)) {
81 String msg = "Expected " + counter.getName() + " to equal 0";
82 assertEQ(counter.longValue(), 0L, msg);
83 }
84 }
85
86 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
87 long before = getUsed(ns);
88 fooClass = compileAndLoad("Foo", "public class Foo { }");
89 System.gc();
90 long after = getUsed(ns);
91
92 assertGT(after, before);
93 }
94
95 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
96 List<PerfCounter> counters = new ArrayList<>();
97 for (String name : counterNames) {
98 counters.add(PerfCounters.findByName(ns + "." + name));
99 }
100 return counters;
101 }
102
103 private static Class<?> compileAndLoad(String name, String source) throws Exception {
104 byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
105 return ByteCodeLoader.load(name, byteCode);
106 }
|
67 private static void checkPerfCounters(String ns) throws Exception {
68 long minCapacity = getMinCapacity(ns);
69 long maxCapacity = getMaxCapacity(ns);
70 long capacity = getCapacity(ns);
71 long used = getUsed(ns);
72
73 assertGTE(minCapacity, 0L);
74 assertGTE(used, minCapacity);
75 assertGTE(capacity, used);
76 assertGTE(maxCapacity, capacity);
77 }
78
79 private static void checkEmptyPerfCounters(String ns) throws Exception {
80 for (PerfCounter counter : countersInNamespace(ns)) {
81 String msg = "Expected " + counter.getName() + " to equal 0";
82 assertEQ(counter.longValue(), 0L, msg);
83 }
84 }
85
86 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
87 // Need to ensure that used is up to date and the all unloadable
88 // classes are unloaded before doing this check.
89 System.gc();
90 long before = getUsed(ns);
91 fooClass = compileAndLoad("Foo", "public class Foo { }");
92 System.gc();
93 long after = getUsed(ns);
94
95 assertGT(after, before);
96 }
97
98 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
99 List<PerfCounter> counters = new ArrayList<>();
100 for (String name : counterNames) {
101 counters.add(PerfCounters.findByName(ns + "." + name));
102 }
103 return counters;
104 }
105
106 private static Class<?> compileAndLoad(String name, String source) throws Exception {
107 byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
108 return ByteCodeLoader.load(name, byteCode);
109 }
|