test/hotspot/jtreg/gc/TestAgeOutput.java
author lkorinth
Mon, 28 Jan 2019 15:53:56 +0100
changeset 53523 4c5184c56dc2
parent 50455 2b73cce96dce
child 53693 af078dd4a224
permissions -rw-r--r--
8214799: Add package declaration to each JTREG test case in the gc folder Reviewed-by: lmesnik, tschatzl
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
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
     2
 * Copyright (c) 2016, 2019, 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
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
    24
package gc;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
    25
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    26
/*
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    27
 * @test TestAgeOutput
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    28
 * @bug 8164936
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    29
 * @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
    30
 * @key gc
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    31
 * @requires vm.gc=="null"
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    32
 * @modules java.base/jdk.internal.misc
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    33
 * @library /test/lib
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    34
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    35
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
    36
 * @run main/othervm -XX:+UseSerialGC gc.TestAgeOutput UseSerialGC
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
    37
 * @run main/othervm -XX:+UseG1GC gc.TestAgeOutput UseG1GC
50455
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
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    40
/*
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    41
 * @test TestAgeOutputCMS
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    42
 * @bug 8164936
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    43
 * @key gc
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    44
 * @comment Graal does not support CMS
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    45
 * @requires vm.gc=="null" & !vm.graal.enabled
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    46
 * @modules java.base/jdk.internal.misc
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    47
 * @library /test/lib
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    48
 * @build sun.hotspot.WhiteBox
2b73cce96dce 8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents: 48791
diff changeset
    49
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 50455
diff changeset
    50
 * @run main/othervm -XX:+UseConcMarkSweepGC gc.TestAgeOutput UseConcMarkSweepGC
40914
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    51
 */
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 sun.hotspot.WhiteBox;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    54
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    55
import java.util.regex.Matcher;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    56
import java.util.regex.Pattern;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    57
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    58
import jdk.test.lib.Platform;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    59
import jdk.test.lib.process.OutputAnalyzer;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    60
import jdk.test.lib.process.ProcessTools;
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
import static jdk.test.lib.Asserts.*;
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 class TestAgeOutput {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    65
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    66
    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
    67
        Pattern r = Pattern.compile(pattern);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    68
        Matcher m = r.matcher(what);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    69
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    70
        if (!m.find()) {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    71
            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
    72
        }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    73
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    74
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    75
    public static void runTest(String gcArg) throws Exception {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    76
        final String[] arguments = {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    77
            "-Xbootclasspath/a:.",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    78
            "-XX:+UnlockExperimentalVMOptions",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    79
            "-XX:+UnlockDiagnosticVMOptions",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    80
            "-XX:+WhiteBoxAPI",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    81
            "-XX:+" + gcArg,
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    82
            "-Xmx10M",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    83
            "-Xlog:gc+age=trace",
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    84
            GCTest.class.getName()
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    85
            };
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    86
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    87
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    88
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
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
        output.shouldHaveExitValue(0);
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
        System.out.println(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
        String stdout = output.getStdout();
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    95
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    96
        checkPattern(".*GC\\(0\\) .*Desired survivor size.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    97
        checkPattern(".*GC\\(0\\) .*Age table with threshold.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    98
        checkPattern(".*GC\\(0\\) .*- age   1:.*", stdout);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
    99
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   100
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   101
    public static void main(String[] args) throws Exception {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   102
        runTest(args[0]);
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   103
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   104
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   105
    static class GCTest {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   106
        private static final WhiteBox WB = WhiteBox.getWhiteBox();
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 Object holder;
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   109
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   110
        public static void main(String [] args) {
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   111
            holder = new byte[100];
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   112
            WB.youngGC();
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   113
            System.out.println(holder);
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
    }
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   116
}
90c87069b39c 8164936: G1 age table printout contains contents from previous GC
tschatzl
parents:
diff changeset
   117