Path: blob/master/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java
40942 views
/*1* Copyright (c) 2014, 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.arguments;2425/*26* @test TestParallelGCThreads27* @bug 8059527 808138228* @summary Tests argument processing for ParallelGCThreads29* @library /test/lib30* @library /31* @modules java.base/jdk.internal.misc32* java.management33* @build sun.hotspot.WhiteBox34* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox35* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.arguments.TestParallelGCThreads36*/3738import java.util.ArrayList;39import java.util.List;40import jdk.test.lib.Asserts;41import jdk.test.lib.process.OutputAnalyzer;42import jdk.test.lib.process.ProcessTools;43import jtreg.SkippedException;44import sun.hotspot.gc.GC;4546public class TestParallelGCThreads {4748public static void main(String args[]) throws Exception {49testFlags();50testDefaultValue();51}5253private static final String flagName = "ParallelGCThreads";5455// uint ParallelGCThreads = 23 {product}56private static final String printFlagsFinalPattern = " *uint *" + flagName + " *:?= *(\\d+) *\\{product\\} *";5758public static void testDefaultValue() throws Exception {59ProcessBuilder pb = GCArguments.createJavaProcessBuilder(60"-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version");6162OutputAnalyzer output = new OutputAnalyzer(pb.start());63String value = output.firstMatch(printFlagsFinalPattern, 1);6465try {66Asserts.assertNotNull(value, "Couldn't find uint flag " + flagName);6768Long longValue = new Long(value);6970// Sanity check that we got a non-zero value.71Asserts.assertNotEquals(longValue, "0");7273output.shouldHaveExitValue(0);74} catch (Exception e) {75System.err.println(output.getOutput());76throw e;77}78}7980public static void testFlags() throws Exception {81// For each parallel collector (G1, Parallel)82List<String> supportedGC = new ArrayList<String>();8384if (GC.G1.isSupported()) {85supportedGC.add("G1");86}87if (GC.Parallel.isSupported()) {88supportedGC.add("Parallel");89}9091if (supportedGC.isEmpty()) {92throw new SkippedException("Skipping test because none of G1/Parallel is supported.");93}9495for (String gc : supportedGC) {96// Make sure the VM does not allow ParallelGCThreads set to 097ProcessBuilder pb = GCArguments.createJavaProcessBuilder(98"-XX:+Use" + gc + "GC",99"-XX:ParallelGCThreads=0",100"-XX:+PrintFlagsFinal",101"-version");102OutputAnalyzer output = new OutputAnalyzer(pb.start());103output.shouldHaveExitValue(1);104105// Do some basic testing to ensure the flag updates the count106for (long i = 1; i <= 3; i++) {107long count = getParallelGCThreadCount(108"-XX:+Use" + gc + "GC",109"-XX:ParallelGCThreads=" + i,110"-XX:+PrintFlagsFinal",111"-version");112Asserts.assertEQ(count, i, "Specifying ParallelGCThreads=" + i + " for " + gc + "GC does not set the thread count properly!");113}114}115116// 4294967295 == (unsigned int) -1117// So setting ParallelGCThreads=4294967295 should give back 4294967295118// and setting ParallelGCThreads=4294967296 should give back 0. (SerialGC is ok with ParallelGCThreads=0)119for (long i = 4294967295L; i <= 4294967296L; i++) {120long count = getParallelGCThreadCount(121"-XX:+UseSerialGC",122"-XX:ParallelGCThreads=" + i,123"-XX:+PrintFlagsFinal",124"-version");125Asserts.assertEQ(count, i % 4294967296L, "Specifying ParallelGCThreads=" + i + " does not set the thread count properly!");126}127}128129public static long getParallelGCThreadCount(String... flags) throws Exception {130ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flags);131OutputAnalyzer output = new OutputAnalyzer(pb.start());132output.shouldHaveExitValue(0);133String stdout = output.getStdout();134return FlagsValue.getFlagLongValue("ParallelGCThreads", stdout);135}136}137138139