< prev index next >

test/hotspot/jtreg/gc/metaspace/TestMetaspacePerfCounters.java

Print this page

 30 import jdk.test.lib.ByteCodeLoader;
 31 import jdk.test.lib.compiler.InMemoryJavaCompiler;
 32 import jdk.test.lib.Platform;
 33 
 34 import sun.management.ManagementFactoryHelper;
 35 
 36 import static jdk.test.lib.Asserts.*;
 37 import gc.testlibrary.PerfCounter;
 38 import gc.testlibrary.PerfCounters;
 39 
 40 /* @test TestMetaspacePerfCountersSerial
 41  * @bug 8014659
 42  * @requires vm.gc.Serial
 43  * @library /test/lib /
 44  * @summary Tests that performance counters for metaspace and compressed class
 45  *          space exists and works.
 46  * @modules java.base/jdk.internal.misc
 47  *          java.compiler
 48  *          java.management/sun.management
 49  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 50  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC gc.metaspace.TestMetaspacePerfCounters
 51  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC gc.metaspace.TestMetaspacePerfCounters
 52  */
 53 
 54 /* @test TestMetaspacePerfCountersParallel
 55  * @bug 8014659
 56  * @requires vm.gc.Parallel
 57  * @library /test/lib /
 58  * @summary Tests that performance counters for metaspace and compressed class
 59  *          space exists and works.
 60  * @modules java.base/jdk.internal.misc
 61  *          java.compiler
 62  *          java.management/sun.management
 63  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 64  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC gc.metaspace.TestMetaspacePerfCounters
 65  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC gc.metaspace.TestMetaspacePerfCounters
 66  */
 67 
 68 /* @test TestMetaspacePerfCountersG1
 69  * @bug 8014659
 70  * @requires vm.gc.G1
 71  * @library /test/lib /
 72  * @summary Tests that performance counters for metaspace and compressed class
 73  *          space exists and works.
 74  * @modules java.base/jdk.internal.misc
 75  *          java.compiler
 76  *          java.management/sun.management
 77  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 78  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC gc.metaspace.TestMetaspacePerfCounters
 79  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC gc.metaspace.TestMetaspacePerfCounters
 80  */
 81 
 82 /* @test TestMetaspacePerfCountersShenandoah
 83  * @bug 8014659
 84  * @requires vm.gc.Shenandoah
 85  * @library /test/lib /
 86  * @summary Tests that performance counters for metaspace and compressed class
 87  *          space exists and works.
 88  * @modules java.base/jdk.internal.misc
 89  *          java.compiler
 90  *          java.management/sun.management
 91  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 92  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC gc.metaspace.TestMetaspacePerfCounters
 93  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC gc.metaspace.TestMetaspacePerfCounters
 94  */
 95 public class TestMetaspacePerfCounters {
 96     public static Class<?> fooClass = null;
 97     private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
 98     private static final List<GarbageCollectorMXBean> gcBeans = ManagementFactoryHelper.getGarbageCollectorMXBeans();
 99 
100     public static void main(String[] args) throws Exception {
101         String metaspace = "sun.gc.metaspace";
102         String ccs = "sun.gc.compressedclassspace";
103 
104         checkPerfCounters(metaspace);
105 
106         if (isUsingCompressedClassPointers()) {
107             checkPerfCounters(ccs);
108             checkUsedIncreasesWhenLoadingClass(ccs);
109         } else {
110             checkEmptyPerfCounters(ccs);
111             checkUsedIncreasesWhenLoadingClass(metaspace);
112         }
113     }

157         System.gc();
158         long after = getUsed(ns);
159 
160         assertGT(after, before);
161     }
162 
163     private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
164         List<PerfCounter> counters = new ArrayList<>();
165         for (String name : counterNames) {
166             counters.add(PerfCounters.findByName(ns + "." + name));
167         }
168         return counters;
169     }
170 
171     private static Class<?> compileAndLoad(String name, String source) throws Exception {
172         byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
173         return ByteCodeLoader.load(name, byteCode);
174     }
175 
176     private static boolean isUsingCompressedClassPointers() {
177         return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
178     }
179 
180     private static long getMinCapacity(String ns) throws Exception {
181         return PerfCounters.findByName(ns + ".minCapacity").longValue();
182     }
183 
184     private static long getCapacity(String ns) throws Exception {
185         return PerfCounters.findByName(ns + ".capacity").longValue();
186     }
187 
188     private static long getMaxCapacity(String ns) throws Exception {
189         return PerfCounters.findByName(ns + ".maxCapacity").longValue();
190     }
191 
192     private static long getUsed(String ns) throws Exception {
193         return PerfCounters.findByName(ns + ".used").longValue();
194     }
195 
196     private static long currentGCCount() {
197         long gcCount = 0;

 30 import jdk.test.lib.ByteCodeLoader;
 31 import jdk.test.lib.compiler.InMemoryJavaCompiler;
 32 import jdk.test.lib.Platform;
 33 
 34 import sun.management.ManagementFactoryHelper;
 35 
 36 import static jdk.test.lib.Asserts.*;
 37 import gc.testlibrary.PerfCounter;
 38 import gc.testlibrary.PerfCounters;
 39 
 40 /* @test TestMetaspacePerfCountersSerial
 41  * @bug 8014659
 42  * @requires vm.gc.Serial
 43  * @library /test/lib /
 44  * @summary Tests that performance counters for metaspace and compressed class
 45  *          space exists and works.
 46  * @modules java.base/jdk.internal.misc
 47  *          java.compiler
 48  *          java.management/sun.management
 49  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 50  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:+UsePerfData -XX:+UseSerialGC gc.metaspace.TestMetaspacePerfCounters
 51  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UsePerfData -XX:+UseSerialGC gc.metaspace.TestMetaspacePerfCounters
 52  */
 53 
 54 /* @test TestMetaspacePerfCountersParallel
 55  * @bug 8014659
 56  * @requires vm.gc.Parallel
 57  * @library /test/lib /
 58  * @summary Tests that performance counters for metaspace and compressed class
 59  *          space exists and works.
 60  * @modules java.base/jdk.internal.misc
 61  *          java.compiler
 62  *          java.management/sun.management
 63  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 64  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:+UsePerfData -XX:+UseParallelGC gc.metaspace.TestMetaspacePerfCounters
 65  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UsePerfData -XX:+UseParallelGC gc.metaspace.TestMetaspacePerfCounters
 66  */
 67 
 68 /* @test TestMetaspacePerfCountersG1
 69  * @bug 8014659
 70  * @requires vm.gc.G1
 71  * @library /test/lib /
 72  * @summary Tests that performance counters for metaspace and compressed class
 73  *          space exists and works.
 74  * @modules java.base/jdk.internal.misc
 75  *          java.compiler
 76  *          java.management/sun.management
 77  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 78  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:+UsePerfData -XX:+UseG1GC gc.metaspace.TestMetaspacePerfCounters
 79  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UsePerfData -XX:+UseG1GC gc.metaspace.TestMetaspacePerfCounters
 80  */
 81 
 82 /* @test TestMetaspacePerfCountersShenandoah
 83  * @bug 8014659
 84  * @requires vm.gc.Shenandoah
 85  * @library /test/lib /
 86  * @summary Tests that performance counters for metaspace and compressed class
 87  *          space exists and works.
 88  * @modules java.base/jdk.internal.misc
 89  *          java.compiler
 90  *          java.management/sun.management
 91  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 92  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC gc.metaspace.TestMetaspacePerfCounters
 93  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC gc.metaspace.TestMetaspacePerfCounters
 94  */
 95 public class TestMetaspacePerfCounters {
 96     public static Class<?> fooClass = null;
 97     private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
 98     private static final List<GarbageCollectorMXBean> gcBeans = ManagementFactoryHelper.getGarbageCollectorMXBeans();
 99 
100     public static void main(String[] args) throws Exception {
101         String metaspace = "sun.gc.metaspace";
102         String ccs = "sun.gc.compressedclassspace";
103 
104         checkPerfCounters(metaspace);
105 
106         if (isUsingCompressedClassPointers()) {
107             checkPerfCounters(ccs);
108             checkUsedIncreasesWhenLoadingClass(ccs);
109         } else {
110             checkEmptyPerfCounters(ccs);
111             checkUsedIncreasesWhenLoadingClass(metaspace);
112         }
113     }

157         System.gc();
158         long after = getUsed(ns);
159 
160         assertGT(after, before);
161     }
162 
163     private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
164         List<PerfCounter> counters = new ArrayList<>();
165         for (String name : counterNames) {
166             counters.add(PerfCounters.findByName(ns + "." + name));
167         }
168         return counters;
169     }
170 
171     private static Class<?> compileAndLoad(String name, String source) throws Exception {
172         byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
173         return ByteCodeLoader.load(name, byteCode);
174     }
175 
176     private static boolean isUsingCompressedClassPointers() {
177         return Platform.is64bit();
178     }
179 
180     private static long getMinCapacity(String ns) throws Exception {
181         return PerfCounters.findByName(ns + ".minCapacity").longValue();
182     }
183 
184     private static long getCapacity(String ns) throws Exception {
185         return PerfCounters.findByName(ns + ".capacity").longValue();
186     }
187 
188     private static long getMaxCapacity(String ns) throws Exception {
189         return PerfCounters.findByName(ns + ".maxCapacity").longValue();
190     }
191 
192     private static long getUsed(String ns) throws Exception {
193         return PerfCounters.findByName(ns + ".used").longValue();
194     }
195 
196     private static long currentGCCount() {
197         long gcCount = 0;
< prev index next >