Path: blob/master/test/hotspot/jtreg/gc/arguments/TestParallelRefProc.java
40942 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;39import jdk.test.lib.process.ProcessTools;4041import jtreg.SkippedException;42import sun.hotspot.gc.GC;4344public class TestParallelRefProc {4546public static void main(String args[]) throws Exception {47boolean noneGCSupported = true;48if (GC.Serial.isSupported()) {49noneGCSupported = false;50testFlag(new String[] { "-XX:+UseSerialGC" }, false);51}52if (GC.Parallel.isSupported()) {53noneGCSupported = false;54testFlag(new String[] { "-XX:+UseParallelGC" }, false);55}56if (GC.G1.isSupported()) {57noneGCSupported = false;58testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=1" }, false);59testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=2" }, true);60testFlag(new String[] { "-XX:+UseG1GC", "-XX:-ParallelRefProcEnabled", "-XX:ParallelGCThreads=2" }, false);61}62if (noneGCSupported) {63throw new SkippedException("Skipping test because none of Serial/Parallel/G1 is supported.");64}65}6667private static final String parallelRefProcEnabledPattern =68" *bool +ParallelRefProcEnabled *= *true +\\{product\\}";6970private static final String parallelRefProcDisabledPattern =71" *bool +ParallelRefProcEnabled *= *false +\\{product\\}";7273private static void testFlag(String[] args, boolean expectedTrue) throws Exception {74ArrayList<String> result = new ArrayList<String>();75result.addAll(Arrays.asList(args));76result.add("-XX:+PrintFlagsFinal");77result.add("-version");78ProcessBuilder pb = GCArguments.createJavaProcessBuilder(result);7980OutputAnalyzer output = new OutputAnalyzer(pb.start());8182output.shouldHaveExitValue(0);8384final String expectedPattern = expectedTrue ? parallelRefProcEnabledPattern : parallelRefProcDisabledPattern;8586String value = output.firstMatch(expectedPattern);87if (value == null) {88throw new RuntimeException(89Arrays.toString(args) + " didn't set ParallelRefProcEnabled to " + expectedTrue + " as expected");90}91}92}939495