author | ykantser |
Mon, 04 May 2015 16:30:07 +0200 | |
changeset 30604 | b8d532cb6420 |
parent 29678 | dd2f3932c21e |
child 37244 | 9b8f2dc281ad |
child 36847 | 3b6a93156b10 |
permissions | -rw-r--r-- |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
4 |
* |
e35f9ed4f081
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 |
e35f9ed4f081
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 |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
8 |
* |
e35f9ed4f081
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 |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e35f9ed4f081
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 |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
13 |
* accompanied this code). |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
14 |
* |
e35f9ed4f081
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 |
e35f9ed4f081
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, |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
18 |
* |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e35f9ed4f081
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 |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
21 |
* questions. |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
22 |
*/ |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
23 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
24 |
import java.util.List; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
25 |
import java.util.ArrayList; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
26 |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
27 |
import jdk.test.lib.*; |
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
28 |
import static jdk.test.lib.Asserts.*; |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
29 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
30 |
/* @test TestMetaspacePerfCounters |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
31 |
* @bug 8014659 |
27692
11c231c781dc
8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
eistepan
parents:
20001
diff
changeset
|
32 |
* @requires vm.gc=="null" |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
33 |
* @library /testlibrary |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
34 |
* @summary Tests that performance counters for metaspace and compressed class |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
35 |
* space exists and works. |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
36 |
* @modules java.base/sun.misc |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
37 |
* java.compiler |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
38 |
* java.management |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
39 |
* jdk.jvmstat/sun.jvmstat.monitor |
19979
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
40 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
41 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
42 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
43 |
* |
19979
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
44 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
45 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters |
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
46 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
47 |
*/ |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
48 |
public class TestMetaspacePerfCounters { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
49 |
public static Class fooClass = null; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
50 |
private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"}; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
51 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
52 |
public static void main(String[] args) throws Exception { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
53 |
String metaspace = "sun.gc.metaspace"; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
54 |
String ccs = "sun.gc.compressedclassspace"; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
55 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
56 |
checkPerfCounters(metaspace); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
57 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
58 |
if (isUsingCompressedClassPointers()) { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
59 |
checkPerfCounters(ccs); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
60 |
checkUsedIncreasesWhenLoadingClass(ccs); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
61 |
} else { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
62 |
checkEmptyPerfCounters(ccs); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
63 |
checkUsedIncreasesWhenLoadingClass(metaspace); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
64 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
65 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
66 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
67 |
private static void checkPerfCounters(String ns) throws Exception { |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
68 |
long minCapacity = getMinCapacity(ns); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
69 |
long maxCapacity = getMaxCapacity(ns); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
70 |
long capacity = getCapacity(ns); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
71 |
long used = getUsed(ns); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
72 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
73 |
assertGTE(minCapacity, 0L); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
74 |
assertGTE(used, minCapacity); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
75 |
assertGTE(capacity, used); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
76 |
assertGTE(maxCapacity, capacity); |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
77 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
78 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
79 |
private static void checkEmptyPerfCounters(String ns) throws Exception { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
80 |
for (PerfCounter counter : countersInNamespace(ns)) { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
81 |
String msg = "Expected " + counter.getName() + " to equal 0"; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
82 |
assertEQ(counter.longValue(), 0L, msg); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
83 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
84 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
85 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
86 |
private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception { |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
87 |
long before = getUsed(ns); |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
88 |
fooClass = compileAndLoad("Foo", "public class Foo { }"); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
89 |
System.gc(); |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
90 |
long after = getUsed(ns); |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
91 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
92 |
assertGT(after, before); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
93 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
94 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
95 |
private static List<PerfCounter> countersInNamespace(String ns) throws Exception { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
96 |
List<PerfCounter> counters = new ArrayList<>(); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
97 |
for (String name : counterNames) { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
98 |
counters.add(PerfCounters.findByName(ns + "." + name)); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
99 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
100 |
return counters; |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
101 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
102 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
103 |
private static Class<?> compileAndLoad(String name, String source) throws Exception { |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
104 |
byte[] byteCode = InMemoryJavaCompiler.compile(name, source); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
105 |
return ByteCodeLoader.load(name, byteCode); |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
106 |
} |
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
107 |
|
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
108 |
private static boolean isUsingCompressedClassPointers() { |
19979
ebe1dbb6e1aa
8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents:
19322
diff
changeset
|
109 |
return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers"); |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
110 |
} |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
111 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
112 |
private static long getMinCapacity(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
113 |
return PerfCounters.findByName(ns + ".minCapacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
114 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
115 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
116 |
private static long getCapacity(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
117 |
return PerfCounters.findByName(ns + ".capacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
118 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
119 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
120 |
private static long getMaxCapacity(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
121 |
return PerfCounters.findByName(ns + ".maxCapacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
122 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
123 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
124 |
private static long getUsed(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
125 |
return PerfCounters.findByName(ns + ".used").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
19979
diff
changeset
|
126 |
} |
19322
e35f9ed4f081
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
127 |
} |