annotate test/gc/metaspace/TestMetaspacePerfCounters.java @ 24234:ea6f94ab283b default tip

Added tag jvmci-0.36 for changeset 8128b98d4736
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 18 Sep 2017 18:49:45 +0200
parents f967da7f0c3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
1 /*
22981
f967da7f0c3c 8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
jwilhelm
parents: 12248
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
4 *
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
7 * published by the Free Software Foundation.
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
8 *
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
13 * accompanied this code).
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
14 *
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
18 *
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
21 * questions.
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
22 */
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
23
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
24 import java.util.List;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
25 import java.util.ArrayList;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
26
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
27 import com.oracle.java.testlibrary.*;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
28 import static com.oracle.java.testlibrary.Asserts.*;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
29
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
30 /* @test TestMetaspacePerfCounters
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
31 * @bug 8014659
22981
f967da7f0c3c 8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
jwilhelm
parents: 12248
diff changeset
32 * @requires vm.gc=="null"
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
33 * @library /testlibrary
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
34 * @summary Tests that performance counters for metaspace and compressed class
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
35 * space exists and works.
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
36 *
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
37 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
38 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
39 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
40 *
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
41 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
42 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
43 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
44 */
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
45 public class TestMetaspacePerfCounters {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
46 public static Class fooClass = null;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
47 private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
48
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
49 public static void main(String[] args) throws Exception {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
50 String metaspace = "sun.gc.metaspace";
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
51 String ccs = "sun.gc.compressedclassspace";
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
52
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
53 checkPerfCounters(metaspace);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
54
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
55 if (isUsingCompressedClassPointers()) {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
56 checkPerfCounters(ccs);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
57 checkUsedIncreasesWhenLoadingClass(ccs);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
58 } else {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
59 checkEmptyPerfCounters(ccs);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
60 checkUsedIncreasesWhenLoadingClass(metaspace);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
61 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
62 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
63
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
64 private static void checkPerfCounters(String ns) throws Exception {
12248
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
65 long minCapacity = getMinCapacity(ns);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
66 long maxCapacity = getMaxCapacity(ns);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
67 long capacity = getCapacity(ns);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
68 long used = getUsed(ns);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
69
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
70 assertGTE(minCapacity, 0L);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
71 assertGTE(used, minCapacity);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
72 assertGTE(capacity, used);
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
73 assertGTE(maxCapacity, capacity);
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
74 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
75
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
76 private static void checkEmptyPerfCounters(String ns) throws Exception {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
77 for (PerfCounter counter : countersInNamespace(ns)) {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
78 String msg = "Expected " + counter.getName() + " to equal 0";
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
79 assertEQ(counter.longValue(), 0L, msg);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
80 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
81 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
82
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
83 private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
12248
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
84 long before = getUsed(ns);
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
85 fooClass = compileAndLoad("Foo", "public class Foo { }");
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
86 System.gc();
12248
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
87 long after = getUsed(ns);
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
88
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
89 assertGT(after, before);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
90 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
91
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
92 private static List<PerfCounter> countersInNamespace(String ns) throws Exception {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
93 List<PerfCounter> counters = new ArrayList<>();
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
94 for (String name : counterNames) {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
95 counters.add(PerfCounters.findByName(ns + "." + name));
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
96 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
97 return counters;
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
98 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
99
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
100 private static Class<?> compileAndLoad(String name, String source) throws Exception {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
101 byte[] byteCode = InMemoryJavaCompiler.compile(name, source);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
102 return ByteCodeLoader.load(name, byteCode);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
103 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
104
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
105 private static boolean isUsingCompressedClassPointers() {
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12063
diff changeset
106 return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
107 }
12248
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
108
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
109 private static long getMinCapacity(String ns) throws Exception {
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
110 return PerfCounters.findByName(ns + ".minCapacity").longValue();
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
111 }
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
112
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
113 private static long getCapacity(String ns) throws Exception {
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
114 return PerfCounters.findByName(ns + ".capacity").longValue();
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
115 }
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
116
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
117 private static long getMaxCapacity(String ns) throws Exception {
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
118 return PerfCounters.findByName(ns + ".maxCapacity").longValue();
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
119 }
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
120
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
121 private static long getUsed(String ns) throws Exception {
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
122 return PerfCounters.findByName(ns + ".used").longValue();
73d0d0218068 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents: 12226
diff changeset
123 }
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
124 }