test/hotspot/jtreg/gc/metaspace/TestPerfCountersAndMemoryPools.java
author lmesnik
Fri, 26 Apr 2019 11:33:32 -0700
changeset 54638 9b8926bf85c1
parent 53693 af078dd4a224
permissions -rw-r--r--
8220813: update hotspot tier1_gc tests depending on GC to use @requires vm.gc.X Reviewed-by: pliden, lmesnik Contributed-by: aoqi@loongson.cn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.PerfCounters;
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    32
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    33
/* @test TestPerfCountersAndMemoryPools
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    34
 * @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
    35
 * @library /test/lib /
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 37297
diff changeset
    36
 * @requires vm.gc.Serial
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    37
 * @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
    38
 *          report the same data.
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 36847
diff changeset
    39
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27692
diff changeset
    40
 *          java.management
43467
f91da24c6bca 8152206: Simplify jvmstat modules
gtriantafill
parents: 40631
diff changeset
    41
 *          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
    42
 * @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
    43
 * @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
    44
 */
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    45
public class TestPerfCountersAndMemoryPools {
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    46
    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
    47
        checkMemoryUsage("Metaspace", "sun.gc.metaspace");
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    48
37244
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    49
        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
    50
            checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace");
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
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    54
    private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) {
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    55
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    56
        for (MemoryPoolMXBean pool : pools) {
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    57
            if (pool.getName().equals(memoryPoolName)) {
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    58
                return pool;
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    59
            }
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
        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
    63
                                   memoryPoolName);
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    64
    }
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
    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
    67
        throws Exception {
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    68
        MemoryPoolMXBean pool = getMemoryPool(memoryPoolName);
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    69
35373
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    70
        // First, call all the methods to let them allocate their own slab of metadata
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    71
        getMinCapacity(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    72
        getCapacity(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    73
        getUsed(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    74
        pool.getUsage().getInit();
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    75
        pool.getUsage().getUsed();
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    76
        pool.getUsage().getCommitted();
37244
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    77
        assertEQ(1L, 1L, "Make assert load");
35373
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    78
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    79
        // 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
    80
        System.gc();
37244
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    81
        assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit(), "MinCapacity out of sync");
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    82
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    83
        // 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
    84
        // 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
    85
        System.gc();
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    86
        assertEQ(getUsed(perfNS), pool.getUsage().getUsed(), "Used out of sync");
9b8f2dc281ad 8151460: Metaspace counters can have inconsistent values
sjohanss
parents: 35373
diff changeset
    87
        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
    88
    }
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
    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
    91
        return PerfCounters.findByName(ns + ".minCapacity").longValue();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    92
    }
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
    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
    95
        return PerfCounters.findByName(ns + ".capacity").longValue();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    96
    }
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
    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
    99
        return PerfCounters.findByName(ns + ".used").longValue();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
   100
    }
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
   101
}