1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package gc.arguments; 25 26 /* 27 * @test TestParallelRefProc 28 * @key gc 29 * @requires vm.gc.Serial & vm.gc.ConcMarkSweep & vm.gc.Parallel & vm.gc.G1 30 * @summary Test defaults processing for -XX:+ParallelRefProcEnabled. 31 * @library /test/lib 32 * @run driver gc.arguments.TestParallelRefProc 33 */ 34 35 import java.util.Arrays; 36 import java.util.ArrayList; 37 38 import jdk.test.lib.process.OutputAnalyzer; 39 import jdk.test.lib.process.ProcessTools; 40 41 public class TestParallelRefProc { 42 43 public static void main(String args[]) throws Exception { 44 testFlag(new String[] { "-XX:+UseSerialGC" }, false); 45 testFlag(new String[] { "-XX:+UseConcMarkSweepGC" }, false); 46 testFlag(new String[] { "-XX:+UseParallelGC" }, false); 47 testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=1" }, false); 48 testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=2" }, true); 49 testFlag(new String[] { "-XX:+UseG1GC", "-XX:-ParallelRefProcEnabled", "-XX:ParallelGCThreads=2" }, false); 50 } 51 52 private static final String parallelRefProcEnabledPattern = 53 " *bool +ParallelRefProcEnabled *= *true +\\{product\\}"; 54 55 private static final String parallelRefProcDisabledPattern = 56 " *bool +ParallelRefProcEnabled *= *false +\\{product\\}"; 57 58 private static void testFlag(String[] args, boolean expectedTrue) throws Exception { 59 ArrayList<String> result = new ArrayList<String>(); 60 result.addAll(Arrays.asList(args)); 61 result.add("-XX:+PrintFlagsFinal"); 62 result.add("-version"); 63 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(result.toArray(new String[0])); 64 65 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 66 67 output.shouldHaveExitValue(0); 68 69 final String expectedPattern = expectedTrue ? parallelRefProcEnabledPattern : parallelRefProcDisabledPattern; 70 71 String value = output.firstMatch(expectedPattern); 72 if (value == null) { 73 throw new RuntimeException( 74 Arrays.toString(args) + " didn't set ParallelRefProcEnabled to " + expectedTrue + " as expected"); 75 } 76 } 77 }