Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/arguments/TestG1ConcRefinementThreads.java
32285 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test TestG1ConcRefinementThreads25* @key gc26* @bug 804797627* @summary Tests argument processing for G1ConcRefinementThreads28* @library /testlibrary29*/3031import com.oracle.java.testlibrary.*;32import java.util.*;33import java.util.regex.*;3435public class TestG1ConcRefinementThreads {3637static final int AUTO_SELECT_THREADS_COUNT = 0;38static final int PASSED_THREADS_COUNT = 11;3940public static void main(String args[]) throws Exception {41// default case42runG1ConcRefinementThreadsTest(43new String[]{}, // automatically selected44AUTO_SELECT_THREADS_COUNT /* use default setting */);4546// zero setting case47runG1ConcRefinementThreadsTest(48new String[]{"-XX:G1ConcRefinementThreads=0"}, // automatically selected49AUTO_SELECT_THREADS_COUNT /* set to zero */);5051// non-zero sestting case52runG1ConcRefinementThreadsTest(53new String[]{"-XX:G1ConcRefinementThreads="+Integer.toString(PASSED_THREADS_COUNT)},54PASSED_THREADS_COUNT);55}5657private static void runG1ConcRefinementThreadsTest(String[] passedOpts,58int expectedValue) throws Exception {59List<String> vmOpts = new ArrayList<>();60if (passedOpts.length > 0) {61Collections.addAll(vmOpts, passedOpts);62}63Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:+PrintFlagsFinal", "-version");6465ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));66OutputAnalyzer output = new OutputAnalyzer(pb.start());6768output.shouldHaveExitValue(0);69String stdout = output.getStdout();70checkG1ConcRefinementThreadsConsistency(stdout, expectedValue);71}7273private static void checkG1ConcRefinementThreadsConsistency(String output, int expectedValue) {74int actualValue = getIntValue("G1ConcRefinementThreads", output);7576if (expectedValue == 0) {77// If expectedValue is automatically selected, set it same as ParallelGCThreads.78expectedValue = getIntValue("ParallelGCThreads", output);79}8081if (expectedValue != actualValue) {82throw new RuntimeException(83"Actual G1ConcRefinementThreads(" + Integer.toString(actualValue)84+ ") is not equal to expected value(" + Integer.toString(expectedValue) + ")");85}86}8788public static int getIntValue(String flag, String where) {89Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);90if (!m.find()) {91throw new RuntimeException("Could not find value for flag " + flag + " in output string");92}93String match = m.group();94return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));95}96}979899