Path: blob/master/test/hotspot/jtreg/gc/TestNumWorkerOutput.java
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc;2425/*26* @test TestNumWorkerOutputG127* @bug 816529228* @summary Check that when PrintGCDetails is enabled, gc,task output is printed only once per collection.29* @requires vm.gc.G130* @modules java.base/jdk.internal.misc31* @library /test/lib32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run driver gc.TestNumWorkerOutput UseG1GC35*/3637import sun.hotspot.WhiteBox;3839import java.util.regex.Matcher;40import java.util.regex.Pattern;4142import jdk.test.lib.process.OutputAnalyzer;43import jdk.test.lib.process.ProcessTools;4445public class TestNumWorkerOutput {4647public static void checkPatternOnce(String pattern, String what) throws Exception {48Pattern r = Pattern.compile(pattern);49Matcher m = r.matcher(what);5051if (!m.find()) {52throw new RuntimeException("Could not find pattern " + pattern + " in output");53}54if (m.find()) {55throw new RuntimeException("Could find pattern " + pattern + " in output more than once");56}57}5859public static void runTest(String gcArg) throws Exception {60ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(61"-Xbootclasspath/a:.",62"-XX:+UnlockExperimentalVMOptions",63"-XX:+UnlockDiagnosticVMOptions",64"-XX:+WhiteBoxAPI",65"-XX:+" + gcArg,66"-Xmx10M",67"-XX:+PrintGCDetails",68GCTest.class.getName());69OutputAnalyzer output = new OutputAnalyzer(pb.start());7071output.shouldHaveExitValue(0);7273System.out.println(output.getStdout());7475String stdout = output.getStdout();7677checkPatternOnce(".*[info.*].*[gc,task.*].*GC\\(0\\) .*Using \\d+ workers of \\d+ for evacuation.*", stdout);78}7980public static void main(String[] args) throws Exception {81runTest(args[0]);82}8384static class GCTest {85private static final WhiteBox WB = WhiteBox.getWhiteBox();8687public static Object holder;8889public static void main(String [] args) {90holder = new byte[100];91WB.youngGC();92System.out.println(holder);93}94}95}96979899