hotspot/test/gc/arguments/TestG1ConcRefinementThreads.java
changeset 26932 33d6fa41d290
child 29678 dd2f3932c21e
equal deleted inserted replaced
26854:781be83089fb 26932:33d6fa41d290
       
     1 /*
       
     2 * Copyright (c) 2014, 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 TestG1ConcRefinementThreads
       
    26  * @key gc
       
    27  * @bug 8047976
       
    28  * @summary Tests argument processing for G1ConcRefinementThreads
       
    29  * @library /testlibrary
       
    30  */
       
    31 
       
    32 import com.oracle.java.testlibrary.*;
       
    33 import java.util.*;
       
    34 import java.util.regex.*;
       
    35 
       
    36 public class TestG1ConcRefinementThreads {
       
    37 
       
    38   static final int AUTO_SELECT_THREADS_COUNT = 0;
       
    39   static final int PASSED_THREADS_COUNT = 11;
       
    40 
       
    41   public static void main(String args[]) throws Exception {
       
    42     // default case
       
    43     runG1ConcRefinementThreadsTest(
       
    44         new String[]{}, // automatically selected
       
    45         AUTO_SELECT_THREADS_COUNT /* use default setting */);
       
    46 
       
    47     // zero setting case
       
    48     runG1ConcRefinementThreadsTest(
       
    49         new String[]{"-XX:G1ConcRefinementThreads=0"}, // automatically selected
       
    50         AUTO_SELECT_THREADS_COUNT /* set to zero */);
       
    51 
       
    52     // non-zero sestting case
       
    53     runG1ConcRefinementThreadsTest(
       
    54         new String[]{"-XX:G1ConcRefinementThreads="+Integer.toString(PASSED_THREADS_COUNT)},
       
    55         PASSED_THREADS_COUNT);
       
    56   }
       
    57 
       
    58   private static void runG1ConcRefinementThreadsTest(String[] passedOpts,
       
    59           int expectedValue) throws Exception {
       
    60     List<String> vmOpts = new ArrayList<>();
       
    61     if (passedOpts.length > 0) {
       
    62       Collections.addAll(vmOpts, passedOpts);
       
    63     }
       
    64     Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:+PrintFlagsFinal", "-version");
       
    65 
       
    66     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
       
    67     OutputAnalyzer output = new OutputAnalyzer(pb.start());
       
    68 
       
    69     output.shouldHaveExitValue(0);
       
    70     String stdout = output.getStdout();
       
    71     checkG1ConcRefinementThreadsConsistency(stdout, expectedValue);
       
    72   }
       
    73 
       
    74   private static void checkG1ConcRefinementThreadsConsistency(String output, int expectedValue) {
       
    75     int actualValue = getIntValue("G1ConcRefinementThreads", output);
       
    76 
       
    77     if (expectedValue == 0) {
       
    78       // If expectedValue is automatically selected, set it same as ParallelGCThreads.
       
    79       expectedValue = getIntValue("ParallelGCThreads", output);
       
    80     }
       
    81 
       
    82     if (expectedValue != actualValue) {
       
    83       throw new RuntimeException(
       
    84             "Actual G1ConcRefinementThreads(" + Integer.toString(actualValue)
       
    85             + ") is not equal to expected value(" + Integer.toString(expectedValue) + ")");
       
    86     }
       
    87   }
       
    88 
       
    89   public static int getIntValue(String flag, String where) {
       
    90     Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
       
    91     if (!m.find()) {
       
    92       throw new RuntimeException("Could not find value for flag " + flag + " in output string");
       
    93     }
       
    94     String match = m.group();
       
    95     return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
       
    96   }
       
    97 }