Path: blob/master/test/hotspot/jtreg/gc/arguments/TestG1ConcRefinementThreads.java
40942 views
/*1* Copyright (c) 2014, 2020, 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.arguments;2425/*26* @test TestG1ConcRefinementThreads27* @bug 804797628* @requires vm.gc.G129* @summary Tests argument processing for G1ConcRefinementThreads30* @library /test/lib31* @library /32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.arguments.TestG1ConcRefinementThreads35*/3637import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.process.ProcessTools;39import java.util.*;40import java.util.regex.*;4142public class TestG1ConcRefinementThreads {4344static final int AUTO_SELECT_THREADS_COUNT = -1;45static final int PASSED_THREADS_COUNT = 11;4647public static void main(String args[]) throws Exception {48// default case49runG1ConcRefinementThreadsTest(50new String[]{}, // automatically selected51AUTO_SELECT_THREADS_COUNT /* use default setting */);5253// zero setting case54runG1ConcRefinementThreadsTest(55new String[]{"-XX:G1ConcRefinementThreads=0"},560);5758// non-zero sestting case59runG1ConcRefinementThreadsTest(60new String[]{"-XX:G1ConcRefinementThreads="+Integer.toString(PASSED_THREADS_COUNT)},61PASSED_THREADS_COUNT);62}6364private static void runG1ConcRefinementThreadsTest(String[] passedOpts,65int expectedValue) throws Exception {66List<String> vmOpts = new ArrayList<>();67if (passedOpts.length > 0) {68Collections.addAll(vmOpts, passedOpts);69}70Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:+PrintFlagsFinal", "-version");7172ProcessBuilder pb = GCArguments.createJavaProcessBuilder(vmOpts);73OutputAnalyzer output = new OutputAnalyzer(pb.start());7475output.shouldHaveExitValue(0);76String stdout = output.getStdout();77checkG1ConcRefinementThreadsConsistency(stdout, expectedValue);78}7980private static void checkG1ConcRefinementThreadsConsistency(String output, int expectedValue) {81int actualValue = getIntValue("G1ConcRefinementThreads", output);8283if (expectedValue == AUTO_SELECT_THREADS_COUNT) {84// If expectedValue is automatically selected, set it same as ParallelGCThreads.85expectedValue = getIntValue("ParallelGCThreads", output);86}8788if (expectedValue != actualValue) {89throw new RuntimeException(90"Actual G1ConcRefinementThreads(" + Integer.toString(actualValue)91+ ") is not equal to expected value(" + Integer.toString(expectedValue) + ")");92}93}9495public static int getIntValue(String flag, String where) {96Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);97if (!m.find()) {98throw new RuntimeException("Could not find value for flag " + flag + " in output string");99}100String match = m.group();101return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));102}103}104105106