test/hotspot/jtreg/gc/TestFullGCCount.java
author lkorinth
Wed, 13 Nov 2019 11:37:29 +0100
changeset 59053 ba6c248cae19
parent 53694 a0a327cae58f
permissions -rw-r--r--
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector Reviewed-by: kbarrett, tschatzl, erikj, coleenp, dholmes
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
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
35504
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
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    24
package gc;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    25
42572
faf8f5152129 8165955: TestFullGCCount test failed with CMS and -XX:+ExplicitGCInvokesConcurrent
mchernov
parents: 35504
diff changeset
    26
/**
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    27
 * @test TestFullGCCount.java
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    28
 * @bug 7072527
59053
ba6c248cae19 8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents: 53694
diff changeset
    29
 * @summary JMM GC counters overcount in some cases
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 47216
diff changeset
    30
 * @comment Shenandoah has "ExplicitGCInvokesConcurrent" on by default
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 47216
diff changeset
    31
 * @requires !(vm.gc == "Shenandoah"    & vm.opt.ExplicitGCInvokesConcurrent != false)
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    32
 * @modules java.management
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    33
 * @run main/othervm -Xlog:gc gc.TestFullGCCount
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    34
 */
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    35
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    36
import java.lang.management.GarbageCollectorMXBean;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    37
import java.lang.management.ManagementFactory;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    38
import java.util.ArrayList;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    39
import java.util.HashMap;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    40
import java.util.List;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    41
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    42
/*
59053
ba6c248cae19 8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents: 53694
diff changeset
    43
 * Originally for a specific failure in CMS[[keep]], this test now monitors all
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    44
 * collectors for double-counting of collections.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    45
 */
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    46
public class TestFullGCCount {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    47
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    48
    static List<GarbageCollectorMXBean> collectors = ManagementFactory.getGarbageCollectorMXBeans();
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    49
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    50
    public static void main(String[] args) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    51
        int iterations = 20;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    52
        boolean failed = false;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    53
        String errorMessage = "";
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
    54
        HashMap<String, List<Long>> counts = new HashMap<>();
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    55
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    56
        // 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
    57
        for (int i = 0; i < collectors.size(); i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    58
            GarbageCollectorMXBean collector = collectors.get(i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    59
            counts.put(collector.getName(), new ArrayList<>(iterations));
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    60
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    61
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    62
        // Perform some gc, record collector counts.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    63
        for (int i = 0; i < iterations; i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    64
            System.gc();
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    65
            addCollectionCount(counts, i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    66
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    67
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    68
        // Check the increments:
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    69
        //   Old gen collectors should increase by one,
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    70
        //   New collectors may or may not increase.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    71
        //   Any increase >=2 is unexpected.
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    72
        for (String collector : counts.keySet()) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    73
            System.out.println("Checking: " + collector);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    74
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    75
            for (int i = 0; i < iterations - 1; i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    76
                List<Long> theseCounts = counts.get(collector);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    77
                long a = theseCounts.get(i);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    78
                long b = theseCounts.get(i + 1);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    79
                if (b - a >= 2) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    80
                    failed = true;
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    81
                    errorMessage += "Collector '" + collector + "' has increment " + (b - a) +
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    82
                                    " at iteration " + i + "\n";
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    83
                }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    84
            }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    85
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    86
        if (failed) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    87
            System.err.println(errorMessage);
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    88
            throw new RuntimeException("FAILED: System.gc collections miscounted.");
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
        System.out.println("Passed.");
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    91
    }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    92
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
    93
    private static void addCollectionCount(HashMap<String, List<Long>> counts, int iteration) {
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    94
        for (int i = 0; i < collectors.size(); i++) {
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    95
            GarbageCollectorMXBean collector = collectors.get(i);
53694
a0a327cae58f 8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents: 53523
diff changeset
    96
            List<Long> thisList = counts.get(collector.getName());
35504
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    97
            thisList.add(collector.getCollectionCount());
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    98
        }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
    99
    }
aabd81013e37 8147075: Rename old GC JTreg tests to the new naming scheme
dfazunen
parents:
diff changeset
   100
}