hotspot/test/gc/metaspace/TestPerfCountersAndMemoryPools.java
author jwilhelm
Mon, 04 Apr 2016 20:39:42 +0200
changeset 36847 3b6a93156b10
parent 35373 51858d53abfb
child 37267 ad8c0e8de29f
child 36851 03e2f4d0a421
permissions -rw-r--r--
8153410: Disable tests until JDK-8151460 gets to main Reviewed-by: gtriantafill, dcubed
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
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27692
diff changeset
     2
 * Copyright (c) 2013, 2015, 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
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
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    27
import jdk.test.lib.*;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    28
import static jdk.test.lib.Asserts.*;
20001
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
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    32
 * @library /testlibrary
27692
11c231c781dc 8062537: [TESTBUG] Conflicting GC combinations in hotspot tests
eistepan
parents: 20314
diff changeset
    33
 * @requires vm.gc=="Serial" | vm.gc=="null"
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    34
 * @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
    35
 *          report the same data.
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27692
diff changeset
    36
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27692
diff changeset
    37
 *          java.management
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 27692
diff changeset
    38
 *          jdk.jvmstat/sun.jvmstat.monitor
36847
3b6a93156b10 8153410: Disable tests until JDK-8151460 gets to main
jwilhelm
parents: 35373
diff changeset
    39
 * @ignore 8151460
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    40
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    41
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers -XX:+UseSerialGC -XX:+UsePerfData -Xint TestPerfCountersAndMemoryPools
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    42
 */
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    43
public class TestPerfCountersAndMemoryPools {
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    44
    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
    45
        checkMemoryUsage("Metaspace", "sun.gc.metaspace");
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    46
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    47
        if (InputArguments.contains("-XX:+UseCompressedKlassPointers") && Platform.is64bit()) {
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    48
            checkMemoryUsage("Compressed Class Space", "sun.gc.compressedclassspace");
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    49
        }
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    50
    }
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    51
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    52
    private static MemoryPoolMXBean getMemoryPool(String memoryPoolName) {
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    53
        List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    54
        for (MemoryPoolMXBean pool : pools) {
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    55
            if (pool.getName().equals(memoryPoolName)) {
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    56
                return pool;
20001
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
        }
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
        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
    61
                                   memoryPoolName);
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
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    64
    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
    65
        throws Exception {
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    66
        MemoryPoolMXBean pool = getMemoryPool(memoryPoolName);
20001
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    67
35373
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    68
        // 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
    69
        getMinCapacity(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    70
        getCapacity(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    71
        getUsed(perfNS);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    72
        pool.getUsage().getInit();
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    73
        pool.getUsage().getUsed();
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    74
        pool.getUsage().getCommitted();
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    75
        assertEQ(1L, 1L);
51858d53abfb 8148483: JEP 280: Indify String Concatenation
shade
parents: 30604
diff changeset
    76
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    77
        // 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
    78
        System.gc();
20314
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    79
        assertEQ(getMinCapacity(perfNS), pool.getUsage().getInit());
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    80
        assertEQ(getUsed(perfNS), pool.getUsage().getUsed());
150e62794be5 8025226: TestPerfCountersAndMemoryPools.java fails with -Xmixed or -Xcomp
ehelin
parents: 20001
diff changeset
    81
        assertEQ(getCapacity(perfNS), pool.getUsage().getCommitted());
20001
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
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    84
    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
    85
        return PerfCounters.findByName(ns + ".minCapacity").longValue();
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    86
    }
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    87
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    88
    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
    89
        return PerfCounters.findByName(ns + ".capacity").longValue();
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
7446501f55bc 8024718: Metaspace performance counters and memory pools should report the same data
ehelin
parents:
diff changeset
    92
    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
    93
        return PerfCounters.findByName(ns + ".used").longValue();
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
}