Path: blob/master/test/hotspot/jtreg/gc/arguments/TestParallelRefProc.java
64474 views
/*1* Copyright (c) 2018, 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 TestParallelRefProc27* @summary Test defaults processing for -XX:+ParallelRefProcEnabled.28* @library /test/lib29* @library /30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.arguments.TestParallelRefProc33*/3435import java.util.Arrays;36import java.util.ArrayList;3738import jdk.test.lib.process.OutputAnalyzer;3940import jtreg.SkippedException;41import sun.hotspot.gc.GC;4243public class TestParallelRefProc {4445public static void main(String args[]) throws Exception {46boolean noneGCSupported = true;47if (GC.Serial.isSupported()) {48noneGCSupported = false;49testFlag(new String[] { "-XX:+UseSerialGC" }, false);50}51if (GC.Parallel.isSupported()) {52noneGCSupported = false;53testFlag(new String[] { "-XX:+UseParallelGC", "-XX:ParallelGCThreads=1" }, false);54testFlag(new String[] { "-XX:+UseParallelGC", "-XX:ParallelGCThreads=2" }, true);55testFlag(new String[] { "-XX:+UseParallelGC", "-XX:-ParallelRefProcEnabled", "-XX:ParallelGCThreads=2" }, false);56}57if (GC.G1.isSupported()) {58noneGCSupported = false;59testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=1" }, false);60testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=2" }, true);61testFlag(new String[] { "-XX:+UseG1GC", "-XX:-ParallelRefProcEnabled", "-XX:ParallelGCThreads=2" }, false);62}63if (noneGCSupported) {64throw new SkippedException("Skipping test because none of Serial/Parallel/G1 is supported.");65}66}6768private static final String parallelRefProcEnabledPattern =69" *bool +ParallelRefProcEnabled *= *true +\\{product\\}";7071private static final String parallelRefProcDisabledPattern =72" *bool +ParallelRefProcEnabled *= *false +\\{product\\}";7374private static void testFlag(String[] args, boolean expectedTrue) throws Exception {75ArrayList<String> result = new ArrayList<String>();76result.addAll(Arrays.asList(args));77result.add("-XX:+PrintFlagsFinal");78result.add("-version");79ProcessBuilder pb = GCArguments.createJavaProcessBuilder(result);8081OutputAnalyzer output = new OutputAnalyzer(pb.start());8283output.shouldHaveExitValue(0);8485final String expectedPattern = expectedTrue ? parallelRefProcEnabledPattern : parallelRefProcDisabledPattern;8687String value = output.firstMatch(expectedPattern);88if (value == null) {89throw new RuntimeException(90Arrays.toString(args) + " didn't set ParallelRefProcEnabled to " + expectedTrue + " as expected");91}92}93}949596