test/hotspot/jtreg/gc/arguments/TestParallelRefProc.java
changeset 50624 724ed31f9d05
child 53523 4c5184c56dc2
equal deleted inserted replaced
50623:5209d8a6303e 50624:724ed31f9d05
       
     1 /*
       
     2  * Copyright (c) 2018, 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 /*
       
    25  * @test TestParallelRefProc
       
    26  * @key gc
       
    27  * @summary Test defaults processing for -XX:+ParallelRefProcEnabled.
       
    28  * @library /test/lib
       
    29  * @run driver TestParallelRefProc
       
    30  */
       
    31 
       
    32 import java.util.Arrays;
       
    33 import java.util.ArrayList;
       
    34 
       
    35 import jdk.test.lib.process.OutputAnalyzer;
       
    36 import jdk.test.lib.process.ProcessTools;
       
    37 
       
    38 public class TestParallelRefProc {
       
    39 
       
    40     public static void main(String args[]) throws Exception {
       
    41         testFlag(new String[] { "-XX:+UseSerialGC" }, false);
       
    42         testFlag(new String[] { "-XX:+UseConcMarkSweepGC" }, false);
       
    43         testFlag(new String[] { "-XX:+UseParallelGC" }, false);
       
    44         testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=1" }, false);
       
    45         testFlag(new String[] { "-XX:+UseG1GC", "-XX:ParallelGCThreads=2" }, true);
       
    46         testFlag(new String[] { "-XX:+UseG1GC", "-XX:-ParallelRefProcEnabled", "-XX:ParallelGCThreads=2" }, false);
       
    47     }
       
    48 
       
    49     private static final String parallelRefProcEnabledPattern =
       
    50         " *bool +ParallelRefProcEnabled *= *true +\\{product\\}";
       
    51 
       
    52     private static final String parallelRefProcDisabledPattern =
       
    53         " *bool +ParallelRefProcEnabled *= *false +\\{product\\}";
       
    54 
       
    55     private static void testFlag(String[] args, boolean expectedTrue) throws Exception {
       
    56         ArrayList<String> result = new ArrayList<String>();
       
    57         result.addAll(Arrays.asList(args));
       
    58         result.add("-XX:+PrintFlagsFinal");
       
    59         result.add("-version");
       
    60         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(result.toArray(new String[0]));
       
    61 
       
    62         OutputAnalyzer output = new OutputAnalyzer(pb.start());
       
    63 
       
    64         output.shouldHaveExitValue(0);
       
    65 
       
    66         final String expectedPattern = expectedTrue ? parallelRefProcEnabledPattern : parallelRefProcDisabledPattern;
       
    67 
       
    68         String value = output.firstMatch(expectedPattern);
       
    69         if (value == null) {
       
    70             throw new RuntimeException(
       
    71                 Arrays.toString(args) + " didn't set ParallelRefProcEnabled to " + expectedTrue + " as expected");
       
    72         }
       
    73     }
       
    74 }