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