test/gc/metaspace/TestMetaspacePerfCounters.java

Tue, 28 Jan 2014 14:56:01 -0800

author
katleman
date
Tue, 28 Jan 2014 14:56:01 -0800
changeset 6578
2fdc8a2268d2
parent 5716
73d0d0218068
child 6876
710a3c8b516e
child 7785
f967da7f0c3c
permissions
-rw-r--r--

Added tag jdk8u5-b06 for changeset 956c0e048ef2

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@5694 36 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
ehelin@5694 37 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
ehelin@5694 38 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
ehelin@5531 39 *
ehelin@5694 40 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
ehelin@5694 41 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
ehelin@5694 42 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -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@5716 64 long minCapacity = getMinCapacity(ns);
ehelin@5716 65 long maxCapacity = getMaxCapacity(ns);
ehelin@5716 66 long capacity = getCapacity(ns);
ehelin@5716 67 long used = getUsed(ns);
ehelin@5716 68
ehelin@5716 69 assertGTE(minCapacity, 0L);
ehelin@5716 70 assertGTE(used, minCapacity);
ehelin@5716 71 assertGTE(capacity, used);
ehelin@5716 72 assertGTE(maxCapacity, capacity);
ehelin@5531 73 }
ehelin@5531 74
ehelin@5531 75 private static void checkEmptyPerfCounters(String ns) throws Exception {
ehelin@5531 76 for (PerfCounter counter : countersInNamespace(ns)) {
ehelin@5531 77 String msg = "Expected " + counter.getName() + " to equal 0";
ehelin@5531 78 assertEQ(counter.longValue(), 0L, msg);
ehelin@5531 79 }
ehelin@5531 80 }
ehelin@5531 81
ehelin@5531 82 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
ehelin@5716 83 long before = getUsed(ns);
ehelin@5531 84 fooClass = compileAndLoad("Foo", "public class Foo { }");
ehelin@5531 85 System.gc();
ehelin@5716 86 long after = getUsed(ns);
ehelin@5531 87
ehelin@5531 88 assertGT(after, before);
ehelin@5531 89 }
ehelin@5531 90
ehelin@5531 91 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
ehelin@5531 92 List<PerfCounter> counters = new ArrayList<>();
ehelin@5531 93 for (String name : counterNames) {
ehelin@5531 94 counters.add(PerfCounters.findByName(ns + "." + name));
ehelin@5531 95 }
ehelin@5531 96 return counters;
ehelin@5531 97 }
ehelin@5531 98
ehelin@5531 99 private static Class<?> compileAndLoad(String name, String source) throws Exception {
ehelin@5531 100 byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
ehelin@5531 101 return ByteCodeLoader.load(name, byteCode);
ehelin@5531 102 }
ehelin@5531 103
ehelin@5531 104 private static boolean isUsingCompressedClassPointers() {
ehelin@5694 105 return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
ehelin@5531 106 }
ehelin@5716 107
ehelin@5716 108 private static long getMinCapacity(String ns) throws Exception {
ehelin@5716 109 return PerfCounters.findByName(ns + ".minCapacity").longValue();
ehelin@5716 110 }
ehelin@5716 111
ehelin@5716 112 private static long getCapacity(String ns) throws Exception {
ehelin@5716 113 return PerfCounters.findByName(ns + ".capacity").longValue();
ehelin@5716 114 }
ehelin@5716 115
ehelin@5716 116 private static long getMaxCapacity(String ns) throws Exception {
ehelin@5716 117 return PerfCounters.findByName(ns + ".maxCapacity").longValue();
ehelin@5716 118 }
ehelin@5716 119
ehelin@5716 120 private static long getUsed(String ns) throws Exception {
ehelin@5716 121 return PerfCounters.findByName(ns + ".used").longValue();
ehelin@5716 122 }
ehelin@5531 123 }

mercurial