hotspot/test/gc/TestFullGCCount.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 42572 faf8f5152129
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     1
/*
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     4
 *
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     8
 *
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    13
 * accompanied this code).
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    14
 *
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    18
 *
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    21
 * questions.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    22
 */
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    23
42572
faf8f5152129 8165955: TestFullGCCount test failed with CMS and -XX:+ExplicitGCInvokesConcurrent
mchernov
parents: 35504
diff changeset
    24
/**
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    25
 * @test TestFullGCCount.java
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    26
 * @bug 7072527
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    27
 * @summary CMS: JMM GC counters overcount in some cases
42572
faf8f5152129 8165955: TestFullGCCount test failed with CMS and -XX:+ExplicitGCInvokesConcurrent
mchernov
parents: 35504
diff changeset
    28
 * @requires !(vm.gc.ConcMarkSweep & vm.opt.ExplicitGCInvokesConcurrent == true)
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    29
 * @modules java.management
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    30
 * @run main/othervm -Xlog:gc TestFullGCCount
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    31
 */
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    32
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    33
import java.lang.management.GarbageCollectorMXBean;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    34
import java.lang.management.ManagementFactory;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    35
import java.util.ArrayList;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    36
import java.util.HashMap;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    37
import java.util.List;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    38
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    39
/*
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    40
 * Originally for a specific failure in CMS, this test now monitors all
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    41
 * collectors for double-counting of collections.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    42
 */
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    43
public class TestFullGCCount {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    44
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    45
    static List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans();
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    46
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    47
    public static void main(String[] args) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    48
        int iterations = 20;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    49
        boolean failed = false;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    50
        String errorMessage = "";
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    51
        HashMap<String, List> counts = new HashMap<>();
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    52
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    53
        // Prime the collection of count lists for all collectors.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    54
        for (int i = 0; i < collectors.size(); i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    55
            GarbageCollectorMXBean collector = collectors.get(i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    56
            counts.put(collector.getName(), new ArrayList<>(iterations));
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    57
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    58
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    59
        // Perform some gc, record collector counts.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    60
        for (int i = 0; i < iterations; i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    61
            System.gc();
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    62
            addCollectionCount(counts, i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    63
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    64
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    65
        // Check the increments:
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    66
        //   Old gen collectors should increase by one,
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    67
        //   New collectors may or may not increase.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    68
        //   Any increase >=2 is unexpected.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    69
        for (String collector : counts.keySet()) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    70
            System.out.println("Checking: " + collector);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    71
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    72
            for (int i = 0; i < iterations - 1; i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    73
                List<Long> theseCounts = counts.get(collector);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    74
                long a = theseCounts.get(i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    75
                long b = theseCounts.get(i + 1);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    76
                if (b - a >= 2) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    77
                    failed = true;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    78
                    errorMessage += "Collector '" + collector + "' has increment " + (b - a) +
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    79
                                    " at iteration " + i + "\n";
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    80
                }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    81
            }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    82
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    83
        if (failed) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    84
            System.err.println(errorMessage);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    85
            throw new RuntimeException("FAILED: System.gc collections miscounted.");
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    86
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    87
        System.out.println("Passed.");
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    88
    }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    89
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    90
    private static void addCollectionCount(HashMap<String, List> counts, int iteration) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    91
        for (int i = 0; i < collectors.size(); i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    92
            GarbageCollectorMXBean collector = collectors.get(i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    93
            List thisList = counts.get(collector.getName());
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    94
            thisList.add(collector.getCollectionCount());
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    95
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    96
    }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    97
}