2
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
28
* @requires vm.gc.Serial
29
* @summary Verify the expected space counters exist.
30
* @modules java.base/jdk.internal.misc
31
* @modules java.management/sun.management
32
* @modules jdk.internal.jvmstat/sun.jvmstat.monitor
33
* @library /test/lib /
34
* @run main/othervm -XX:+UseSerialGC -XX:+UsePerfData gc.TestSpaceCounters
39
* @requires vm.gc.Parallel
40
* @summary Verify the expected space counters exist.
41
* @modules java.base/jdk.internal.misc
42
* @modules java.management/sun.management
43
* @modules jdk.internal.jvmstat/sun.jvmstat.monitor
44
* @library /test/lib /
45
* @run main/othervm -XX:+UseParallelGC -XX:+UsePerfData gc.TestSpaceCounters
48
import gc.testlibrary.Helpers;
49
import gc.testlibrary.PerfCounter;
50
import gc.testlibrary.PerfCounters;
51
import sun.jvmstat.monitor.MonitorException;
53
public class TestSpaceCounters {
54
private static final String GENERATION_NAMESPACE = "sun.gc.generation.";
56
// Each space has these counters.
57
private static final String[] COUNTER_NAMES = {
58
"maxCapacity", "capacity", "used", "initCapacity" };
60
private static String counterName(String name, int generation, int space) {
61
return GENERATION_NAMESPACE + generation + ".space." + space + "." + name;
64
private static PerfCounter counter(String name, int generation, int space) {
65
String cname = counterName(name, generation, space);
67
return PerfCounters.findByName(cname);
68
} catch (MonitorException e) {
69
throw new RuntimeException(e.toString());
73
private static long value(String name, int generation, int space) {
74
PerfCounter pc = counter(name, generation, space);
75
return pc.longValue();
78
private static void checkCounters(int generation, int space) {
79
for (int i = 0; i < COUNTER_NAMES.length; ++i) {
80
value(COUNTER_NAMES[i], generation, space);
84
private static final int YOUNG_GENERATION = 0;
85
private static final int OLD_GENERATION = 1;
87
public static void main(String[] args) {
88
// Young Generation has 3 spaces - eden, and two survivor spaces.
89
checkCounters(YOUNG_GENERATION, 0);
90
checkCounters(YOUNG_GENERATION, 1);
91
checkCounters(YOUNG_GENERATION, 2);
92
// Old Generation has 1 space.
93
checkCounters(OLD_GENERATION, 0);