test/hotspot/jtreg/gc/TestAgeOutput.java
author kvn
Thu, 07 Jun 2018 17:38:34 -0700
changeset 50455 2b73cce96dce
parent 48791 6e079ff6c83c
child 53523 4c5184c56dc2
permissions -rw-r--r--
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal Reviewed-by: iignatyev, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     1
/*
50455
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     4
 *
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     8
 *
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    14
 *
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    18
 *
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    21
 * questions.
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    22
 */
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    23
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    24
/*
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    25
 * @test TestAgeOutput
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    26
 * @bug 8164936
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    27
 * @summary Check that collectors using age table based aging print an age table even for the first garbage collection
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    28
 * @key gc
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    29
 * @requires vm.gc=="null"
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    31
 * @library /test/lib
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    32
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    34
 * @run main/othervm -XX:+UseSerialGC TestAgeOutput UseSerialGC
50455
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    35
 * @run main/othervm -XX:+UseG1GC TestAgeOutput UseG1GC
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    36
 */
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    37
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    38
/*
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    39
 * @test TestAgeOutputCMS
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    40
 * @bug 8164936
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    41
 * @key gc
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    42
 * @comment Graal does not support CMS
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    43
 * @requires vm.gc=="null" & !vm.graal.enabled
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    44
 * @modules java.base/jdk.internal.misc
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    45
 * @library /test/lib
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    46
 * @build sun.hotspot.WhiteBox
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    47
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    48
 * @run main/othervm -XX:+UseConcMarkSweepGC TestAgeOutput UseConcMarkSweepGC
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    49
 */
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    50
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    51
import sun.hotspot.WhiteBox;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    52
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    53
import java.util.regex.Matcher;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    54
import java.util.regex.Pattern;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    55
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    56
import jdk.test.lib.Platform;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    57
import jdk.test.lib.process.OutputAnalyzer;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    58
import jdk.test.lib.process.ProcessTools;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    59
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    60
import static jdk.test.lib.Asserts.*;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    61
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    62
public class TestAgeOutput {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    63
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    64
    public static void checkPattern(String pattern, String what) throws Exception {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    65
        Pattern r = Pattern.compile(pattern);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    66
        Matcher m = r.matcher(what);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    67
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    68
        if (!m.find()) {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    69
            throw new RuntimeException("Could not find pattern " + pattern + " in output");
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    70
        }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    71
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    72
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    73
    public static void runTest(String gcArg) throws Exception {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    74
        final String[] arguments = {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    75
            "-Xbootclasspath/a:.",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    76
            "-XX:+UnlockExperimentalVMOptions",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    77
            "-XX:+UnlockDiagnosticVMOptions",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    78
            "-XX:+WhiteBoxAPI",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    79
            "-XX:+" + gcArg,
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    80
            "-Xmx10M",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    81
            "-Xlog:gc+age=trace",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    82
            GCTest.class.getName()
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    83
            };
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    84
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    85
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    86
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    87
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    88
        output.shouldHaveExitValue(0);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    89
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    90
        System.out.println(output.getStdout());
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    91
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    92
        String stdout = output.getStdout();
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    93
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    94
        checkPattern(".*GC\\(0\\) .*Desired survivor size.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    95
        checkPattern(".*GC\\(0\\) .*Age table with threshold.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    96
        checkPattern(".*GC\\(0\\) .*- age   1:.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    97
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    98
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    99
    public static void main(String[] args) throws Exception {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   100
        runTest(args[0]);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   101
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   102
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   103
    static class GCTest {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   104
        private static final WhiteBox WB = WhiteBox.getWhiteBox();
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   105
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   106
        public static Object holder;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   107
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   108
        public static void main(String [] args) {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   109
            holder = new byte[100];
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   110
            WB.youngGC();
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   111
            System.out.println(holder);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   112
        }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   113
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   114
}
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   115