test/gc/metaspace/TestMetaspacePerfCounters.java

Wed, 07 Aug 2013 16:47:32 +0200

author
ehelin
date
Wed, 07 Aug 2013 16:47:32 +0200
changeset 5531
1a8fb39bdbc4
child 5694
7944aba7ba41
permissions
-rw-r--r--

8014659: NPG: performance counters for compressed klass space
Reviewed-by: mgerdin, coleenp, hseigel, jmasa, ctornqvi

ehelin@5531 1 /*
ehelin@5531 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
ehelin@5531 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ehelin@5531 4 *
ehelin@5531 5 * This code is free software; you can redistribute it and/or modify it
ehelin@5531 6 * under the terms of the GNU General Public License version 2 only, as
ehelin@5531 7 * published by the Free Software Foundation.
ehelin@5531 8 *
ehelin@5531 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ehelin@5531 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ehelin@5531 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ehelin@5531 12 * version 2 for more details (a copy is included in the LICENSE file that
ehelin@5531 13 * accompanied this code).
ehelin@5531 14 *
ehelin@5531 15 * You should have received a copy of the GNU General Public License version
ehelin@5531 16 * 2 along with this work; if not, write to the Free Software Foundation,
ehelin@5531 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ehelin@5531 18 *
ehelin@5531 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ehelin@5531 20 * or visit www.oracle.com if you need additional information or have any
ehelin@5531 21 * questions.
ehelin@5531 22 */
ehelin@5531 23
ehelin@5531 24 import java.util.List;
ehelin@5531 25 import java.util.ArrayList;
ehelin@5531 26
ehelin@5531 27 import com.oracle.java.testlibrary.*;
ehelin@5531 28 import static com.oracle.java.testlibrary.Asserts.*;
ehelin@5531 29
ehelin@5531 30 /* @test TestMetaspacePerfCounters
ehelin@5531 31 * @bug 8014659
ehelin@5531 32 * @library /testlibrary
ehelin@5531 33 * @summary Tests that performance counters for metaspace and compressed class
ehelin@5531 34 * space exists and works.
ehelin@5531 35 *
ehelin@5531 36 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
ehelin@5531 37 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
ehelin@5531 38 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
ehelin@5531 39 *
ehelin@5531 40 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
ehelin@5531 41 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
ehelin@5531 42 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
ehelin@5531 43 */
ehelin@5531 44 public class TestMetaspacePerfCounters {
ehelin@5531 45 public static Class fooClass = null;
ehelin@5531 46 private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
ehelin@5531 47
ehelin@5531 48 public static void main(String[] args) throws Exception {
ehelin@5531 49 String metaspace = "sun.gc.metaspace";
ehelin@5531 50 String ccs = "sun.gc.compressedclassspace";
ehelin@5531 51
ehelin@5531 52 checkPerfCounters(metaspace);
ehelin@5531 53
ehelin@5531 54 if (isUsingCompressedClassPointers()) {
ehelin@5531 55 checkPerfCounters(ccs);
ehelin@5531 56 checkUsedIncreasesWhenLoadingClass(ccs);
ehelin@5531 57 } else {
ehelin@5531 58 checkEmptyPerfCounters(ccs);
ehelin@5531 59 checkUsedIncreasesWhenLoadingClass(metaspace);
ehelin@5531 60 }
ehelin@5531 61 }
ehelin@5531 62
ehelin@5531 63 private static void checkPerfCounters(String ns) throws Exception {
ehelin@5531 64 for (PerfCounter counter : countersInNamespace(ns)) {
ehelin@5531 65 String msg = "Expected " + counter.getName() + " to be larger than 0";
ehelin@5531 66 assertGT(counter.longValue(), 0L, msg);
ehelin@5531 67 }
ehelin@5531 68 }
ehelin@5531 69
ehelin@5531 70 private static void checkEmptyPerfCounters(String ns) throws Exception {
ehelin@5531 71 for (PerfCounter counter : countersInNamespace(ns)) {
ehelin@5531 72 String msg = "Expected " + counter.getName() + " to equal 0";
ehelin@5531 73 assertEQ(counter.longValue(), 0L, msg);
ehelin@5531 74 }
ehelin@5531 75 }
ehelin@5531 76
ehelin@5531 77 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
ehelin@5531 78 PerfCounter used = PerfCounters.findByName(ns + ".used");
ehelin@5531 79
ehelin@5531 80 long before = used.longValue();
ehelin@5531 81 fooClass = compileAndLoad("Foo", "public class Foo { }");
ehelin@5531 82 System.gc();
ehelin@5531 83 long after = used.longValue();
ehelin@5531 84
ehelin@5531 85 assertGT(after, before);
ehelin@5531 86 }
ehelin@5531 87
ehelin@5531 88 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
ehelin@5531 89 List<PerfCounter> counters = new ArrayList<>();
ehelin@5531 90 for (String name : counterNames) {
ehelin@5531 91 counters.add(PerfCounters.findByName(ns + "." + name));
ehelin@5531 92 }
ehelin@5531 93 return counters;
ehelin@5531 94 }
ehelin@5531 95
ehelin@5531 96 private static Class<?> compileAndLoad(String name, String source) throws Exception {
ehelin@5531 97 byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
ehelin@5531 98 return ByteCodeLoader.load(name, byteCode);
ehelin@5531 99 }
ehelin@5531 100
ehelin@5531 101 private static boolean isUsingCompressedClassPointers() {
ehelin@5531 102 return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedKlassPointers");
ehelin@5531 103 }
ehelin@5531 104 }

mercurial