author | lkorinth |
Mon, 28 Jan 2019 15:53:56 +0100 | |
changeset 53523 | 4c5184c56dc2 |
parent 48117 | d64722b0b371 |
child 53693 | af078dd4a224 |
permissions | -rw-r--r-- |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48117
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
4 |
* |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
8 |
* |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
13 |
* accompanied this code). |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
14 |
* |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
18 |
* |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
21 |
* questions. |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
22 |
*/ |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
23 |
|
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48117
diff
changeset
|
24 |
package gc.metaspace; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48117
diff
changeset
|
25 |
|
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
26 |
import java.util.List; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
27 |
import java.lang.management.*; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
28 |
|
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39414
diff
changeset
|
29 |
import jdk.test.lib.Platform; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
30 |
import static jdk.test.lib.Asserts.*; |
48117
d64722b0b371
8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
47216
diff
changeset
|
31 |
import gc.testlibrary.PerfCounter; |
d64722b0b371
8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
47216
diff
changeset
|
32 |
import gc.testlibrary.PerfCounters; |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
33 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
34 |
/* @test TestPerfCountersAndMemoryPools |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
35 |
* @bug 8023476 |
48117
d64722b0b371
8080345: With perm gen gone, perfdata counter sun.gc.policy.generations should be 2, not 3
ehelin
parents:
47216
diff
changeset
|
36 |
* @library /test/lib / |
39414
4adf52148100
8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents:
37297
diff
changeset
|
37 |
* @requires vm.gc.Serial |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
38 |
* @summary Tests that a MemoryPoolMXBeans and PerfCounters for metaspace |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
39 |
* report the same data. |
36851 | 40 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27692
diff
changeset
|
41 |
* java.management |
43467 | 42 |
* jdk.internal.jvmstat/sun.jvmstat.monitor |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48117
diff
changeset
|
43 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint gc.metaspace.TestPerfCountersAndMemoryPools |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
48117
diff
changeset
|
44 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint gc.metaspace.TestPerfCountersAndMemoryPools |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
45 |
*/ |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
46 |
public class TestPerfCountersAndMemoryPools { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
48 |
checkMemoryUsage("Metaspace", "sun.gc.metaspace"); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
49 |
|
37244
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
50 |
if (InputArguments.contains("-XX:+UseCompressedClassPointers") && Platform.is64bit()) { |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
51 |
checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace"); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
52 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
53 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
54 |
|
20314
150e62794be5
8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents:
20001
diff
changeset
|
55 |
private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) { |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
56 |
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
57 |
for (MemoryPoolMXBean pool : pools) { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
58 |
if (pool.getName().equals(memoryPoolName)) { |
20314
150e62794be5
8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents:
20001
diff
changeset
|
59 |
return pool; |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
60 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
61 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
62 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
63 |
throw new RuntimeException("Excpted to find a memory pool with name " + |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
64 |
memoryPoolName); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
65 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
66 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
67 |
private static void checkMemoryUsage(String memoryPoolName, String perfNS) |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
68 |
throws Exception { |
20314
150e62794be5
8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents:
20001
diff
changeset
|
69 |
MemoryPoolMXBean pool = getMemoryPool(memoryPoolName); |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
70 |
|
35373 | 71 |
// First, call all the methods to let them allocate their own slab of metadata |
72 |
getMinCapacity(perfNS); |
|
73 |
getCapacity(perfNS); |
|
74 |
getUsed(perfNS); |
|
75 |
pool.getUsage().getInit(); |
|
76 |
pool.getUsage().getUsed(); |
|
77 |
pool.getUsage().getCommitted(); |
|
37244
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
78 |
assertEQ(1L, 1L, "Make assert load"); |
35373 | 79 |
|
20314
150e62794be5
8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents:
20001
diff
changeset
|
80 |
// Must do a GC to update performance counters |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
81 |
System.gc(); |
37244
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
82 |
assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit(), "MinCapacity out of sync"); |
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
83 |
|
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
84 |
// Adding a second GC due to metadata allocations caused by getting the |
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
85 |
// initial size from the pool. This is needed when running with -Xcomp. |
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
86 |
System.gc(); |
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
87 |
assertEQ(getUsed(perfNS), pool.getUsage().getUsed(), "Used out of sync"); |
9b8f2dc281ad
8151460: Metaspace counters can have inconsistent values
sjohanss
parents:
35373
diff
changeset
|
88 |
assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted(), "Committed out of sync"); |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
89 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
90 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
91 |
private static long getMinCapacity(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
92 |
return PerfCounters.findByName(ns + ".minCapacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
93 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
94 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
95 |
private static long getCapacity(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
96 |
return PerfCounters.findByName(ns + ".capacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
97 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
98 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
99 |
private static long getUsed(String ns) throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
100 |
return PerfCounters.findByName(ns + ".used").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
101 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
102 |
} |