jdk

Форк
0
/
TestSpaceCounters.java 
95 строк · 3.4 Кб
1
/*
2
 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
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.
8
 *
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).
14
 *
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.
18
 *
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
21
 * questions.
22
 */
23

24
package gc;
25

26
/**
27
 * @test id=Serial
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
35
 */
36

37
/**
38
 * @test id=Parallel
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
46
 */
47

48
import gc.testlibrary.Helpers;
49
import gc.testlibrary.PerfCounter;
50
import gc.testlibrary.PerfCounters;
51
import sun.jvmstat.monitor.MonitorException;
52

53
public class TestSpaceCounters {
54
    private static final String GENERATION_NAMESPACE = "sun.gc.generation.";
55

56
    // Each space has these counters.
57
    private static final String[] COUNTER_NAMES = {
58
        "maxCapacity", "capacity", "used", "initCapacity" };
59

60
    private static String counterName(String name, int generation, int space) {
61
        return GENERATION_NAMESPACE + generation + ".space." + space + "." + name;
62
    }
63

64
    private static PerfCounter counter(String name, int generation, int space) {
65
        String cname = counterName(name, generation, space);
66
        try {
67
            return PerfCounters.findByName(cname);
68
        } catch (MonitorException e) {
69
            throw new RuntimeException(e.toString());
70
        }
71
    }
72

73
    private static long value(String name, int generation, int space) {
74
        PerfCounter pc = counter(name, generation, space);
75
        return pc.longValue();
76
    }
77

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);
81
        }
82
    }
83

84
    private static final int YOUNG_GENERATION = 0;
85
    private static final int OLD_GENERATION = 1;
86

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);
94
    }
95
}
96

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.