hotspot/test/gc/TestNumWorkerOutput.java
author sspitsyn
Wed, 03 May 2017 02:32:02 +0000
changeset 46426 02a1fc064144
parent 40922 d9f1eaf18f9a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40922
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     1
/*
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     4
 *
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     8
 *
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    14
 *
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    18
 *
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    21
 * questions.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    22
 */
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    23
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    24
/*
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    25
 * @test TestNumWorkerOutput
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    26
 * @bug 8165292
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    27
 * @summary Check that when PrintGCDetails is enabled, gc,task output is printed only once per collection.
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    28
 * @key gc
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    29
 * @requires vm.gc=="null"
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    31
 * @library /test/lib
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    32
 * @build sun.hotspot.WhiteBox
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    33
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    34
 * @run main/othervm -XX:+UseConcMarkSweepGC TestNumWorkerOutput UseConcMarkSweepGC
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    35
 * @run main/othervm -XX:+UseG1GC TestNumWorkerOutput UseG1GC
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    36
 */
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    37
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    38
import sun.hotspot.WhiteBox;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    39
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    40
import java.util.regex.Matcher;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    41
import java.util.regex.Pattern;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    42
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    43
import jdk.test.lib.Platform;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    44
import jdk.test.lib.process.OutputAnalyzer;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    45
import jdk.test.lib.process.ProcessTools;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    46
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    47
import static jdk.test.lib.Asserts.*;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    48
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    49
public class TestNumWorkerOutput {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    50
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    51
    public static void checkPatternOnce(String pattern, String what) throws Exception {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    52
        Pattern r = Pattern.compile(pattern);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    53
        Matcher m = r.matcher(what);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    54
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    55
        if (!m.find()) {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    56
            throw new RuntimeException("Could not find pattern " + pattern + " in output");
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    57
        }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    58
        if (m.find()) {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    59
            throw new RuntimeException("Could find pattern " + pattern + " in output more than once");
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    60
        }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    61
    }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    62
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    63
    public static void runTest(String gcArg) throws Exception {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    64
        final String[] arguments = {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    65
            "-Xbootclasspath/a:.",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    66
            "-XX:+UnlockExperimentalVMOptions",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    67
            "-XX:+UnlockDiagnosticVMOptions",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    68
            "-XX:+WhiteBoxAPI",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    69
            "-XX:+" + gcArg,
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    70
            "-Xmx10M",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    71
            "-XX:+PrintGCDetails",
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    72
            GCTest.class.getName()
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    73
            };
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    74
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    75
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    76
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    77
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    78
        output.shouldHaveExitValue(0);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    79
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    80
        System.out.println(output.getStdout());
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    81
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    82
        String stdout = output.getStdout();
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    83
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    84
        checkPatternOnce(".*[info.*].*[gc,task.*].*GC\\(0\\) .*Using \\d+ workers of \\d+ for evacuation.*", stdout);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    85
    }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    86
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    87
    public static void main(String[] args) throws Exception {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    88
        runTest(args[0]);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    89
    }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    90
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    91
    static class GCTest {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    92
        private static final WhiteBox WB = WhiteBox.getWhiteBox();
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    93
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    94
        public static Object holder;
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    95
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    96
        public static void main(String [] args) {
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    97
            holder = new byte[100];
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    98
            WB.youngGC();
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
    99
            System.out.println(holder);
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
   100
        }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
   101
    }
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
   102
}
d9f1eaf18f9a 8165292: The gc+task logging is repeated a lot, decreasing the usefulness of -Xlog:gc*=info
tschatzl
parents:
diff changeset
   103