author | ehelin |
Tue, 17 Sep 2013 20:59:07 +0200 | |
changeset 20001 | 7446501f55bc |
child 20314 | 150e62794be5 |
permissions | -rw-r--r-- |
20001
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
1 |
/* |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
24 |
import java.util.List; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
25 |
import java.lang.management.*; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
26 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
27 |
import com.oracle.java.testlibrary.*; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
28 |
import static com.oracle.java.testlibrary.Asserts.*; |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
29 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
30 |
/* @test TestPerfCountersAndMemoryPools |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
31 |
* @bug 8023476 |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
32 |
* @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
|
33 |
* report the same data. |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
34 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
35 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData TestPerfCountersAndMemoryPools |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
36 |
*/ |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
37 |
public class TestPerfCountersAndMemoryPools { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
38 |
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
|
39 |
checkMemoryUsage("Metaspace", "sun.gc.metaspace"); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
40 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
41 |
if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
42 |
checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace"); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
43 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
44 |
} |
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 |
private static MemoryUsage getMemoryUsage(String memoryPoolName) { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
47 |
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
48 |
for (MemoryPoolMXBean pool : pools) { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
49 |
if (pool.getName().equals(memoryPoolName)) { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
50 |
return pool.getUsage(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
51 |
} |
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 |
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
|
55 |
memoryPoolName); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
56 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
57 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
58 |
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
|
59 |
throws Exception { |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
60 |
// Need to do a gc before each comparison to update the perf counters |
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 |
System.gc(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
63 |
MemoryUsage mu = getMemoryUsage(memoryPoolName); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
64 |
assertEQ(getMinCapacity(perfNS), mu.getInit()); |
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 |
System.gc(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
67 |
mu = getMemoryUsage(memoryPoolName); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
68 |
assertEQ(getUsed(perfNS), mu.getUsed()); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
69 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
70 |
System.gc(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
71 |
mu = getMemoryUsage(memoryPoolName); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
72 |
assertEQ(getCapacity(perfNS), mu.getCommitted()); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
73 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
74 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
75 |
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
|
76 |
return PerfCounters.findByName(ns + ".minCapacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
77 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
78 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
79 |
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
|
80 |
return PerfCounters.findByName(ns + ".capacity").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
81 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
82 |
|
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
83 |
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
|
84 |
return PerfCounters.findByName(ns + ".used").longValue(); |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
85 |
} |
7446501f55bc
8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff
changeset
|
86 |
} |